~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2009-11-18 06:24:48 UTC
  • mfrom: (1220.1.15 staging)
  • Revision ID: brian@gaz-20091118062448-o36lo3yv81sc6u9z
Merge Brian + Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2010 Brian Aker
5
4
 *  Copyright (C) 2008 MySQL
6
5
 *
7
6
 *  This program is free software; you can redistribute it and/or modify
23
22
 * @file This file implements the Field class and API
24
23
 */
25
24
 
26
 
#include "config.h"
27
 
#include <cstdio>
 
25
#include "drizzled/server_includes.h"
28
26
#include <errno.h>
29
 
#include <float.h>
30
27
#include "drizzled/sql_select.h"
31
28
#include "drizzled/error.h"
32
29
#include "drizzled/field/str.h"
33
30
#include "drizzled/field/num.h"
34
31
#include "drizzled/field/blob.h"
35
 
#include "drizzled/field/boolean.h"
36
32
#include "drizzled/field/enum.h"
37
33
#include "drizzled/field/null.h"
38
34
#include "drizzled/field/date.h"
39
35
#include "drizzled/field/decimal.h"
40
36
#include "drizzled/field/real.h"
41
37
#include "drizzled/field/double.h"
42
 
#include "drizzled/field/int32.h"
43
 
#include "drizzled/field/int64.h"
 
38
#include "drizzled/field/long.h"
 
39
#include "drizzled/field/int64_t.h"
44
40
#include "drizzled/field/num.h"
45
 
#include "drizzled/field/time.h"
46
 
#include "drizzled/field/epoch.h"
 
41
#include "drizzled/field/timestamp.h"
47
42
#include "drizzled/field/datetime.h"
48
 
#include "drizzled/field/microtime.h"
49
43
#include "drizzled/field/varstring.h"
50
 
#include "drizzled/field/uuid.h"
51
 
#include "drizzled/time_functions.h"
52
 
#include "drizzled/internal/m_string.h"
53
 
 
54
 
#include "drizzled/display.h"
55
 
 
56
 
namespace drizzled
57
 
