2
* Drizzle Client & Protocol Library
4
* Copyright (C) 2008 Eric Day (eday@oddments.org)
7
* Use and distribution licensed under the BSD license. See
8
* the COPYING file in this directory for full text.
13
* @brief Column definitions
22
static drizzle_column_type_t _column_type_drizzle_map_to[]=
24
DRIZZLE_COLUMN_TYPE_TINY,
25
DRIZZLE_COLUMN_TYPE_LONG,
26
DRIZZLE_COLUMN_TYPE_DOUBLE,
27
DRIZZLE_COLUMN_TYPE_NULL,
28
DRIZZLE_COLUMN_TYPE_TIMESTAMP,
29
DRIZZLE_COLUMN_TYPE_LONGLONG,
30
DRIZZLE_COLUMN_TYPE_DATETIME,
31
DRIZZLE_COLUMN_TYPE_NEWDATE,
32
DRIZZLE_COLUMN_TYPE_VARCHAR,
33
DRIZZLE_COLUMN_TYPE_NEWDECIMAL,
34
DRIZZLE_COLUMN_TYPE_ENUM,
35
DRIZZLE_COLUMN_TYPE_BLOB
38
static drizzle_column_type_drizzle_t _column_type_drizzle_map_from[]=
40
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 0 */
41
DRIZZLE_COLUMN_TYPE_DRIZZLE_TINY,
42
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
43
DRIZZLE_COLUMN_TYPE_DRIZZLE_LONG,
44
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
45
DRIZZLE_COLUMN_TYPE_DRIZZLE_DOUBLE,
46
DRIZZLE_COLUMN_TYPE_DRIZZLE_NULL,
47
DRIZZLE_COLUMN_TYPE_DRIZZLE_TIMESTAMP,
48
DRIZZLE_COLUMN_TYPE_DRIZZLE_LONGLONG,
49
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
51
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 10 */
52
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
53
DRIZZLE_COLUMN_TYPE_DRIZZLE_DATETIME,
54
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
55
DRIZZLE_COLUMN_TYPE_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
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
317
DRIZZLE_COLUMN_TYPE_DRIZZLE_BLOB,
318
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
319
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
320
DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX
327
drizzle_column_st *drizzle_column_create(drizzle_result_st *result,
328
drizzle_column_st *column)
332
column= malloc(sizeof(drizzle_column_st));
335
drizzle_set_error(result->con->drizzle, "drizzle_column_create",
340
memset(column, 0, sizeof(drizzle_column_st));
341
column->options|= DRIZZLE_COLUMN_ALLOCATED;
344
memset(column, 0, sizeof(drizzle_column_st));
346
column->result= result;
348
if (result->column_list)
349
result->column_list->prev= column;
350
column->next= result->column_list;
351
result->column_list= column;
356
void drizzle_column_free(drizzle_column_st *column)
358
if (column->result->column_list == column)
359
column->result->column_list= column->next;
361
column->prev->next= column->next;
363
column->next->prev= column->prev;
365
if (column->options & DRIZZLE_COLUMN_ALLOCATED)
369
drizzle_result_st *drizzle_column_drizzle_result(drizzle_column_st *column)
371
return column->result;
374
const char *drizzle_column_catalog(drizzle_column_st *column)
376
return column->catalog;
379
const char *drizzle_column_db(drizzle_column_st *column)
384
const char *drizzle_column_table(drizzle_column_st *column)
386
return column->table;
389
const char *drizzle_column_orig_table(drizzle_column_st *column)
391
return column->orig_table;
394
const char *drizzle_column_name(drizzle_column_st *column)
399
const char *drizzle_column_orig_name(drizzle_column_st *column)
401
return column->orig_name;
404
drizzle_charset_t drizzle_column_charset(drizzle_column_st *column)
406
return column->charset;
409
uint32_t drizzle_column_size(drizzle_column_st *column)
414
size_t drizzle_column_max_size(drizzle_column_st *column)
416
return column->max_size;
419
void drizzle_column_set_max_size(drizzle_column_st *column, size_t size)
421
column->max_size= size;
424
drizzle_column_type_t drizzle_column_type(drizzle_column_st *column)
429
drizzle_column_type_drizzle_t
430
drizzle_column_type_drizzle(drizzle_column_st *column)
432
return _column_type_drizzle_map_from[column->type];
435
drizzle_column_flags_t drizzle_column_flags(drizzle_column_st *column)
437
return column->flags;
440
uint8_t drizzle_column_decimals(drizzle_column_st *column)
442
return column->decimals;
445
const uint8_t *drizzle_column_default_value(drizzle_column_st *column,
448
*size= column->default_value_size;
449
return column->default_value;
456
drizzle_return_t drizzle_column_skip(drizzle_result_st *result)
458
if (drizzle_state_none(result->con))
460
result->options|= DRIZZLE_RESULT_SKIP_COLUMN;
462
drizzle_state_push(result->con, drizzle_state_column_read);
463
drizzle_state_push(result->con, drizzle_state_packet_read);
466
return drizzle_state_loop(result->con);
469
drizzle_column_st *drizzle_column_read(drizzle_result_st *result,
470
drizzle_column_st *column,
471
drizzle_return_t *ret_ptr)
473
if (drizzle_state_none(result->con))
475
result->column= column;
477
drizzle_state_push(result->con, drizzle_state_column_read);
478
drizzle_state_push(result->con, drizzle_state_packet_read);
481
*ret_ptr= drizzle_state_loop(result->con);
482
return result->column;
485
drizzle_return_t drizzle_column_buffer(drizzle_result_st *result)
487
drizzle_return_t ret;
489
if (result->column_buffer == NULL)
491
if (result->column_count == 0)
493
result->options|= DRIZZLE_RESULT_BUFFER_COLUMN;
494
return DRIZZLE_RETURN_OK;
497
result->column_buffer= malloc(sizeof(drizzle_column_st) *
498
result->column_count);
499
if (result->column_buffer == NULL)
501
drizzle_set_error(result->con->drizzle, "drizzle_column_buffer",
503
return DRIZZLE_RETURN_MEMORY;
507
/* No while body, just keep calling to buffer columns. */
508
while (drizzle_column_read(result,
509
&(result->column_buffer[result->column_current]),
510
&ret) != NULL && ret == DRIZZLE_RETURN_OK);
511
if (ret == DRIZZLE_RETURN_OK)
513
result->column_current= 0;
514
result->options|= DRIZZLE_RESULT_BUFFER_COLUMN;
520
drizzle_column_st *drizzle_column_next(drizzle_result_st *result)
522
if (result->column_current == result->column_count)
525
result->column_current++;
526
return &(result->column_buffer[result->column_current - 1]);
529
drizzle_column_st *drizzle_column_prev(drizzle_result_st *result)
531
if (result->column_current == 0)
534
result->column_current--;
535
return &(result->column_buffer[result->column_current]);
538
void drizzle_column_seek(drizzle_result_st *result, uint16_t column)
540
if (column <= result->column_count)
541
result->column_current= column;
544
drizzle_column_st *drizzle_column_index(drizzle_result_st *result,
547
if (column >= result->column_count)
550
return &(result->column_buffer[column]);
553
uint16_t drizzle_column_current(drizzle_result_st *result)
555
return result->column_current;
562
drizzle_return_t drizzle_column_write(drizzle_result_st *result,
563
drizzle_column_st *column)
565
if (drizzle_state_none(result->con))
567
result->column= column;
569
drizzle_state_push(result->con, drizzle_state_column_write);
572
return drizzle_state_loop(result->con);
575
void drizzle_column_set_catalog(drizzle_column_st *column, const char *catalog)
578
column->catalog[0]= 0;
581
strncpy(column->catalog, catalog, DRIZZLE_MAX_CATALOG_SIZE);
582
column->catalog[DRIZZLE_MAX_CATALOG_SIZE - 1]= 0;
586
void drizzle_column_set_db(drizzle_column_st *column, const char *db)
592
strncpy(column->db, db, DRIZZLE_MAX_DB_SIZE);
593
column->db[DRIZZLE_MAX_DB_SIZE - 1]= 0;
597
void drizzle_column_set_table(drizzle_column_st *column, const char *table)
603
strncpy(column->table, table, DRIZZLE_MAX_TABLE_SIZE);
604
column->table[DRIZZLE_MAX_TABLE_SIZE - 1]= 0;
608
void drizzle_column_set_orig_table(drizzle_column_st *column,
609
const char *orig_table)
611
if (orig_table == NULL)
612
column->orig_table[0]= 0;
615
strncpy(column->orig_table, orig_table, DRIZZLE_MAX_TABLE_SIZE);
616
column->orig_table[DRIZZLE_MAX_TABLE_SIZE - 1]= 0;
620
void drizzle_column_set_name(drizzle_column_st *column, const char *name)
626
strncpy(column->name, name, DRIZZLE_MAX_COLUMN_NAME_SIZE);
627
column->name[DRIZZLE_MAX_COLUMN_NAME_SIZE - 1]= 0;
631
void drizzle_column_set_orig_name(drizzle_column_st *column,
632
const char *orig_name)
634
if (orig_name == NULL)
635
column->orig_name[0]= 0;
638
strncpy(column->orig_name, orig_name, DRIZZLE_MAX_COLUMN_NAME_SIZE);
639
column->orig_name[DRIZZLE_MAX_COLUMN_NAME_SIZE - 1]= 0;
643
void drizzle_column_set_charset(drizzle_column_st *column,
644
drizzle_charset_t charset)
646
column->charset= charset;
649
void drizzle_column_set_size(drizzle_column_st *column, uint32_t size)
654
void drizzle_column_set_type(drizzle_column_st *column,
655
drizzle_column_type_t type)
660
void drizzle_column_set_flags(drizzle_column_st *column,
661
drizzle_column_flags_t flags)
663
column->flags= flags;
666
void drizzle_column_set_decimals(drizzle_column_st *column, uint8_t decimals)
668
column->decimals= decimals;
671
void drizzle_column_set_default_value(drizzle_column_st *column,
672
const uint8_t *default_value,
675
if (default_value == NULL)
676
column->default_value[0]= 0;
679
if (size < DRIZZLE_MAX_DEFAULT_VALUE_SIZE)
681
memcpy(column->default_value, default_value, size);
682
column->default_value[size]= 0;
683
column->default_value_size= size;
687
memcpy(column->default_value, default_value,
688
DRIZZLE_MAX_DEFAULT_VALUE_SIZE - 1);
689
column->default_value[DRIZZLE_MAX_DEFAULT_VALUE_SIZE - 1]= 0;
690
column->default_value_size= DRIZZLE_MAX_DEFAULT_VALUE_SIZE;
696
* Internal state functions.
699
drizzle_return_t drizzle_state_column_read(drizzle_con_st *con)
701
drizzle_column_st *column;
702
drizzle_column_type_drizzle_t drizzle_type;
704
drizzle_log_debug(con->drizzle, "drizzle_state_column_read");
706
/* Assume the entire column packet will fit in the buffer. */
707
if (con->buffer_size < con->packet_size)
709
drizzle_state_push(con, drizzle_state_read);
710
return DRIZZLE_RETURN_OK;
713
if (con->packet_size == 5 && con->buffer_ptr[0] == 254)
715
/* EOF packet marking end of columns. */
716
con->result->column= NULL;
717
con->result->warning_count= drizzle_get_byte2(con->buffer_ptr + 1);
718
con->status= drizzle_get_byte2(con->buffer_ptr + 3);
720
con->buffer_size-= 5;
722
drizzle_state_pop(con);
724
else if (con->result->options & DRIZZLE_RESULT_SKIP_COLUMN)
726
con->buffer_ptr+= con->packet_size;
727
con->buffer_size-= con->packet_size;
730
drizzle_state_push(con, drizzle_state_packet_read);
734
column= drizzle_column_create(con->result, con->result->column);
736
return DRIZZLE_RETURN_MEMORY;
738
con->result->column= column;
740
/* These functions can only fail if they need to read data, but we know we
741
buffered the entire packet, so ignore returns. */
742
(void)drizzle_unpack_string(con, column->catalog, DRIZZLE_MAX_CATALOG_SIZE);
743
(void)drizzle_unpack_string(con, column->db, DRIZZLE_MAX_DB_SIZE);
744
(void)drizzle_unpack_string(con, column->table, DRIZZLE_MAX_TABLE_SIZE);
745
(void)drizzle_unpack_string(con, column->orig_table,
746
DRIZZLE_MAX_TABLE_SIZE);
747
(void)drizzle_unpack_string(con, column->name,
748
DRIZZLE_MAX_COLUMN_NAME_SIZE);
749
(void)drizzle_unpack_string(con, column->orig_name,
750
DRIZZLE_MAX_COLUMN_NAME_SIZE);
752
/* Skip one filler byte. */
753
column->charset= (drizzle_charset_t)drizzle_get_byte2(con->buffer_ptr + 1);
754
column->size= drizzle_get_byte4(con->buffer_ptr + 3);
756
if (con->options & DRIZZLE_CON_MYSQL)
757
column->type= con->buffer_ptr[7];
760
drizzle_type= con->buffer_ptr[7];
761
if (drizzle_type >= DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX)
762
drizzle_type= DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX;
763
column->type= _column_type_drizzle_map_to[drizzle_type];
766
column->flags= drizzle_get_byte2(con->buffer_ptr + 8);
767
if (column->type <= DRIZZLE_COLUMN_TYPE_INT24 &&
768
column->type != DRIZZLE_COLUMN_TYPE_TIMESTAMP)
770
column->flags|= DRIZZLE_COLUMN_FLAGS_NUM;
773
column->decimals= con->buffer_ptr[10];
774
/* Skip two reserved bytes. */
776
con->buffer_ptr+= 13;
777
con->buffer_size-= 13;
778
con->packet_size-= 13;
780
if (con->packet_size > 0)
782
drizzle_column_set_default_value(column, con->buffer_ptr,
785
con->buffer_ptr+= con->packet_size;
786
con->buffer_size-= con->packet_size;
789
column->default_value[0]= 0;
791
con->result->column_current++;
793
drizzle_state_pop(con);
796
return DRIZZLE_RETURN_OK;
799
drizzle_return_t drizzle_state_column_write(drizzle_con_st *con)
801
uint8_t *start= con->buffer_ptr + con->buffer_size;
803
drizzle_column_st *column= con->result->column;
805
drizzle_log_debug(con->drizzle, "drizzle_state_column_write");
807
/* Calculate max packet size. */
808
con->packet_size= 9 + strlen(column->catalog)
809
+ 9 + strlen(column->db)
810
+ 9 + strlen(column->table)
811
+ 9 + strlen(column->orig_table)
812
+ 9 + strlen(column->name)
813
+ 9 + strlen(column->orig_name)
821
+ column->default_value_size;
823
/* Assume the entire column packet will fit in the buffer. */
824
if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE)
826
drizzle_set_error(con->drizzle, "drizzle_state_column_write",
827
"buffer too small:%zu", con->packet_size + 4);
828
return DRIZZLE_RETURN_INTERNAL_ERROR;
831
/* Flush buffer if there is not enough room. */
832
if (((size_t)DRIZZLE_MAX_BUFFER_SIZE - (size_t)(start - con->buffer)) <
835
drizzle_state_push(con, drizzle_state_write);
836
return DRIZZLE_RETURN_OK;
839
/* Store packet size at the end since it may change. */
841
ptr[3]= con->packet_number;
842
con->packet_number++;
845
ptr= drizzle_pack_string(column->catalog, ptr);
846
ptr= drizzle_pack_string(column->db, ptr);
847
ptr= drizzle_pack_string(column->table, ptr);
848
ptr= drizzle_pack_string(column->orig_table, ptr);
849
ptr= drizzle_pack_string(column->name, ptr);
850
ptr= drizzle_pack_string(column->orig_name, ptr);
852
/* This unused byte is set to 12 for some reason. */
856
drizzle_set_byte2(ptr, column->charset);
859
drizzle_set_byte4(ptr, column->size);
862
if (con->options & DRIZZLE_CON_MYSQL)
863
ptr[0]= column->type;
865
ptr[0]= _column_type_drizzle_map_from[column->type];
868
drizzle_set_byte2(ptr, column->flags);
871
ptr[0]= column->decimals;
877
if (column->default_value_size > 0)
879
memcpy(ptr, column->default_value, column->default_value_size);
880
ptr+= column->default_value_size;
883
con->packet_size= ((size_t)(ptr - start) - 4);
884
con->buffer_size+= (4 + con->packet_size);
886
/* Store packet size now. */
887
drizzle_set_byte3(start, con->packet_size);
889
con->result->column_current++;
891
drizzle_state_pop(con);
893
return DRIZZLE_RETURN_OK;