~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-2.0/result.cc

  • Committer: Brian Aker
  • Date: 2011-11-18 16:11:02 UTC
  • mto: (2463.1.1 drizzle-include)
  • mto: This revision was merged to the branch mainline in revision 2462.
  • Revision ID: brian@tangent.org-20111118161102-d1mbswn88iwc2iv1
Pass through refactoring.

Never throw exceptions from libraries. You can not have the assumption that in a driver that the above language can handle this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
{
52
52
  if (result == NULL)
53
53
  {
54
 
    result= new drizzle_result_st;
 
54
    result= new (std::nothrow) drizzle_result_st;
 
55
 
 
56
    if (result == NULL)
 
57
    {
 
58
      return NULL;
 
59
    }
 
60
 
55
61
    result->options|= DRIZZLE_RESULT_ALLOCATED;
56
62
  }
57
63
  else
328
334
    return DRIZZLE_RETURN_INVALID_ARGUMENT;
329
335
  }
330
336
 
331
 
  drizzle_return_t ret;
332
 
  drizzle_row_t row;
333
 
 
334
337
  if (!(result->options & DRIZZLE_RESULT_BUFFER_COLUMN))
335
338
  {
336
 
    ret= drizzle_column_buffer(result);
 
339
    drizzle_return_t ret= drizzle_column_buffer(result);
337
340
    if (ret != DRIZZLE_RETURN_OK)
 
341
    {
338
342
      return ret;
 
343
    }
339
344
  }
340
345
 
341
346
  if (result->column_count == 0)
346
351
 
347
352
  while (1)
348
353
  {
349
 
    row= drizzle_row_buffer(result, &ret);
 
354
    drizzle_return_t ret;
 
355
    drizzle_row_t row= drizzle_row_buffer(result, &ret);
350
356
    if (ret != DRIZZLE_RETURN_OK)
 
357
    {
351
358
      return ret;
 
359
    }
352
360
 
353
361
    if (row == NULL)
 
362
    {
354
363
      break;
 
364
    }
355
365
 
356
366
    if (result->row_list == NULL)
357
367
    {
358
 
      result->row_list= new drizzle_row_list_t;
 
368
      result->row_list= new (std::nothrow) drizzle_row_list_t;
 
369
 
 
370
      if (result->row_list == NULL)
 
371
      {
 
372
        return DRIZZLE_RETURN_MEMORY;
 
373
      }
359
374
    }
360
375
 
361
376
 
362
377
    if (result->field_sizes_list == NULL)
363
378
    {
364
 
      result->field_sizes_list= new drizzle_field_sizes_list_t;
 
379
      result->field_sizes_list= new (std::nothrow) drizzle_field_sizes_list_t;
 
380
 
 
381
      if (result->field_sizes_list == NULL)
 
382
      {
 
383
      }
365
384
    }
366
385
 
367
386
    result->row_list->push_back(row);
369
388
  }
370
389
 
371
390
  result->options|= DRIZZLE_RESULT_BUFFER_ROW;
 
391
 
372
392
  return DRIZZLE_RETURN_OK;
373
393
}
374
394
 
426
446
    return;
427
447
  }
428
448
 
429
 
  uint16_t x;
430
 
 
431
449
  result->con->packet_size= 0;
432
450
 
433
 
  for (x= 0; x < result->column_count; x++)
 
451
  for (uint16_t x= 0; x < result->column_count; x++)
434
452
  {
435
453
    if (field[x] == NULL)
 
454
    {
436
455
      result->con->packet_size++;
 
456
    }
437
457
    else if (size[x] < 251)
 
458
    {
438
459
      result->con->packet_size+= (1 + size[x]);
 
460
    }
439
461
    else if (size[x] < 65536)
 
462
    {
440
463
      result->con->packet_size+= (3 + size[x]);
 
464
    }
441
465
    else if (size[x] < 16777216)
 
466
    {
442
467
      result->con->packet_size+= (4 + size[x]);
 
468
    }
443
469
    else
 
470
    {
444
471
      result->con->packet_size+= (9 + size[x]);
 
472
    }
445
473
  }
446
474
}
447
475
 
453
481
  }
454
482
 
455
483
  if (is_eof)
 
484
  {
456
485
    result->options|= DRIZZLE_RESULT_EOF_PACKET;
 
486
  }
457
487
  else
 
488
  {
458
489
    result->options&= ~DRIZZLE_RESULT_EOF_PACKET;
 
490
  }
459
491
}
460
492
 
461
493
void drizzle_result_set_info(drizzle_result_st *result, const char *info)
580
612
  if (con->buffer_size < con->packet_size)
581
613
  {
582
614
    drizzle_state_push(con, drizzle_state_read);
 
615
 
583
616
    return DRIZZLE_RETURN_OK;
584
617
  }
585
618
 
649
682
  }
650
683
 
651
684
  drizzle_state_pop(con);
 
685
 
652
686
  return ret;
653
687
}
654
688
 
676
710
  /* Assume the entire result packet will fit in the buffer. */
677
711
  if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE)
678
712
  {
679
 
    drizzle_set_error(con->drizzle, "drizzle_state_result_write",
680
 
                      "buffer too small:%zu", con->packet_size + 4);
 
713
    drizzle_set_error(con->drizzle, "drizzle_state_result_write", "buffer too small:%zu", con->packet_size + 4);
 
714
 
681
715
    return DRIZZLE_RETURN_INTERNAL_ERROR;
682
716
  }
683
717
 
686
720
      con->packet_size)
687
721
  {
688
722
    drizzle_state_push(con, drizzle_state_write);
 
723
 
689
724
    return DRIZZLE_RETURN_OK;
690
725
  }
691
726
 
750
785
  drizzle_set_byte3(start, con->packet_size);
751
786
 
752
787
  drizzle_state_pop(con);
 
788
 
753
789
  return DRIZZLE_RETURN_OK;
754
790
}