{
58
44
 
59
45
/*****************************************************************************
60
46
  Instansiate templates and static variables
61
47
*****************************************************************************/
62
48
 
 
49
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
 
50
template class List<CreateField>;
 
51
template class List_iterator<CreateField>;
 
52
#endif
 
53
 
63
54
static enum_field_types
64
 
field_types_merge_rules [enum_field_types_size][enum_field_types_size]=
 
55
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
65
56
{
66
57
  /* DRIZZLE_TYPE_LONG -> */
67
58
  {
87
78
    DRIZZLE_TYPE_VARCHAR,
88
79
    //DRIZZLE_TYPE_BLOB
89
80
    DRIZZLE_TYPE_BLOB,
90
 
    //DRIZZLE_TYPE_TIME
91
 
    DRIZZLE_TYPE_TIME,
92
 
    //DRIZZLE_TYPE_BOOLEAN
93
 
    DRIZZLE_TYPE_VARCHAR,
94
 
    //DRIZZLE_TYPE_UUID
95
 
    DRIZZLE_TYPE_VARCHAR,
96
 
    //DRIZZLE_TYPE_MICROTIME
97
 
    DRIZZLE_TYPE_VARCHAR,
98
81
  },
99
82
  /* DRIZZLE_TYPE_DOUBLE -> */
100
83
  {
120
103
    DRIZZLE_TYPE_VARCHAR,
121
104
    //DRIZZLE_TYPE_BLOB
122
105
    DRIZZLE_TYPE_BLOB,
123
 
    //DRIZZLE_TYPE_TIME
124
 
    DRIZZLE_TYPE_TIME,
125
 
    //DRIZZLE_TYPE_BOOLEAN
126
 
    DRIZZLE_TYPE_VARCHAR,
127
 
    //DRIZZLE_TYPE_UUID
128
 
    DRIZZLE_TYPE_VARCHAR,
129
 
    //DRIZZLE_TYPE_MICROTIME
130
 
    DRIZZLE_TYPE_VARCHAR,
131
106
  },
132
107
  /* DRIZZLE_TYPE_NULL -> */
133
108
  {
153
128
    DRIZZLE_TYPE_ENUM,
154
129
    //DRIZZLE_TYPE_BLOB
155
130
    DRIZZLE_TYPE_BLOB,
156
 
    //DRIZZLE_TYPE_TIME
157
 
    DRIZZLE_TYPE_TIME,
158
 
    //DRIZZLE_TYPE_BOOLEAN
159
 
    DRIZZLE_TYPE_BOOLEAN,
160
 
    //DRIZZLE_TYPE_UUID
161
 
    DRIZZLE_TYPE_UUID,
162
 
    //DRIZZLE_TYPE_MICROTIME
163
 
    DRIZZLE_TYPE_MICROTIME,
164
131
  },
165
132
  /* DRIZZLE_TYPE_TIMESTAMP -> */
166
133
  {
186
153
    DRIZZLE_TYPE_VARCHAR,
187
154
    //DRIZZLE_TYPE_BLOB
188
155
    DRIZZLE_TYPE_BLOB,
189
 
    //DRIZZLE_TYPE_TIME
190
 
    DRIZZLE_TYPE_TIME,
191
 
    //DRIZZLE_TYPE_BOOLEAN
192
 
    DRIZZLE_TYPE_VARCHAR,
193
 
    //DRIZZLE_TYPE_UUID
194
 
    DRIZZLE_TYPE_VARCHAR,
195
 
    //DRIZZLE_TYPE_MICROTIME
196
 
    DRIZZLE_TYPE_VARCHAR,
197
156
  },
198
157
  /* DRIZZLE_TYPE_LONGLONG -> */
199
158
  {
218
177
    DRIZZLE_TYPE_VARCHAR,
219
178
    //DRIZZLE_TYPE_BLOB
220
179
    DRIZZLE_TYPE_BLOB,
221
 
    //DRIZZLE_TYPE_TIME
222
 
    DRIZZLE_TYPE_TIME,
223
 
    //DRIZZLE_TYPE_BOOLEAN
224
 
    DRIZZLE_TYPE_VARCHAR,
225
 
    //DRIZZLE_TYPE_UUID
226
 
    DRIZZLE_TYPE_VARCHAR,
227
 
    //DRIZZLE_TYPE_MICROTIME
228
 
    DRIZZLE_TYPE_VARCHAR,
229
180
  },
230
181
  /* DRIZZLE_TYPE_DATETIME -> */
231
182
  {
251
202
    DRIZZLE_TYPE_VARCHAR,
252
203
    //DRIZZLE_TYPE_BLOB
253
204
    DRIZZLE_TYPE_BLOB,
254
 
    //DRIZZLE_TYPE_TIME
255
 
    DRIZZLE_TYPE_TIME,
256
 
    //DRIZZLE_TYPE_BOOLEAN
257
 
    DRIZZLE_TYPE_VARCHAR,
258
 
    //DRIZZLE_TYPE_UUID
259
 
    DRIZZLE_TYPE_VARCHAR,
260
 
    //DRIZZLE_TYPE_MICROTIME
261
 
    DRIZZLE_TYPE_VARCHAR,
262
205
  },
263
206
  /* DRIZZLE_TYPE_DATE -> */
264
207
  {
284
227
    DRIZZLE_TYPE_VARCHAR,
285
228
    //DRIZZLE_TYPE_BLOB
286
229
    DRIZZLE_TYPE_BLOB,
287
 
    //DRIZZLE_TYPE_TIME
288
 
    DRIZZLE_TYPE_TIME,
289
 
    //DRIZZLE_TYPE_BOOLEAN
290
 
    DRIZZLE_TYPE_VARCHAR,
291
 
    //DRIZZLE_TYPE_UUID
292
 
    DRIZZLE_TYPE_VARCHAR,
293
 
    //DRIZZLE_TYPE_MICROTIME
294
 
    DRIZZLE_TYPE_VARCHAR,
295
230
  },
296
231
  /* DRIZZLE_TYPE_VARCHAR -> */
297
232
  {
317
252
    DRIZZLE_TYPE_VARCHAR,
318
253
    //DRIZZLE_TYPE_BLOB
319
254
    DRIZZLE_TYPE_BLOB,
320
 
    //DRIZZLE_TYPE_TIME
321
 
    DRIZZLE_TYPE_TIME,
322
 
    //DRIZZLE_TYPE_BOOLEAN
323
 
    DRIZZLE_TYPE_VARCHAR,
324
 
    //DRIZZLE_TYPE_UUID
325
 
    DRIZZLE_TYPE_VARCHAR,
326
 
    //DRIZZLE_TYPE_MICROTIME
327
 
    DRIZZLE_TYPE_VARCHAR,
328
255
  },
329
256
  /* DRIZZLE_TYPE_DECIMAL -> */
330
257
  {
350
277
    DRIZZLE_TYPE_VARCHAR,
351
278
    //DRIZZLE_TYPE_BLOB
352
279
    DRIZZLE_TYPE_BLOB,
353
 
    //DRIZZLE_TYPE_TIME
354
 
    DRIZZLE_TYPE_TIME,
355
 
    //DRIZZLE_TYPE_BOOLEAN
356
 
    DRIZZLE_TYPE_VARCHAR,
357
 
    //DRIZZLE_TYPE_UUID
358
 
    DRIZZLE_TYPE_VARCHAR,
359
 
    //DRIZZLE_TYPE_MICROTIME
360
 
    DRIZZLE_TYPE_VARCHAR,
361
280
  },
362
281
  /* DRIZZLE_TYPE_ENUM -> */
363
282
  {
383
302
    DRIZZLE_TYPE_VARCHAR,
384
303
    //DRIZZLE_TYPE_BLOB
385
304
    DRIZZLE_TYPE_BLOB,
386
 
    //DRIZZLE_TYPE_TIME
387
 
    DRIZZLE_TYPE_TIME,
388
 
    //DRIZZLE_TYPE_BOOLEAN
389
 
    DRIZZLE_TYPE_VARCHAR,
390
 
    //DRIZZLE_TYPE_UUID
391
 
    DRIZZLE_TYPE_VARCHAR,
392
 
    //DRIZZLE_TYPE_MICROTIME
393
 
    DRIZZLE_TYPE_VARCHAR,
394
 
   },
 
305
  },
395
306
  /* DRIZZLE_TYPE_BLOB -> */
396
307
  {
397
308
    //DRIZZLE_TYPE_LONG
416
327
    DRIZZLE_TYPE_BLOB,
417
328
    //DRIZZLE_TYPE_BLOB
418
329
    DRIZZLE_TYPE_BLOB,
419
 
    //DRIZZLE_TYPE_TIME
420
 
    DRIZZLE_TYPE_TIME,
421
 
    //DRIZZLE_TYPE_BOOLEAN
422
 
    DRIZZLE_TYPE_VARCHAR,
423
 
    //DRIZZLE_TYPE_UUID
424
 
    DRIZZLE_TYPE_VARCHAR,
425
 
    //DRIZZLE_TYPE_MICROTIME
426
 
    DRIZZLE_TYPE_VARCHAR,
427
 
  },
428
 
  /* DRIZZLE_TYPE_TIME -> */
429
 
  {
430
 
    //DRIZZLE_TYPE_LONG
431
 
    DRIZZLE_TYPE_VARCHAR,
432
 
    //DRIZZLE_TYPE_DOUBLE
433
 
    DRIZZLE_TYPE_VARCHAR,
434
 
    //DRIZZLE_TYPE_NULL
435
 
    DRIZZLE_TYPE_TIME,
436
 
    //DRIZZLE_TYPE_TIMESTAMP
437
 
    DRIZZLE_TYPE_VARCHAR,
438
 
    //DRIZZLE_TYPE_LONGLONG
439
 
    DRIZZLE_TYPE_VARCHAR,
440
 
    //DRIZZLE_TYPE_DATETIME
441
 
    DRIZZLE_TYPE_VARCHAR,
442
 
    //DRIZZLE_TYPE_DATE
443
 
    DRIZZLE_TYPE_VARCHAR,
444
 
    //DRIZZLE_TYPE_VARCHAR
445
 
    DRIZZLE_TYPE_VARCHAR,
446
 
    //DRIZZLE_TYPE_DECIMAL
447
 
    DRIZZLE_TYPE_VARCHAR,
448
 
    //DRIZZLE_TYPE_VARCHAR,
449
 
    DRIZZLE_TYPE_VARCHAR,
450
 
    //DRIZZLE_TYPE_BLOB
451
 
    DRIZZLE_TYPE_BLOB,
452
 
    //DRIZZLE_TYPE_TIME
453
 
    DRIZZLE_TYPE_TIME,
454
 
    //DRIZZLE_TYPE_BOOLEAN
455
 
    DRIZZLE_TYPE_VARCHAR,
456
 
    //DRIZZLE_TYPE_UUID
457
 
    DRIZZLE_TYPE_UUID,
458
 
    //DRIZZLE_TYPE_MICROTIME
459
 
    DRIZZLE_TYPE_VARCHAR,
460
 
  },
461
 
  /* DRIZZLE_TYPE_BOOLEAN -> */
462
 
  {
463
 
    //DRIZZLE_TYPE_LONG
464
 
    DRIZZLE_TYPE_VARCHAR,
465
 
    //DRIZZLE_TYPE_DOUBLE
466
 
    DRIZZLE_TYPE_VARCHAR,
467
 
    //DRIZZLE_TYPE_NULL
468
 
    DRIZZLE_TYPE_BOOLEAN,
469
 
    //DRIZZLE_TYPE_TIMESTAMP
470
 
    DRIZZLE_TYPE_VARCHAR,
471
 
    //DRIZZLE_TYPE_LONGLONG
472
 
    DRIZZLE_TYPE_VARCHAR,
473
 
    //DRIZZLE_TYPE_DATETIME
474
 
    DRIZZLE_TYPE_VARCHAR,
475
 
    //DRIZZLE_TYPE_DATE
476
 
    DRIZZLE_TYPE_VARCHAR,
477
 
    //DRIZZLE_TYPE_VARCHAR
478
 
    DRIZZLE_TYPE_VARCHAR,
479
 
    //DRIZZLE_TYPE_DECIMAL
480
 
    DRIZZLE_TYPE_VARCHAR,
481
 
    //DRIZZLE_TYPE_VARCHAR,
482
 
    DRIZZLE_TYPE_VARCHAR,
483
 
    //DRIZZLE_TYPE_BLOB
484
 
    DRIZZLE_TYPE_BLOB,
485
 
    //DRIZZLE_TYPE_TIME
486
 
    DRIZZLE_TYPE_TIME,
487
 
    //DRIZZLE_TYPE_BOOLEAN
488
 
    DRIZZLE_TYPE_BOOLEAN,
489
 
    //DRIZZLE_TYPE_UUID
490
 
    DRIZZLE_TYPE_VARCHAR,
491
 
    //DRIZZLE_TYPE_MICROTIME
492
 
    DRIZZLE_TYPE_VARCHAR,
493
 
  },
494
 
  /* DRIZZLE_TYPE_UUID -> */
495
 
  {
496
 
    //DRIZZLE_TYPE_LONG
497
 
    DRIZZLE_TYPE_VARCHAR,
498
 
    //DRIZZLE_TYPE_DOUBLE
499
 
    DRIZZLE_TYPE_VARCHAR,
500
 
    //DRIZZLE_TYPE_NULL
501
 
    DRIZZLE_TYPE_UUID,
502
 
    //DRIZZLE_TYPE_TIMESTAMP
503
 
    DRIZZLE_TYPE_VARCHAR,
504
 
    //DRIZZLE_TYPE_LONGLONG
505
 
    DRIZZLE_TYPE_VARCHAR,
506
 
    //DRIZZLE_TYPE_DATETIME
507
 
    DRIZZLE_TYPE_VARCHAR,
508
 
    //DRIZZLE_TYPE_DATE
509
 
    DRIZZLE_TYPE_VARCHAR,
510
 
    //DRIZZLE_TYPE_VARCHAR
511
 
    DRIZZLE_TYPE_VARCHAR,
512
 
    //DRIZZLE_TYPE_DECIMAL
513
 
    DRIZZLE_TYPE_VARCHAR,
514
 
    //DRIZZLE_TYPE_VARCHAR,
515
 
    DRIZZLE_TYPE_VARCHAR,
516
 
    //DRIZZLE_TYPE_BLOB
517
 
    DRIZZLE_TYPE_BLOB,
518
 
    //DRIZZLE_TYPE_TIME
519
 
    DRIZZLE_TYPE_TIME,
520
 
    //DRIZZLE_TYPE_BOOLEAN
521
 
    DRIZZLE_TYPE_VARCHAR,
522
 
    //DRIZZLE_TYPE_UUID
523
 
    DRIZZLE_TYPE_UUID,
524
 
    //DRIZZLE_TYPE_MICROTIME
525
 
    DRIZZLE_TYPE_VARCHAR,
526
 
  },
527
 
  /* DRIZZLE_TYPE_MICROTIME -> */
528
 
  {
529
 
    //DRIZZLE_TYPE_LONG
530
 
    DRIZZLE_TYPE_VARCHAR,
531
 
    //DRIZZLE_TYPE_DOUBLE
532
 
    DRIZZLE_TYPE_VARCHAR,
533
 
    //DRIZZLE_TYPE_NULL
534
 
    DRIZZLE_TYPE_MICROTIME,
535
 
    //DRIZZLE_TYPE_TIMESTAMP
536
 
    DRIZZLE_TYPE_VARCHAR,
537
 
    //DRIZZLE_TYPE_LONGLONG
538
 
    DRIZZLE_TYPE_VARCHAR,
539
 
    //DRIZZLE_TYPE_DATETIME
540
 
    DRIZZLE_TYPE_VARCHAR,
541
 
    //DRIZZLE_TYPE_DATE
542
 
    DRIZZLE_TYPE_VARCHAR,
543
 
    //DRIZZLE_TYPE_VARCHAR
544
 
    DRIZZLE_TYPE_VARCHAR,
545
 
    //DRIZZLE_TYPE_DECIMAL
546
 
    DRIZZLE_TYPE_VARCHAR,
547
 
    //DRIZZLE_TYPE_VARCHAR,
548
 
    DRIZZLE_TYPE_VARCHAR,
549
 
    //DRIZZLE_TYPE_BLOB
550
 
    DRIZZLE_TYPE_BLOB,
551
 
    //DRIZZLE_TYPE_TIME
552
 
    DRIZZLE_TYPE_TIME,
553
 
    //DRIZZLE_TYPE_BOOLEAN
554
 
    DRIZZLE_TYPE_VARCHAR,
555
 
    //DRIZZLE_TYPE_UUID
556
 
    DRIZZLE_TYPE_UUID,
557
 
    //DRIZZLE_TYPE_MICROTIME
558
 
    DRIZZLE_TYPE_MICROTIME,
559
330
  },
560
331
};
561
332
 
