~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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
4
5
 *  Copyright (C) 2008 MySQL
5
6
 *
6
7
 *  This program is free software; you can redistribute it and/or modify
22
23
 * @file This file implements the Field class and API
23
24
 */
24
25
 
25
 
#include "config.h"
 
26
#include <config.h>
26
27
#include <cstdio>
27
28
#include <errno.h>
28
29
#include <float.h>
29
 
#include "drizzled/sql_select.h"
30
 
#include "drizzled/error.h"
31
 
#include "drizzled/field/str.h"
32
 
#include "drizzled/field/num.h"
33
 
#include "drizzled/field/blob.h"
34
 
#include "drizzled/field/enum.h"
35
 
#include "drizzled/field/null.h"
36
 
#include "drizzled/field/date.h"
37
 
#include "drizzled/field/decimal.h"
38
 
#include "drizzled/field/real.h"
39
 
#include "drizzled/field/double.h"
40
 
#include "drizzled/field/int32.h"
41
 
#include "drizzled/field/int64.h"
42
 
#include "drizzled/field/num.h"
43
 
#include "drizzled/field/time.h"
44
 
#include "drizzled/field/epoch.h"
45
 
#include "drizzled/field/datetime.h"
46
 
#include "drizzled/field/varstring.h"
47
 
#include "drizzled/field/uuid.h"
48
 
#include "drizzled/time_functions.h"
49
 
#include "drizzled/internal/m_string.h"
50
 
 
51
 
#include "drizzled/display.h"
 
30
#include <drizzled/sql_select.h>
 
31
#include <drizzled/error.h>
 
32
#include <drizzled/field/str.h>
 
33
#include <drizzled/field/num.h>
 
34
#include <drizzled/field/blob.h>
 
35
#include <drizzled/field/boolean.h>
 
36
#include <drizzled/field/enum.h>
 
37
#include <drizzled/field/null.h>
 
38
#include <drizzled/field/date.h>
 
39
#include <drizzled/field/decimal.h>
 
40
#include <drizzled/field/real.h>
 
41
#include <drizzled/field/double.h>
 
42
#include <drizzled/field/int32.h>
 
43
#include <drizzled/field/int64.h>
 
44
#include <drizzled/field/num.h>
 
45
#include <drizzled/field/time.h>
 
46
#include <drizzled/field/epoch.h>
 
47
#include <drizzled/field/datetime.h>
 
48
#include <drizzled/field/microtime.h>
 
49
#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
#include <drizzled/table.h>
 
54
#include <drizzled/util/test.h>
 
55
#include <drizzled/session.h>
 
56
#include <drizzled/current_session.h>
 
57
#include <drizzled/display.h>
 
58
#include <drizzled/typelib.h>
52
59
 
53
60
namespace drizzled
54
61
{
86
93
    DRIZZLE_TYPE_BLOB,
87
94
    //DRIZZLE_TYPE_TIME
88
95
    DRIZZLE_TYPE_TIME,
 
96
    //DRIZZLE_TYPE_BOOLEAN
 
97
    DRIZZLE_TYPE_VARCHAR,
89
98
    //DRIZZLE_TYPE_UUID
90
99
    DRIZZLE_TYPE_VARCHAR,
 
100
    //DRIZZLE_TYPE_MICROTIME
 
101
    DRIZZLE_TYPE_VARCHAR,
91
102
  },
92
103
  /* DRIZZLE_TYPE_DOUBLE -> */
93
104
  {
115
126
    DRIZZLE_TYPE_BLOB,
116
127
    //DRIZZLE_TYPE_TIME
117
128
    DRIZZLE_TYPE_TIME,
 
129
    //DRIZZLE_TYPE_BOOLEAN
 
130
    DRIZZLE_TYPE_VARCHAR,
118
131
    //DRIZZLE_TYPE_UUID
119
132
    DRIZZLE_TYPE_VARCHAR,
 
133
    //DRIZZLE_TYPE_MICROTIME
 
134
    DRIZZLE_TYPE_VARCHAR,
120
135
  },
121
136
  /* DRIZZLE_TYPE_NULL -> */
