50
58
return len > 4 ? 8 : len;
53
class virtual_column_info: public Sql_alloc
60
: expr_item(0), item_free_list(0),
61
field_type(DRIZZLE_TYPE_VIRTUAL),
62
is_stored(false), data_inited(false)
67
~virtual_column_info() {}
68
enum_field_types get_real_type()
71
return data_inited ? field_type : DRIZZLE_TYPE_VIRTUAL;
73
void set_field_type(enum_field_types fld_type)
75
/* Calling this function can only be done once. */
76
assert(not data_inited);
80
bool get_field_stored()
83
return data_inited ? is_stored : true;
85
void set_field_stored(bool stored)
91
The following data is only updated by the parser and read
92
when a Create_field object is created/initialized.
94
enum_field_types field_type; /* Real field type*/
95
bool is_stored; /* Indication that the field is
96
phisically stored in the database*/
98
This flag is used to prevent other applications from
99
reading and using incorrect data.
106
63
Field(const Item &); /* Prevent use of these */
124
81
/* Field is part of the following keys */
125
82
key_map key_start, part_of_key, part_of_key_not_clustered;
126
83
key_map part_of_sortkey;
128
We use three additional unireg types for TIMESTAMP to overcome limitation
129
of current binary format of .frm file. We'd like to be able to support
130
NOW() as default and on update value for such fields but unable to hold
85
We use three additional unireg types for TIMESTAMP to overcome limitation
86
of current binary format of .frm file. We'd like to be able to support
87
NOW() as default and on update value for such fields but unable to hold
131
88
this info anywhere except unireg_check field. This issue will be resolved
132
89
in more clean way with transition to new text based .frm format.
133
90
See also comment for Field_timestamp::Field_timestamp().
135
92
enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
136
CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
93
CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
137
94
BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
138
95
TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
139
96
enum imagetype { itRAW, itMBR};
168
125
const char *field_name_arg);
169
126
virtual ~Field() {}
170
127
/* Store functions returns 1 on overflow and -1 on fatal error */
171
virtual int store(const char *to, uint32_t length, const CHARSET_INFO * const cs)=0;
128
virtual int store(const char *to, uint32_t length,
129
const CHARSET_INFO * const cs)=0;
172
130
virtual int store(double nr)=0;
173
131
virtual int store(int64_t nr, bool unsigned_val)=0;
174
132
virtual int store_decimal(const my_decimal *d)=0;
175
virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
133
virtual int store_time(DRIZZLE_TIME *ltime,
134
enum enum_drizzle_timestamp_type t_type);
176
135
int store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
177
136
enum_check_fields check_level);
178
137
virtual double val_real(void)=0;
201
160
virtual Item_result result_type () const=0;
202
161
virtual Item_result cmp_type () const { return result_type(); }
203
162
virtual Item_result cast_to_int_type () const { return result_type(); }
164
Check whether a field type can be partially indexed by a key.
166
This is a static method, rather than a virtual function, because we need
167
to check the type of a non-Field in mysql_alter_table().
169
@param type field type
172
true Type can have a prefixed key
174
false Type can not have a prefixed key
204
176
static bool type_can_have_key_part(enum_field_types);
205
177
static enum_field_types field_type_merge(enum_field_types, enum_field_types);
180
Detect Item_result by given field type of UNION merge result.
182
@param field_type given field type
185
Item_result (type of internal MySQL expression result)
206
187
static Item_result result_merge_type(enum_field_types);
207
virtual bool eq(Field *field)
209
return (ptr == field->ptr && null_ptr == field->null_ptr &&
210
null_bit == field->null_bit);
189
virtual bool eq(Field *field);
212
190
virtual bool eq_def(Field *field);
215
193
pack_length() returns size (in bytes) used to store field data in memory
216
194
(i.e. it returns the maximum size of the field in a row of the table,
217
195
which is located in RAM).
219
virtual uint32_t pack_length() const { return (uint32_t) field_length; }
197
virtual uint32_t pack_length() const;
222
200
pack_length_in_rec() returns size (in bytes) used to store field data on
223
201
storage (i.e. it returns the maximal size of the field in a row of the
224
202
table, which is located on disk).
226
virtual uint32_t pack_length_in_rec() const { return pack_length(); }
204
virtual uint32_t pack_length_in_rec() const;
227
205
virtual int compatible_field_size(uint32_t field_metadata);
228
virtual uint32_t pack_length_from_metadata(uint32_t field_metadata)
229
{ return field_metadata; }
206
virtual uint32_t pack_length_from_metadata(uint32_t field_metadata);
231
209
This method is used to return the size of the data in a row-based
232
210
replication row record. The default implementation of returning 0 is
233
211
designed to allow fields that do not use metadata to return true (1)
234
212
from compatible_field_size() which uses this function in the comparison.
235
The default value for field metadata for fields that do not have
213
The default value for field metadata for fields that do not have
236
214
metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
238
216
Note: While most classes that override this method return pack_length(),
239
the classes Field_varstring, and Field_blob return
217
the classes Field_varstring, and Field_blob return
240
218
field_length + 1, field_length, and pack_length_no_ptr() respectfully.
242
virtual uint32_t row_pack_length() { return 0; }
243
virtual int save_field_metadata(unsigned char *first_byte)
244
{ return do_save_field_metadata(first_byte); }
220
virtual uint32_t row_pack_length();
221
virtual int save_field_metadata(unsigned char *first_byte);
247
224
data_length() return the "real size" of the data in memory.
248
225
For varstrings, this does _not_ include the length bytes.
250
virtual uint32_t data_length() { return pack_length(); }
227
virtual uint32_t data_length();
252
229
used_length() returns the number of bytes actually used to store the data
253
230
of the field. So for a varstring it includes both lenght byte(s) and
254
231
string data, and anything after data_length() bytes are unused.
256
virtual uint32_t used_length() { return pack_length(); }
257
virtual uint32_t sort_length() const { return pack_length(); }
233
virtual uint32_t used_length();
234
virtual uint32_t sort_length() const;
260
237
Get the maximum size of the data in packed format.
262
239
@return Maximum data length of the field when packed using the
263
240
Field::pack() function.
265
virtual uint32_t max_data_length() const {
266
return pack_length();
269
virtual int reset(void) { memset(ptr, 0, pack_length()); return 0; }
270
virtual void reset_fields() {}
271
virtual void set_default()
273
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
274
memcpy(ptr, ptr + l_offset, pack_length());
276
*null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
278
virtual bool binary() const { return 1; }
279
virtual bool zero_pack() const { return 1; }
280
virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
281
virtual uint32_t key_length() const { return pack_length(); }
242
virtual uint32_t max_data_length() const;
243
virtual int reset(void);
244
virtual void reset_fields();
245
virtual void set_default();
246
virtual bool binary() const;
247
virtual bool zero_pack() const;
248
virtual enum ha_base_keytype key_type() const;
249
virtual uint32_t key_length() const;
282
250
virtual enum_field_types type() const =0;
283
virtual enum_field_types real_type() const { return type(); }
251
virtual enum_field_types real_type() const;
284
252
inline int cmp(const unsigned char *str) { return cmp(ptr,str); }
285
253
virtual int cmp_max(const unsigned char *a, const unsigned char *b,
286
uint32_t max_len __attribute__((unused)))
287
{ return cmp(a, b); }
288
255
virtual int cmp(const unsigned char *,const unsigned char *)=0;
289
256
virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
290
uint32_t __attribute__((unused)) max_length=UINT32_MAX)
291
{ return memcmp(a,b,pack_length()); }
292
virtual int cmp_offset(uint32_t row_offset)
293
{ return cmp(ptr,ptr+row_offset); }
294
virtual int cmp_binary_offset(uint32_t row_offset)
295
{ return cmp_binary(ptr, ptr+row_offset); };
296
virtual int key_cmp(const unsigned char *a,const unsigned char *b)
297
{ return cmp(a, b); }
298
virtual int key_cmp(const unsigned char *str, uint32_t length __attribute__((unused)))
299
{ return cmp(ptr,str); }
300
virtual uint32_t decimals() const { return 0; }
257
uint32_t max_length=UINT32_MAX);
258
virtual int cmp_offset(uint32_t row_offset);
259
virtual int cmp_binary_offset(uint32_t row_offset);
260
virtual int key_cmp(const unsigned char *a,const unsigned char *b);
261
virtual int key_cmp(const unsigned char *str, uint32_t length);
262
virtual uint32_t decimals() const;
302
265
Caller beware: sql_type can change str.Ptr, so check
303
266
ptr() to see if it changed if you are using your own buffer
304
267
in str and restore it with set() if needed
306
269
virtual void sql_type(String &str) const =0;
307
virtual uint32_t size_of() const =0; // For new field
308
inline bool is_null(my_ptrdiff_t row_offset= 0)
309
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
310
inline bool is_real_null(my_ptrdiff_t row_offset= 0)
311
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
312
inline bool is_null_in_record(const unsigned char *record)
316
return test(record[(uint32_t) (null_ptr -table->record[0])] &
319
inline bool is_null_in_record_with_offset(my_ptrdiff_t offset)
323
return test(null_ptr[offset] & null_bit);
325
inline void set_null(my_ptrdiff_t row_offset= 0)
326
{ if (null_ptr) null_ptr[row_offset]|= null_bit; }
327
inline void set_notnull(my_ptrdiff_t row_offset= 0)
328
{ if (null_ptr) null_ptr[row_offset]&= (unsigned char) ~null_bit; }
329
inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
330
inline bool real_maybe_null(void) { return null_ptr != 0; }
272
virtual uint32_t size_of() const =0;
274
bool is_null(my_ptrdiff_t row_offset= 0);
275
bool is_real_null(my_ptrdiff_t row_offset= 0);
276
bool is_null_in_record(const unsigned char *record);
277
bool is_null_in_record_with_offset(my_ptrdiff_t offset);
278
void set_null(my_ptrdiff_t row_offset= 0);
279
void set_notnull(my_ptrdiff_t row_offset= 0);
280
bool maybe_null(void);
281
bool real_maybe_null(void);
333
284
LAST_NULL_BYTE_UNDEF= 0
452
399
virtual bool send_binary(Protocol *protocol);
454
401
virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
455
uint32_t max_length, bool low_byte_first);
402
uint32_t max_length, bool low_byte_first);
457
@overload Field::pack(unsigned char*, const unsigned char*, uint32_t, bool)
404
@overload Field::pack(unsigned char*, const unsigned char*,
459
unsigned char *pack(unsigned char *to, const unsigned char *from)
461
unsigned char *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
407
unsigned char *pack(unsigned char *to, const unsigned char *from);
465
virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
466
uint32_t param_data, bool low_byte_first);
409
virtual const unsigned char *unpack(unsigned char* to,
410
const unsigned char *from,
412
bool low_byte_first);
468
@overload Field::unpack(unsigned char*, const unsigned char*, uint32_t, bool)
414
@overload Field::unpack(unsigned char*, const unsigned char*,
470
const unsigned char *unpack(unsigned char* to, const unsigned char *from)
472
const unsigned char *result= unpack(to, from, 0U, table->s->db_low_byte_first);
417
const unsigned char *unpack(unsigned char* to, const unsigned char *from);
476
419
virtual unsigned char *pack_key(unsigned char* to, const unsigned char *from,
477
420
uint32_t max_length, bool low_byte_first)
479
422
return pack(to, from, max_length, low_byte_first);
481
virtual unsigned char *pack_key_from_key_image(unsigned char* to, const unsigned char *from,
482
uint32_t max_length, bool low_byte_first)
424
virtual unsigned char *pack_key_from_key_image(unsigned char* to,
425
const unsigned char *from,
484
429
return pack(to, from, max_length, low_byte_first);
486
virtual const unsigned char *unpack_key(unsigned char* to, const unsigned char *from,
487
uint32_t max_length, bool low_byte_first)
431
virtual const unsigned char *unpack_key(unsigned char* to,
432
const unsigned char *from,
489
436
return unpack(to, from, max_length, low_byte_first);
491
virtual uint32_t packed_col_length(const unsigned char *to __attribute__((unused)),
438
virtual uint32_t packed_col_length(const unsigned char *to, uint32_t length);
494
439
virtual uint32_t max_packed_col_length(uint32_t max_length)
495
440
{ return max_length;}
497
442
virtual int pack_cmp(const unsigned char *a,const unsigned char *b,
498
uint32_t key_length_arg __attribute__((unused)),
499
bool insert_or_update __attribute__((unused)))
443
uint32_t key_length_arg,
444
bool insert_or_update);
501
445
virtual int pack_cmp(const unsigned char *b,
502
uint32_t key_length_arg __attribute__((unused)),
503
bool insert_or_update __attribute__((unused)))
504
{ return cmp(ptr,b); }
446
uint32_t key_length_arg,
447
bool insert_or_update);
505
449
uint32_t offset(unsigned char *record)
507
451
return (uint32_t) (ptr - record);