562
 
static Item_result field_types_result_type [enum_field_types_size]=
 
333
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
563
334
{
564
335
  //DRIZZLE_TYPE_LONG
565
336
  INT_RESULT,
583
354
  STRING_RESULT,
584
355
  //DRIZZLE_TYPE_BLOB
585
356
  STRING_RESULT,
586
 
  //DRIZZLE_TYPE_TIME
587
 
  STRING_RESULT,
588
 
  //DRIZZLE_TYPE_BOOLEAN
589
 
  STRING_RESULT,
590
 
  //DRIZZLE_TYPE_UUID
591
 
  STRING_RESULT,
592
 
  //DRIZZLE_TYPE_MICROTIME
593
 
  STRING_RESULT,
594
357
};
595
358
 
596
359
bool test_if_important_data(const CHARSET_INFO * const cs, 
602
365
  return (str < strend);
603
366
}
604
367
 
605
 
void *Field::operator new(size_t size)
606
 
{
607
 
  return memory::sql_alloc(size);
608
 
}
609
 
 
610
 
void *Field::operator new(size_t size, memory::Root *mem_root)
611
 
{
612
 
  return mem_root->alloc_root(static_cast<uint32_t>(size));
613
 
}
614
 
 
615
368
enum_field_types Field::field_type_merge(enum_field_types a,
616
369
                                         enum_field_types b)
