21 #include "sql_string.h"
23 #include "sql_error.h"
24 #include "mysql_version.h"
83 enum enum_check_fields
87 CHECK_FIELD_ERROR_FOR_NULL
93 DERIVATION_IGNORABLE= 6,
94 DERIVATION_NUMERIC= 5,
95 DERIVATION_COERCIBLE= 4,
96 DERIVATION_SYSCONST= 3,
97 DERIVATION_IMPLICIT= 2,
99 DERIVATION_EXPLICIT= 0
108 enum type_conversion_status
116 TYPE_NOTE_TIME_TRUNCATED,
121 TYPE_WARN_OUT_OF_RANGE,
142 TYPE_ERR_NULL_CONSTRAINT_VIOLATION,
153 #define STORAGE_TYPE_MASK 7
154 #define COLUMN_FORMAT_MASK 7
155 #define COLUMN_FORMAT_SHIFT 3
157 #define my_charset_numeric my_charset_latin1
158 #define MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII
163 inline uint get_enum_pack_length(
int elements)
165 return elements < 256 ? 1 : 2;
168 inline uint get_set_pack_length(
int elements)
170 uint len= (elements + 7) / 8;
171 return len > 4 ? 8 : len;
174 inline type_conversion_status
175 decimal_err_to_type_conv_status(
int dec_error)
177 if (dec_error & E_DEC_OOM)
180 if (dec_error & (E_DEC_DIV_ZERO | E_DEC_BAD_NUM))
181 return TYPE_ERR_BAD_VALUE;
183 if (dec_error & E_DEC_TRUNCATED)
184 return TYPE_NOTE_TRUNCATED;
186 if (dec_error & E_DEC_OVERFLOW)
187 return TYPE_WARN_OUT_OF_RANGE;
189 if (dec_error == E_DEC_OK)
194 return TYPE_ERR_BAD_VALUE;
201 inline type_conversion_status
202 time_warning_to_type_conversion_status(
const int warn)
204 if (warn & MYSQL_TIME_NOTE_TRUNCATED)
205 return TYPE_NOTE_TIME_TRUNCATED;
207 if (warn & MYSQL_TIME_WARN_OUT_OF_RANGE)
208 return TYPE_WARN_OUT_OF_RANGE;
210 if (warn & MYSQL_TIME_WARN_TRUNCATED)
211 return TYPE_NOTE_TRUNCATED;
213 if (warn & (MYSQL_TIME_WARN_ZERO_DATE | MYSQL_TIME_WARN_ZERO_IN_DATE))
214 return TYPE_ERR_BAD_VALUE;
216 if (warn & MYSQL_TIME_WARN_INVALID_TIMESTAMP)
224 #define ASSERT_COLUMN_MARKED_FOR_READ \
225 DBUG_ASSERT(!table || (!table->read_set || \
226 bitmap_is_set(table->read_set, field_index)))
227 #define ASSERT_COLUMN_MARKED_FOR_WRITE \
228 DBUG_ASSERT(!table || (!table->write_set || \
229 bitmap_is_set(table->write_set, field_index)))
240 inline bool is_temporal_type(enum_field_types
type)
244 case MYSQL_TYPE_TIME:
245 case MYSQL_TYPE_DATETIME:
246 case MYSQL_TYPE_TIMESTAMP:
247 case MYSQL_TYPE_DATE:
248 case MYSQL_TYPE_NEWDATE:
265 inline bool is_temporal_real_type(enum_field_types type)
269 case MYSQL_TYPE_TIME2:
270 case MYSQL_TYPE_TIMESTAMP2:
271 case MYSQL_TYPE_DATETIME2:
274 return is_temporal_type(type);
287 inline bool is_temporal_type_with_time(enum_field_types type)
291 case MYSQL_TYPE_TIME:
292 case MYSQL_TYPE_DATETIME:
293 case MYSQL_TYPE_TIMESTAMP:
309 inline bool is_temporal_type_with_date(enum_field_types type)
313 case MYSQL_TYPE_DATE:
314 case MYSQL_TYPE_DATETIME:
315 case MYSQL_TYPE_TIMESTAMP:
331 inline bool is_temporal_type_with_date_and_time(enum_field_types type)
335 case MYSQL_TYPE_DATETIME:
336 case MYSQL_TYPE_TIMESTAMP:
352 inline bool real_type_with_now_as_default(enum_field_types type)
354 return type == MYSQL_TYPE_TIMESTAMP || type == MYSQL_TYPE_TIMESTAMP2 ||
355 type == MYSQL_TYPE_DATETIME || type == MYSQL_TYPE_DATETIME2;
367 inline bool real_type_with_now_on_update(enum_field_types type)
369 return type == MYSQL_TYPE_TIMESTAMP || type == MYSQL_TYPE_TIMESTAMP2 ||
370 type == MYSQL_TYPE_DATETIME || type == MYSQL_TYPE_DATETIME2;
378 inline bool is_timestamp_type(enum_field_types type)
380 return type == MYSQL_TYPE_TIMESTAMP || type == MYSQL_TYPE_TIMESTAMP2;
391 inline enum_field_types real_type_to_type(enum_field_types real_type)
395 case MYSQL_TYPE_TIME2:
396 return MYSQL_TYPE_TIME;
397 case MYSQL_TYPE_DATETIME2:
398 return MYSQL_TYPE_DATETIME;
399 case MYSQL_TYPE_TIMESTAMP2:
400 return MYSQL_TYPE_TIMESTAMP;
401 case MYSQL_TYPE_NEWDATE:
402 return MYSQL_TYPE_DATE;
404 default:
return real_type;
427 template<
bool Is_big_endian>
428 void copy_integer(uchar *
to,
int to_length,
429 const uchar* from,
int from_length,
437 to[0]= (char)(from[0] ^ 128);
438 memcpy(to + 1, from + 1, to_length - 1);
442 const int sign_byte= from[from_length - 1];
446 to[0]=
static_cast<char>(sign_byte ^ 128);
447 for (
int i= 1, j= from_length - 2;
i < to_length; ++
i, --j)
456 void operator=(
Field &);
459 bool has_insert_default_function()
const
461 return unireg_check == TIMESTAMP_DN_FIELD ||
462 unireg_check == TIMESTAMP_DNUN_FIELD;
465 bool has_update_default_function()
const
467 return unireg_check == TIMESTAMP_UN_FIELD ||
468 unireg_check == TIMESTAMP_DNUN_FIELD;
472 static void *
operator new(
size_t size)
throw ()
473 {
return sql_alloc(
size); }
474 static void *
operator new(
size_t size,
MEM_ROOT *mem_root)
throw () {
475 return alloc_root(mem_root,
size);
477 static void operator delete(
void *ptr,
MEM_ROOT *mem_root)
478 { DBUG_ASSERT(
false); }
480 static void operator delete(
void *ptr_arg,
size_t size)
throw()
481 { TRASH(ptr_arg,
size); }
499 const char **table_name, *field_name;
504 key_map part_of_key_not_clustered;
514 enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
515 CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
516 BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
517 TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
520 GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3,
521 GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6,
522 GEOM_GEOMETRYCOLLECTION = 7
524 enum imagetype { itRAW, itMBR};
542 Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
543 uchar null_bit_arg, utype unireg_check_arg,
544 const char *field_name_arg);
548 virtual type_conversion_status store(
const char *to, uint length,
550 virtual type_conversion_status store(
double nr)=0;
551 virtual type_conversion_status store(longlong nr,
bool unsigned_val)=0;
567 virtual type_conversion_status store_decimal(
const my_decimal *d)=0;
596 type_conversion_status store(
const char *to, uint length,
598 enum_check_fields check_level);
599 virtual double val_real(
void)=0;
600 virtual longlong val_int(
void)=0;
628 if (type() == MYSQL_TYPE_TIME)
630 DBUG_ASSERT(is_temporal_with_date());
634 inline String *val_str(
String *str) {
return val_str(str, str); }
653 virtual bool str_needs_quotes() {
return FALSE; }
654 virtual Item_result result_type ()
const=0;
667 return result_type();
669 virtual Item_result cmp_type ()
const {
return result_type(); }
670 virtual Item_result cast_to_int_type ()
const {
return result_type(); }
672 static enum_field_types
field_type_merge(enum_field_types, enum_field_types);
674 virtual bool eq(
Field *field)
677 null_bit == field->null_bit && field->type() == type());
686 virtual uint32 pack_length()
const {
return (uint32) field_length; }
693 virtual uint32 pack_length_in_rec()
const {
return pack_length(); }
695 uint16 mflags,
int *order);
696 virtual uint pack_length_from_metadata(uint field_metadata)
698 DBUG_ENTER(
"Field::pack_length_from_metadata");
699 DBUG_RETURN(field_metadata);
701 virtual uint row_pack_length()
const {
return 0; }
702 virtual int save_field_metadata(uchar *first_byte)
703 {
return do_save_field_metadata(first_byte); }
708 virtual uint32 data_length() {
return pack_length(); }
709 virtual uint32 sort_length()
const {
return pack_length(); }
718 return pack_length();
721 virtual type_conversion_status reset(
void)
723 memset(ptr, 0, pack_length());
726 virtual void reset_fields() {}
779 virtual void set_default()
781 if (has_insert_default_function())
787 my_ptrdiff_t l_offset= (my_ptrdiff_t) (
table->s->default_values -
789 memcpy(ptr, ptr + l_offset, pack_length());
811 virtual bool binary()
const {
return 1; }
812 virtual bool zero_pack()
const {
return 1; }
813 virtual enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_BINARY; }
814 virtual uint32 key_length()
const {
return pack_length(); }
815 virtual enum_field_types
type()
const =0;
816 virtual enum_field_types real_type()
const {
return type(); }
817 virtual enum_field_types binlog_type()
const
838 inline int cmp(
const uchar *str) {
return cmp(ptr,str); }
839 virtual int cmp_max(
const uchar *a,
const uchar *b, uint max_len)
840 {
return cmp(a, b); }
841 virtual int cmp(
const uchar *,
const uchar *)=0;
842 virtual int cmp_binary(
const uchar *a,
const uchar *b, uint32 max_length=~0L)
843 {
return memcmp(a,b,pack_length()); }
844 virtual int cmp_offset(uint row_offset)
845 {
return cmp(ptr,ptr+row_offset); }
846 virtual int cmp_binary_offset(uint row_offset)
847 {
return cmp_binary(ptr, ptr+row_offset); };
848 virtual int key_cmp(
const uchar *a,
const uchar *b)
849 {
return cmp(a, b); }
850 virtual int key_cmp(
const uchar *str, uint length)
851 {
return cmp(ptr,str); }
852 virtual uint decimals()
const {
return 0; }
858 virtual void sql_type(
String &str)
const =0;
860 bool is_temporal()
const
861 {
return is_temporal_type(
type()); }
863 bool is_temporal_with_date()
const
864 {
return is_temporal_type_with_date(
type()); }
866 bool is_temporal_with_time()
const
867 {
return is_temporal_type_with_time(
type()); }
869 bool is_temporal_with_date_and_time()
const
870 {
return is_temporal_type_with_date_and_time(
type()); }
872 bool is_null(my_ptrdiff_t row_offset= 0)
const
897 bool is_real_null(my_ptrdiff_t row_offset= 0)
const
900 bool is_null_in_record(
const uchar *
record)
const
903 void set_null(my_ptrdiff_t row_offset= 0)
909 void set_notnull(my_ptrdiff_t row_offset= 0)
912 null_ptr[row_offset]&= (uchar) ~null_bit;
915 bool maybe_null(
void)
const
922 uint null_offset(
const uchar *record)
const
923 {
return (uint) (
null_ptr - record); }
925 uint null_offset()
const
926 {
return null_offset(
table->record[0]); }
928 void set_null_ptr(uchar *p_null_ptr, uint p_null_bit)
931 null_bit= p_null_bit;
935 LAST_NULL_BYTE_UNDEF= 0
953 size_t last_null_byte()
const {
954 size_t bytes= do_last_null_byte();
955 DBUG_PRINT(
"debug", (
"last_null_byte() ==> %ld", (
long) bytes));
956 DBUG_ASSERT(bytes <= table->s->null_bytes);
973 virtual bool optimize_range(uint idx, uint part);
981 virtual bool can_be_compared_as_longlong()
const {
return false; }
982 virtual void free() {}
986 uchar *new_ptr, uchar *new_null_ptr,
990 {
return new_key_field(root, new_table, new_ptr,
null_ptr, null_bit); }
1014 inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
1016 ptr=ptr_arg;
null_ptr=null_ptr_arg; null_bit=null_bit_arg;
1018 inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; }
1019 virtual void move_field_offset(my_ptrdiff_t ptr_diff)
1021 ptr=ADD_TO_PTR(ptr,ptr_diff, uchar*);
1025 virtual void get_image(uchar *buff, uint length,
const CHARSET_INFO *cs)
1026 { memcpy(buff,ptr,length); }
1027 virtual void set_image(
const uchar *buff,uint length,
1029 { memcpy(ptr,buff,length); }
1058 virtual uint get_key_image(uchar *buff, uint length, imagetype type)
1060 get_image(buff, length, &my_charset_bin);
1063 virtual void set_key_image(
const uchar *buff,uint length)
1064 { set_image(buff,length, &my_charset_bin); }
1065 inline longlong val_int_offset(uint row_offset)
1068 longlong tmp=val_int();
1072 inline longlong val_int(
const uchar *new_ptr)
1074 uchar *old_ptr= ptr;
1075 longlong return_value;
1076 ptr= (uchar*) new_ptr;
1077 return_value= val_int();
1079 return return_value;
1081 inline String *val_str(
String *str,
const uchar *new_ptr)
1083 uchar *old_ptr= ptr;
1084 ptr= (uchar*) new_ptr;
1089 virtual bool send_binary(
Protocol *protocol);
1091 virtual uchar *
pack(uchar *to,
const uchar *from,
1092 uint max_length,
bool low_byte_first);
1096 uchar *
pack(uchar *to,
const uchar *from)
1098 DBUG_ENTER(
"Field::pack");
1099 uchar *result= this->
pack(to, from, UINT_MAX,
table->s->db_low_byte_first);
1100 DBUG_RETURN(result);
1103 virtual const uchar *
unpack(uchar* to,
const uchar *from,
1104 uint param_data,
bool low_byte_first);
1108 const uchar *
unpack(uchar* to,
const uchar *from)
1110 DBUG_ENTER(
"Field::unpack");
1111 const uchar *result=
unpack(to, from, 0
U,
table->s->db_low_byte_first);
1112 DBUG_RETURN(result);
1115 virtual uint packed_col_length(
const uchar *to, uint length)
1117 virtual uint max_packed_col_length(uint max_length)
1118 {
return max_length;}
1120 uint
offset(uchar *record)
1122 return (uint) (ptr - record);
1124 void copy_from_tmp(
int offset);
1126 virtual bool get_date(
MYSQL_TIME *ltime,uint fuzzydate);
1128 virtual const CHARSET_INFO *charset(
void)
const {
return &my_charset_bin; }
1129 virtual const CHARSET_INFO *charset_for_protocol(
void)
const
1130 {
return binary() ? &my_charset_bin : charset(); }
1131 virtual const CHARSET_INFO *sort_charset(
void)
const {
return charset(); }
1132 virtual bool has_charset(
void)
const {
return FALSE; }
1143 virtual bool match_collation_to_optimize_range()
const {
return false; };
1144 virtual enum Derivation derivation(
void)
const
1145 {
return DERIVATION_IMPLICIT; }
1146 virtual uint repertoire(
void)
const {
return MY_REPERTOIRE_UNICODE30; }
1147 virtual void set_derivation(
enum Derivation derivation_arg) { }
1148 bool set_warning(Sql_condition::enum_warning_level,
unsigned int code,
1149 int cuted_increment)
const;
1150 inline bool check_overflow(
int op_result)
1152 return (op_result == E_DEC_OVERFLOW);
1154 inline bool check_truncated(
int op_result)
1156 return (op_result == E_DEC_TRUNCATED);
1159 void init(
TABLE *table_arg)
1161 orig_table=
table= table_arg;
1166 virtual uint32 max_display_length()= 0;
1178 bool *has_overflow);
1180 virtual uint32 char_length()
1182 return field_length / charset()->mbmaxlen;
1185 virtual geometry_type get_geometry_type()
1189 return GEOM_GEOMETRY;
1196 fprintf(DBUG_FILE,
"NULL");
1200 String str(buf,
sizeof(buf), &my_charset_bin);
1203 pstr= val_str(&str);
1204 fprintf(DBUG_FILE,
"'%s'", pstr->c_ptr_safe());
1209 ha_storage_media field_storage_type()
const
1211 return (ha_storage_media)
1212 ((
flags >> FIELD_FLAGS_STORAGE_MEDIA) & 3);
1215 void set_storage_type(ha_storage_media storage_type_arg)
1217 DBUG_ASSERT(field_storage_type() == HA_SM_DEFAULT);
1218 flags |= (storage_type_arg << FIELD_FLAGS_STORAGE_MEDIA);
1221 column_format_type column_format()
const
1223 return (column_format_type)
1224 ((
flags >> FIELD_FLAGS_COLUMN_FORMAT) & 3);
1227 void set_column_format(column_format_type column_format_arg)
1229 DBUG_ASSERT(column_format() == COLUMN_FORMAT_TYPE_DEFAULT);
1230 flags |= (column_format_arg << FIELD_FLAGS_COLUMN_FORMAT);
1234 virtual type_conversion_status validate_stored_val(THD *thd)
1238 virtual void hash(ulong *nr, ulong *nr2);
1239 friend int cre_myisam(
char *
name,
register TABLE *
form, uint options,
1240 ulonglong auto_increment_value);
1246 friend class Item_sum_str;
1266 virtual size_t do_last_null_byte()
const;
1278 virtual int do_save_field_metadata(uchar *metadata_ptr)
1282 static void handle_int16(uchar *to,
const uchar *from,
1283 bool low_byte_first_from,
bool low_byte_first_to)
1286 #ifdef WORDS_BIGENDIAN
1287 if (low_byte_first_from)
1288 val = sint2korr(from);
1291 shortget(val, from);
1293 #ifdef WORDS_BIGENDIAN
1294 if (low_byte_first_to)
1298 shortstore(to, val);
1301 static void handle_int24(uchar *to,
const uchar *from,
1302 bool low_byte_first_from,
bool low_byte_first_to)
1305 #ifdef WORDS_BIGENDIAN
1306 if (low_byte_first_from)
1307 val = sint3korr(from);
1310 val= (from[0] << 16) + (from[1] << 8) + from[2];
1312 #ifdef WORDS_BIGENDIAN
1313 if (low_byte_first_to)
1318 to[0]= 0xFF & (val >> 16);
1319 to[1]= 0xFF & (val >> 8);
1327 static void handle_int32(uchar *to,
const uchar *from,
1328 bool low_byte_first_from,
bool low_byte_first_to)
1331 #ifdef WORDS_BIGENDIAN
1332 if (low_byte_first_from)
1333 val = sint4korr(from);
1338 #ifdef WORDS_BIGENDIAN
1339 if (low_byte_first_to)
1349 static void handle_int64(uchar* to,
const uchar *from,
1350 bool low_byte_first_from,
bool low_byte_first_to)
1353 #ifdef WORDS_BIGENDIAN
1354 if (low_byte_first_from)
1355 val = sint8korr(from);
1358 longlongget(val, from);
1360 #ifdef WORDS_BIGENDIAN
1361 if (low_byte_first_to)
1365 longlongstore(to, val);
1368 uchar *pack_int16(uchar *to,
const uchar *from,
bool low_byte_first_to)
1370 handle_int16(to, from, table->s->db_low_byte_first, low_byte_first_to);
1371 return to +
sizeof(int16);
1374 const uchar *unpack_int16(uchar* to,
const uchar *from,
1375 bool low_byte_first_from)
1377 handle_int16(to, from, low_byte_first_from, table->s->db_low_byte_first);
1378 return from +
sizeof(int16);
1381 uchar *pack_int24(uchar *to,
const uchar *from,
bool low_byte_first_to)
1383 handle_int24(to, from, table->s->db_low_byte_first, low_byte_first_to);
1387 const uchar *unpack_int24(uchar* to,
const uchar *from,
1388 bool low_byte_first_from)
1390 handle_int24(to, from, low_byte_first_from, table->s->db_low_byte_first);
1394 uchar *pack_int32(uchar *to,
const uchar *from,
bool low_byte_first_to)
1396 handle_int32(to, from, table->s->db_low_byte_first, low_byte_first_to);
1397 return to +
sizeof(int32);
1400 const uchar *unpack_int32(uchar* to,
const uchar *from,
1401 bool low_byte_first_from)
1403 handle_int32(to, from, low_byte_first_from, table->s->db_low_byte_first);
1404 return from +
sizeof(int32);
1407 uchar *pack_int64(uchar* to,
const uchar *from,
bool low_byte_first_to)
1409 handle_int64(to, from, table->s->db_low_byte_first, low_byte_first_to);
1410 return to +
sizeof(int64);
1413 const uchar *unpack_int64(uchar* to,
const uchar *from,
1414 bool low_byte_first_from)
1416 handle_int64(to, from, low_byte_first_from, table->s->db_low_byte_first);
1417 return from +
sizeof(int64);
1420 bool field_flags_are_binary()
1422 return (
flags & (BINCMP_FLAG | BINARY_FLAG)) != 0;
1431 bool zerofill,unsigned_flag;
1432 Field_num(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
1433 uchar null_bit_arg, utype unireg_check_arg,
1434 const char *field_name_arg,
1435 uint8 dec_arg,
bool zero_arg,
bool unsigned_arg);
1436 Item_result result_type ()
const {
return REAL_RESULT; }
1437 enum Derivation derivation(
void)
const {
return DERIVATION_NUMERIC; }
1438 uint repertoire(
void)
const {
return MY_REPERTOIRE_NUMERIC; }
1439 const CHARSET_INFO *charset(
void)
const {
return &my_charset_numeric; }
1440 void prepend_zeros(
String *value);
1441 void add_zerofill_and_unsigned(
String &res)
const;
1443 uint decimals()
const {
return (uint) dec; }
1448 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate);
1451 uint row_pack_length()
const {
return pack_length(); }
1452 uint32 pack_length_from_metadata(uint field_metadata) {
1453 uint32 length= pack_length();
1454 DBUG_PRINT(
"result", (
"pack_length_from_metadata(%d): %u",
1455 field_metadata, length));
1459 const char *str,
int length,
1460 const char *int_end,
int error);
1462 const char *from, uint len,
1463 longlong *rnd, ulonglong unsigned_max,
1464 longlong signed_min, longlong signed_max);
1471 enum Derivation field_derivation;
1473 Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
1474 uchar null_bit_arg, utype unireg_check_arg,
1475 const char *field_name_arg,
const CHARSET_INFO *charset);
1476 Item_result result_type ()
const {
return STRING_RESULT; }
1481 uint decimals()
const {
return NOT_FIXED_DEC; }
1483 type_conversion_status
store(
double nr);
1484 type_conversion_status
store(longlong nr,
bool unsigned_val)=0;
1486 type_conversion_status
store(
const char *to, uint length,
1488 uint repertoire(
void)
const
1490 return my_charset_repertoire(field_charset);
1492 const CHARSET_INFO *charset(
void)
const {
return field_charset; }
1494 { field_charset= charset_arg; }
1495 enum Derivation derivation(
void)
const {
return field_derivation; }
1496 virtual void set_derivation(
enum Derivation derivation_arg)
1497 { field_derivation= derivation_arg; }
1498 bool binary()
const {
return field_charset == &my_charset_bin; }
1499 uint32 max_display_length() {
return field_length; }
1501 virtual bool str_needs_quotes() {
return TRUE; }
1511 type_conversion_status report_if_important_data(
const char *ptr,
1513 bool count_spaces)
const;
1514 type_conversion_status
1516 const char *cannot_convert_error_pos,
1517 const char *from_end_pos,
1522 Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1523 uchar null_bit_arg, utype unireg_check_arg,
1524 const char *field_name_arg,
const CHARSET_INFO *charset_arg)
1525 :
Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
1526 field_name_arg, charset_arg)
1538 Field_real(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1539 uchar null_bit_arg, utype unireg_check_arg,
1540 const char *field_name_arg,
1541 uint8 dec_arg,
bool zero_arg,
bool unsigned_arg)
1542 :
Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
1543 field_name_arg, dec_arg, zero_arg, unsigned_arg),
1544 not_fixed(dec_arg >= NOT_FIXED_DEC)
1549 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate);
1551 bool truncate(
double *nr,
double max_length);
1552 uint32 max_display_length() {
return field_length; }
1553 virtual const uchar *
unpack(uchar* to,
const uchar *from,
1554 uint param_data,
bool low_byte_first);
1555 virtual uchar *
pack(uchar* to,
const uchar *from,
1556 uint max_length,
bool low_byte_first);
1562 Field_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1564 enum utype unireg_check_arg,
const char *field_name_arg,
1565 uint8 dec_arg,
bool zero_arg,
bool unsigned_arg)
1566 :
Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1567 unireg_check_arg, field_name_arg,
1568 dec_arg, zero_arg, unsigned_arg)
1570 enum_field_types type()
const {
return MYSQL_TYPE_DECIMAL;}
1571 enum ha_base_keytype key_type()
const
1572 {
return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
1573 type_conversion_status reset(
void);
1574 type_conversion_status store(
const char *to, uint length,
1576 type_conversion_status store(
double nr);
1577 type_conversion_status store(longlong nr,
bool unsigned_val);
1578 double val_real(
void);
1579 longlong val_int(
void);
1581 int cmp(
const uchar *,
const uchar *);
1583 void overflow(
bool negative);
1584 bool zero_pack()
const {
return 0; }
1585 void sql_type(
String &str)
const;
1587 DBUG_ASSERT(type() == MYSQL_TYPE_DECIMAL);
1591 DBUG_ASSERT(type() == MYSQL_TYPE_DECIMAL);
1594 virtual const uchar *
unpack(uchar* to,
const uchar *from,
1595 uint param_data,
bool low_byte_first)
1599 virtual uchar *
pack(uchar* to,
const uchar *from,
1600 uint max_length,
bool low_byte_first)
1602 return Field::pack(to, from, max_length, low_byte_first);
1610 int do_save_field_metadata(uchar *first_byte);
1624 enum utype unireg_check_arg,
const char *field_name_arg,
1625 uint8 dec_arg,
bool zero_arg,
bool unsigned_arg);
1627 const char *field_name_arg, uint8 dec_arg,
1629 enum_field_types type()
const {
return MYSQL_TYPE_NEWDECIMAL;}
1630 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_BINARY; }
1631 Item_result result_type ()
const {
return DECIMAL_RESULT; }
1632 type_conversion_status reset(
void);
1635 type_conversion_status store(
const char *to, uint length,
1637 type_conversion_status store(
double nr);
1638 type_conversion_status store(longlong nr,
bool unsigned_val);
1641 double val_real(
void);
1642 longlong val_int(
void);
1644 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate);
1647 int cmp(
const uchar *,
const uchar *);
1649 bool zero_pack()
const {
return 0; }
1650 void sql_type(
String &str)
const;
1651 uint32 max_display_length() {
return field_length; }
1652 uint32 pack_length()
const {
return (uint32) bin_size; }
1654 uint row_pack_length()
const {
return pack_length(); }
1656 uint16 mflags,
int *order_var);
1659 DBUG_ASSERT(type() == MYSQL_TYPE_NEWDECIMAL);
1663 DBUG_ASSERT(type() == MYSQL_TYPE_NEWDECIMAL);
1666 virtual const uchar *
unpack(uchar* to,
const uchar *from,
1667 uint param_data,
bool low_byte_first);
1668 static Field *create_from_item (
Item *);
1674 Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1676 enum utype unireg_check_arg,
const char *field_name_arg,
1677 bool zero_arg,
bool unsigned_arg)
1678 :
Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1679 unireg_check_arg, field_name_arg,
1680 0, zero_arg,unsigned_arg)
1682 enum Item_result result_type ()
const {
return INT_RESULT; }
1683 enum_field_types type()
const {
return MYSQL_TYPE_TINY;}
1684 enum ha_base_keytype key_type()
const
1685 {
return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
1686 type_conversion_status store(
const char *to, uint length,
1688 type_conversion_status store(
double nr);
1689 type_conversion_status store(longlong nr,
bool unsigned_val);
1690 type_conversion_status reset(
void) { ptr[0]=0;
return TYPE_OK; }
1691 double val_real(
void);
1692 longlong val_int(
void);
1694 bool send_binary(
Protocol *protocol);
1695 int cmp(
const uchar *,
const uchar *);
1697 uint32 pack_length()
const {
return 1; }
1698 void sql_type(
String &str)
const;
1699 uint32 max_display_length() {
return 4; }
1701 DBUG_ASSERT(type() == MYSQL_TYPE_TINY);
1705 DBUG_ASSERT(type() == MYSQL_TYPE_TINY);
1708 virtual uchar *
pack(uchar* to,
const uchar *from,
1709 uint max_length,
bool low_byte_first)
1715 virtual const uchar *
unpack(uchar* to,
const uchar *from,
1716 uint param_data,
bool low_byte_first)
1726 Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1728 enum utype unireg_check_arg,
const char *field_name_arg,
1729 bool zero_arg,
bool unsigned_arg)
1730 :
Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1731 unireg_check_arg, field_name_arg,
1732 0, zero_arg,unsigned_arg)
1734 Field_short(uint32 len_arg,
bool maybe_null_arg,
const char *field_name_arg,
1736 :
Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*)
"": 0,0,
1737 NONE, field_name_arg, 0, 0, unsigned_arg)
1739 enum Item_result result_type ()
const {
return INT_RESULT; }
1740 enum_field_types type()
const {
return MYSQL_TYPE_SHORT;}
1741 enum ha_base_keytype key_type()
const
1742 {
return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;}
1743 type_conversion_status store(
const char *to, uint length,
1745 type_conversion_status store(
double nr);
1746 type_conversion_status store(longlong nr,
bool unsigned_val);
1747 type_conversion_status reset(
void) { ptr[0]=ptr[1]=0;
return TYPE_OK; }
1748 double val_real(
void);
1749 longlong val_int(
void);
1751 bool send_binary(
Protocol *protocol);
1752 int cmp(
const uchar *,
const uchar *);
1754 uint32 pack_length()
const {
return 2; }
1755 void sql_type(
String &str)
const;
1756 uint32 max_display_length() {
return 6; }
1758 DBUG_ASSERT(type() == MYSQL_TYPE_SHORT);
1762 DBUG_ASSERT(type() == MYSQL_TYPE_SHORT);
1765 virtual uchar *
pack(uchar* to,
const uchar *from,
1766 uint max_length,
bool low_byte_first)
1768 return pack_int16(to, from, low_byte_first);
1771 virtual const uchar *
unpack(uchar* to,
const uchar *from,
1772 uint param_data,
bool low_byte_first)
1774 return unpack_int16(to, from, low_byte_first);
1780 Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1782 enum utype unireg_check_arg,
const char *field_name_arg,
1783 bool zero_arg,
bool unsigned_arg)
1784 :
Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1785 unireg_check_arg, field_name_arg,
1786 0, zero_arg,unsigned_arg)
1788 enum Item_result result_type ()
const {
return INT_RESULT; }
1789 enum_field_types type()
const {
return MYSQL_TYPE_INT24;}
1790 enum ha_base_keytype key_type()
const
1791 {
return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; }
1792 type_conversion_status store(
const char *to, uint length,
1794 type_conversion_status store(
double nr);
1795 type_conversion_status store(longlong nr,
bool unsigned_val);
1796 type_conversion_status reset(
void)
1798 ptr[0]=ptr[1]=ptr[2]=0;
1801 double val_real(
void);
1802 longlong val_int(
void);
1804 bool send_binary(
Protocol *protocol);
1805 int cmp(
const uchar *,
const uchar *);
1807 uint32 pack_length()
const {
return 3; }
1808 void sql_type(
String &str)
const;
1809 uint32 max_display_length() {
return 8; }
1811 DBUG_ASSERT(type() == MYSQL_TYPE_INT24);
1815 DBUG_ASSERT(type() == MYSQL_TYPE_INT24);
1818 virtual uchar *
pack(uchar* to,
const uchar *from,
1819 uint max_length,
bool low_byte_first)
1821 return Field::pack(to, from, max_length, low_byte_first);
1824 virtual const uchar *
unpack(uchar* to,
const uchar *from,
1825 uint param_data,
bool low_byte_first)
1835 static const int PACK_LENGTH= 4;
1837 Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1839 enum utype unireg_check_arg,
const char *field_name_arg,
1840 bool zero_arg,
bool unsigned_arg)
1841 :
Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1842 unireg_check_arg, field_name_arg,
1843 0, zero_arg,unsigned_arg)
1845 Field_long(uint32 len_arg,
bool maybe_null_arg,
const char *field_name_arg,
1847 :
Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*)
"": 0,0,
1848 NONE, field_name_arg,0,0,unsigned_arg)
1850 enum Item_result result_type ()
const {
return INT_RESULT; }
1851 enum_field_types type()
const {
return MYSQL_TYPE_LONG;}
1852 enum ha_base_keytype key_type()
const
1853 {
return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; }
1854 type_conversion_status store(
const char *to, uint length,
1856 type_conversion_status store(
double nr);
1857 type_conversion_status store(longlong nr,
bool unsigned_val);
1858 type_conversion_status reset(
void)
1860 ptr[0]=ptr[1]=ptr[2]=ptr[3]=0;
1863 double val_real(
void);
1864 longlong val_int(
void);
1865 bool send_binary(
Protocol *protocol);
1867 int cmp(
const uchar *,
const uchar *);
1869 uint32 pack_length()
const {
return PACK_LENGTH; }
1870 void sql_type(
String &str)
const;
1871 uint32 max_display_length() {
return MY_INT32_NUM_DECIMAL_DIGITS; }
1873 DBUG_ASSERT(type() == MYSQL_TYPE_LONG);
1877 DBUG_ASSERT(type() == MYSQL_TYPE_LONG);
1880 virtual uchar *pack(uchar* to,
const uchar *from,
1881 uint max_length __attribute__((unused)),
1882 bool low_byte_first)
1884 return pack_int32(to, from, low_byte_first);
1886 virtual const uchar *unpack(uchar* to,
const uchar *from,
1887 uint param_data __attribute__((unused)),
1888 bool low_byte_first)
1890 return unpack_int32(to, from, low_byte_first);
1895 #ifdef HAVE_LONG_LONG
1896 class Field_longlong :
public Field_num {
1898 static const int PACK_LENGTH= 8;
1900 Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1902 enum utype unireg_check_arg,
const char *field_name_arg,
1903 bool zero_arg,
bool unsigned_arg)
1904 :
Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1905 unireg_check_arg, field_name_arg,
1906 0, zero_arg,unsigned_arg)
1908 Field_longlong(uint32 len_arg,
bool maybe_null_arg,
1909 const char *field_name_arg,
1911 :
Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*)
"": 0,0,
1912 NONE, field_name_arg,0,0,unsigned_arg)
1914 enum Item_result result_type ()
const {
return INT_RESULT; }
1915 enum_field_types
type()
const {
return MYSQL_TYPE_LONGLONG;}
1916 enum ha_base_keytype key_type()
const
1917 {
return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
1918 type_conversion_status store(
const char *to, uint length,
1920 type_conversion_status store(
double nr);
1921 type_conversion_status store(longlong nr,
bool unsigned_val);
1922 type_conversion_status reset(
void)
1924 ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
1927 double val_real(
void);
1928 longlong val_int(
void);
1930 bool send_binary(
Protocol *protocol);
1931 int cmp(
const uchar *,
const uchar *);
1933 uint32 pack_length()
const {
return PACK_LENGTH; }
1934 void sql_type(
String &str)
const;
1935 bool can_be_compared_as_longlong()
const {
return true; }
1936 uint32 max_display_length() {
return 20; }
1938 DBUG_ASSERT(
type() == MYSQL_TYPE_LONGLONG);
1939 return new (mem_root) Field_longlong(*
this);
1941 Field_longlong *
clone()
const {
1942 DBUG_ASSERT(
type() == MYSQL_TYPE_LONGLONG);
1943 return new Field_longlong(*
this);
1945 virtual uchar *
pack(uchar* to,
const uchar *from,
1946 uint max_length __attribute__((unused)),
1947 bool low_byte_first)
1949 return pack_int64(to, from, low_byte_first);
1951 virtual const uchar *
unpack(uchar* to,
const uchar *from,
1952 uint param_data __attribute__((unused)),
1953 bool low_byte_first)
1955 return unpack_int64(to, from, low_byte_first);
1963 Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1965 enum utype unireg_check_arg,
const char *field_name_arg,
1966 uint8 dec_arg,
bool zero_arg,
bool unsigned_arg)
1967 :
Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1968 unireg_check_arg, field_name_arg,
1969 dec_arg, zero_arg, unsigned_arg)
1971 Field_float(uint32 len_arg,
bool maybe_null_arg,
const char *field_name_arg,
1973 :
Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*)
"": 0, (uint) 0,
1974 NONE, field_name_arg, dec_arg, 0, 0)
1976 enum_field_types type()
const {
return MYSQL_TYPE_FLOAT;}
1977 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_FLOAT; }
1978 type_conversion_status store(
const char *to, uint length,
1980 type_conversion_status store(
double nr);
1981 type_conversion_status store(longlong nr,
bool unsigned_val);
1982 type_conversion_status reset(
void)
1984 memset(ptr, 0,
sizeof(
float));
1987 double val_real(
void);
1988 longlong val_int(
void);
1990 bool send_binary(
Protocol *protocol);
1991 int cmp(
const uchar *,
const uchar *);
1993 uint32 pack_length()
const {
return sizeof(float); }
1994 uint row_pack_length()
const {
return pack_length(); }
1995 void sql_type(
String &str)
const;
1997 DBUG_ASSERT(type() == MYSQL_TYPE_FLOAT);
2001 DBUG_ASSERT(type() == MYSQL_TYPE_FLOAT);
2005 int do_save_field_metadata(uchar *first_byte);
2011 Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2013 enum utype unireg_check_arg,
const char *field_name_arg,
2014 uint8 dec_arg,
bool zero_arg,
bool unsigned_arg)
2015 :
Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
2016 unireg_check_arg, field_name_arg,
2017 dec_arg, zero_arg, unsigned_arg)
2019 Field_double(uint32 len_arg,
bool maybe_null_arg,
const char *field_name_arg,
2021 :
Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*)
"" : 0, (uint) 0,
2022 NONE, field_name_arg, dec_arg, 0, 0)
2024 Field_double(uint32 len_arg,
bool maybe_null_arg,
const char *field_name_arg,
2025 uint8 dec_arg, my_bool not_fixed_arg)
2026 :
Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*)
"" : 0, (uint) 0,
2027 NONE, field_name_arg, dec_arg, 0, 0)
2028 {not_fixed= not_fixed_arg; }
2029 enum_field_types type()
const {
return MYSQL_TYPE_DOUBLE;}
2030 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_DOUBLE; }
2031 type_conversion_status store(
const char *to, uint length,
2033 type_conversion_status store(
double nr);
2034 type_conversion_status store(longlong nr,
bool unsigned_val);
2035 type_conversion_status reset(
void)
2037 memset(ptr, 0,
sizeof(
double));
2040 double val_real(
void);
2041 longlong val_int(
void);
2043 bool send_binary(
Protocol *protocol);
2044 int cmp(
const uchar *,
const uchar *);
2046 uint32 pack_length()
const {
return sizeof(double); }
2047 uint row_pack_length()
const {
return pack_length(); }
2048 void sql_type(
String &str)
const;
2050 DBUG_ASSERT(type() == MYSQL_TYPE_DOUBLE);
2054 DBUG_ASSERT(type() == MYSQL_TYPE_DOUBLE);
2058 int do_save_field_metadata(uchar *first_byte);
2065 static uchar null[1];
2068 enum utype unireg_check_arg,
const char *field_name_arg,
2071 unireg_check_arg, field_name_arg, cs)
2073 enum_field_types type()
const {
return MYSQL_TYPE_NULL;}
2074 type_conversion_status store(
const char *to, uint length,
2080 type_conversion_status
store(
double nr) { null[0]=1;
return TYPE_OK; }
2081 type_conversion_status store(longlong nr,
bool unsigned_val)
2091 type_conversion_status reset(
void) {
return TYPE_OK; }
2092 double val_real(
void) {
return 0.0;}
2093 longlong val_int(
void) {
return 0;}
2096 { value2->length(0);
return value2;}
2097 int cmp(
const uchar *a,
const uchar *b) {
return 0;}
2099 uint32 pack_length()
const {
return 0; }
2100 void sql_type(
String &str)
const;
2101 uint32 max_display_length() {
return 4; }
2103 DBUG_ASSERT(type() == MYSQL_TYPE_NULL);
2107 DBUG_ASSERT(type() == MYSQL_TYPE_NULL);
2125 {
return dec_arg == NOT_FIXED_DEC ? DATETIME_MAX_DECIMALS : dec_arg; }
2161 type_conversion_status
store_lldiv_t(
const lldiv_t *lld,
int *warning);
2244 return date_flags(table ? table->in_use : current_thd);
2258 timestamp_type ts_type,
int cuted_increment);
2271 uchar *null_ptr_arg, uchar null_bit_arg,
2272 enum utype unireg_check_arg,
const char *field_name_arg,
2273 uint32 len_arg, uint8 dec_arg)
2276 null_ptr_arg, null_bit_arg,
2277 unireg_check_arg, field_name_arg)
2278 { flags|= BINARY_FLAG; }
2287 uint32 len_arg, uint8 dec_arg)
2290 maybe_null_arg ? (uchar *)
"" : 0, 0,
2291 NONE, field_name_arg)
2292 { flags|= BINARY_FLAG; }
2293 virtual Item_result result_type()
const {
return STRING_RESULT; }
2294 virtual uint32 max_display_length() {
return field_length; }
2295 virtual bool str_needs_quotes() {
return TRUE; }
2299 return dec ? DECIMAL_RESULT : INT_RESULT;
2301 enum Item_result cmp_type()
const {
return INT_RESULT; }
2302 enum Derivation derivation()
const {
return DERIVATION_NUMERIC; }
2303 uint repertoire()
const {
return MY_REPERTOIRE_NUMERIC; }
2304 const CHARSET_INFO *charset()
const {
return &my_charset_numeric; }
2305 bool can_be_compared_as_longlong()
const {
return true; }
2306 bool binary()
const {
return true; }
2307 type_conversion_status
store(
const char *str, uint len,
2309 type_conversion_status store_decimal(
const my_decimal *decimal);
2310 type_conversion_status
store(longlong nr,
bool unsigned_val);
2311 type_conversion_status
store(
double nr);
2314 return (
double) val_int();
2361 enum utype unireg_check_arg,
2362 const char *field_name_arg,
2363 uint8 int_length_arg, uint8 dec_arg)
2365 unireg_check_arg, field_name_arg,
2366 int_length_arg, dec_arg)
2376 uint int_length_arg, uint8 dec_arg)
2378 NONE, field_name_arg, int_length_arg, dec_arg)
2380 bool send_binary(
Protocol *protocol);
2387 return get_date(ltime, TIME_FUZZY_DATE);
2401 int do_save_field_metadata(uchar *metadata_ptr)
2405 *metadata_ptr= decimals();
2424 bool convert_TIME_to_timestamp(THD *thd,
const MYSQL_TIME *ltime,
2425 struct timeval *tm,
int *error);
2439 enum utype unireg_check_arg,
2440 const char *field_name_arg,
2443 unireg_check_arg, field_name_arg,
2444 MAX_DATETIME_WIDTH, dec_arg)
2446 void store_timestamp(
const struct timeval *tm);
2457 int do_save_field_metadata(uchar *metadata_ptr)
2459 *metadata_ptr= decimals();
2474 enum utype unireg_check_arg,
2475 const char *field_name_arg,
2478 unireg_check_arg, field_name_arg,
2488 const char *field_name_arg,
2491 maybe_null_arg ? (uchar*)
"" : 0, 0,
2492 NONE, field_name_arg, dec_arg)
2495 uint decimals()
const {
return dec; }
2496 const CHARSET_INFO *sort_charset()
const {
return &my_charset_bin; }
2498 int cmp(
const uchar *a_ptr,
const uchar *b_ptr)
2500 return memcmp(a_ptr, b_ptr, pack_length());
2502 uint row_pack_length()
const {
return pack_length(); }
2520 static const int PACK_LENGTH= 4;
2522 uchar *null_ptr_arg, uchar null_bit_arg,
2523 enum utype unireg_check_arg,
const char *field_name_arg);
2525 enum_field_types type()
const {
return MYSQL_TYPE_TIMESTAMP;}
2526 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_ULONG_INT; }
2528 type_conversion_status reset(
void)
2530 ptr[0]=ptr[1]=ptr[2]=ptr[3]=0;
2533 longlong val_int(
void);
2534 int cmp(
const uchar *,
const uchar *);
2536 uint32 pack_length()
const {
return PACK_LENGTH; }
2537 void sql_type(
String &str)
const;
2538 bool zero_pack()
const {
return 0; }
2541 bool get_date(
MYSQL_TIME *ltime,uint fuzzydate);
2543 DBUG_ASSERT(type() == MYSQL_TYPE_TIMESTAMP);
2548 DBUG_ASSERT(type() == MYSQL_TYPE_TIMESTAMP);
2551 uchar *pack(uchar *to,
const uchar *from,
2552 uint max_length __attribute__((unused)),
bool low_byte_first)
2554 return pack_int32(to, from, low_byte_first);
2556 const uchar *unpack(uchar* to,
const uchar *from,
2557 uint param_data __attribute__((unused)),
2558 bool low_byte_first)
2560 return unpack_int32(to, from, low_byte_first);
2577 static const int PACK_LENGTH= 8;
2589 enum utype unireg_check_arg,
const char *field_name_arg,
2601 DBUG_ASSERT(type() == MYSQL_TYPE_TIMESTAMP);
2606 DBUG_ASSERT(type() == MYSQL_TYPE_TIMESTAMP);
2610 enum_field_types type()
const {
return MYSQL_TYPE_TIMESTAMP; }
2611 enum_field_types real_type()
const {
return MYSQL_TYPE_TIMESTAMP2; }
2612 enum_field_types binlog_type()
const {
return MYSQL_TYPE_TIMESTAMP2; }
2613 bool zero_pack()
const {
return 0; }
2615 uint32 pack_length()
const
2617 return my_timestamp_binary_length(dec);
2619 virtual uint pack_length_from_metadata(uint field_metadata)
2621 DBUG_ENTER(
"Field_timestampf::pack_length_from_metadata");
2622 uint tmp= my_timestamp_binary_length(field_metadata);
2626 type_conversion_status reset();
2628 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate);
2629 void sql_type(
String &str)
const;
2639 Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2641 enum utype unireg_check_arg,
const char *field_name_arg)
2642 :
Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
2643 unireg_check_arg, field_name_arg, 1, 1)
2645 enum_field_types type()
const {
return MYSQL_TYPE_YEAR;}
2646 type_conversion_status store(
const char *to,uint length,
2648 type_conversion_status store(
double nr);
2649 type_conversion_status store(longlong nr,
bool unsigned_val);
2651 double val_real(
void);
2652 longlong val_int(
void);
2654 bool send_binary(
Protocol *protocol);
2655 void sql_type(
String &str)
const;
2656 bool can_be_compared_as_longlong()
const {
return true; }
2658 DBUG_ASSERT(type() == MYSQL_TYPE_YEAR);
2662 DBUG_ASSERT(type() == MYSQL_TYPE_YEAR);
2670 static const int PACK_LENGTH= 3;
2676 Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
2677 enum utype unireg_check_arg,
const char *field_name_arg)
2679 unireg_check_arg, field_name_arg,
2682 Field_newdate(
bool maybe_null_arg,
const char *field_name_arg)
2684 0, NONE, field_name_arg, MAX_DATE_WIDTH, 0)
2686 enum_field_types type()
const {
return MYSQL_TYPE_DATE;}
2687 enum_field_types real_type()
const {
return MYSQL_TYPE_NEWDATE; }
2688 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_UINT24; }
2689 type_conversion_status reset(
void)
2691 ptr[0]=ptr[1]=ptr[2]=0;
2695 longlong val_int(
void);
2699 bool send_binary(
Protocol *protocol);
2700 int cmp(
const uchar *,
const uchar *);
2702 uint32 pack_length()
const {
return PACK_LENGTH; }
2703 void sql_type(
String &str)
const;
2704 bool zero_pack()
const {
return 1; }
2705 bool get_date(
MYSQL_TIME *ltime,uint fuzzydate);
2708 DBUG_ASSERT(type() == MYSQL_TYPE_DATE);
2709 DBUG_ASSERT(real_type() == MYSQL_TYPE_NEWDATE);
2714 DBUG_ASSERT(type() == MYSQL_TYPE_DATE);
2715 DBUG_ASSERT(real_type() == MYSQL_TYPE_NEWDATE);
2760 enum utype unireg_check_arg,
const char *field_name_arg,
2763 unireg_check_arg, field_name_arg,
2764 MAX_TIME_WIDTH, dec_arg)
2774 :
Field_temporal((uchar *) 0, maybe_null_arg ? (uchar *)
"" : 0, 0,
2775 NONE, field_name_arg, MAX_TIME_WIDTH, dec_arg)
2781 bool send_binary(
Protocol *protocol);
2793 Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
2794 enum utype unireg_check_arg,
const char *field_name_arg)
2796 unireg_check_arg, field_name_arg, 0)
2798 Field_time(
bool maybe_null_arg,
const char *field_name_arg)
2800 NONE, field_name_arg, 0)
2802 enum_field_types type()
const {
return MYSQL_TYPE_TIME;}
2803 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_INT24; }
2805 type_conversion_status reset(
void)
2807 ptr[0]=ptr[1]=ptr[2]=0;
2810 longlong val_int(
void);
2813 int cmp(
const uchar *,
const uchar *);
2815 uint32 pack_length()
const {
return 3; }
2816 void sql_type(
String &str)
const;
2817 bool zero_pack()
const {
return 1; }
2819 DBUG_ASSERT(type() == MYSQL_TYPE_TIME);
2823 DBUG_ASSERT(type() == MYSQL_TYPE_TIME);
2834 int do_save_field_metadata(uchar *metadata_ptr)
2836 *metadata_ptr= decimals();
2852 enum utype unireg_check_arg,
const char *field_name_arg,
2855 unireg_check_arg, field_name_arg, dec_arg)
2863 Field_timef(
bool maybe_null_arg,
const char *field_name_arg, uint8 dec_arg)
2865 NONE, field_name_arg, dec_arg)
2869 DBUG_ASSERT(type() == MYSQL_TYPE_TIME);
2874 DBUG_ASSERT(type() == MYSQL_TYPE_TIME);
2877 uint decimals()
const {
return dec; }
2878 enum_field_types type()
const {
return MYSQL_TYPE_TIME;}
2879 enum_field_types real_type()
const {
return MYSQL_TYPE_TIME2; }
2880 enum_field_types binlog_type()
const {
return MYSQL_TYPE_TIME2; }
2882 type_conversion_status reset();
2888 uint32 pack_length()
const
2890 return my_time_binary_length(dec);
2892 virtual uint pack_length_from_metadata(uint field_metadata)
2894 DBUG_ENTER(
"Field_timef::pack_length_from_metadata");
2895 uint tmp= my_time_binary_length(field_metadata);
2898 uint row_pack_length()
const {
return pack_length(); }
2899 void sql_type(
String &str)
const;
2900 bool zero_pack()
const {
return 1; }
2901 const CHARSET_INFO *sort_charset(
void)
const {
return &my_charset_bin; }
2903 int cmp(
const uchar *a_ptr,
const uchar *b_ptr)
2905 return memcmp(a_ptr, b_ptr, pack_length());
2922 static const int PACK_LENGTH= 8;
2950 enum utype unireg_check_arg,
const char *field_name_arg)
2952 unireg_check_arg, field_name_arg, 0)
2956 maybe_null_arg ? (uchar *)
"" : 0,
2957 0, NONE, field_name_arg, 0)
2959 enum_field_types type()
const {
return MYSQL_TYPE_DATETIME;}
2960 #ifdef HAVE_LONG_LONG
2961 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_ULONGLONG; }
2964 type_conversion_status store(longlong nr,
bool unsigned_val);
2966 type_conversion_status reset(
void)
2968 ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
2971 longlong val_int(
void);
2973 int cmp(
const uchar *,
const uchar *);
2975 uint32 pack_length()
const {
return PACK_LENGTH; }
2976 void sql_type(
String &str)
const;
2977 bool zero_pack()
const {
return 1; }
2978 bool get_date(
MYSQL_TIME *ltime,uint fuzzydate);
2981 DBUG_ASSERT(type() == MYSQL_TYPE_DATETIME);
2986 DBUG_ASSERT(type() == MYSQL_TYPE_DATETIME);
2989 uchar *pack(uchar* to,
const uchar *from,
2990 uint max_length __attribute__((unused)),
bool low_byte_first)
2992 return pack_int64(to, from, low_byte_first);
2994 const uchar *unpack(uchar* to,
const uchar *from,
2995 uint param_data __attribute__((unused)),
2996 bool low_byte_first)
2998 return unpack_int64(to, from, low_byte_first);
3024 enum utype unireg_check_arg,
const char *field_name_arg,
3027 unireg_check_arg, field_name_arg,
3040 maybe_null_arg ? (uchar *)
"" : 0, 0,
3041 NONE, field_name_arg, dec_arg)
3045 DBUG_ASSERT(type() == MYSQL_TYPE_DATETIME);
3050 DBUG_ASSERT(type() == MYSQL_TYPE_DATETIME);
3054 enum_field_types type()
const {
return MYSQL_TYPE_DATETIME;}
3055 enum_field_types real_type()
const {
return MYSQL_TYPE_DATETIME2; }
3056 enum_field_types binlog_type()
const {
return MYSQL_TYPE_DATETIME2; }
3057 uint32 pack_length()
const
3059 return my_datetime_binary_length(dec);
3061 virtual uint pack_length_from_metadata(uint field_metadata)
3063 DBUG_ENTER(
"Field_datetimef::pack_length_from_metadata");
3064 uint tmp= my_datetime_binary_length(field_metadata);
3067 bool zero_pack()
const {
return 1; }
3070 type_conversion_status reset();
3072 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate);
3073 void sql_type(
String &str)
const;
3079 bool can_alter_field_type;
3080 Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
3082 enum utype unireg_check_arg,
const char *field_name_arg,
3084 :
Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
3085 unireg_check_arg, field_name_arg, cs),
3086 can_alter_field_type(1) {};
3087 Field_string(uint32 len_arg,
bool maybe_null_arg,
const char *field_name_arg,
3089 :
Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*)
"": 0, 0,
3090 NONE, field_name_arg, cs),
3091 can_alter_field_type(1) {};
3093 enum_field_types type()
const
3095 return ((can_alter_field_type && orig_table &&
3096 orig_table->s->db_create_options & HA_OPTION_PACK_RECORD &&
3097 field_length >= 4) &&
3098 orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ?
3099 MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING);
3101 bool match_collation_to_optimize_range()
const {
return true; }
3102 enum ha_base_keytype key_type()
const
3103 {
return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
3104 bool zero_pack()
const {
return 0; }
3105 type_conversion_status reset(
void)
3107 charset()->cset->fill(charset(),(
char*) ptr, field_length,
3108 (has_charset() ?
' ' : 0));
3111 type_conversion_status store(
const char *to,uint length,
3113 type_conversion_status store(longlong nr,
bool unsigned_val);
3116 double val_real(
void);
3117 longlong val_int(
void);
3120 int cmp(
const uchar *,
const uchar *);
3122 void sql_type(
String &str)
const;
3123 virtual uchar *
pack(uchar *to,
const uchar *from,
3124 uint max_length,
bool low_byte_first);
3125 virtual const uchar *
unpack(uchar* to,
const uchar *from,
3126 uint param_data,
bool low_byte_first);
3127 uint pack_length_from_metadata(uint field_metadata)
3129 DBUG_PRINT(
"debug", (
"field_metadata: 0x%04x", field_metadata));
3130 if (field_metadata == 0)
3131 return row_pack_length();
3132 return (((field_metadata >> 4) & 0x300) ^ 0x300) + (field_metadata & 0x00ff);
3135 uint16 mflags,
int *order_var);
3136 uint row_pack_length()
const {
return field_length; }
3137 int pack_cmp(
const uchar *a,
const uchar *b,uint key_length,
3138 my_bool insert_or_update);
3139 int pack_cmp(
const uchar *b,uint key_length,my_bool insert_or_update);
3140 uint packed_col_length(
const uchar *to, uint length);
3141 uint max_packed_col_length(uint max_length);
3142 enum_field_types real_type()
const {
return MYSQL_TYPE_STRING; }
3143 bool has_charset(
void)
const
3144 {
return charset() == &my_charset_bin ? FALSE : TRUE; }
3147 DBUG_ASSERT(real_type() == MYSQL_TYPE_STRING);
3151 DBUG_ASSERT(real_type() == MYSQL_TYPE_STRING);
3154 virtual uint get_key_image(uchar *buff,uint length, imagetype type);
3156 int do_save_field_metadata(uchar *first_byte);
3166 static const uint MAX_SIZE;
3168 uint32 length_bytes;
3170 uint32 len_arg, uint length_bytes_arg,
3171 uchar *null_ptr_arg, uchar null_bit_arg,
3172 enum utype unireg_check_arg,
const char *field_name_arg,
3174 :
Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
3175 unireg_check_arg, field_name_arg, cs),
3176 length_bytes(length_bytes_arg)
3178 share->varchar_fields++;
3181 const char *field_name_arg,
3183 :
Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*)
"": 0, 0,
3184 NONE, field_name_arg, cs),
3185 length_bytes(len_arg < 256 ? 1 :2)
3187 share->varchar_fields++;
3190 enum_field_types type()
const {
return MYSQL_TYPE_VARCHAR; }
3191 bool match_collation_to_optimize_range()
const {
return true; }
3192 enum ha_base_keytype key_type()
const;
3193 uint row_pack_length()
const {
return field_length; }
3194 bool zero_pack()
const {
return 0; }
3195 type_conversion_status reset(
void)
3197 memset(ptr, 0, field_length+length_bytes);
3200 uint32 pack_length()
const {
return (uint32) field_length+length_bytes; }
3201 uint32 key_length()
const {
return (uint32) field_length; }
3202 uint32 sort_length()
const
3204 return (uint32) field_length + (field_charset == &my_charset_bin ?
3207 type_conversion_status store(
const char *to,uint length,
3209 type_conversion_status store(longlong nr,
bool unsigned_val);
3212 double val_real(
void);
3213 longlong val_int(
void);
3216 int cmp_max(
const uchar *,
const uchar *, uint max_length);
3217 int cmp(
const uchar *a,
const uchar *b)
3219 return cmp_max(a, b, ~0L);
3222 uint get_key_image(uchar *buff,uint length, imagetype type);
3223 void set_key_image(
const uchar *buff,uint length);
3224 void sql_type(
String &str)
const;
3225 virtual uchar *
pack(uchar *to,
const uchar *from,
3226 uint max_length,
bool low_byte_first);
3227 virtual const uchar *
unpack(uchar* to,
const uchar *from,
3228 uint param_data,
bool low_byte_first);
3229 int cmp_binary(
const uchar *a,
const uchar *b, uint32 max_length=~0L);
3230 int key_cmp(
const uchar *,
const uchar*);
3231 int key_cmp(
const uchar *str, uint length);
3232 uint packed_col_length(
const uchar *to, uint length);
3233 uint max_packed_col_length(uint max_length);
3234 uint32 data_length();
3235 enum_field_types real_type()
const {
return MYSQL_TYPE_VARCHAR; }
3236 bool has_charset(
void)
const
3237 {
return charset() == &my_charset_bin ? FALSE : TRUE; }
3240 uchar *new_ptr, uchar *new_null_ptr,
3243 DBUG_ASSERT(type() == MYSQL_TYPE_VARCHAR);
3244 DBUG_ASSERT(real_type() == MYSQL_TYPE_VARCHAR);
3248 DBUG_ASSERT(type() == MYSQL_TYPE_VARCHAR);
3249 DBUG_ASSERT(real_type() == MYSQL_TYPE_VARCHAR);
3253 void hash(ulong *nr, ulong *nr2);
3255 int do_save_field_metadata(uchar *first_byte);
3260 virtual type_conversion_status store_internal(
const char *from, uint length,
3265 type_conversion_status store_to_mem(
const char *from, uint length,
3285 store_length(length);
3286 bmove(ptr +
packlength, &from,
sizeof(
char *));
3290 Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
3291 enum utype unireg_check_arg,
const char *field_name_arg,
3293 Field_blob(uint32 len_arg,
bool maybe_null_arg,
const char *field_name_arg,
3295 :
Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*)
"": 0, 0,
3296 NONE, field_name_arg, cs),
3301 Field_blob(uint32 len_arg,
bool maybe_null_arg,
const char *field_name_arg,
3303 :
Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*)
"": 0, 0,
3304 NONE, field_name_arg, cs)
3310 uint32 l_char_length= len_arg/cs->mbmaxlen;
3312 l_char_length <= 65535 ? 2 :
3313 l_char_length <= 16777215 ? 3 : 4;
3317 :
Field_longstr((uchar*) 0, 0, (uchar*)
"", 0, NONE,
"temp", system_charset_info),
3320 enum_field_types type()
const {
return MYSQL_TYPE_BLOB;}
3321 bool match_collation_to_optimize_range()
const {
return true; }
3322 enum ha_base_keytype key_type()
const
3323 {
return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
3324 type_conversion_status store(
const char *to, uint length,
3326 type_conversion_status store(
double nr);
3327 type_conversion_status store(longlong nr,
bool unsigned_val);
3328 double val_real(
void);
3329 longlong val_int(
void);
3332 int cmp_max(
const uchar *,
const uchar *, uint max_length);
3333 int cmp(
const uchar *a,
const uchar *b)
3334 {
return cmp_max(a, b, ~0L); }
3335 int cmp(
const uchar *a, uint32 a_length,
const uchar *b, uint32 b_length);
3336 int cmp_binary(
const uchar *a,
const uchar *b, uint32 max_length=~0L);
3337 int key_cmp(
const uchar *,
const uchar*);
3338 int key_cmp(
const uchar *str, uint length);
3339 uint32 key_length()
const {
return 0; }
3341 uint32 pack_length()
const
3342 {
return (uint32) (
packlength + portable_sizeof_char_ptr); }
3355 uint32 sort_length()
const;
3358 return (uint32) (((ulonglong) 1 << (
packlength*8)) -1);
3360 type_conversion_status reset(
void)
3365 void reset_fields() { memset(&
value, 0,
sizeof(
value)); }
3366 uint32 get_field_buffer_size(
void) {
return value.alloced_length(); }
3367 #ifndef WORDS_BIGENDIAN
3370 void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number,
bool low_byte_first);
3371 void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number)
3373 store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
3375 inline void store_length(uint32 number)
3391 inline uint32 get_length(uint row_offset= 0)
3392 {
return get_length(ptr+row_offset, this->
packlength, table->s->db_low_byte_first); }
3393 uint32 get_length(
const uchar *ptr, uint
packlength,
bool low_byte_first);
3394 uint32 get_length(
const uchar *ptr_arg)
3395 {
return get_length(ptr_arg, this->
packlength, table->s->db_low_byte_first); }
3397 inline void get_ptr(uchar **str)
3401 inline void get_ptr(uchar **str, uint row_offset)
3403 memcpy(str, ptr+
packlength+row_offset,
sizeof(
char*));
3405 inline void set_ptr(uchar *length, uchar *data)
3410 void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data)
3412 uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
3414 memcpy(ptr_ofs+
packlength, &data,
sizeof(
char*));
3416 inline void set_ptr(uint32 length, uchar *data)
3418 set_ptr_offset(0, length, data);
3420 uint get_key_image(uchar *buff,uint length, imagetype type);
3421 void set_key_image(
const uchar *buff,uint length);
3422 void sql_type(
String &str)
const;
3427 if (
value.copy((
char*) tmp, get_length(), charset()))
3429 Field_blob::reset();
3432 tmp=(uchar*)
value.ptr();
3437 DBUG_ASSERT(type() == MYSQL_TYPE_BLOB);
3441 DBUG_ASSERT(type() == MYSQL_TYPE_BLOB);
3444 virtual uchar *
pack(uchar *to,
const uchar *from,
3445 uint max_length,
bool low_byte_first);
3446 virtual const uchar *
unpack(uchar *to,
const uchar *from,
3447 uint param_data,
bool low_byte_first);
3448 uint packed_col_length(
const uchar *col_ptr, uint length);
3449 uint max_packed_col_length(uint max_length);
3450 void free() {
value.free(); }
3451 inline void clear_temporary() { memset(&
value, 0,
sizeof(
value)); }
3453 bool has_charset(
void)
const
3454 {
return charset() == &my_charset_bin ? FALSE : TRUE; }
3458 inline bool in_read_set() {
return bitmap_is_set(table->read_set, field_index); }
3459 inline bool in_write_set() {
return bitmap_is_set(table->write_set, field_index); }
3461 int do_save_field_metadata(uchar *first_byte);
3467 virtual type_conversion_status store_internal(
const char *from, uint length,
3470 enum geometry_type geom_type;
3472 Field_geom(uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
3473 enum utype unireg_check_arg,
const char *field_name_arg,
3475 enum geometry_type geom_type_arg)
3476 :
Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
3477 field_name_arg, share, blob_pack_length, &my_charset_bin)
3478 { geom_type= geom_type_arg; }
3479 Field_geom(uint32 len_arg,
bool maybe_null_arg,
const char *field_name_arg,
3480 TABLE_SHARE *share,
enum geometry_type geom_type_arg)
3481 :
Field_blob(len_arg, maybe_null_arg, field_name_arg, &my_charset_bin)
3482 { geom_type= geom_type_arg; }
3483 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_VARBINARY2; }
3484 enum_field_types
type()
const {
return MYSQL_TYPE_GEOMETRY; }
3485 bool match_collation_to_optimize_range()
const {
return false; }
3486 void sql_type(
String &str)
const;
3487 using Field_blob::store;
3488 type_conversion_status store(
double nr);
3489 type_conversion_status store(longlong nr,
bool unsigned_val);
3496 type_conversion_status reset(
void)
3498 type_conversion_status res= Field_blob::reset();
3501 return maybe_null() ? TYPE_OK : TYPE_ERR_NULL_CONSTRAINT_VIOLATION;
3504 geometry_type get_geometry_type() {
return geom_type; };
3506 DBUG_ASSERT(
type() == MYSQL_TYPE_GEOMETRY);
3507 return new (mem_root) Field_geom(*
this);
3509 Field_geom *
clone()
const {
3510 DBUG_ASSERT(
type() == MYSQL_TYPE_GEOMETRY);
3511 return new Field_geom(*
this);
3523 Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
3525 enum utype unireg_check_arg,
const char *field_name_arg,
3526 uint packlength_arg,
3529 :
Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
3530 unireg_check_arg, field_name_arg, charset_arg),
3531 packlength(packlength_arg),typelib(typelib_arg)
3536 enum_field_types type()
const {
return MYSQL_TYPE_STRING; }
3537 bool match_collation_to_optimize_range()
const {
return false; }
3538 enum Item_result cmp_type ()
const {
return INT_RESULT; }
3539 enum Item_result cast_to_int_type ()
const {
return INT_RESULT; }
3540 enum ha_base_keytype key_type()
const;
3541 type_conversion_status
store(
const char *to,uint length,
3543 type_conversion_status
store(
double nr);
3544 type_conversion_status
store(longlong nr,
bool unsigned_val);
3545 double val_real(
void);
3547 longlong val_int(
void);
3549 int cmp(
const uchar *,
const uchar *);
3551 uint32 pack_length()
const {
return (uint32) packlength; }
3552 void store_type(ulonglong value);
3553 void sql_type(
String &str)
const;
3554 enum_field_types real_type()
const {
return MYSQL_TYPE_ENUM; }
3555 uint pack_length_from_metadata(uint field_metadata)
3556 {
return (field_metadata & 0x00ff); }
3557 uint row_pack_length()
const {
return pack_length(); }
3558 virtual bool zero_pack()
const {
return 0; }
3559 bool optimize_range(uint idx, uint part) {
return 0; }
3561 bool has_charset(
void)
const {
return TRUE; }
3563 CHARSET_INFO *sort_charset(
void)
const {
return &my_charset_bin; }
3565 DBUG_ASSERT(real_type() == MYSQL_TYPE_ENUM);
3569 DBUG_ASSERT(real_type() == MYSQL_TYPE_ENUM);
3572 virtual uchar *
pack(uchar *to,
const uchar *from,
3573 uint max_length,
bool low_byte_first);
3574 virtual const uchar *
unpack(uchar *to,
const uchar *from,
3575 uint param_data,
bool low_byte_first);
3578 int do_save_field_metadata(uchar *first_byte);
3585 Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
3587 enum utype unireg_check_arg,
const char *field_name_arg,
3588 uint32 packlength_arg,
3590 :
Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
3591 unireg_check_arg, field_name_arg,
3593 typelib_arg,charset_arg),
3594 empty_set_string(
"", 0, charset_arg)
3596 flags= (flags & ~ENUM_FLAG) | SET_FLAG;
3598 type_conversion_status
store(
const char *to, uint length,
3604 type_conversion_status
store(longlong nr,
bool unsigned_val);
3605 virtual bool zero_pack()
const {
return 1; }
3607 void sql_type(
String &str)
const;
3608 enum_field_types real_type()
const {
return MYSQL_TYPE_SET; }
3609 bool has_charset(
void)
const {
return TRUE; }
3611 DBUG_ASSERT(real_type() == MYSQL_TYPE_SET);
3615 DBUG_ASSERT(real_type() == MYSQL_TYPE_SET);
3619 const String empty_set_string;
3643 Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
3644 uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
3645 enum utype unireg_check_arg,
const char *field_name_arg);
3646 enum_field_types type()
const {
return MYSQL_TYPE_BIT; }
3647 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_BIT; }
3648 uint32 key_length()
const {
return (uint32) (field_length + 7) / 8; }
3650 uint32 max_display_length() {
return field_length; }
3651 Item_result result_type ()
const {
return INT_RESULT; }
3652 type_conversion_status reset(
void)
3654 memset(ptr, 0, bytes_in_rec);
3655 if (bit_ptr && (bit_len > 0))
3656 clr_rec_bits(bit_ptr, bit_ofs, bit_len);
3659 type_conversion_status store(
const char *to, uint length,
3661 type_conversion_status store(
double nr);
3662 type_conversion_status store(longlong nr,
bool unsigned_val);
3663 type_conversion_status store_decimal(
const my_decimal *);
3664 double val_real(
void);
3665 longlong val_int(
void);
3667 virtual bool str_needs_quotes() {
return TRUE; }
3669 int cmp(
const uchar *a,
const uchar *b)
3671 DBUG_ASSERT(ptr == a || ptr == b);
3673 return Field_bit::key_cmp(b, bytes_in_rec+
test(bit_len));
3675 return Field_bit::key_cmp(a, bytes_in_rec+
test(bit_len)) * -1;
3677 int cmp_binary_offset(uint row_offset)
3678 {
return cmp_offset(row_offset); }
3679 int cmp_max(
const uchar *a,
const uchar *b, uint max_length);
3680 int key_cmp(
const uchar *a,
const uchar *b)
3681 {
return cmp_binary((uchar *) a, (uchar *) b); }
3682 int key_cmp(
const uchar *str, uint length);
3683 int cmp_offset(uint row_offset);
3684 void get_image(uchar *buff, uint length,
const CHARSET_INFO *cs)
3685 { get_key_image(buff, length, itRAW); }
3686 void set_image(
const uchar *buff,uint length,
const CHARSET_INFO *cs)
3687 { Field_bit::store((
char *) buff, length, cs); }
3688 uint get_key_image(uchar *buff, uint length, imagetype type);
3689 void set_key_image(
const uchar *buff, uint length)
3690 { Field_bit::store((
char*) buff, length, &my_charset_bin); }
3692 { get_key_image(buff, length, itRAW); }
3693 uint32 pack_length()
const {
return (uint32) (field_length + 7) / 8; }
3694 uint32 pack_length_in_rec()
const {
return bytes_in_rec; }
3696 uint row_pack_length()
const
3697 {
return (bytes_in_rec + ((bit_len > 0) ? 1 : 0)); }
3699 uint16 mflags,
int *order_var);
3700 void sql_type(
String &str)
const;
3701 virtual uchar *
pack(uchar *to,
const uchar *from,
3702 uint max_length,
bool low_byte_first);
3703 virtual const uchar *
unpack(uchar *to,
const uchar *from,
3704 uint param_data,
bool low_byte_first);
3705 virtual void set_default();
3708 uchar *new_ptr, uchar *new_null_ptr,
3710 void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg)
3712 bit_ptr= bit_ptr_arg;
3713 bit_ofs= bit_ofs_arg;
3715 bool eq(
Field *field)
3717 return (Field::eq(field) &&
3718 bit_ptr == ((
Field_bit *)field)->bit_ptr &&
3719 bit_ofs == ((
Field_bit *)field)->bit_ofs);
3722 void move_field_offset(my_ptrdiff_t ptr_diff)
3724 Field::move_field_offset(ptr_diff);
3725 bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*);
3727 void hash(ulong *nr, ulong *nr2);
3729 DBUG_ASSERT(type() == MYSQL_TYPE_BIT);
3733 DBUG_ASSERT(type() == MYSQL_TYPE_BIT);
3737 virtual size_t do_last_null_byte()
const;
3738 int do_save_field_metadata(uchar *first_byte);
3753 enum utype unireg_check_arg,
const char *field_name_arg);
3754 enum ha_base_keytype key_type()
const {
return HA_KEYTYPE_BINARY; }
3755 type_conversion_status store(
const char *to, uint length,
3757 type_conversion_status store(
double nr) {
return Field_bit::store(nr); }
3758 type_conversion_status store(longlong nr,
bool unsigned_val)
3759 {
return Field_bit::store(nr, unsigned_val); }
3760 void sql_type(
String &str)
const;
3775 const char *field_name;
3789 enum enum_field_types sql_type;
3800 uint decimals, flags, pack_length, key_length;
3801 Field::utype unireg_check;
3807 Field::geometry_type geom_type;
3810 uint8 row,col,sc_length,interval_id;
3811 uint offset,pack_flag;
3821 uint32 max_length, uint32 decimals,
3822 bool maybe_null,
bool is_unsigned,
3823 uint pack_length = ~0
U);
3825 bool init(THD *thd,
char *field_name, enum_field_types type,
char *length,
3826 char *decimals, uint type_modifier,
Item *default_value,
3829 uint uint_geom_type);
3831 bool field_flags_are_binary()
3833 return (flags & (BINCMP_FLAG | BINARY_FLAG)) != 0;
3836 ha_storage_media field_storage_type()
const
3838 return (ha_storage_media)
3839 ((flags >> FIELD_FLAGS_STORAGE_MEDIA) & 3);
3842 column_format_type column_format()
const
3844 return (column_format_type)
3845 ((flags >> FIELD_FLAGS_COLUMN_FORMAT) & 3);
3856 const char *db_name;
3857 const char *table_name,*org_table_name;
3858 const char *col_name,*org_col_name;
3860 uint charsetnr, flags, decimals;
3861 enum_field_types type;
3876 Copy_func *get_copy_func(
Field *to,
Field *from);
3878 uchar *from_ptr,*to_ptr;
3879 uchar *from_null_ptr,*to_null_ptr;
3881 uint from_bit,to_bit;
3900 Field *from_field,*to_field;
3906 void set(uchar *
to,
Field *from);
3913 uchar *null_pos, uchar null_bit,
3914 uint pack_flag, enum_field_types field_type,
3916 Field::geometry_type geom_type,
3917 Field::utype unireg_check,
3918 TYPELIB *interval,
const char *field_name);
3919 uint pack_length_to_packflag(uint type);
3920 enum_field_types get_blob_type_from_length(ulong length);
3921 uint32 calc_pack_length(enum_field_types type,uint32 length);
3922 type_conversion_status set_field_to_null(
Field *field);
3924 bool no_conversions);
3930 #define FIELDFLAG_DECIMAL 1
3931 #define FIELDFLAG_BINARY 1 // Shares same flag
3932 #define FIELDFLAG_NUMBER 2
3933 #define FIELDFLAG_ZEROFILL 4
3934 #define FIELDFLAG_PACK 120 // Bits used for packing
3935 #define FIELDFLAG_INTERVAL 256 // mangled with decimals!
3936 #define FIELDFLAG_BITFIELD 512 // mangled with decimals!
3937 #define FIELDFLAG_BLOB 1024 // mangled with decimals!
3938 #define FIELDFLAG_GEOM 2048 // mangled with decimals!
3940 #define FIELDFLAG_TREAT_BIT_AS_CHAR 4096
3942 #define FIELDFLAG_LEFT_FULLSCREEN 8192
3943 #define FIELDFLAG_RIGHT_FULLSCREEN 16384
3944 #define FIELDFLAG_FORMAT_NUMBER 16384 // predit: ###,,## in output
3945 #define FIELDFLAG_NO_DEFAULT 16384
3946 #define FIELDFLAG_SUM ((uint) 32768)// predit: +#fieldflag
3947 #define FIELDFLAG_MAYBE_NULL ((uint) 32768)// sql
3948 #define FIELDFLAG_HEX_ESCAPE ((uint) 0x10000)
3949 #define FIELDFLAG_PACK_SHIFT 3
3950 #define FIELDFLAG_DEC_SHIFT 8
3951 #define FIELDFLAG_MAX_DEC 31
3952 #define FIELDFLAG_NUM_SCREEN_TYPE 0x7F01
3953 #define FIELDFLAG_ALFA_SCREEN_TYPE 0x7800
3955 #define MTYP_TYPENR(type) (type & 127)
3957 #define f_is_dec(x) ((x) & FIELDFLAG_DECIMAL)
3958 #define f_is_num(x) ((x) & FIELDFLAG_NUMBER)
3959 #define f_is_zerofill(x) ((x) & FIELDFLAG_ZEROFILL)
3960 #define f_is_packed(x) ((x) & FIELDFLAG_PACK)
3961 #define f_packtype(x) (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
3962 #define f_decimals(x) ((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
3963 #define f_is_alpha(x) (!f_is_num(x))
3964 #define f_is_binary(x) ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
3965 #define f_is_enum(x) (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
3966 #define f_is_bitfield(x) (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
3967 #define f_is_blob(x) (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
3968 #define f_is_geom(x) (((x) & (FIELDFLAG_GEOM | FIELDFLAG_NUMBER)) == FIELDFLAG_GEOM)
3969 #define f_is_equ(x) ((x) & (1+2+FIELDFLAG_PACK+31*256))
3970 #define f_settype(x) (((int) x) << FIELDFLAG_PACK_SHIFT)
3971 #define f_maybe_null(x) (x & FIELDFLAG_MAYBE_NULL)
3972 #define f_no_default(x) (x & FIELDFLAG_NO_DEFAULT)
3973 #define f_bit_as_char(x) ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
3974 #define f_is_hex_escape(x) ((x) & FIELDFLAG_HEX_ESCAPE)