~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

Fixed the clock_gettime test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 */
24
24
 
25
25
#include "config.h"
26
 
#include <cstdio>
27
26
#include <errno.h>
28
27
#include <float.h>
29
28
#include "drizzled/sql_select.h"
37
36
#include "drizzled/field/decimal.h"
38
37
#include "drizzled/field/real.h"
39
38
#include "drizzled/field/double.h"
40
 
#include "drizzled/field/int32.h"
41
 
#include "drizzled/field/int64.h"
 
39
#include "drizzled/field/long.h"
 
40
#include "drizzled/field/int64_t.h"
42
41
#include "drizzled/field/num.h"
43
42
#include "drizzled/field/timestamp.h"
44
43
#include "drizzled/field/datetime.h"
45
44
#include "drizzled/field/varstring.h"
46
 
#include "drizzled/field/uuid.h"
47
45
#include "drizzled/time_functions.h"
48
46
#include "drizzled/internal/m_string.h"
49
47
 
50
 
#include "drizzled/display.h"
51
 
 
52
 
namespace drizzled
53
 
{
 
48
using namespace drizzled;
54
49
 
55
50
/*****************************************************************************
56
51
  Instansiate templates and static variables
57
52
*****************************************************************************/
58
53
 
59
54
static enum_field_types
60
 
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]=
61
56
{
62
57
  /* DRIZZLE_TYPE_LONG -> */
63
58
  {
83
78
    DRIZZLE_TYPE_VARCHAR,
84
79
    //DRIZZLE_TYPE_BLOB
85
80
    DRIZZLE_TYPE_BLOB,
86
 
    //DRIZZLE_TYPE_UUID
87
 
    DRIZZLE_TYPE_VARCHAR,
88
81
  },
89
82
  /* DRIZZLE_TYPE_DOUBLE -> */
90
83
  {
110
103
    DRIZZLE_TYPE_VARCHAR,
111
104
    //DRIZZLE_TYPE_BLOB
112
105
    DRIZZLE_TYPE_BLOB,
113
 
    //DRIZZLE_TYPE_UUID
114
 
    DRIZZLE_TYPE_VARCHAR,
115
106
  },
116
107
  /* DRIZZLE_TYPE_NULL -> */
117
108
  {
137
128
    DRIZZLE_TYPE_ENUM,
138
129
    //DRIZZLE_TYPE_BLOB
139
130
    DRIZZLE_TYPE_BLOB,
140
 
    //DRIZZLE_TYPE_UUID
141
 
    DRIZZLE_TYPE_UUID,
142
131
  },
143
132
  /* DRIZZLE_TYPE_TIMESTAMP -> */
144
133
  {
164
153
    DRIZZLE_TYPE_VARCHAR,
165
154
    //DRIZZLE_TYPE_BLOB
166
155
    DRIZZLE_TYPE_BLOB,
167
 
    //DRIZZLE_TYPE_UUID
168
 
    DRIZZLE_TYPE_VARCHAR,
169
156
  },
170
157
  /* DRIZZLE_TYPE_LONGLONG -> */
171
158
  {
190
177
    DRIZZLE_TYPE_VARCHAR,
191
178
    //DRIZZLE_TYPE_BLOB
192
179
    DRIZZLE_TYPE_BLOB,
193
 
    //DRIZZLE_TYPE_UUID
194
 
    DRIZZLE_TYPE_VARCHAR,
195
180
  },
196
181
  /* DRIZZLE_TYPE_DATETIME -> */
197
182
  {
217
202
    DRIZZLE_TYPE_VARCHAR,
218
203
    //DRIZZLE_TYPE_BLOB
219
204
    DRIZZLE_TYPE_BLOB,
220
 
    //DRIZZLE_TYPE_UUID
221
 
    DRIZZLE_TYPE_VARCHAR,
222
205
  },
223
206
  /* DRIZZLE_TYPE_DATE -> */
224
207
  {
244
227
    DRIZZLE_TYPE_VARCHAR,
245
228
    //DRIZZLE_TYPE_BLOB
246
229
    DRIZZLE_TYPE_BLOB,
247
 
    //DRIZZLE_TYPE_UUID
248
 
    DRIZZLE_TYPE_VARCHAR,
249
230
  },
250
231
  /* DRIZZLE_TYPE_VARCHAR -> */
251
232
  {
271
252
    DRIZZLE_TYPE_VARCHAR,
272
253
    //DRIZZLE_TYPE_BLOB
273
254
    DRIZZLE_TYPE_BLOB,
274
 
    //DRIZZLE_TYPE_UUID
275
 
    DRIZZLE_TYPE_VARCHAR,
276
255
  },
277
256
  /* DRIZZLE_TYPE_DECIMAL -> */
278
257
  {
298
277
    DRIZZLE_TYPE_VARCHAR,
299
278
    //DRIZZLE_TYPE_BLOB
300
279
    DRIZZLE_TYPE_BLOB,
301
 
    //DRIZZLE_TYPE_UUID
302
 
    DRIZZLE_TYPE_VARCHAR,
303
280
  },
304
281
  /* DRIZZLE_TYPE_ENUM -> */
305
282
  {
325
302
    DRIZZLE_TYPE_VARCHAR,
326
303
    //DRIZZLE_TYPE_BLOB
327
304
    DRIZZLE_TYPE_BLOB,
328
 
    //DRIZZLE_TYPE_UUID
329
 
    DRIZZLE_TYPE_VARCHAR,
330
 
   },
 
305
  },
