354
354
drizzle_column_st *drizzle_column_create(drizzle_result_st *result,
355
355
drizzle_column_st *column)
357
362
if (column == NULL)
359
column= new drizzle_column_st;
360
column->result = result;
364
column= new (std::nothrow) drizzle_column_st;
371
column->result= result;
361
372
/* SET BELOW: column->next */
363
374
column->options= DRIZZLE_COLUMN_ALLOCATED;
364
column->catalog[0] = '\0';
365
column->db[0] = '\0';
366
column->table[0] = '\0';
367
column->orig_table[0] = '\0';
368
column->name[0] = '\0';
369
column->orig_name[0] = '\0';
372
column->max_size = 0;
373
column->type = static_cast<drizzle_column_type_t>(0);
374
column->flags = drizzle_column_flags_t();
375
column->decimals = 0;
375
column->catalog[0]= '\0';
376
column->schema[0]= '\0';
377
column->table[0]= '\0';
378
column->orig_table[0]= '\0';
379
column->name[0]= '\0';
380
column->orig_name[0]= '\0';
384
column->type= static_cast<drizzle_column_type_t>(0);
385
column->flags= drizzle_column_flags_t();
376
387
/* UNSET: column->default_value */
377
column->default_value_size = 0;
388
column->default_value_size= 0;
412
422
void drizzle_column_free(drizzle_column_st *column)
414
429
if (column->result->column_list == column)
415
431
column->result->column_list= column->next;
416
434
if (column->prev)
417
436
column->prev->next= column->next;
418
439
if (column->next)
419
441
column->next->prev= column->prev;
421
444
if (column->options & DRIZZLE_COLUMN_ALLOCATED)
425
450
drizzle_result_st *drizzle_column_drizzle_result(drizzle_column_st *column)
427
457
return column->result;
430
460
const char *drizzle_column_catalog(drizzle_column_st *column)
432
467
return column->catalog;
470
const char *drizzle_column_shema(drizzle_column_st *column)
477
return column->schema;
435
480
const char *drizzle_column_db(drizzle_column_st *column)
482
return drizzle_column_shema(column);
440
485
const char *drizzle_column_table(drizzle_column_st *column)
442
492
return column->table;
445
495
const char *drizzle_column_orig_table(drizzle_column_st *column)
447
502
return column->orig_table;
450
505
const char *drizzle_column_name(drizzle_column_st *column)
452
512
return column->name;
455
515
const char *drizzle_column_orig_name(drizzle_column_st *column)
457
522
return column->orig_name;
460
525
drizzle_charset_t drizzle_column_charset(drizzle_column_st *column)
462
532
return column->charset;
465
535
uint32_t drizzle_column_size(drizzle_column_st *column)
467
542
return column->size;
470
545
size_t drizzle_column_max_size(drizzle_column_st *column)
472
552
return column->max_size;
475
555
void drizzle_column_set_max_size(drizzle_column_st *column, size_t size)
477
562
column->max_size= size;
480
565
drizzle_column_type_t drizzle_column_type(drizzle_column_st *column)
569
return drizzle_column_type_t();
482
572
return column->type;
485
drizzle_column_type_drizzle_t
486
drizzle_column_type_drizzle(drizzle_column_st *column)
575
drizzle_column_type_drizzle_t drizzle_column_type_drizzle(drizzle_column_st *column)
579
return drizzle_column_type_drizzle_t();
488
582
return _column_type_drizzle_map_from[column->type];
491
585
int drizzle_column_flags(drizzle_column_st *column)
493
592
return column->flags;
496
595
uint8_t drizzle_column_decimals(drizzle_column_st *column)
498
602
return column->decimals;
519
627
drizzle_state_push(result->con, drizzle_state_column_read);
520
628
drizzle_state_push(result->con, drizzle_state_packet_read);
522
ret= drizzle_state_loop(result->con);
630
drizzle_return_t ret= drizzle_state_loop(result->con);
523
631
result->options&= ~DRIZZLE_RESULT_SKIP_COLUMN;
527
635
drizzle_return_t drizzle_column_skip_all(drizzle_result_st *result)
529
drizzle_return_t ret;
639
return DRIZZLE_RETURN_INVALID_ARGUMENT;
532
for (it= 1; it <= result->column_count; it++)
642
for (uint16_t it= 1; it <= result->column_count; it++)
534
ret= drizzle_column_skip(result);
644
drizzle_return_t ret= drizzle_column_skip(result);
535
645
if (ret != DRIZZLE_RETURN_OK)
539
651
return DRIZZLE_RETURN_OK;
567
689
return DRIZZLE_RETURN_OK;
570
result->column_buffer= new drizzle_column_st[result->column_count];
692
result->column_buffer= new (std::nothrow) drizzle_column_st[result->column_count];
694
if (result->column_buffer == NULL)
696
return DRIZZLE_RETURN_MEMORY;
573
700
/* No while body, just keep calling to buffer columns. */
588
715
drizzle_column_st *drizzle_column_next(drizzle_result_st *result)
590
722
if (result->column_current == result->column_count)
593
727
result->column_current++;
594
728
return &(result->column_buffer[result->column_current - 1]);
606
740
void drizzle_column_seek(drizzle_result_st *result, uint16_t column)
608
747
if (column <= result->column_count)
609
749
result->column_current= column;
612
drizzle_column_st *drizzle_column_index(drizzle_result_st *result,
753
drizzle_column_st *drizzle_column_index(drizzle_result_st *result, uint16_t column)
615
760
if (column >= result->column_count)
618
765
return &(result->column_buffer[column]);
621
768
uint16_t drizzle_column_current(drizzle_result_st *result)
623
775
return result->column_current;
630
782
drizzle_return_t drizzle_column_write(drizzle_result_st *result,
631
783
drizzle_column_st *column)
787
return DRIZZLE_RETURN_INVALID_ARGUMENT;
633
790
if (drizzle_state_none(result->con))
635
792
result->column= column;
654
void drizzle_column_set_db(drizzle_column_st *column, const char *db)
818
void drizzle_column_set_schema(drizzle_column_st *column, const char *schema)
827
column->schema[0]= 0;
660
strncpy(column->db, db, DRIZZLE_MAX_DB_SIZE);
661
column->db[DRIZZLE_MAX_DB_SIZE - 1]= 0;
831
strncpy(column->schema, schema, DRIZZLE_MAX_DB_SIZE);
832
column->schema[DRIZZLE_MAX_DB_SIZE - 1]= 0;
836
void drizzle_column_set_db(drizzle_column_st *column, const char *schema)
838
drizzle_column_set_schema(column, schema);
665
842
void drizzle_column_set_table(drizzle_column_st *column, const char *table)
667
849
if (table == NULL)
668
851
column->table[0]= 0;
671
855
strncpy(column->table, table, DRIZZLE_MAX_TABLE_SIZE);
711
910
void drizzle_column_set_charset(drizzle_column_st *column,
712
911
drizzle_charset_t charset)
714
918
column->charset= charset;
717
921
void drizzle_column_set_size(drizzle_column_st *column, uint32_t size)
719
928
column->size= size;
722
931
void drizzle_column_set_type(drizzle_column_st *column,
723
932
drizzle_column_type_t type)
725
939
column->type= type;
728
942
void drizzle_column_set_flags(drizzle_column_st *column,
731
950
column->flags= flags;
734
953
void drizzle_column_set_decimals(drizzle_column_st *column, uint8_t decimals)
736
960
column->decimals= decimals;
740
964
const uint8_t *default_value,
743
972
if (default_value == NULL)
744
974
column->default_value[0]= 0;
747
978
if (size < DRIZZLE_MAX_DEFAULT_VALUE_SIZE)
809
1045
/* These functions can only fail if they need to read data, but we know we
810
1046
buffered the entire packet, so ignore returns. */
811
1047
(void)drizzle_unpack_string(con, column->catalog, DRIZZLE_MAX_CATALOG_SIZE);
812
(void)drizzle_unpack_string(con, column->db, DRIZZLE_MAX_DB_SIZE);
1048
(void)drizzle_unpack_string(con, column->schema, DRIZZLE_MAX_DB_SIZE);
813
1049
(void)drizzle_unpack_string(con, column->table, DRIZZLE_MAX_TABLE_SIZE);
814
1050
(void)drizzle_unpack_string(con, column->orig_table,
815
1051
DRIZZLE_MAX_TABLE_SIZE);
868
1104
drizzle_return_t drizzle_state_column_write(drizzle_con_st *con)
1108
return DRIZZLE_RETURN_INVALID_ARGUMENT;
870
1111
uint8_t *start= con->buffer_ptr + con->buffer_size;
872
1113
drizzle_column_st *column= con->result->column;
876
1117
/* Calculate max packet size. */
877
1118
con->packet_size= 9 + strlen(column->catalog)
878
+ 9 + strlen(column->db)
1119
+ 9 + strlen(column->schema)
879
1120
+ 9 + strlen(column->table)
880
1121
+ 9 + strlen(column->orig_table)
881
1122
+ 9 + strlen(column->name)
914
1155
ptr= drizzle_pack_string(column->catalog, ptr);
915
ptr= drizzle_pack_string(column->db, ptr);
1156
ptr= drizzle_pack_string(column->schema, ptr);
916
1157
ptr= drizzle_pack_string(column->table, ptr);
917
1158
ptr= drizzle_pack_string(column->orig_table, ptr);
918
1159
ptr= drizzle_pack_string(column->name, ptr);