122
137
  {
144
159
    DRIZZLE_TYPE_BLOB,
145
160
    //DRIZZLE_TYPE_TIME
146
161
    DRIZZLE_TYPE_TIME,
 
162
    //DRIZZLE_TYPE_BOOLEAN
 
163
    DRIZZLE_TYPE_BOOLEAN,
147
164
    //DRIZZLE_TYPE_UUID
148
165
    DRIZZLE_TYPE_UUID,
 
166
    //DRIZZLE_TYPE_MICROTIME
 
167
    DRIZZLE_TYPE_MICROTIME,
149
168
  },
150
169
  /* DRIZZLE_TYPE_TIMESTAMP -> */
151
170
  {
173
192
    DRIZZLE_TYPE_BLOB,
174
193
    //DRIZZLE_TYPE_TIME
175
194
    DRIZZLE_TYPE_TIME,
 
195
    //DRIZZLE_TYPE_BOOLEAN
 
196
    DRIZZLE_TYPE_VARCHAR,
176
197
    //DRIZZLE_TYPE_UUID
177
198
    DRIZZLE_TYPE_VARCHAR,
 
199
    //DRIZZLE_TYPE_MICROTIME
 
200
    DRIZZLE_TYPE_VARCHAR,
178
201
  },
179
202
  /* DRIZZLE_TYPE_LONGLONG -> */
180
203
  {
201
224
    DRIZZLE_TYPE_BLOB,
202
225
    //DRIZZLE_TYPE_TIME
203
226
    DRIZZLE_TYPE_TIME,
 
227
    //DRIZZLE_TYPE_BOOLEAN
 
228
    DRIZZLE_TYPE_VARCHAR,
204
229
    //DRIZZLE_TYPE_UUID
205
230
    DRIZZLE_TYPE_VARCHAR,
 
231
    //DRIZZLE_TYPE_MICROTIME
 
232
    DRIZZLE_TYPE_VARCHAR,
206
233
  },
207
234
  /* DRIZZLE_TYPE_DATETIME -> */
208
235
  {
230
257
    DRIZZLE_TYPE_BLOB,
231
258
    //DRIZZLE_TYPE_TIME
232
259
    DRIZZLE_TYPE_TIME,
 
260
    //DRIZZLE_TYPE_BOOLEAN
 
261
    DRIZZLE_TYPE_VARCHAR,
233
262
    //DRIZZLE_TYPE_UUID
234
263
    DRIZZLE_TYPE_VARCHAR,
 
264
    //DRIZZLE_TYPE_MICROTIME
 
265
    DRIZZLE_TYPE_VARCHAR,
235
266
  },
236
267
  /* DRIZZLE_TYPE_DATE -> */
237
268
  {
259
290
    DRIZZLE_TYPE_BLOB,
260
291
    //DRIZZLE_TYPE_TIME
261
292
    DRIZZLE_TYPE_TIME,
 
293
    //DRIZZLE_TYPE_BOOLEAN
 
294
    DRIZZLE_TYPE_VARCHAR,
262
295
    //DRIZZLE_TYPE_UUID
263
296
    DRIZZLE_TYPE_VARCHAR,
 
297
    //DRIZZLE_TYPE_MICROTIME
 
298
    DRIZZLE_TYPE_VARCHAR,
264
299
  },
265
300
  /* DRIZZLE_TYPE_VARCHAR -> */
266
301
  {
288
323
    DRIZZLE_TYPE_BLOB,
289
324
    //DRIZZLE_TYPE_TIME
290
325
    DRIZZLE_TYPE_TIME,
 
326
    //DRIZZLE_TYPE_BOOLEAN
 
327
    DRIZZLE_TYPE_VARCHAR,
291
328
    //DRIZZLE_TYPE_UUID
292
329
    DRIZZLE_TYPE_VARCHAR,
 
330
    //DRIZZLE_TYPE_MICROTIME
 
331
    DRIZZLE_TYPE_VARCHAR,
293
332
  },
294
333
  /* DRIZZLE_TYPE_DECIMAL -> */