331
306
  /* DRIZZLE_TYPE_BLOB -> */
332
307
  {
333
308
    //DRIZZLE_TYPE_LONG
352
327
    DRIZZLE_TYPE_BLOB,
353
328
    //DRIZZLE_TYPE_BLOB
354
329
    DRIZZLE_TYPE_BLOB,
355
 
    //DRIZZLE_TYPE_UUID
356
 
    DRIZZLE_TYPE_VARCHAR,
357
 
  },
358
 
  /* DRIZZLE_TYPE_UUID -> */
359
 
  {
360
 
    //DRIZZLE_TYPE_LONG
361
 
    DRIZZLE_TYPE_VARCHAR,
362
 
    //DRIZZLE_TYPE_DOUBLE
363
 
    DRIZZLE_TYPE_VARCHAR,
364
 
    //DRIZZLE_TYPE_NULL
365
 
    DRIZZLE_TYPE_UUID,
366
 
    //DRIZZLE_TYPE_TIMESTAMP
367
 
    DRIZZLE_TYPE_VARCHAR,
368
 
    //DRIZZLE_TYPE_LONGLONG
369
 
    DRIZZLE_TYPE_VARCHAR,
370
 
    //DRIZZLE_TYPE_DATETIME
371
 
    DRIZZLE_TYPE_VARCHAR,
372
 
    //DRIZZLE_TYPE_DATE
373
 
    DRIZZLE_TYPE_VARCHAR,
374
 
    //DRIZZLE_TYPE_VARCHAR
375
 
    DRIZZLE_TYPE_VARCHAR,
376
 
    //DRIZZLE_TYPE_DECIMAL
377
 
    DRIZZLE_TYPE_VARCHAR,
378
 
    //DRIZZLE_TYPE_VARCHAR,
379
 
    DRIZZLE_TYPE_VARCHAR,
380
 
    //DRIZZLE_TYPE_BLOB
381
 
    DRIZZLE_TYPE_BLOB,
382
 
    //DRIZZLE_TYPE_UUID
383
 
    DRIZZLE_TYPE_UUID,
384
330
  },
385
331
};
386
332
 
387
 
static Item_result field_types_result_type [enum_field_types_size]=
 
333
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
388
334
{
389
335
  //DRIZZLE_TYPE_LONG
390
336
  INT_RESULT,
408
354
  STRING_RESULT,
409
355
  //DRIZZLE_TYPE_BLOB
410
356
  STRING_RESULT,
411
 
  //DRIZZLE_TYPE_UUID
412
 
  STRING_RESULT,
413
357
};
414
358
 
