~drizzle-trunk/drizzle/development

1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
1
/*
2
 * Drizzle Client & Protocol Library
3
 *
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5
 * All rights reserved.
6
 *
1971.2.1 by kalebral at gmail
update files that did not have license or had incorrect license structure
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions are
9
 * met:
10
 *
11
 *     * Redistributions of source code must retain the above copyright
12
 * notice, this list of conditions and the following disclaimer.
13
 *
14
 *     * Redistributions in binary form must reproduce the above
15
 * copyright notice, this list of conditions and the following disclaimer
16
 * in the documentation and/or other materials provided with the
17
 * distribution.
18
 *
19
 *     * The names of its contributors may not be used to endorse or
20
 * promote products derived from this software without specific prior
21
 * written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
 *
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
35
 */
36
1971.2.1 by kalebral at gmail
update files that did not have license or had incorrect license structure
37
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
38
/**
39
 * @file
40
 * @brief Column definitions
41
 */
42
43
#include "common.h"
44
45
/*
46
 * Private variables.
47
 */
48
49
static drizzle_column_type_t _column_type_drizzle_map_to[]=
50
{
51
 DRIZZLE_COLUMN_TYPE_TINY,
52
 DRIZZLE_COLUMN_TYPE_LONG,
53
 DRIZZLE_COLUMN_TYPE_DOUBLE,
54
 DRIZZLE_COLUMN_TYPE_NULL,
55
 DRIZZLE_COLUMN_TYPE_TIMESTAMP,
56
 DRIZZLE_COLUMN_TYPE_LONGLONG,
57
 DRIZZLE_COLUMN_TYPE_DATETIME,
58
 DRIZZLE_COLUMN_TYPE_NEWDATE,
59
 DRIZZLE_COLUMN_TYPE_VARCHAR,
60
 DRIZZLE_COLUMN_TYPE_NEWDECIMAL,
61
 DRIZZLE_COLUMN_TYPE_ENUM,
62
 DRIZZLE_COLUMN_TYPE_BLOB
63
};
64
65
static drizzle_column_type_drizzle_t _column_type_drizzle_map_from[]=
66
{
67
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 0 */
68
 DRIZZLE_COLUMN_TYPE_DRIZZLE_TINY,
69
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
70
 DRIZZLE_COLUMN_TYPE_DRIZZLE_LONG,
71
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
72
 DRIZZLE_COLUMN_TYPE_DRIZZLE_DOUBLE,
73
 DRIZZLE_COLUMN_TYPE_DRIZZLE_NULL,
74
 DRIZZLE_COLUMN_TYPE_DRIZZLE_TIMESTAMP,
75
 DRIZZLE_COLUMN_TYPE_DRIZZLE_LONGLONG,
76
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
77
78
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 10 */
79
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
80
 DRIZZLE_COLUMN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E_COLUMN_TYPE_DRIZZLE_MAX,
175
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
176
177
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 100 */
178
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
179
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
180
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
181
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
182
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
183
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
184
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
185
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
186
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
187
188
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 110 */
189
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
190
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
191
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
192
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
193
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
194
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
195
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
196
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
197
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
198
199
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 120 */
200
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
201
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
202
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
203
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
204
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
205
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
206
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
207
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
208
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
209
210
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 130 */
211
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
212
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
213
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
214
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
215
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
216
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
217
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
218
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
219
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
220
221
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 140 */
222
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
223
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
224
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
225
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
226
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
227
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
228
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
229
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
230
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
231
232
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 150 */
233
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
234
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
235
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
236
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
237
 DRIZZLE_COLU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
269
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
270
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
271
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
272
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
273
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
274
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
275
276
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 190 */
277
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
278
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
279
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
280
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
281
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
282
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
283
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
284
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
285
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
286
287
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 200 */
288
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
289
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
290
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
291
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
292
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
293
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
294
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
295
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
296
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
297
298
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 210 */
299
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
300
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
301
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
302
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
303
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
304
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
305
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
306
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
307
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
308
309
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 220 */
310
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
311
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
312
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
313
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
314
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
315
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
316
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
317
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
318
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
319
320
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 230 */
321
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
322
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
323
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
324
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
325
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
326
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
327
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
328
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
329
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
330
331
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 240 */
332
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
333
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
334
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
335
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
336
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
337
 DRIZZLE_COLUMN_TYPE_DRIZZLE_NEWDECIMAL,
338
 DRIZZLE_COLUMN_TYPE_DRIZZLE_ENUM,
339
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
340
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
341
342
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 250 */
343
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
344
 DRIZZLE_COLUMN_TYPE_DRIZZLE_BLOB,
345
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
346
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX,
347
 DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX
348
};
349
350
/*
351
 * Common definitions
352
 */