617
370
{
618
 
  assert(a < enum_field_types_size);
619
 
  assert(b < enum_field_types_size);
 
371
  assert(a <= DRIZZLE_TYPE_MAX);
 
372
  assert(b <= DRIZZLE_TYPE_MAX);
620
373
  return field_types_merge_rules[a][b];
621
374
}
622
375
 
623
376
Item_result Field::result_merge_type(enum_field_types field_type)
624
377
{
625
 
  assert(field_type < enum_field_types_size);
 
378
  assert(field_type <= DRIZZLE_TYPE_MAX);
626
379
  return field_types_result_type[field_type];
627
380
}
628
381
 
642
395
  return pack_length();
643
396
}
644
397
 
 
398
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
 
399
{
 
400
  return field_metadata;
 
401
}
 
402
 
 
403
uint32_t Field::row_pack_length()
 
404
{
 
405
  return 0;
 
406
}
 
407
 
 
408
int Field::save_field_metadata(unsigned char *first_byte)
 
409
{
 
410
  return do_save_field_metadata(first_byte);
 
411
}
 
412
 
645
413
uint32_t Field::data_length()
646
414
{
647
415
  return pack_length();
673
441
 
674
442
void Field::set_default()
675
443
{
676
 
  ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->getInsertRecord());
 
444
  ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->record[0]);
677
445
  memcpy(ptr, ptr + l_offset, pack_length());
678
446
  if (null_ptr)
679
447
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
758
526
{
759
527
  if (! null_ptr)
760
528
    return false;
761
 
  return test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
 
529
  return test(record[(uint32_t) (null_ptr -table->record[0])] & null_bit);
762
530
}
763
531
 
764
532
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset)
819
587
void Field::init(Table *table_arg)
820
588
{
821
589
  orig_table= table= table_arg;
 
590
  table_name= &table_arg->alias;
 
591
}
 
592
 
 
593
String *Field::val_int_as_str(String *val_buffer, bool unsigned_val)
 
594
{
 
595
  const CHARSET_INFO * const cs= &my_charset_bin;
 
596
  uint32_t length;
 
597
  int64_t value= val_int();
 
598
 
 
599
  if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
 
600
    return 0;
 
601
  length= (uint32_t) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
 
602
                                                MY_INT64_NUM_DECIMAL_DIGITS,
 
603
                                                unsigned_val ? 10 : -10,
 
604
                                                value);
 
605
  val_buffer->length(length);
 
606
  return val_buffer;
822
607
}
823
608
 
824
609
/// This is used as a table name when the table structure is not set up
827
612
             unsigned char *null_ptr_arg,
828
613
             unsigned char null_bit_arg,
829
614
             utype unireg_check_arg, 
830
 
             const char *field_name_arg) :
 
615
             const char *field_name_arg)
 
616
  :
831
617
    ptr(ptr_arg),
832
618
    null_ptr(null_ptr_arg),
833
619
    table(NULL),
834
620
    orig_table(NULL),
 
621
    table_name(NULL),
835
622
    field_name(field_name_arg),
836
 
    comment(NULL_LEX_STRING),
837
623
    key_start(0),