415
359
bool test_if_important_data(const CHARSET_INFO * const cs, 
428
372
 
429
373
void *Field::operator new(size_t size, memory::Root *mem_root)
430
374
{
431
 
  return mem_root->alloc_root(static_cast<uint32_t>(size));
 
375
  return alloc_root(mem_root, static_cast<uint32_t>(size));
432
376
}
433
377
 
434
378
enum_field_types Field::field_type_merge(enum_field_types a,
435
379
                                         enum_field_types b)
436
380
{
437
 
  assert(a < enum_field_types_size);
438
 
  assert(b < enum_field_types_size);
 
381
  assert(a <= DRIZZLE_TYPE_MAX);
 
382
  assert(b <= DRIZZLE_TYPE_MAX);
439
383
  return field_types_merge_rules[a][b];
440
384
}
441
385
 
442
386
Item_result Field::result_merge_type(enum_field_types field_type)
443
387
{
444
 
  assert(field_type < enum_field_types_size);
 
388
  assert(field_type <= DRIZZLE_TYPE_MAX);
445
389
  return field_types_result_type[field_type];
446
390
}
447
391
 
461
405
  return pack_length();
462
406
}
463
407
 
 
408
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
 
409
{
 
410
  return field_metadata;
 
411
}
 
412
 
 
413
uint32_t Field::row_pack_length()
 
414
{
 
415
  return 0;
 
416
}
 
417
 
464
418
uint32_t Field::data_length()
465
419
{
466
420
  return pack_length();
492
446
 
493
447
void Field::set_default()
494
448
{
495
 
  ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->getInsertRecord());
 
449
  ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->record[0]);
496
450
  memcpy(ptr, ptr + l_offset, pack_length());
497
451
  if (null_ptr)
498
452
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
577
531
{
578
532
  if (! null_ptr)
579
533
    return false;
580
 
  return test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
 
534
  return test(record[(uint32_t) (null_ptr -table->record[0])] & null_bit);
581
535
}
582
536
 
583
537
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset)
638
592
void Field::init(Table *table_arg)
639
593
{
640
594
  orig_table= table= table_arg;
 
595
  table_name= &table_arg->alias;
 
596
}
 
597
 
 
598
String *Field::val_int_as_str(String *val_buffer, bool unsigned_val)
 
599
{
 
600
  const CHARSET_INFO * const cs= &my_charset_bin;
 
601
  uint32_t length;
 
602
  int64_t value= val_int();
 
603
 
 
604
  if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
 
605
    return 0;
 
606
  length= (uint32_t) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
 
607
                                                MY_INT64_NUM_DECIMAL_DIGITS,
 
608
                                                unsigned_val ? 10 : -10,
 
609
                                                value);
 
610
  val_buffer->length(length);
 
611
  return val_buffer;
641
612
}
642
613
 
643
614
/// This is used as a table name when the table structure is not set up
652
623
    null_ptr(null_ptr_arg),
653
624
    table(NULL),
654
625
    orig_table(NULL),
 
626
    table_name(NULL),
655
627
    field_name(field_name_arg),
656
628
    key_start(0),
657
629
    part_of_key(0),
694
666
  }
695
667
}
696
668
 
697
 
int Field::store_and_check(enum_check_fields check_level,
698
 
                           const char *to, 
699
 
                           uint32_t length,
700
 
                           const CHARSET_INFO * const cs)
 
669
int Field::compatible_field_size(uint32_t field_metadata)
 
670
{
 
671
  uint32_t const source_size= pack_length_from_metadata(field_metadata);
 
672
  uint32_t const destination_size= row_pack_length();
 
673
  return (source_size <= destination_size);
 
674
}
701
675
 
 
676
int Field::store(const char *to, 
 
677
                 uint32_t length,
 
678
                 const CHARSET_INFO * const cs,
 
679
                 enum_check_fields check_level)
702
680
{
703
681
  int res;
704
682
  enum_check_fields old_check_level= table->in_use->count_cuted_fields;
718
696
 
719
697
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
720
698
{
721
 
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->getShare()->db_low_byte_first);
 
699
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->s->db_low_byte_first);
722
700
  return(result);
723
701
}
724
702
 
756
734
 