353
354
drizzle_column_st *drizzle_column_create(drizzle_result_st *result,
355
                                         drizzle_column_st *column)
356
{
357
  if (column == NULL)
358
  {
359
    column= malloc(sizeof(drizzle_column_st));
360
    if (column == NULL)
361
    {
362
      drizzle_set_error(result->con->drizzle, "drizzle_column_create",
363
                        "malloc");
364
      return NULL;
365
    }
366
367
    memset(column, 0, sizeof(drizzle_column_st));
368
    column->options|= DRIZZLE_COLUMN_ALLOCATED;
369
  }
370
  else
371
    memset(column, 0, sizeof(drizzle_column_st));
372
373
  column->result= result;
374
375
  if (result->column_list)
376
    result->column_list->prev= column;
377
  column->next= result->column_list;
378
  result->column_list= column;
379
380
  return column;
381
}
382
383
void drizzle_column_free(drizzle_column_st *column)
384
{
385
  if (column->result->column_list == column)
386
    column->result->column_list= column->next;
387
  if (column->prev)
388
    column->prev->next= column->next;
389
  if (column->next)
390
    column->next->prev= column->prev;
391
392
  if (column->options & DRIZZLE_COLUMN_ALLOCATED)
393
    free(column);
394
}
395
396
drizzle_result_st *drizzle_column_drizzle_result(drizzle_column_st *column)
397
{
398
  return column->result;
399
}
400
401
const char *drizzle_column_catalog(drizzle_column_st *column)
402
{
403
  return column->catalog;
404
}
405
406
const char *drizzle_column_db(drizzle_column_st *column)
407
{
408
  return column->db;
409
}
410
411
const char *drizzle_column_table(drizzle_column_st *column)
412
{
413
  return column->table;
414
}
415
416
const char *drizzle_column_orig_table(drizzle_column_st *column)
417
{
418
  return column->orig_table;
419
}
420
421
const char *drizzle_column_name(drizzle_column_st *column)
422
{
423
  return column->name;
424
}
425
426
const char *drizzle_column_orig_name(drizzle_column_st *column)
427
{
428
  return column->orig_name;
429
}
430
431
drizzle_charset_t drizzle_column_charset(drizzle_column_st *column)
432
{
433
  return column->charset;
434
}
435
436
uint32_t drizzle_column_size(drizzle_column_st *column)
437
{
438
  return column->size;
439
}
440
441
size_t drizzle_column_max_size(drizzle_column_st *column)
442
{
443
  return column->max_size;
444
}
445
446
void drizzle_column_set_max_size(drizzle_column_st *column, size_t size)
447
{
448
  column->max_size= size;
449
}
450
451
drizzle_column_type_t drizzle_column_type(drizzle_column_st *column)
452
{
453
  return column->type;
454
}
455
456
drizzle_column_type_drizzle_t
457
drizzle_column_type_drizzle(drizzle_column_st *column)
458
{
459
  return _column_type_drizzle_map_from[column->type];
460
}
461
462
drizzle_column_flags_t drizzle_column_flags(drizzle_column_st *column)
463
{
464
  return column->flags;
465
}
466
467
uint8_t drizzle_column_decimals(drizzle_column_st *column)
468
{
469
  return column->decimals;
470
}
471
472
const uint8_t *drizzle_column_default_value(drizzle_column_st *column,
473
                                            size_t *size)
