~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-1.0/column.c

  • Committer: Brian Aker
  • Date: 2011-11-04 21:06:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2450.
  • Revision ID: brian@tangent.org-20111104210616-2at42agch94dkwb0
Additional fixes for libdrizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 * @brief Column definitions
41
41
 */
42
42
 
43
 
#include <libdrizzle-1.0/common.h>
 
43
#include "common.h"
44
44
 
45
45
/*
46
46
 * Private variables.
356
356
{
357
357
  if (column == NULL)
358
358
  {
359
 
    column= new (std::nothrow) (drizzle_column_st);
 
359
    column= malloc(sizeof(drizzle_column_st));
360
360
    if (column == NULL)
361
361
    {
362
362
      drizzle_set_error(result->con->drizzle, "drizzle_column_create",
377
377
    column->charset = 0;
378
378
    column->size = 0;
379
379
    column->max_size = 0;
380
 
    column->type = drizzle_column_type_t();
381
 
    column->flags = drizzle_column_flags_t();
 
380
    column->type = 0;
 
381
    column->flags = 0;
382
382
    column->decimals = 0;
383
383
    /* UNSET: column->default_value */
384
384
    column->default_value_size = 0;
389
389
    column->result = result;
390
390
    /* SET BELOW: column->next */
391
391
    column->prev = NULL;
392
 
    column->options= drizzle_column_options_t();
 
392
    column->options= 0;
393
393
    column->catalog[0] = '\0';
394
394
    column->db[0] = '\0';
395
395
    column->table[0] = '\0';
399
399
    column->charset = 0;
400
400
    column->size = 0;
401
401
    column->max_size = 0;
402
 
    column->type = drizzle_column_type_t();
403
 
    column->flags = drizzle_column_flags_t();
 
402
    column->type = 0;
 
403
    column->flags = 0;
404
404
    column->decimals = 0;
405
405
    /* UNSET: column->default_value */
406
406
    column->default_value_size = 0;
426
426
    column->next->prev= column->prev;
427
427
 
428
428
  if (column->options & DRIZZLE_COLUMN_ALLOCATED)
429
 
  {
430
 
    delete [] column;
431
 
  }
 
429
    free(column);
432
430
}
433
431
 
434
432
drizzle_result_st *drizzle_column_drizzle_result(drizzle_column_st *column)
499
497
 
500
498
drizzle_column_flags_t drizzle_column_flags(drizzle_column_st *column)
501
499
{
502
 
  return drizzle_column_flags_t(column->flags);
 
500
  return column->flags;
503
501
}
504
502
 
505
503
uint8_t drizzle_column_decimals(drizzle_column_st *column)
523
521
  drizzle_return_t ret;
524
522
  if (drizzle_state_none(result->con))
525
523
  {
526
 
    result->options|= int(DRIZZLE_RESULT_SKIP_COLUMN);
 
524
    result->options|= DRIZZLE_RESULT_SKIP_COLUMN;
527
525
 
528
526
    drizzle_state_push(result->con, drizzle_state_column_read);
529
527
    drizzle_state_push(result->con, drizzle_state_packet_read);
530
528
  }
531
529
  ret= drizzle_state_loop(result->con);
532
 
  result->options&= ~int(DRIZZLE_RESULT_SKIP_COLUMN);
 
530
  result->options&= ~DRIZZLE_RESULT_SKIP_COLUMN;
533
531
  return ret;
534
532
}
535
533
 
572
570
  {
573
571
    if (result->column_count == 0)
574
572
    {
575
 
      result->options|= int(DRIZZLE_RESULT_BUFFER_COLUMN);
 
573
      result->options|= DRIZZLE_RESULT_BUFFER_COLUMN;
576
574
      return DRIZZLE_RETURN_OK;
577
575
    }
578
576
 
579
 
    result->column_buffer= new (std::nothrow) drizzle_column_st[result->column_count];
 
577
    result->column_buffer= malloc(sizeof(drizzle_column_st) *
 
578
                                  result->column_count);
580
579
    if (result->column_buffer == NULL)
581
580
    {
582
 
      drizzle_set_error(result->con->drizzle, __func__, "malloc");
583
 
 
 
581
      drizzle_set_error(result->con->drizzle, "drizzle_column_buffer",
 
582
                        "malloc");
584
583
      return DRIZZLE_RETURN_MEMORY;
585
584
    }
586
585
  }
796
795
    /* EOF packet marking end of columns. */
797
796
    con->result->column= NULL;
798
797
    con->result->warning_count= drizzle_get_byte2(con->buffer_ptr + 1);
799
 
    con->status= drizzle_con_status_t(drizzle_get_byte2(con->buffer_ptr + 3));
 
798
    con->status= drizzle_get_byte2(con->buffer_ptr + 3);
800
799
    con->buffer_ptr+= 5;
801
800
    con->buffer_size-= 5;
802
801
 
836
835
    column->size= drizzle_get_byte4(con->buffer_ptr + 3);
837
836
 
838
837
    if (con->options & DRIZZLE_CON_MYSQL)
839
 
    {
840
 
      column->type= drizzle_column_type_t(con->buffer_ptr[7]);
841
 
    }
 
838
      column->type= con->buffer_ptr[7];
842
839
    else
843
840
    {
844
 
      drizzle_type= drizzle_column_type_drizzle_t(con->buffer_ptr[7]);
 
841
      drizzle_type= con->buffer_ptr[7];
845
842
      if (drizzle_type >= DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX)
846
843
        drizzle_type= DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX;
847
844
      column->type= _column_type_drizzle_map_to[drizzle_type];
848
845
    }
849
846
 
850
 
    column->flags= drizzle_column_flags_t(drizzle_get_byte2(con->buffer_ptr + 8));
 
847
    column->flags= drizzle_get_byte2(con->buffer_ptr + 8);
851
848
    if (column->type <= DRIZZLE_COLUMN_TYPE_INT24 &&
852
849
        column->type != DRIZZLE_COLUMN_TYPE_TIMESTAMP)
853
850
    {
854
 
      column->flags|= int(DRIZZLE_COLUMN_FLAGS_NUM);
 
851
      column->flags|= DRIZZLE_COLUMN_FLAGS_NUM;
855
852
    }
856
853
 
857
854
    column->decimals= con->buffer_ptr[10];