295
334
  {
317
356
    DRIZZLE_TYPE_BLOB,
318
357
    //DRIZZLE_TYPE_TIME
319
358
    DRIZZLE_TYPE_TIME,
 
359
    //DRIZZLE_TYPE_BOOLEAN
 
360
    DRIZZLE_TYPE_VARCHAR,
320
361
    //DRIZZLE_TYPE_UUID
321
362
    DRIZZLE_TYPE_VARCHAR,
 
363
    //DRIZZLE_TYPE_MICROTIME
 
364
    DRIZZLE_TYPE_VARCHAR,
322
365
  },
323
366
  /* DRIZZLE_TYPE_ENUM -> */
324
367
  {
346
389
    DRIZZLE_TYPE_BLOB,
347
390
    //DRIZZLE_TYPE_TIME
348
391
    DRIZZLE_TYPE_TIME,
 
392
    //DRIZZLE_TYPE_BOOLEAN
 
393
    DRIZZLE_TYPE_VARCHAR,
349
394
    //DRIZZLE_TYPE_UUID
350
395
    DRIZZLE_TYPE_VARCHAR,
 
396
    //DRIZZLE_TYPE_MICROTIME
 
397
    DRIZZLE_TYPE_VARCHAR,
351
398
   },
352
399
  /* DRIZZLE_TYPE_BLOB -> */
353
400
  {
375
422
    DRIZZLE_TYPE_BLOB,
376
423
    //DRIZZLE_TYPE_TIME
377
424
    DRIZZLE_TYPE_TIME,
 
425
    //DRIZZLE_TYPE_BOOLEAN
 
426
    DRIZZLE_TYPE_VARCHAR,
378
427
    //DRIZZLE_TYPE_UUID
379
428
    DRIZZLE_TYPE_VARCHAR,
 
429
    //DRIZZLE_TYPE_MICROTIME
 
430
    DRIZZLE_TYPE_VARCHAR,
380
431
  },
381
432
  /* DRIZZLE_TYPE_TIME -> */
382
433
  {
404
455
    DRIZZLE_TYPE_BLOB,
405
456
    //DRIZZLE_TYPE_TIME
406
457
    DRIZZLE_TYPE_TIME,
 
458
    //DRIZZLE_TYPE_BOOLEAN
 
459
    DRIZZLE_TYPE_VARCHAR,
407
460
    //DRIZZLE_TYPE_UUID
408
461
    DRIZZLE_TYPE_UUID,
 
462
    //DRIZZLE_TYPE_MICROTIME
 
463
    DRIZZLE_TYPE_VARCHAR,
 
464
  },
 
465
  /* DRIZZLE_TYPE_BOOLEAN -> */
 
466
  {
 
467
    //DRIZZLE_TYPE_LONG
 
468
    DRIZZLE_TYPE_VARCHAR,
 
469
    //DRIZZLE_TYPE_DOUBLE
 
470
    DRIZZLE_TYPE_VARCHAR,
 
471
    //DRIZZLE_TYPE_NULL
 
472
    DRIZZLE_TYPE_BOOLEAN,
 
473
    //DRIZZLE_TYPE_TIMESTAMP
 
474
    DRIZZLE_TYPE_VARCHAR,
 
475
    //DRIZZLE_TYPE_LONGLONG
 
476
    DRIZZLE_TYPE_VARCHAR,
 
477
    //DRIZZLE_TYPE_DATETIME
 
478
    DRIZZLE_TYPE_VARCHAR,
 
479
    //DRIZZLE_TYPE_DATE
 
480
    DRIZZLE_TYPE_VARCHAR,
 
481
    //DRIZZLE_TYPE_VARCHAR
 
482
    DRIZZLE_TYPE_VARCHAR,
 
483
    //DRIZZLE_TYPE_DECIMAL
 
484
    DRIZZLE_TYPE_VARCHAR,
 
485
    //DRIZZLE_TYPE_VARCHAR,
 
486
    DRIZZLE_TYPE_VARCHAR,
 
487
    //DRIZZLE_TYPE_BLOB
 
488
    DRIZZLE_TYPE_BLOB,
 
489
    //DRIZZLE_TYPE_TIME
 
490
    DRIZZLE_TYPE_TIME,
 
491
    //DRIZZLE_TYPE_BOOLEAN
 
492
    DRIZZLE_TYPE_BOOLEAN,
 
493
    //DRIZZLE_TYPE_UUID
 
494
    DRIZZLE_TYPE_VARCHAR,
 
495
    //DRIZZLE_TYPE_MICROTIME
 
496
    DRIZZLE_TYPE_VARCHAR,
409
497
  },