474
{
475
  *size= column->default_value_size;
476
  return column->default_value;
477
}
478
479
/*
480
 * Client definitions
481
 */
482
483
drizzle_return_t drizzle_column_skip(drizzle_result_st *result)
484
{
485
  if (drizzle_state_none(result->con))
486
  {
487
    result->options|= DRIZZLE_RESULT_SKIP_COLUMN;
488
489
    drizzle_state_push(result->con, drizzle_state_column_read);
490
    drizzle_state_push(result->con, drizzle_state_packet_read);
491
  }
492
493
  return drizzle_state_loop(result->con);
494
}
495
496
drizzle_column_st *drizzle_column_read(drizzle_result_st *result,
497
                                       drizzle_column_st *column,
498
                                       drizzle_return_t *ret_ptr)
499
{
500
  if (drizzle_state_none(result->con))
501
  {
502
    result->column= column;
503
504
    drizzle_state_push(result->con, drizzle_state_column_read);
505
    drizzle_state_push(result->con, drizzle_state_packet_read);
506
  }
507
508
  *ret_ptr= drizzle_state_loop(result->con);
509
  return result->column;
510
}
511
512
drizzle_return_t drizzle_column_buffer(drizzle_result_st *result)
513
{
514
  drizzle_return_t ret;
515
516
  if (result->column_buffer == NULL)
517
  {
518
    if (result->column_count == 0)
519
    {
520
      result->options|= DRIZZLE_RESULT_BUFFER_COLUMN;
521
      return DRIZZLE_RETURN_OK;
522
    }
523
524
    result->column_buffer= malloc(sizeof(drizzle_column_st) *
525
                                  result->column_count);
526
    if (result->column_buffer == NULL)
527
    {
528
      drizzle_set_error(result->con->drizzle, "drizzle_column_buffer",
529
                        "malloc");
530
      return DRIZZLE_RETURN_MEMORY;
531
    }
532
  }
533
534
  /* No while body, just keep calling to buffer columns. */
535
  while (drizzle_column_read(result,
536
                             &(result->column_buffer[result->column_current]),
537
                             &ret) != NULL && ret == DRIZZLE_RETURN_OK);
538
  if (ret == DRIZZLE_RETURN_OK)
539
  {
540
    result->column_current= 0;
541
    result->options|= DRIZZLE_RESULT_BUFFER_COLUMN;
542
  }
543
544
  return ret;
545
}
546
547
drizzle_column_st *drizzle_column_next(drizzle_result_st *result)
548
{
549
  if (result->column_current == result->column_count)
550
    return NULL;
551
552
  result->column_current++;
553
  return &(result->column_buffer[result->column_current - 1]);
554
}
555
556
drizzle_column_st *drizzle_column_prev(drizzle_result_st *result)
557
{
558
  if (result->column_current == 0)
559
    return NULL;
560
561
  result->column_current--;
562
  return &(result->column_buffer[result->column_current]);
563
}
564
565
void drizzle_column_seek(drizzle_result_st *result, uint16_t column)
566
{
567
  if (column <= result->column_count)
568
    result->column_current= column;
569
}
570
571
drizzle_column_st *drizzle_column_index(drizzle_result_st *result,
572
                                        uint16_t column)
573
{
574
  if (column >= result->column_count)
575
    return NULL;
576
577
  return &(result->column_buffer[column]);
578
}
579
580
uint16_t drizzle_column_current(drizzle_result_st *result)
581
{
582
  return result->column_current;
583
}
584
585
/*
586
 * Server definitions
587
 */
588
589
drizzle_return_t drizzle_column_write(drizzle_result_st *result,
590
                                      drizzle_column_st *column)