757
735
const unsigned char *Field::unpack(unsigned char* to, const unsigned char *from)
758
736
{
759
 
  const unsigned char *result= unpack(to, from, 0U, table->getShare()->db_low_byte_first);
 
737
  const unsigned char *result= unpack(to, from, 0U, table->s->db_low_byte_first);
760
738
  return(result);
761
739
}
762
740
 
770
748
 
771
749
void Field::make_field(SendField *field)
772
750
{
773
 
  if (orig_table && orig_table->getShare()->getSchemaName() && *orig_table->getShare()->getSchemaName())
 
751
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
774
752
  {
775
 
    field->db_name= orig_table->getShare()->getSchemaName();
776
 
    field->org_table_name= orig_table->getShare()->getTableName();
 
753
    field->db_name= orig_table->s->db.str;
 
754
    field->org_table_name= orig_table->s->table_name.str;
777
755
  }
778
756
  else
779
757
    field->org_table_name= field->db_name= "";
780
758
  if (orig_table)
781
759
  {
782
 
    field->table_name= orig_table->getAlias();
 
760
    field->table_name= orig_table->alias;
783
761
    field->org_col_name= field_name;
784
762
  }
785
763
  else
808
786
  return i;
809
787
}
810
788
 
811
 
uint32_t Field::fill_cache_field(CacheField *copy)
 