410
498
  /* DRIZZLE_TYPE_UUID -> */
411
499
  {
433
521
    DRIZZLE_TYPE_BLOB,
434
522
    //DRIZZLE_TYPE_TIME
435
523
    DRIZZLE_TYPE_TIME,
436
 
    //DRIZZLE_TYPE_UUID
437
 
    DRIZZLE_TYPE_UUID,
 
524
    //DRIZZLE_TYPE_BOOLEAN
 
525
    DRIZZLE_TYPE_VARCHAR,
 
526
    //DRIZZLE_TYPE_UUID
 
527
    DRIZZLE_TYPE_UUID,
 
528
    //DRIZZLE_TYPE_MICROTIME
 
529
    DRIZZLE_TYPE_VARCHAR,
 
530
  },
 
531
  /* DRIZZLE_TYPE_MICROTIME -> */
 
532
  {
 
533
    //DRIZZLE_TYPE_LONG
 
534
    DRIZZLE_TYPE_VARCHAR,
 
535
    //DRIZZLE_TYPE_DOUBLE
 
536
    DRIZZLE_TYPE_VARCHAR,
 
537
    //DRIZZLE_TYPE_NULL
 
538
    DRIZZLE_TYPE_MICROTIME,
 
539
    //DRIZZLE_TYPE_TIMESTAMP
 
540
    DRIZZLE_TYPE_VARCHAR,
 
541
    //DRIZZLE_TYPE_LONGLONG
 
542
    DRIZZLE_TYPE_VARCHAR,
 
543
    //DRIZZLE_TYPE_DATETIME
 
544
    DRIZZLE_TYPE_VARCHAR,
 
545
    //DRIZZLE_TYPE_DATE
 
546
    DRIZZLE_TYPE_VARCHAR,
 
547
    //DRIZZLE_TYPE_VARCHAR
 
548
    DRIZZLE_TYPE_VARCHAR,
 
549
    //DRIZZLE_TYPE_DECIMAL
 
550
    DRIZZLE_TYPE_VARCHAR,
 
551
    //DRIZZLE_TYPE_VARCHAR,
 
552
    DRIZZLE_TYPE_VARCHAR,
 
553
    //DRIZZLE_TYPE_BLOB
 
554
    DRIZZLE_TYPE_BLOB,
 
555
    //DRIZZLE_TYPE_TIME
 
556
    DRIZZLE_TYPE_TIME,
 
557
    //DRIZZLE_TYPE_BOOLEAN
 
558
    DRIZZLE_TYPE_VARCHAR,
 
559
    //DRIZZLE_TYPE_UUID
 
560
    DRIZZLE_TYPE_UUID,
 
561
    //DRIZZLE_TYPE_MICROTIME
 
562
    DRIZZLE_TYPE_MICROTIME,
438
563
  },
439
564
};
440
565
 
464
589
  STRING_RESULT,
465
590
  //DRIZZLE_TYPE_TIME
466
591
  STRING_RESULT,
 
592
  //DRIZZLE_TYPE_BOOLEAN
 
593
  STRING_RESULT,
467
594
  //DRIZZLE_TYPE_UUID
468
595
  STRING_RESULT,
 
596
  //DRIZZLE_TYPE_MICROTIME
 
597
  STRING_RESULT,
469
598
};
470
599
 
471
600
bool test_if_important_data(const CHARSET_INFO * const cs, 
617
746
  return 0;
618
747
}
619
748
 
620
 
bool Field::is_null(ptrdiff_t row_offset)
 