591
{
592
  if (drizzle_state_none(result->con))
593
  {
594
    result->column= column;
595
596
    drizzle_state_push(result->con, drizzle_state_column_write);
597
  }
598
599
  return drizzle_state_loop(result->con);
600
}
601
602
void drizzle_column_set_catalog(drizzle_column_st *column, const char *catalog)
603
{
604
  if (catalog == NULL)
605
    column->catalog[0]= 0;
606
  else
607
  {
608
    strncpy(column->catalog, catalog, DRIZZLE_MAX_CATALOG_SIZE);
609
    column->catalog[DRIZZLE_MAX_CATALOG_SIZE - 1]= 0;
610
  }
611
}
612
613
void drizzle_column_set_db(drizzle_column_st *column, const char *db)
614
{
615
  if (db == NULL)
616
    column->db[0]= 0;
617
  else
618
  {
619
    strncpy(column->db, db, DRIZZLE_MAX_DB_SIZE);
620
    column->db[DRIZZLE_MAX_DB_SIZE - 1]= 0;
621
  }
622
}
623
624
void drizzle_column_set_table(drizzle_column_st *column, const char *table)
625
{
626
  if (table == NULL)
627
    column->table[0]= 0;
628
  else
629
  {
630
    strncpy(column->table, table, DRIZZLE_MAX_TABLE_SIZE);
631
    column->table[DRIZZLE_MAX_TABLE_SIZE - 1]= 0;
632
  }
633
}
634
635
void drizzle_column_set_orig_table(drizzle_column_st *column,
636
                                   const char *orig_table)
637
{
638
  if (orig_table == NULL)
639
    column->orig_table[0]= 0;
640
  else
641
  {
642
    strncpy(column->orig_table, orig_table, DRIZZLE_MAX_TABLE_SIZE);
643
    column->orig_table[DRIZZLE_MAX_TABLE_SIZE - 1]= 0;
644
  }
645
}
646
647
void drizzle_column_set_name(drizzle_column_st *column, const char *name)
648
{
649
  if (name == NULL)
650
    column->name[0]= 0;
651
  else
652
  {
653
    strncpy(column->name, name, DRIZZLE_MAX_COLUMN_NAME_SIZE);
654
    column->name[DRIZZLE_MAX_COLUMN_NAME_SIZE - 1]= 0;
655
  }
656
}
657
658
void drizzle_column_set_orig_name(drizzle_column_st *column,
659
                                  const char *orig_name)
660
{
661
  if (orig_name == NULL)
662
    column->orig_name[0]= 0;
663
  else
664
  {
665
    strncpy(column->orig_name, orig_name, DRIZZLE_MAX_COLUMN_NAME_SIZE);
666
    column->orig_name[DRIZZLE_MAX_COLUMN_NAME_SIZE - 1]= 0;
667
  }
668
}
669
670
void drizzle_column_set_charset(drizzle_column_st *column,
671
                                drizzle_charset_t charset)
672
{
673
  column->charset= charset;
674
}
675
676
void drizzle_column_set_size(drizzle_column_st *column, uint32_t size)
677
{
678
  column->size= size;
679
}
680
681
void drizzle_column_set_type(drizzle_column_st *column,
682
                             drizzle_column_type_t type)
683
{
684
  column->type= type;
685
}
686
687
void drizzle_column_set_flags(drizzle_column_st *column,
688
                              drizzle_column_flags_t flags)
689
{
690
  column->flags= flags;
691
}
692
693
void drizzle_column_set_decimals(drizzle_column_st *column, uint8_t decimals)
694
{
695
  column->decimals= decimals;
696
}
697
698
void drizzle_column_set_default_value(drizzle_column_st *column,
699
                                      const uint8_t *default_value,
700
                                      size_t size)
701
{
702
  if (default_value == NULL)
703
    column->default_value[0]= 0;
704
  else
705
  {
706
    if (size < DRIZZLE_MAX_DEFAULT_VALUE_SIZE)
707
    {
708
      memcpy(column->default_value, default_value, size);
709
      column->default_value[size]= 0;
710
      column->default_value_size= size;
711
    }
712
    else
713
    {
714
      memcpy(column->default_value, default_value,
715
             DRIZZLE_MAX_DEFAULT_VALUE_SIZE - 1);
716
      column->default_value[DRIZZLE_MAX_DEFAULT_VALUE_SIZE - 1]= 0;
717
      column->default_value_size= DRIZZLE_MAX_DEFAULT_VALUE_SIZE;
718
    }
719
  }
720
}
721
722
/*
723
 * Internal state functions.
724
 */