789
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
812
790
{
813
791
  uint32_t store_length;
814
792
  copy->str=ptr;
818
796
  {
819
797
    copy->blob_field=(Field_blob*) this;
820
798
    copy->strip=0;
821
 
    copy->length-= table->getShare()->blob_ptr_size;
 
799
    copy->length-= table->s->blob_ptr_size;
822
800
    return copy->length;
823
801
  }
824
802
  else
833
811
{
834
812
  char buff[40];
835
813
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
836
 
  if (!(res=val_str_internal(&tmp)) || str_to_datetime_with_warn(res->ptr(), res->length(),
837
 
                                                                 ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
838
 
  {
 
814
  if (!(res=val_str(&tmp)) ||
 
815
      str_to_datetime_with_warn(res->ptr(), res->length(),
 
816
                                ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
839
817
    return 1;
840
 
  }
841
 
 
842
818
  return 0;
843
819
}
844
820
 
846
822
{
847
823
  char buff[40];
848
824
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
849
 
 
850
 
  if (!(res=val_str_internal(&tmp)) || str_to_time_with_warn(res->ptr(), res->length(), ltime))
851
 
  {
 
825
  if (!(res=val_str(&tmp)) ||
 
826
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
852
827
    return 1;
853
 
  }
854
 
 
855
828
  return 0;
856
829
}
857
830
 
870
843
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
871
844
{
872
845
  Field *tmp;
873
 
  if (!(tmp= (Field*) root->memdup_root((char*) this,size_of())))
 
846
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
874
847
    return 0;
875
848
 
876
849
  if (tmp->table->maybe_null)
880
853
  tmp->part_of_key.reset();
881
854
  tmp->part_of_sortkey.reset();
882
855
  tmp->unireg_check= Field::NONE;
883
 
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
 
856
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
884
857
  tmp->reset_fields();
885
858
  return tmp;
886
859
}
903
876
Field *Field::clone(memory::Root *root, Table *new_table)
904
877
{
905
878
  Field *tmp;
906
 
  if ((tmp= (Field*) root->memdup_root((char*) this,size_of())))
 
879
  if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
907
880
  {
908
881
    tmp->init(new_table);
909
 
    tmp->move_field_offset((ptrdiff_t) (new_table->getInsertRecord() -
910
 
                                           new_table->getDefaultValues()));
 
882
    tmp->move_field_offset((ptrdiff_t) (new_table->record[0] -
 
883
                                           new_table->s->default_values));
911
884
  }
912
885
  return tmp;
913
886
}
948
921
{
949
922
  switch (type) {
950
923
  case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
951
 
  case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
952
 
  case DRIZZLE_TYPE_DATE:
953
 
  case DRIZZLE_TYPE_ENUM:
 
924
  case DRIZZLE_TYPE_DATE: return 3;
 
925
  case DRIZZLE_TYPE_TIMESTAMP:
954
926
  case DRIZZLE_TYPE_LONG: return 4;
955
927
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
956
928
  case DRIZZLE_TYPE_DATETIME:
957
 
  case DRIZZLE_TYPE_TIMESTAMP:
958
929
  case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
959
930
  case DRIZZLE_TYPE_NULL: return 0;
960
931
  case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
 
932
  case DRIZZLE_TYPE_ENUM:
961
933
  case DRIZZLE_TYPE_DECIMAL:
962
 
                          assert(0);
963
 
                          abort();
 
934
    abort();
 
935
  default:
 
936
    return 0;
964
937
  }
965
 
 
966
 
  assert(0);
967
 
  abort();
968
938
}
969
939
 
970
940
uint32_t pack_length_to_packflag(uint32_t type)
973
943
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
974
944
    case 2: assert(1);
975
945
    case 3: assert(1);
976
 
    case 4: return f_settype(DRIZZLE_TYPE_LONG);
977
 
    case 8: return f_settype(DRIZZLE_TYPE_LONGLONG);
 
946
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
 
947
    case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
978
948
  }
979
949
  return 0;                                     // This shouldn't happen
980
950
}
981
951
 
 
952
Field *make_field(TableShare *share,
 
953
                  memory::Root *root,
 
954
                  unsigned char *ptr,
 
955
                  uint32_t field_length,
 
956
                  bool is_nullable,
 
957
                  unsigned char *null_pos,
 
958
                  unsigned char null_bit,
 
959
                  uint8_t decimals,
 
960
                  enum_field_types field_type,
 
961
                  const CHARSET_INFO * field_charset,
 
962
                  Field::utype unireg_check,
 
963
                  TYPELIB *interval,
 
964
                  const char *field_name)
 
965
{
 
966
  if(! root)
 
967
    root= current_mem_root();
 
968
 
 
969
  if (! is_nullable)
 
970
  {
 
971
    null_pos=0;
 
972
    null_bit=0;
 
973
  }
 
974
  else
 
975
  {
 
976
    null_bit= ((unsigned char) 1) << null_bit;
 
977
  }
 
978
 
 
979
  switch (field_type) 
 
980
  {
 
981
  case DRIZZLE_TYPE_DATE:
 
982
  case DRIZZLE_TYPE_DATETIME:
 
983
  case DRIZZLE_TYPE_TIMESTAMP:
 
984
    field_charset= &my_charset_bin;
 
985
  default: break;
 
986
  }
 
987
 
 
988
  if (field_type == DRIZZLE_TYPE_VARCHAR ||
 
989
      field_type == DRIZZLE_TYPE_BLOB ||
 
990
      field_type == DRIZZLE_TYPE_ENUM)
 
991
  {
 
992
    if (field_type == DRIZZLE_TYPE_VARCHAR)
 
993
      return new (root) Field_varstring(ptr,field_length,
 
994
                                  HA_VARCHAR_PACKLENGTH(field_length),
 
995
                                  null_pos,null_bit,
 
996
                                  field_name,
 
997
                                  share,
 
998
                                  field_charset);
 
999
 
 
1000
    if (field_type == DRIZZLE_TYPE_BLOB)
 
1001
    {
 
1002
      return new (root) Field_blob(ptr,
 
1003
                                   null_pos,
 
1004
                                   null_bit,
 
1005
                                   field_name,
 
1006
                                   share,
 
1007
                                   calc_pack_length(DRIZZLE_TYPE_LONG, 0),
 
1008
                                   field_charset);
 
1009
    }
 
1010
 
 
1011
    if (interval)
 
1012
    {
 
1013
      return new (root) Field_enum(ptr,
 
1014
                                   field_length,
 
1015
                                   null_pos,
 
1016
                                   null_bit,
 
1017
                                   field_name,
 
1018
                                   get_enum_pack_length(interval->count),
 
1019
                                   interval,
 
1020
                                   field_charset);
 
1021
    }
 
1022
  }
 
1023
 
 
1024
  switch (field_type)
 
1025
  {
 
1026
  case DRIZZLE_TYPE_DECIMAL:
 
1027
    return new (root) Field_decimal(ptr,
 
1028
                                    field_length,
 
1029
                                    null_pos,
 
1030
                                    null_bit,
 
1031
                                    unireg_check,
 
1032
                                    field_name,
 
1033
                                    decimals,
 
1034
                                    false,
 
1035
                                    false /* is_unsigned */);
 
1036
  case DRIZZLE_TYPE_DOUBLE:
 
1037
    return new (root) Field_double(ptr,
 
1038
                                   field_length,
 
1039
                                   null_pos,
 
1040
                                   null_bit,
 
1041
                                   unireg_check,
 
1042
                                   field_name,
 
1043
                                   decimals,
 
1044
                                   false,
 
1045
                                   false /* is_unsigned */);
 
1046
  case DRIZZLE_TYPE_LONG:
 
1047
    return new (root) Field_long(ptr,
 
1048
                                 field_length,
 
1049
                                 null_pos,
 
1050
                                 null_bit,
 
1051
                                 unireg_check,
 
1052
                                 field_name,
 
1053
                                 false,
 
1054
                                 false /* is_unsigned */);
 
1055
  case DRIZZLE_TYPE_LONGLONG:
 
1056
    return new (root) Field_int64_t(ptr,
 
1057
                                    field_length,
 
1058
                                    null_pos,
 
1059
                                    null_bit,
 
1060
                                    unireg_check,
 
1061
                                    field_name,
 
1062
                                    false,
 
1063
                                    false /* is_unsigned */);
 
1064
  case DRIZZLE_TYPE_TIMESTAMP:
 
1065
    return new (root) Field_timestamp(ptr,
 
1066
                                      field_length,
 
1067
                                      null_pos,
 
1068
                                      null_bit,
 
1069
                                      unireg_check,
 
1070
                                      field_name,
 
1071
                                      share,
 
1072
                                      field_charset);
 
1073
  case DRIZZLE_TYPE_DATE:
 
1074
    return new (root) Field_date(ptr,
 
1075
                                 null_pos,
 
1076
                                 null_bit,
 
1077
                                 field_name,
 
1078
                                 field_charset);
 
1079
  case DRIZZLE_TYPE_DATETIME:
 
1080
    return new (root) Field_datetime(ptr,
 
1081
                                     null_pos,
 
1082
                                     null_bit,
 
1083
                                     field_name,
 
1084
                                     field_charset);
 
1085
  case DRIZZLE_TYPE_NULL:
 
1086
    return new (root) Field_null(ptr,
 
1087
                                 field_length,
 
1088
                                 field_name,
 
1089
                                 field_charset);
 
1090
  default: // Impossible (Wrong version)
 
1091
    break;
 
1092
  }
 
1093
  return 0;
 
1094
}
 
1095
 
982
1096
/*****************************************************************************
983
1097
 Warning handling
984
1098
*****************************************************************************/
1029
1143
      set_warning(level, code, cuted_increment))
1030
1144
  {
1031
1145
    char str_nr[22];
1032
 
    char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
 
1146
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
1033
1147
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
1034
1148
                                 ts_type, field_name);
1035
1149
  }
1046
1160
  {
1047
1161
    /* DBL_DIG is enough to print '-[digits].E+###' */
1048
1162
    char str_nr[DBL_DIG + 8];
1049
 
    uint32_t str_len= snprintf(str_nr, sizeof(str_nr), "%g", nr);
 
1163
    uint32_t str_len= sprintf(str_nr, "%g", nr);
1050
1164
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
1051
1165
                                 field_name);
1052
1166
  }
1077
1191
  else
1078
1192
    table->clearWriteSet(field_index);
1079
1193
}
1080
 
 
1081
 
std::ostream& operator<<(std::ostream& output, const Field &field)
1082
 
{
1083
 
  output << "Field:(";
1084
 
  output <<  field.field_name;
1085
 
  output << ", ";
1086
 
  output << drizzled::display::type(field.real_type());
1087
 
  output << ")";
1088
 
 
1089
 
  return output;  // for multiple << operators.
1090
 
}
1091
 
 
1092
 
} /* namespace drizzled */