838
624
    part_of_key(0),
839
625
    part_of_key_not_clustered(0),
840
626
    part_of_sortkey(0),
841
627
    unireg_check(unireg_check_arg),
842
628
    field_length(length_arg),
843
 
    flags(null_ptr ? 0: NOT_NULL_FLAG),
844
 
    field_index(0),
845
629
    null_bit(null_bit_arg),
846
630
    is_created_from_null_item(false)
847
631
{
 
632
  flags= null_ptr ? 0: NOT_NULL_FLAG;
 
633
  comment.str= (char*) "";
 
634
  comment.length= 0;
 
635
  field_index= 0;
848
636
}
849
637
 
850
638
void Field::hash(uint32_t *nr, uint32_t *nr2)
873
661
  }
874
662
}
875
663
 
876
 
int Field::store_and_check(enum_check_fields check_level,
877
 
                           const char *to, 
878
 
                           uint32_t length,
879
 
                           const CHARSET_INFO * const cs)
 
664
int Field::compatible_field_size(uint32_t field_metadata)
 
665
{
 
666
  uint32_t const source_size= pack_length_from_metadata(field_metadata);
 
667
  uint32_t const destination_size= row_pack_length();
 
668
  return (source_size <= destination_size);
 
669
}
880
670
 
 
671
int Field::store(const char *to, 
 
672
                 uint32_t length,
 
673
                 const CHARSET_INFO * const cs,
 
674
                 enum_check_fields check_level)
881
675
{
882
676
  int res;
883
677
  enum_check_fields old_check_level= table->in_use->count_cuted_fields;
897
691
 
898
692
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
899
693
{
900
 
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->getShare()->db_low_byte_first);
 
694
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->s->db_low_byte_first);
901
695
  return(result);
902
696
}
903
697
 
935
729
 
936
730
const unsigned char *Field::unpack(unsigned char* to, const unsigned char *from)
937
731
{
938
 
  const unsigned char *result= unpack(to, from, 0U, table->getShare()->db_low_byte_first);
 
732
  const unsigned char *result= unpack(to, from, 0U, table->s->db_low_byte_first);
939
733
  return(result);
940
734
}
941
735
 
942
 
type::Decimal *Field::val_decimal(type::Decimal *)
 
736
uint32_t Field::packed_col_length(const unsigned char *, uint32_t length)
 
737
{
 
738
  return length;
 
739
}
 
740
 
 
741
int Field::pack_cmp(const unsigned char *a, const unsigned char *b,
 
742
                    uint32_t, bool)
 
743
{
 
744
  return cmp(a,b);
 
745
}
 
746
 
 
747
int Field::pack_cmp(const unsigned char *b, uint32_t, bool)
 
748
{
 
749
  return cmp(ptr,b);
 
750
}
 
751
 
 
752
my_decimal *Field::val_decimal(my_decimal *)
943
753
{
944
754
  /* This never have to be called */
945
755
  assert(0);
949
759
 
950
760
void Field::make_field(SendField *field)
951
761
{
952
 
  if (orig_table && orig_table->getShare()->getSchemaName() && *orig_table->getShare()->getSchemaName())
 
762
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
953
763
  {
954
 
    field->db_name= orig_table->getShare()->getSchemaName();
955
 
    field->org_table_name= orig_table->getShare()->getTableName();
 
764
    field->db_name= orig_table->s->db.str;
 
765
    field->org_table_name= orig_table->s->table_name.str;
956
766
  }
957
767
  else
958
768
    field->org_table_name= field->db_name= "";
959
769
  if (orig_table)
960
770
  {
961
 
    field->table_name= orig_table->getAlias();
 
771
    field->table_name= orig_table->alias;
962
772
    field->org_col_name= field_name;
963
773
  }
964
774
  else
974
784
  field->decimals= 0;
975
785
}
976
786
 
977
 
int64_t Field::convert_decimal2int64_t(const type::Decimal *val, bool, int *err)
 
787
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
978
788
{
979
789
  int64_t i;
980
 
  if (warn_if_overflow(val->val_int32(E_DEC_ERROR &
 
790
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
981
791
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
982
 
                                      false, &i)))
 
792
                                      val, false, &i)))
983
793
  {
984
794
    i= (val->sign() ? INT64_MIN : INT64_MAX);
985
795
    *err= 1;
987
797
  return i;
988
798
}
989
799
 
990
 
uint32_t Field::fill_cache_field(CacheField *copy)
 
800
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
991
801
{
992
802
  uint32_t store_length;
993
803
  copy->str=ptr;
997
807
  {
998
808
    copy->blob_field=(Field_blob*) this;
999
809
    copy->strip=0;
1000
 
    copy->length-= table->getShare()->sizeBlobPtr();
 
810
    copy->length-= table->s->blob_ptr_size;
1001
811
    return copy->length;
1002
812
  }
1003
813
  else
1008
818
  return copy->length+ store_length;
1009
819
}
1010
820
 
1011
 
bool Field::get_date(type::Time &ltime, uint32_t fuzzydate)
1012
 
