26
26
#define DRIZZLED_FIELD_H
28
28
#include "drizzled/sql_error.h"
29
#include "drizzled/decimal.h"
29
#include "drizzled/my_decimal.h"
30
30
#include "drizzled/key_map.h"
31
31
#include "drizzled/sql_bitmap.h"
32
32
#include "drizzled/sql_list.h"
33
33
#include "drizzled/structs.h"
34
#include "drizzled/charset_info.h"
35
#include "drizzled/item_result.h"
43
38
#define DATETIME_DEC 6
44
39
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
76
* The value stored in the Field object is stored in the
69
* The value stored in the Field object is stored in the
77
70
* unsigned char pointer member variable called ptr. The
78
* val_xxx() methods retrieve this raw byte value and
71
* val_xxx() methods retrieve this raw byte value and
79
72
* convert the byte into the appropriate output (int, decimal, etc).
81
74
* The store_xxx() methods take various input and convert
86
79
/* Prevent use of these */
88
81
void operator=(Field &);
90
83
unsigned char *ptr; /**< Position to field in record. Stores raw field value */
91
84
unsigned char *null_ptr; /**< Byte where null_bit is */
94
* Pointer to the Table object containing this Field
87
* Pointer to the Table object containing this Field
96
89
* @note You can use table->in_use as replacement for current_session member
97
90
* only inside of val_*() and store() members (e.g. you can't use it in cons)
100
93
Table *orig_table; /**< Pointer to the original Table. @TODO What is "the original table"? */
101
94
const char **table_name; /**< Pointer to the name of the table. @TODO This is redundant with Table::table_name. */
102
95
const char *field_name; /**< Name of the field */
109
102
key_map part_of_sortkey;
112
We use three additional unireg types for TIMESTAMP for hysterical
113
raisins and limitations in the MySQL FRM file format.
115
A good TODO is to clean this up as we can support just about
116
anything in the table proto message now.
105
We use three additional unireg types for TIMESTAMP to overcome limitation
106
of current binary format of .frm file. We'd like to be able to support
107
NOW() as default and on update value for such fields but unable to hold
108
this info anywhere except unireg_check field. This issue will be resolved
109
in more clean way with transition to new text based .frm format.
110
See also comment for Field_timestamp::Field_timestamp().
122
116
TIMESTAMP_OLD_FIELD,
141
135
bool is_created_from_null_item;
143
static void *operator new(size_t size);
144
static void *operator new(size_t size, memory::Root *mem_root);
137
static void *operator new(size_t size) {return sql_alloc(size); }
138
static void *operator new(size_t size, MEM_ROOT *mem_root)
139
{ return (void*) alloc_root(mem_root, (uint32_t) size); }
145
140
static void operator delete(void *, size_t)
141
{ TRASH(ptr_arg, size); }
148
143
Field(unsigned char *ptr_arg,
149
144
uint32_t length_arg,
153
148
const char *field_name_arg);
154
149
virtual ~Field() {}
155
150
/* Store functions returns 1 on overflow and -1 on fatal error */
156
virtual int store(const char *to,
151
virtual int store(const char *to,
158
153
const CHARSET_INFO * const cs)=0;
159
154
virtual int store(double nr)=0;
160
155
virtual int store(int64_t nr, bool unsigned_val)=0;
161
156
virtual int store_decimal(const my_decimal *d)=0;
162
int store(const char *to,
157
int store(const char *to,
164
159
const CHARSET_INFO * const cs,
165
160
enum_check_fields check_level);
173
168
virtual double val_real(void)=0;
174
169
virtual int64_t val_int(void)=0;
175
170
virtual my_decimal *val_decimal(my_decimal *);
176
inline String *val_str(String *str)
171
inline String *val_str(String *str)
178
173
return val_str(str, str);
190
185
This trickery is used to decrease a number of malloc calls.
192
187
virtual String *val_str(String*, String *)=0;
189
* Interpret field value as an integer but return the result as a string.
191
* This is used for printing bit_fields as numbers while debugging.
193
String *val_int_as_str(String *val_buffer, bool unsigned_flag);
194
195
str_needs_quotes() returns true if the value returned by val_str() needs
195
196
to be quoted when used in constructing an SQL query.
202
203
Check whether a field type can be partially indexed by a key.
204
205
This is a static method, rather than a virtual function, because we need
205
to check the type of a non-Field in alter_table().
206
to check the type of a non-Field in mysql_alter_table().
207
208
@param type field type
257
258
* table, which is located on disk).
259
260
virtual uint32_t pack_length_in_rec() const;
262
* Return the "real size" of the data in memory.
262
Check to see if field size is compatible with destination.
264
This method is used in row-based replication to verify that the slave's
265
field size is less than or equal to the master's field size. The
266
encoded field metadata (from the master or source) is decoded and compared
267
to the size of this field (the slave or destination).
269
@param field_metadata Encoded size in field metadata
271
@retval 0 if this field's size is < the source field's size
272
@retval 1 if this field's size is >= the source field's size
274
virtual int compatible_field_size(uint32_t field_metadata);
275
virtual uint32_t pack_length_from_metadata(uint32_t field_metadata);
278
This method is used to return the size of the data in a row-based
279
replication row record. The default implementation of returning 0 is
280
designed to allow fields that do not use metadata to return true (1)
281
from compatible_field_size() which uses this function in the comparison.
282
The default value for field metadata for fields that do not have
283
metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
285
Note: While most classes that override this method return pack_length(),
286
the classes Field_varstring, and Field_blob return
287
field_length + 1, field_length, and pack_length_no_ptr() respectfully.
289
virtual uint32_t row_pack_length();
290
virtual int save_field_metadata(unsigned char *first_byte);
293
* Return the "real size" of the data in memory.
263
294
* For varstrings, this does _not_ include the length bytes.
265
296
virtual uint32_t data_length();
310
341
virtual uint32_t size_of() const =0;
312
bool is_null(ptrdiff_t row_offset= 0);
313
bool is_real_null(ptrdiff_t row_offset= 0);
343
bool is_null(my_ptrdiff_t row_offset= 0);
344
bool is_real_null(my_ptrdiff_t row_offset= 0);
314
345
bool is_null_in_record(const unsigned char *record);
315
346
bool is_null_in_record_with_offset(ptrdiff_t offset);
316
347
void set_null(ptrdiff_t row_offset= 0);
328
359
* use field->val_int() for comparison. Used to optimize clauses like
329
360
* 'a_column BETWEEN date_const AND date_const'.
331
virtual bool can_be_compared_as_int64_t() const
362
virtual bool can_be_compared_as_int64_t() const
335
366
virtual void free() {}
336
virtual Field *new_field(memory::Root *root,
367
virtual Field *new_field(MEM_ROOT *root,
337
368
Table *new_table,
339
virtual Field *new_key_field(memory::Root *root, Table *new_table,
340
unsigned char *new_ptr,
370
virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
371
unsigned char *new_ptr,
341
372
unsigned char *new_null_ptr,
342
373
uint32_t new_null_bit);
343
374
/** This is used to generate a field in Table from TableShare */
344
Field *clone(memory::Root *mem_root, Table *new_table);
375
Field *clone(MEM_ROOT *mem_root, Table *new_table);
345
376
inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
388
419
* characters have maximal possible size (mbmaxlen). In the other words,
389
420
* "length" parameter is a number of characters multiplied by
390
421
* field_charset->mbmaxlen.
393
424
* Number of copied bytes (excluding padded zero bytes -- see above).
426
457
inline String *val_str(String *str, const unsigned char *new_ptr)
428
459
unsigned char *old_ptr= ptr;
429
ptr= const_cast<unsigned char*>(new_ptr);
460
ptr= (unsigned char*) new_ptr;
520
551
virtual unsigned char *pack_key(unsigned char* to,
521
552
const unsigned char *from,
523
554
bool low_byte_first)
525
556
return pack(to, from, max_length, low_byte_first);
558
virtual unsigned char *pack_key_from_key_image(unsigned char* to,
559
const unsigned char *from,
563
return pack(to, from, max_length, low_byte_first);
527
565
virtual const unsigned char *unpack_key(unsigned char* to,
528
566
const unsigned char *from,
529
567
uint32_t max_length,
532
570
return unpack(to, from, max_length, low_byte_first);
572
virtual uint32_t packed_col_length(const unsigned char *to, uint32_t length);
534
573
virtual uint32_t max_packed_col_length(uint32_t max_length)
536
575
return max_length;
578
virtual int pack_cmp(const unsigned char *a,
579
const unsigned char *b,
580
uint32_t key_length_arg,
581
bool insert_or_update);
582
virtual int pack_cmp(const unsigned char *b,
583
uint32_t key_length_arg,
584
bool insert_or_update);
539
586
inline uint32_t offset(unsigned char *record)
541
588
return (uint32_t) (ptr - record);
592
639
fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
595
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
642
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
598
645
uint32_t str_len,
599
enum enum_drizzle_timestamp_type ts_type,
646
enum enum_drizzle_timestamp_type ts_type,
600
647
int cuted_increment);
602
649
Produce warning or note about integer datetime value saved into field.
612
659
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
615
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
662
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
618
665
enum enum_drizzle_timestamp_type ts_type,
619
666
int cuted_increment);
630
677
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
633
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
680
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
634
681
const uint32_t code,
636
683
enum enum_drizzle_timestamp_type ts_type);
637
684
inline bool check_overflow(int op_result)
704
751
bool isWriteSet();
705
752
void setReadSet(bool arg= true);
706
753
void setWriteSet(bool arg= true);
758
Retrieve the field metadata for fields.
760
This default implementation returns 0 and saves 0 in the metadata_ptr
763
@param metadata_ptr First byte of field metadata
765
@returns 0 no bytes written.
767
virtual int do_save_field_metadata(unsigned char *)
709
} /* namespace drizzled */
711
/** @TODO Why is this in the middle of the file???*/
712
773
#include "drizzled/create_field.h"
718
776
* A class for sending field information to a client.