749
bool Field::is_null(ptrdiff_t row_offset) const
621
750
{
622
751
  return null_ptr ?
623
752
    (null_ptr[row_offset] & null_bit ? true : false) :
624
753
    table->null_row;
625
754
}
626
755
 
627
 
bool Field::is_real_null(ptrdiff_t row_offset)
 
756
bool Field::is_real_null(ptrdiff_t row_offset) const
628
757
{
629
758
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
630
759
}
631
760
 
632
 
bool Field::is_null_in_record(const unsigned char *record)
 
761
bool Field::is_null_in_record(const unsigned char *record) const
633
762
{
634
763
  if (! null_ptr)
635
764
    return false;
636
765
  return test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
637
766
}
638
767
 
639
 
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset)
 
768
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset) const
640
769
{
641
770
  if (! null_ptr)
642
771
    return false;
655
784
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
656
785
}
657
786
 
658
 
bool Field::maybe_null(void)
 
787
bool Field::maybe_null(void) const
659
788
{
660
789
  return null_ptr != 0 || table->maybe_null;
661
790
}
662
791
 
663
 
bool Field::real_maybe_null(void)
 
792
bool Field::real_maybe_null(void) const
664
793
{
665
794
  return null_ptr != 0;
666
795
}
702
831
             unsigned char *null_ptr_arg,
703
832
             unsigned char null_bit_arg,
704
833
             utype unireg_check_arg, 
705
 
             const char *field_name_arg)
706
 
  :
 
834
             const char *field_name_arg) :
707
835
    ptr(ptr_arg),
708
836
    null_ptr(null_ptr_arg),
709
837
    table(NULL),
710
838
    orig_table(NULL),
711
839
    field_name(field_name_arg),
 
840
    comment(NULL_LEX_STRING),
712
841
    key_start(0),
713
842
    part_of_key(0),
714
843
    part_of_key_not_clustered(0),
715
844
    part_of_sortkey(0),
716
845
    unireg_check(unireg_check_arg),
717
846
    field_length(length_arg),
 
847
    flags(null_ptr ? 0: NOT_NULL_FLAG),
 
848
    field_index(0),
718
849
    null_bit(null_bit_arg),
719
850
    is_created_from_null_item(false)
720
851
{
721
 
  flags= null_ptr ? 0: NOT_NULL_FLAG;
722
 
  comment.str= (char*) "";
723
 
  comment.length= 0;
724
 
  field_index= 0;
725
852
}
726
853
 
727
 
void Field::hash(uint32_t *nr, uint32_t *nr2)
 
854
void Field::hash(uint32_t *nr, uint32_t *nr2) const
728
855
{
729
856
  if (is_null())
730
857
  {
816
943
  return(result);
817
944
}
818
945
 
819
 
my_decimal *Field::val_decimal(my_decimal *)
 
946
type::Decimal *Field::val_decimal(type::Decimal *) const
820
947
{
821
948
  /* This never have to be called */
822
949
  assert(0);
851
978
  field->decimals= 0;
852
979
}
853
980
 
854
 
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
 
981
int64_t Field::convert_decimal2int64_t(const type::Decimal *val, bool, int *err)
855
982
{
856
983
  int64_t i;
857
 
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
984
  if (warn_if_overflow(val->val_int32(E_DEC_ERROR &
858
985
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
859
 
                                      val, false, &i)))
 
986
                                      false, &i)))
860
987
  {
861
988
    i= (val->sign() ? INT64_MIN : INT64_MAX);
862
989
    *err= 1;
874
1001
  {
875
1002
    copy->blob_field=(Field_blob*) this;
876
1003
    copy->strip=0;
877
 
    copy->length-= table->getShare()->blob_ptr_size;
 
1004
    copy->length-= table->getShare()->sizeBlobPtr();
878
1005
    return copy->length;
879
1006
  }
880
1007
  else
885
1012
  return copy->length+ store_length;
886
1013
}
887
1014
 
888
 
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
889
 