725
726
drizzle_return_t drizzle_state_column_read(drizzle_con_st *con)
727
{
728
  drizzle_column_st *column;
729
  drizzle_column_type_drizzle_t drizzle_type;
730
731
  drizzle_log_debug(con->drizzle, "drizzle_state_column_read");
732
733
  /* Assume the entire column packet will fit in the buffer. */
734
  if (con->buffer_size < con->packet_size)
735
  {
736
    drizzle_state_push(con, drizzle_state_read);
737
    return DRIZZLE_RETURN_OK;
738
  }
739
740
  if (con->packet_size == 5 && con->buffer_ptr[0] == 254)
741
  {
742
    /* EOF packet marking end of columns. */
743
    con->result->column= NULL;
744
    con->result->warning_count= drizzle_get_byte2(con->buffer_ptr + 1);
745
    con->status= drizzle_get_byte2(con->buffer_ptr + 3);
746
    con->buffer_ptr+= 5;
747
    con->buffer_size-= 5;
748
749
    drizzle_state_pop(con);
750
  }
751
  else if (con->result->options & DRIZZLE_RESULT_SKIP_COLUMN)
752
  {
753
    con->buffer_ptr+= con->packet_size;
754
    con->buffer_size-= con->packet_size;
755
    con->packet_size= 0;
756
757
    drizzle_state_push(con, drizzle_state_packet_read);
758
  }
759
  else
760
  {
761
    column= drizzle_column_create(con->result, con->result->column);
762
    if (column == NULL)
763
      return DRIZZLE_RETURN_MEMORY;
764
765
    con->result->column= column;
766
767
    /* These functions can only fail if they need to read data, but we know we
768
       buffered the entire packet, so ignore returns. */
769
    (void)drizzle_unpack_string(con, column->catalog, DRIZZLE_MAX_CATALOG_SIZE);
770
    (void)drizzle_unpack_string(con, column->db, DRIZZLE_MAX_DB_SIZE);
771
    (void)drizzle_unpack_string(con, column->table, DRIZZLE_MAX_TABLE_SIZE);
772
    (void)drizzle_unpack_string(con, column->orig_table,
773
                                DRIZZLE_MAX_TABLE_SIZE);
774
    (void)drizzle_unpack_string(con, column->name,
775
                                DRIZZLE_MAX_COLUMN_NAME_SIZE);
776
    (void)drizzle_unpack_string(con, column->orig_name,
777
                                DRIZZLE_MAX_COLUMN_NAME_SIZE);
778
779
    /* Skip one filler byte. */
780
    column->charset= (drizzle_charset_t)drizzle_get_byte2(con->buffer_ptr + 1);
781
    column->size= drizzle_get_byte4(con->buffer_ptr + 3);
782
783
    if (con->options & DRIZZLE_CON_MYSQL)
784
      column->type= con->buffer_ptr[7];
785
    else
786
    {
787
      drizzle_type= con->buffer_ptr[7];
788
      if (drizzle_type >= DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX)
789
        drizzle_type= DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX;
790
      column->type= _column_type_drizzle_map_to[drizzle_type];
791
    }
792
793
    column->flags= drizzle_get_byte2(con->buffer_ptr + 8);
794
    if (column->type <= DRIZZLE_COLUMN_TYPE_INT24 &&
795
        column->type != DRIZZLE_COLUMN_TYPE_TIMESTAMP)
796
    {
797
      column->flags|= DRIZZLE_COLUMN_FLAGS_NUM;
798
    }
799
800
    column->decimals= con->buffer_ptr[10];
801
    /* Skip two reserved bytes. */
802
803
    con->buffer_ptr+= 13;
804
    con->buffer_size-= 13;
805
    con->packet_size-= 13;
806
807
    if (con->packet_size > 0)
808
    {
809
      drizzle_column_set_default_value(column, con->buffer_ptr,
810
                                       con->packet_size);
811
812
      con->buffer_ptr+= con->packet_size;
813
      con->buffer_size-= con->packet_size;
814
    }
815
    else
816
      column->default_value[0]= 0;
817
818
    con->result->column_current++;
819
820
    drizzle_state_pop(con);
821
  }
822
823
  return DRIZZLE_RETURN_OK;
824
}
825
826
drizzle_return_t drizzle_state_column_write(drizzle_con_st *con)
827
{
828
  uint8_t *start= con->buffer_ptr + con->buffer_size;
829
  uint8_t *ptr;
830
  drizzle_column_st *column= con->result->column;
831
832
  drizzle_log_debug(con->drizzle, "drizzle_state_column_write");
833
834
  /* Calculate max packet size. */
835
  con->packet_size= 9 + strlen(column->catalog)
836
                  + 9 + strlen(column->db)
837
                  + 9 + strlen(column->table)
838
                  + 9 + strlen(column->orig_table)
839
                  + 9 + strlen(column->name)
840
                  + 9 + strlen(column->orig_name)
841
                  + 1   /* Unused */
842
                  + 2   /* Charset */
843
                  + 4   /* Size */
844
                  + 1   /* Type */
845
                  + 2   /* Flags */
846
                  + 1   /* Decimals */
847
                  + 2   /* Unused */
848
                  + column->default_value_size;
849
850
  /* Assume the entire column packet will fit in the buffer. */
851
  if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE)
