~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-1.0/result.c

  • Committer: Mark Atwood
  • Date: 2011-11-14 00:30:55 UTC
  • mfrom: (1099.4.245 drizzle)
  • Revision ID: me@mark.atwood.name-20111114003055-aj2nl47a6s9qmn2r
Tags: 2011.11.29
merge translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2
 
 *
 
1
/*
3
2
 * Drizzle Client & Protocol Library
4
3
 *
5
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
56
55
 
57
56
  if (result == NULL)
58
57
  {
59
 
    result= new drizzle_result_st;
 
58
    result= malloc(sizeof(drizzle_result_st));
60
59
    if (result == NULL)
61
60
    {
62
61
      drizzle_set_error(con->drizzle, "drizzle_result_create", "malloc");
94
93
    return NULL;
95
94
  }
96
95
 
97
 
  result->options|= (from->options & ~int(DRIZZLE_RESULT_ALLOCATED));
 
96
  result->options|= (from->options &
 
97
                     (drizzle_result_options_t)~DRIZZLE_RESULT_ALLOCATED);
98
98
 
99
99
  drizzle_result_set_info(result, from->info);
100
100
  result->error_code= from->error_code;
115
115
    return;
116
116
  }
117
117
 
118
 
  for (drizzle_column_st* column= result->column_list; column != NULL; column= result->column_list)
 
118
  drizzle_column_st *column;
 
119
  uint64_t x;
 
120
 
 
121
  for (column= result->column_list; column != NULL; column= result->column_list)
119
122
  {
120
123
    drizzle_column_free(column);
121
124
  }
122
125
 
123
 
  delete [] result->column_buffer;
 
126
  free(result->column_buffer);
124
127
 
125
128
  if (result->options & DRIZZLE_RESULT_BUFFER_ROW)
126
129
  {
127
 
    for (uint64_t x= 0; x < result->row_count; x++)
128
 
    {
 
130
    for (x= 0; x < result->row_count; x++)
129
131
      drizzle_row_free(result, result->row_list[x]);
130
 
    }
131
132
 
132
133
    free(result->row_list);
133
134
    free(result->field_sizes_list);
151
152
 
152
153
  if (result->options & DRIZZLE_RESULT_ALLOCATED)
153
154
  {
154
 
    delete result;
 
155
    free(result);
155
156
  }
156
157
}
157
158
 
351
352
 
352
353
    if (result->row_list_size < result->row_count)
353
354
    {
354
 
      row_list= (drizzle_row_t *)realloc(result->row_list, sizeof(drizzle_row_t) * ((size_t)(result->row_list_size) + DRIZZLE_ROW_GROW_SIZE));
 
355
      row_list= realloc(result->row_list, sizeof(drizzle_row_t) *
 
356
                        ((size_t)(result->row_list_size) +
 
357
                         DRIZZLE_ROW_GROW_SIZE));
355
358
      if (row_list == NULL)
356
359
      {
357
360
        drizzle_row_free(result, row);
362
365
 
363
366
      result->row_list= row_list;
364
367
 
365
 
      field_sizes_list= (size_t **)realloc(result->field_sizes_list, sizeof(size_t *) * ((size_t)(result->row_list_size) + DRIZZLE_ROW_GROW_SIZE));
 
368
      field_sizes_list= realloc(result->field_sizes_list, sizeof(size_t *) *
 
369
                                ((size_t)(result->row_list_size) +
 
370
                                 DRIZZLE_ROW_GROW_SIZE));
366
371
      if (field_sizes_list == NULL)
367
372
      {
368
373
        drizzle_row_free(result, row);
433
438
                                  const drizzle_field_t *field,
434
439
                                  const size_t *size)
435
440
{
 
441
  uint16_t x;
 
442
 
436
443
  if (result == NULL)
437
444
  {
438
445
    return;
440
447
 
441
448
  result->con->packet_size= 0;
442
449
 
443
 
  for (uint16_t x= 0; x < result->column_count; x++)
 
450
  for (x= 0; x < result->column_count; x++)
444
451
  {
445
452
    if (field[x] == NULL)
446
 
    {
447
453
      result->con->packet_size++;
448
 
    }
449
454
    else if (size[x] < 251)
450
 
    {
451
455
      result->con->packet_size+= (1 + size[x]);
452
 
    }
453
456
    else if (size[x] < 65536)
454
 
    {
455
457
      result->con->packet_size+= (3 + size[x]);
456
 
    }
457
458
    else if (size[x] < 16777216)
458
 
    {
459
459
      result->con->packet_size+= (4 + size[x]);
460
 
    }
461
460
    else
462
 
    {
463
461
      result->con->packet_size+= (9 + size[x]);
464
 
    }
465
462
  }
466
463
}
467
464
 
475
472
  if (is_eof)
476
473
    result->options|= DRIZZLE_RESULT_EOF_PACKET;
477
474
  else
478
 
    result->options&= ~int(DRIZZLE_RESULT_EOF_PACKET);
 
475
    result->options&= (drizzle_result_options_t)~DRIZZLE_RESULT_EOF_PACKET;
479
476
}
480
477
 
481
478
void drizzle_result_set_info(drizzle_result_st *result, const char *info)
608
605
    /* We can ignore the returns since we've buffered the entire packet. */
609
606
    con->result->affected_rows= drizzle_unpack_length(con, &ret);
610
607
    con->result->insert_id= drizzle_unpack_length(con, &ret);
611
 
    con->status= drizzle_con_status_t(drizzle_get_byte2(con->buffer_ptr));
 
608
    con->status= drizzle_get_byte2(con->buffer_ptr);
612
609
    con->result->warning_count= drizzle_get_byte2(con->buffer_ptr + 2);
613
610
    con->buffer_ptr+= 4;
614
611
    con->buffer_size-= 5;
626
623
  {
627
624
    con->result->options= DRIZZLE_RESULT_EOF_PACKET;
628
625
    con->result->warning_count= drizzle_get_byte2(con->buffer_ptr + 1);
629
 
    con->status= drizzle_con_status_t(drizzle_get_byte2(con->buffer_ptr + 3));
 
626
    con->status= drizzle_get_byte2(con->buffer_ptr + 3);
630
627
    con->buffer_ptr+= 5;
631
628
    con->buffer_size-= 5;
632
629
    con->packet_size-= 5;