{
1013
 
  char buff[type::Time::MAX_STRING_LENGTH];
1014
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1015
 
 
1016
 
  assert(getTable() and getTable()->getSession());
1017
 
 
1018
 
  if (not (res=val_str_internal(&tmp)) or
1019
 
      str_to_datetime_with_warn(getTable()->getSession(),
1020
 
                                res->ptr(), res->length(),
1021
 
                                &ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
1022
 
  {
1023
 
    return true;
1024
 
  }
1025
 
 
1026
 
  return false;
1027
 
}
1028
 
 
1029
 
bool Field::get_time(type::Time &ltime)
1030
 
{
1031
 
  char buff[type::Time::MAX_STRING_LENGTH];
1032
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1033
 
 
1034
 
  if (not (res= val_str_internal(&tmp)) or
1035
 
      str_to_time_with_warn(getTable()->getSession(), res->ptr(), res->length(), &ltime))
1036
 
  {
1037
 
    return true;
1038
 
  }
1039
 
 
1040
 
  return false;
1041
 
}
1042
 
 
1043
 
int Field::store_time(type::Time &ltime, type::timestamp_t)
1044
 
{
1045
 
  String tmp;
1046
 
 
1047
 
  ltime.convert(tmp);
1048
 
 
1049
 
  return store(tmp.ptr(), tmp.length(), &my_charset_bin);
1050
 
}
1051
 
 
1052
 
bool Field::optimize_range(uint32_t idx, uint32_t)
1053
 
{
1054
 
  return test(table->index_flags(idx) & HA_READ_RANGE);
1055
 
}
1056
 
 
1057
 
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
 
821
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
822
{
 
823
  char buff[40];
 
824
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
 
825
  if (!(res=val_str(&tmp)) ||
 
826
      str_to_datetime_with_warn(res->ptr(), res->length(),
 
827
                                ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
 
828
    return 1;
 
829
  return 0;
 
830
}
 
831
 
 
832
bool Field::get_time(DRIZZLE_TIME *ltime)
 
833
{
 
834
  char buff[40];
 
835
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
 
836
  if (!(res=val_str(&tmp)) ||
 
837
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
 
838
    return 1;
 
839
  return 0;
 
840
}
 
841
 
 
842
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
 
843
{
 
844
  char buff[MAX_DATE_STRING_REP_LENGTH];
 
845
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
 
846
  return store(buff, length, &my_charset_bin);
 
847
}
 
848
 
 
849
bool Field::optimize_range(uint32_t idx, uint32_t part)
 
850
{
 
851
  return test(table->cursor->index_flags(idx, part, 1) & HA_READ_RANGE);
 
852
}
 
853
 
 
854
Field *Field::new_field(MEM_ROOT *root, Table *new_table, bool)
1058
855
{
1059
856
  Field *tmp;
1060
 
  if (!(tmp= (Field*) root->memdup_root((char*) this,size_of())))
 
857
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1061
858
    return 0;
1062
859
 
1063
860
  if (tmp->table->maybe_null)
1067
864
  tmp->part_of_key.reset();
1068
865
  tmp->part_of_sortkey.reset();
1069
866
  tmp->unireg_check= Field::NONE;
1070
 
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
 
867
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
1071
868
  tmp->reset_fields();
1072
869
  return tmp;
1073
870
}
1074
871
 
1075
 
Field *Field::new_key_field(memory::Root *root, Table *new_table,
 
872
Field *Field::new_key_field(MEM_ROOT *root, Table *new_table,
1076
873
                            unsigned char *new_ptr,
1077
874
                            unsigned char *new_null_ptr,
1078
875
                            uint32_t new_null_bit)
1087
884
  return tmp;
1088
885
}
1089
886
 
1090
 
Field *Field::clone(memory::Root *root, Table *new_table)
 
887
Field *Field::clone(MEM_ROOT *root, Table *new_table)
1091
888
{
1092
889
  Field *tmp;
1093
 
  if ((tmp= (Field*) root->memdup_root((char*) this,size_of())))
 
890
  if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1094
891
  {
1095
892
    tmp->init(new_table);
1096
 
    tmp->move_field_offset((ptrdiff_t) (new_table->getInsertRecord() -
1097
 
                                           new_table->getDefaultValues()));
 
893
    tmp->move_field_offset((ptrdiff_t) (new_table->record[0] -
 
894
                                           new_table->s->default_values));
1098
895
  }
1099
896
  return tmp;
1100
897
}
1117
914
{
1118
915
  if (!Field::eq_def(field))
1119
916
    return 0;
1120
 
 
1121
917
  TYPELIB *from_lib=((Field_enum*) field)->typelib;
1122
918
 
1123
919
  if (typelib->count < from_lib->count)
1124
920
    return 0;
1125
 
 
1126
921
  for (uint32_t i=0 ; i < from_lib->count ; i++)
1127
 
  {
1128
922
    if (my_strnncoll(field_charset,
1129
923
                     (const unsigned char*)typelib->type_names[i],
1130
924
                     strlen(typelib->type_names[i]),
1131
925
                     (const unsigned char*)from_lib->type_names[i],
1132
926
                     strlen(from_lib->type_names[i])))
1133
927
      return 0;
1134
 
  }
1135
 
 
1136
928
  return 1;
1137
929
}
1138
930
 
 
931
/*
 
932
  Make a field from the .frm file info
 
933
*/
1139
934
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
1140
935
{
1141
936
  switch (type) {
1142
937
  case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
1143
 
  case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
1144
 
  case DRIZZLE_TYPE_MICROTIME: return field::Microtime::max_string_length();
1145
 
  case DRIZZLE_TYPE_TIMESTAMP: return field::Epoch::max_string_length();
1146
 
  case DRIZZLE_TYPE_BOOLEAN: return field::Boolean::max_string_length();
1147
 
  case DRIZZLE_TYPE_DATE:
1148
 
  case DRIZZLE_TYPE_ENUM:
 
938
  case DRIZZLE_TYPE_DATE: return 3;
 
939
  case DRIZZLE_TYPE_TIMESTAMP:
1149
940
  case DRIZZLE_TYPE_LONG: return 4;
1150
941
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1151
 
  case DRIZZLE_TYPE_TIME:
1152
942
  case DRIZZLE_TYPE_DATETIME:
1153
943
  case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
1154
944
  case DRIZZLE_TYPE_NULL: return 0;
1155
945
  case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
 
946
  case DRIZZLE_TYPE_ENUM:
1156
947
  case DRIZZLE_TYPE_DECIMAL:
1157
 
                          break;
 
948
    abort();
 
949
  default:
 
950
    return 0;
1158
951
  }
1159
 
 
1160
 
  assert(0);
1161
 
  abort();
1162
952
}
1163
953
 
1164
954
uint32_t pack_length_to_packflag(uint32_t type)
1167
957
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
1168
958
    case 2: assert(1);
1169
959
    case 3: assert(1);
1170
 
    case 4: return f_settype(DRIZZLE_TYPE_LONG);
1171
 
    case 8: return f_settype(DRIZZLE_TYPE_LONGLONG);
 
960
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
 
961
    case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
1172
962
  }
1173
963
  return 0;                                     // This shouldn't happen
1174
964
}
1175
965
 
 
966
Field *make_field(TableShare *share,
 
967
                  MEM_ROOT *root,
 
968
                  unsigned char *ptr,
 
969
                  uint32_t field_length,
 
970
                  bool is_nullable,
 
971
                  unsigned char *null_pos,
 
972
                  unsigned char null_bit,
 
973
                  uint8_t decimals,
 
974
                  enum_field_types field_type,
 
975
                  const CHARSET_INFO * field_charset,
 
976
                  Field::utype unireg_check,
 
977
                  TYPELIB *interval,
 
978
                  const char *field_name)
 
979
{
 
980
  if(! root)
 
981
    root= current_mem_root();
 
982
 
 
983
  if (! is_nullable)
 
984
  {
 
985
    null_pos=0;
 
986
    null_bit=0;
 
987
  }
 
988
  else
 
989
  {
 
990
    null_bit= ((unsigned char) 1) << null_bit;
 
991
  }
 
992
 
 
993
  switch (field_type) 
 
994
  {
 
995
  case DRIZZLE_TYPE_DATE:
 
996
  case DRIZZLE_TYPE_DATETIME:
 
997
  case DRIZZLE_TYPE_TIMESTAMP:
 
998
    field_charset= &my_charset_bin;
 
999
  default: break;
 
1000
  }
 
1001
 
 
1002
  if (field_type == DRIZZLE_TYPE_VARCHAR ||
 
1003
      field_type == DRIZZLE_TYPE_BLOB ||
 
1004
      field_type == DRIZZLE_TYPE_ENUM)
 
1005
  {
 
1006
    if (field_type == DRIZZLE_TYPE_VARCHAR)
 
1007
      return new (root) Field_varstring(ptr,field_length,
 
1008
                                  HA_VARCHAR_PACKLENGTH(field_length),
 
1009
                                  null_pos,null_bit,
 
1010
                                  field_name,
 
1011
                                  share,
 
1012
                                  field_charset);
 
1013
 
 
1014
    if (field_type == DRIZZLE_TYPE_BLOB)
 
1015
    {
 
1016
      return new (root) Field_blob(ptr,
 
1017
                                   null_pos,
 
1018
                                   null_bit,
 
1019
                                   field_name,
 
1020
                                   share,
 
1021
                                   calc_pack_length(DRIZZLE_TYPE_LONG, 0),
 
1022
                                   field_charset);
 
1023
    }
 
1024
 
 
1025
    if (interval)
 
1026
    {
 
1027
      return new (root) Field_enum(ptr,
 
1028
                                   field_length,
 
1029
                                   null_pos,
 
1030
                                   null_bit,
 
1031
                                   field_name,
 
1032
                                   get_enum_pack_length(interval->count),
 
1033
                                   interval,
 
1034
                                   field_charset);
 
1035
    }
 
1036
  }
 
1037
 
 
1038
  switch (field_type)
 
1039
  {
 
1040
  case DRIZZLE_TYPE_DECIMAL:
 
1041
    return new (root) Field_decimal(ptr,
 
1042
                                    field_length,
 
1043
                                    null_pos,
 
1044
                                    null_bit,
 
1045
                                    unireg_check,
 
1046
                                    field_name,
 
1047
                                    decimals,
 
1048
                                    false,
 
1049
                                    false /* is_unsigned */);
 
1050
  case DRIZZLE_TYPE_DOUBLE:
 
1051
    return new (root) Field_double(ptr,
 
1052
                                   field_length,
 
1053
                                   null_pos,
 
1054
                                   null_bit,
 
1055
                                   unireg_check,
 
1056
                                   field_name,
 
1057
                                   decimals,
 
1058
                                   false,
 
1059
                                   false /* is_unsigned */);
 
1060
  case DRIZZLE_TYPE_LONG:
 
1061
    return new (root) Field_long(ptr,
 
1062
                                 field_length,
 
1063
                                 null_pos,
 
1064
                                 null_bit,
 
1065
                                 unireg_check,
 
1066
                                 field_name,
 
1067
                                 false,
 
1068
                                 false /* is_unsigned */);
 
1069
  case DRIZZLE_TYPE_LONGLONG:
 
1070
    return new (root) Field_int64_t(ptr,
 
1071
                                    field_length,
 
1072
                                    null_pos,
 
1073
                                    null_bit,
 
1074
                                    unireg_check,
 
1075
                                    field_name,
 
1076
                                    false,
 
1077
                                    false /* is_unsigned */);
 
1078
  case DRIZZLE_TYPE_TIMESTAMP:
 
1079
    return new (root) Field_timestamp(ptr,
 
1080
                                      field_length,
 
1081
                                      null_pos,
 
1082
                                      null_bit,
 
1083
                                      unireg_check,
 
1084
                                      field_name,
 
1085
                                      share,
 
1086
                                      field_charset);
 
1087
  case DRIZZLE_TYPE_DATE:
 
1088
    return new (root) Field_date(ptr,
 
1089
                                 null_pos,
 
1090
                                 null_bit,
 
1091
                                 field_name,
 
1092
                                 field_charset);
 
1093
  case DRIZZLE_TYPE_DATETIME:
 
1094
    return new (root) Field_datetime(ptr,
 
1095
                                     null_pos,
 
1096
                                     null_bit,
 
1097
                                     field_name,
 
1098
                                     field_charset);
 
1099
  case DRIZZLE_TYPE_NULL:
 
1100
    return new (root) Field_null(ptr,
 
1101
                                 field_length,
 
1102
                                 field_name,
 
1103
                                 field_charset);
 
1104
  default: // Impossible (Wrong version)
 
1105
    break;
 
1106
  }
 
1107
  return 0;
 
1108
}
 
1109
 
1176
1110
/*****************************************************************************
1177
1111
 Warning handling
1178
1112
*****************************************************************************/
1179
1113
 
1180
1114
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
1181
 
                        drizzled::error_t code,
 
1115
                        uint32_t code,
1182
1116
                        int cuted_increment)
1183
1117
{
1184
1118
  /*
1198
1132
 
1199
1133
 
1200
1134
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1201
 
                                 drizzled::error_t code,
 
1135
                                 unsigned int code,
1202
1136
                                 const char *str, 
1203
1137
                                 uint32_t str_length,
1204
 
                                 type::timestamp_t ts_type, 
 
1138
                                 enum enum_drizzle_timestamp_type ts_type, 
1205
1139
                                 int cuted_increment)
1206
1140
{
1207
 
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1208
 
 
1209
 
  if ((session->abortOnWarning() and
 
1141
  Session *session= table ? table->in_use : current_session;
 
1142
  if ((session->really_abort_on_warning() &&
1210
1143
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
1211
1144
      set_warning(level, code, cuted_increment))
1212
1145
    make_truncated_value_warning(session, level, str, str_length, ts_type,
1214
1147
}
1215
1148
 
1216
1149
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
1217
 
                                 drizzled::error_t code,
 
1150
                                 uint32_t code,
1218
1151
                                 int64_t nr, 
1219
 
                                 type::timestamp_t ts_type,
 
1152
                                 enum enum_drizzle_timestamp_type ts_type,
1220
1153
                                 int cuted_increment)
1221
1154
{
1222
 
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1223
 
 
1224
 
  if (session->abortOnWarning() or
 
1155
  Session *session= table ? table->in_use : current_session;
 
1156
  if (session->really_abort_on_warning() ||
1225
1157
      set_warning(level, code, cuted_increment))
1226
1158
  {
1227
 
    char str_nr[DECIMAL_LONGLONG_DIGITS];
1228
 
    char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
 
1159
    char str_nr[22];
 
1160
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
1229
1161
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
1230
1162
                                 ts_type, field_name);
1231
1163
  }
1232
1164
}
1233
1165
 
1234
1166
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1235
 
                                 const drizzled::error_t code,
 
1167
                                 const uint32_t code,
1236
1168
                                 double nr, 
1237
 
                                 type::timestamp_t ts_type)
 
1169
                                 enum enum_drizzle_timestamp_type ts_type)
1238
1170
{
1239
 
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1240
 
 
1241
 
  if (session->abortOnWarning() or
 
1171
  Session *session= table ? table->in_use : current_session;
 
1172
  if (session->really_abort_on_warning() ||
1242
1173
      set_warning(level, code, 1))
1243
1174
  {
1244
1175
    /* DBL_DIG is enough to print '-[digits].E+###' */
1245
1176
    char str_nr[DBL_DIG + 8];
1246
 
    uint32_t str_len= snprintf(str_nr, sizeof(str_nr), "%g", nr);
 
1177
    uint32_t str_len= sprintf(str_nr, "%g", nr);
1247
1178
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
1248
1179
                                 field_name);
1249
1180
  }
1274
1205
  else
1275
1206
    table->clearWriteSet(field_index);
1276
1207
}
1277
 
 
1278
 