{
890
 
  char buff[40];
891
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
892
 
  if (!(res=val_str_internal(&tmp)) || str_to_datetime_with_warn(res->ptr(), res->length(),
893
 
                                                                 ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
894
 
  {
895
 
    return 1;
896
 
  }
897
 
 
898
 
  return 0;
899
 
}
900
 
 
901
 
bool Field::get_time(DRIZZLE_TIME *ltime)
902
 
{
903
 
  char buff[40];
904
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
905
 
 
906
 
  if (!(res=val_str_internal(&tmp)) || str_to_time_with_warn(res->ptr(), res->length(), ltime))
907
 
  {
908
 
    return 1;
909
 
  }
910
 
 
911
 
  return 0;
912
 
}
913
 
 
914
 
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
915
 
{
916
 
  char buff[MAX_DATE_STRING_REP_LENGTH];
917
 
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
918
 
  return store(buff, length, &my_charset_bin);
 
1015
bool Field::get_date(type::Time &ltime, uint32_t fuzzydate) const
 
1016
{
 
1017
  char buff[type::Time::MAX_STRING_LENGTH];
 
1018
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
 
1019
 
 
1020
  assert(getTable() and getTable()->getSession());
 
1021
 
 
1022
  if (not (res= val_str_internal(&tmp)) or
 
1023
      str_to_datetime_with_warn(getTable()->getSession(),
 
1024
                                res->ptr(), res->length(),
 
1025
                                &ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
 
1026
  {
 
1027
    return true;
 
1028
  }
 
1029
 
 
1030
  return false;
 
1031
}
 
1032
 
 
1033
bool Field::get_time(type::Time &ltime) const
 
1034
{
 
1035
  char buff[type::Time::MAX_STRING_LENGTH];
 
1036
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
 
1037
 
 
1038
  if (not (res= val_str_internal(&tmp)) or
 
1039
      str_to_time_with_warn(getTable()->getSession(), res->ptr(), res->length(), &ltime))
 
1040
  {
 
1041
    return true;
 
1042
  }
 
1043
 
 
1044
  return false;
 
1045
}
 
1046
 
 
1047
int Field::store_time(type::Time &ltime, type::timestamp_t)
 
1048
{
 
1049
  String tmp;
 
1050
 
 
1051
  ltime.convert(tmp);
 
1052
 
 
1053
  return store(tmp.ptr(), tmp.length(), &my_charset_bin);
919
1054
}
920
1055
 
921
1056
bool Field::optimize_range(uint32_t idx, uint32_t)
986
1121
{
987
1122
  if (!Field::eq_def(field))
988
1123
    return 0;
 
1124
 
989
1125
  TYPELIB *from_lib=((Field_enum*) field)->typelib;
990
1126
 
991
1127
  if (typelib->count < from_lib->count)
992
1128
    return 0;
 
1129
 
993
1130
  for (uint32_t i=0 ; i < from_lib->count ; i++)
 
1131
  {
994
1132
    if (my_strnncoll(field_charset,
995
1133
                     (const unsigned char*)typelib->type_names[i],
996
1134
                     strlen(typelib->type_names[i]),
997
1135
                     (const unsigned char*)from_lib->type_names[i],
998
1136
                     strlen(from_lib->type_names[i])))
999
1137
      return 0;
 
1138
  }
 
1139
 
1000
1140
  return 1;
1001
1141
}
1002
1142
 
1005
1145
  switch (type) {
1006
1146
  case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
1007
1147
  case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
 
1148
  case DRIZZLE_TYPE_MICROTIME: return field::Microtime::max_string_length();
 
1149
  case DRIZZLE_TYPE_TIMESTAMP: return field::Epoch::max_string_length();
 
1150
  case DRIZZLE_TYPE_BOOLEAN: return field::Boolean::max_string_length();
1008
1151
  case DRIZZLE_TYPE_DATE:
1009
1152
  case DRIZZLE_TYPE_ENUM:
1010
1153
  case DRIZZLE_TYPE_LONG: return 4;
1011
1154
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1012
1155
  case DRIZZLE_TYPE_TIME:
1013
1156
  case DRIZZLE_TYPE_DATETIME:
1014
 
  case DRIZZLE_TYPE_TIMESTAMP:
1015
1157
  case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
1016
1158
  case DRIZZLE_TYPE_NULL: return 0;
1017
1159
  case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
1040
1182
*****************************************************************************/
1041
1183
 
1042
1184
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
1043
 
                        uint32_t code,
 
1185
                        drizzled::error_t code,
1044
1186
                        int cuted_increment)
1045
1187
{
1046
1188
  /*
1060
1202
 
1061
1203
 
1062
1204
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1063
 
                                 unsigned int code,
 
1205
                                 drizzled::error_t code,
1064
1206
                                 const char *str, 
1065
1207
                                 uint32_t str_length,
1066
 
                                 enum enum_drizzle_timestamp_type ts_type, 
 
1208
                                 type::timestamp_t ts_type, 
1067
1209
                                 int cuted_increment)
1068
1210
{
1069
 
  Session *session= table ? table->in_use : current_session;
1070
 
  if ((session->really_abort_on_warning() &&
 
1211
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
 
1212
 
 
1213
  if ((session->abortOnWarning() and
1071
1214
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
1072
1215
      set_warning(level, code, cuted_increment))
1073
1216
    make_truncated_value_warning(session, level, str, str_length, ts_type,
1075
1218
}
1076
1219
 
1077
1220
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
1078
 
                                 uint32_t code,
 
1221
                                 drizzled::error_t code,
1079
1222
                                 int64_t nr, 
1080
 
                                 enum enum_drizzle_timestamp_type ts_type,
 
1223
                                 type::timestamp_t ts_type,
1081
1224
                                 int cuted_increment)
1082
1225
{
1083
 
  Session *session= table ? table->in_use : current_session;
1084
 
  if (session->really_abort_on_warning() ||
 
1226
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
 
1227
 
 
1228
  if (session->abortOnWarning() or
1085
1229
      set_warning(level, code, cuted_increment))
1086
1230
  {
1087
 
    char str_nr[22];
 
1231
    char str_nr[DECIMAL_LONGLONG_DIGITS];
1088
1232
    char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
1089
1233
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
1090
1234
                                 ts_type, field_name);
1092
1236
}
1093
1237
 
1094
1238
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1095
 
                                 const uint32_t code,
 
1239
                                 const drizzled::error_t code,
1096
1240
                                 double nr, 
1097
 
                                 enum enum_drizzle_timestamp_type ts_type)
 
1241
                                 type::timestamp_t ts_type)
1098
1242
{
1099
 
  Session *session= table ? table->in_use : current_session;
1100
 
  if (session->really_abort_on_warning() ||
 
1243
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
 
1244
 
 
1245
  if (session->abortOnWarning() or
1101
1246
      set_warning(level, code, 1))
1102
1247
  {
1103
1248
    /* DBL_DIG is enough to print '-[digits].E+###' */
1108
1253
  }
1109
1254
}
1110
1255
 
1111
 
bool Field::isReadSet() 
 
1256
bool Field::isReadSet() const 
1112
1257
1113
1258
  return table->isReadSet(field_index); 
1114
1259
}
1142
1287
  int64_tstore(destination, arg);
1143
1288
}
1144
1289
 
 
1290
void Field::pack_num(uint32_t arg, unsigned char *destination)
 
1291
{
 
1292
  if (not destination)
 
1293
    destination= ptr;
 
1294
 
 
1295
  longstore(destination, arg);
 
1296
}
 
1297
 
1145
1298
uint64_t Field::unpack_num(uint64_t &destination, const unsigned char *arg) const
1146
1299
{
1147
1300
  if (not arg)
1152
1305
  return destination;
1153
1306
}
1154
1307
 
 
1308
uint32_t Field::unpack_num(uint32_t &destination, const unsigned char *arg) const
 
1309
{
 
1310
  if (not arg)
 
1311
    arg= ptr;
 
1312
 
 
1313
  longget(destination, arg);
 
1314
 
 
1315
  return destination;
 
1316
}
 
1317
 
1155
1318
std::ostream& operator<<(std::ostream& output, const Field &field)
1156
1319
{
1157
1320
  output << "Field:(";