852
  {
853
    drizzle_set_error(con->drizzle, "drizzle_state_column_write",
854
                      "buffer too small:%zu", con->packet_size + 4);
855
    return DRIZZLE_RETURN_INTERNAL_ERROR;
856
  }
857
858
  /* Flush buffer if there is not enough room. */
859
  if (((size_t)DRIZZLE_MAX_BUFFER_SIZE - (size_t)(start - con->buffer)) <
860
      con->packet_size)
861
  {
862
    drizzle_state_push(con, drizzle_state_write);
863
    return DRIZZLE_RETURN_OK;
864
  }
865
866
  /* Store packet size at the end since it may change. */
867
  ptr= start;
868
  ptr[3]= con->packet_number;
869
  con->packet_number++;
870
  ptr+= 4;
871
872
  ptr= drizzle_pack_string(column->catalog, ptr);
873
  ptr= drizzle_pack_string(column->db, ptr);
874
  ptr= drizzle_pack_string(column->table, ptr);
875
  ptr= drizzle_pack_string(column->orig_table, ptr);
876
  ptr= drizzle_pack_string(column->name, ptr);
877
  ptr= drizzle_pack_string(column->orig_name, ptr);
878
879
  /* This unused byte is set to 12 for some reason. */
880
  ptr[0]= 12;
881
  ptr++;
882
883
  drizzle_set_byte2(ptr, column->charset);
884
  ptr+= 2;
885
886
  drizzle_set_byte4(ptr, column->size);
887
  ptr+= 4;
888
889
  if (con->options & DRIZZLE_CON_MYSQL)
890
    ptr[0]= column->type;
891
  else
892
    ptr[0]= _column_type_drizzle_map_from[column->type];
893
  ptr++;
894
895
  drizzle_set_byte2(ptr, column->flags);
896
  ptr+= 2;
897
898
  ptr[0]= column->decimals;
899
  ptr++;
900
901
  memset(ptr, 0, 2);
902
  ptr+= 2;
903
904
  if (column->default_value_size > 0)
905
  {
906
    memcpy(ptr, column->default_value, column->default_value_size);
907
    ptr+= column->default_value_size;
908
  }
909
910
  con->packet_size= ((size_t)(ptr - start) - 4);
911
  con->buffer_size+= (4 + con->packet_size);
912
913
  /* Store packet size now. */
914
  drizzle_set_byte3(start, con->packet_size);
915
916
  con->result->column_current++;
917
918
  drizzle_state_pop(con);
919
920
  return DRIZZLE_RETURN_OK;
921
}