void Field::pack_num(uint64_t arg, unsigned char *destination)
1279
 
{
1280
 
  if (not destination)
1281
 
    destination= ptr;
1282
 
 
1283
 
  int64_tstore(destination, arg);
1284
 
}
1285
 
 
1286
 
void Field::pack_num(uint32_t arg, unsigned char *destination)
1287
 
{
1288
 
  if (not destination)
1289
 
    destination= ptr;
1290
 
 
1291
 
  longstore(destination, arg);
1292
 
}
1293
 
 
1294
 
uint64_t Field::unpack_num(uint64_t &destination, const unsigned char *arg) const
1295
 
{
1296
 
  if (not arg)
1297
 
    arg= ptr;
1298
 
 
1299
 
  int64_tget(destination, arg);
1300
 
 
1301
 
  return destination;
1302
 
}
1303
 
 
1304
 
uint32_t Field::unpack_num(uint32_t &destination, const unsigned char *arg) const
1305
 
{
1306
 
  if (not arg)
1307
 
    arg= ptr;
1308
 
 
1309
 
  longget(destination, arg);
1310
 
 
1311
 
  return destination;
1312
 
}
1313
 
 
1314
 
std::ostream& operator<<(std::ostream& output, const Field &field)
1315
 
{
1316
 
  output << "Field:(";
1317
 
  output <<  field.field_name;
1318
 
  output << ", ";
1319
 
  output << drizzled::display::type(field.real_type());
1320
 
  output << ", { ";
1321
 
 
1322
 
  if (field.flags & NOT_NULL_FLAG)
1323
 
    output << " NOT_NULL";
1324
 
 
1325
 
  if (field.flags & PRI_KEY_FLAG)
1326
 
    output << ", PRIMARY KEY";
1327
 
 
1328
 
  if (field.flags & UNIQUE_KEY_FLAG)
1329
 
    output << ", UNIQUE KEY";
1330
 
 
1331
 
  if (field.flags & MULTIPLE_KEY_FLAG)
1332
 
    output << ", MULTIPLE KEY";
1333
 
 
1334
 
  if (field.flags & BLOB_FLAG)
1335
 
    output << ", BLOB";
1336
 
 
1337
 
  if (field.flags & UNSIGNED_FLAG)
1338
 
    output << ", UNSIGNED";
1339
 
 
1340
 
  if (field.flags & BINARY_FLAG)
1341
 
    output << ", BINARY";
1342
 
  output << "}, ";
1343
 
  output << ")";
1344
 
 
1345
 
  return output;  // for multiple << operators.
1346
 
}
1347
 
 
1348
 
} /* namespace drizzled */