27
#ifndef DRIZZLED_FIELD_H
28
#define DRIZZLED_FIELD_H
30
#include <drizzled/sql_error.h>
31
#include <drizzled/type/decimal.h>
32
#include <drizzled/key_map.h>
33
#include <drizzled/sql_list.h>
34
#include <drizzled/structs.h>
35
#include <drizzled/charset_info.h>
36
#include <drizzled/item_result.h>
37
#include <drizzled/charset_info.h>
42
#include <drizzled/visibility.h>
47
26
#define DATETIME_DEC 6
48
27
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
51
#define ASSERT_COLUMN_MARKED_FOR_READ assert(!getTable() || (getTable()->read_set == NULL || isReadSet()))
52
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(!getTable() || (getTable()->write_set == NULL || isWriteSet()))
54
#define ASSERT_COLUMN_MARKED_FOR_READ assert(getTable())
55
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(getTable())
58
typedef struct st_typelib TYPELIB;
60
29
const uint32_t max_field_size= (uint32_t) 4294967295U;
34
struct st_cache_field;
68
35
int field_conv(Field *to,Field *from);
71
* Class representing a Field in a Table
75
* The value stored in the Field object is stored in the
76
* unsigned char pointer member variable called ptr. The
77
* val_xxx() methods retrieve this raw byte value and
78
* convert the byte into the appropriate output (int, decimal, etc).
80
* The store_xxx() methods take various input and convert
81
* the input into the raw bytes stored in the ptr member variable.
83
class DRIZZLED_API Field
85
/* Prevent use of these */
37
inline uint32_t get_enum_pack_length(int elements)
39
return elements < 256 ? 1 : 2;
42
inline uint32_t get_set_pack_length(int elements)
44
uint32_t len= (elements + 7) / 8;
45
return len > 4 ? 8 : len;
48
class virtual_column_info: public Sql_alloc
55
: expr_item(0), item_free_list(0),
56
field_type(DRIZZLE_TYPE_VIRTUAL),
57
is_stored(false), data_inited(false)
62
~virtual_column_info() {}
63
enum_field_types get_real_type()
66
return data_inited ? field_type : DRIZZLE_TYPE_VIRTUAL;
68
void set_field_type(enum_field_types fld_type)
70
/* Calling this function can only be done once. */
71
assert(not data_inited);
75
bool get_field_stored()
78
return data_inited ? is_stored : true;
80
void set_field_stored(bool stored)
86
The following data is only updated by the parser and read
87
when a Create_field object is created/initialized.
89
enum_field_types field_type; /* Real field type*/
90
bool is_stored; /* Indication that the field is
91
phisically stored in the database*/
93
This flag is used to prevent other applications from
94
reading and using incorrect data.
101
Field(const Item &); /* Prevent use of these */
87
102
void operator=(Field &);
90
unsigned char *ptr; /**< Position to field in record. Stores raw field value */
91
unsigned char *null_ptr; /**< Byte where null_bit is */
94
* Pointer to the Table object containing this Field
96
* @note You can use table->in_use as replacement for current_session member
97
* only inside of val_*() and store() members (e.g. you can't use it in cons)
109
Table *getTable() const
115
void setTable(Table *table_arg)
120
Table *orig_table; /**< Pointer to the original Table. @TODO What is "the original table"? */
121
const char *field_name; /**< Name of the field */
122
LEX_STRING comment; /**< A comment about the field */
124
/** The field is part of the following keys */
127
key_map part_of_key_not_clustered;
128
key_map part_of_sortkey;
104
static void *operator new(size_t size) {return sql_alloc(size); }
105
static void operator delete(void *ptr_arg __attribute__((unused)),
106
size_t size __attribute__((unused)))
107
{ TRASH(ptr_arg, size); }
109
unsigned char *ptr; // Position to field in record
110
unsigned char *null_ptr; // Byte where null_bit is
131
We use three additional unireg types for TIMESTAMP for hysterical
132
raisins and limitations in the MySQL FRM file format.
134
A good TODO is to clean this up as we can support just about
135
anything in the table proto message now.
148
uint32_t field_length; /**< Length of this field in bytes */
151
bool isUnsigned() const
153
return flags & UNSIGNED_FLAG;
157
uint16_t field_index; /**< Index of this Field in Table::fields array */
161
uint16_t position() const
166
void setPosition(uint32_t arg)
171
unsigned char null_bit; /**< Bit used to test null bit */
112
Note that you can use table->in_use as replacement for current_thd member
113
only inside of val_*() and store() members (e.g. you can't use it in cons)
115
Table *table; // Pointer for table
116
Table *orig_table; // Pointer to original table
117
const char **table_name, *field_name;
119
/* Field is part of the following keys */
120
key_map key_start, part_of_key, part_of_key_not_clustered;
121
key_map part_of_sortkey;
123
We use three additional unireg types for TIMESTAMP to overcome limitation
124
of current binary format of .frm file. We'd like to be able to support
125
NOW() as default and on update value for such fields but unable to hold
126
this info anywhere except unireg_check field. This issue will be resolved
127
in more clean way with transition to new text based .frm format.
128
See also comment for Field_timestamp::Field_timestamp().
130
enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
131
CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
132
BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
133
TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
134
enum imagetype { itRAW, itMBR};
137
uint32_t field_length; // Length of field
139
uint16_t field_index; // field number in fields array
140
unsigned char null_bit; // Bit used to test null bit
173
142
If true, this field was created in create_tmp_field_from_item from a NULL
174
143
value. This means that the type of the field is just a guess, and the type
332
257
@return Maximum data length of the field when packed using the
333
258
Field::pack() function.
335
virtual uint32_t max_data_length() const;
336
virtual int reset(void);
337
virtual void reset_fields();
338
virtual void set_default();
339
virtual bool binary() const;
340
virtual bool zero_pack() const;
341
virtual enum ha_base_keytype key_type() const;
342
virtual uint32_t key_length() const;
260
virtual uint32_t max_data_length() const {
261
return pack_length();
264
virtual int reset(void) { memset(ptr, 0, pack_length()); return 0; }
265
virtual void reset_fields() {}
266
virtual void set_default()
268
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
269
memcpy(ptr, ptr + l_offset, pack_length());
271
*null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
273
virtual bool binary() const { return 1; }
274
virtual bool zero_pack() const { return 1; }
275
virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
276
virtual uint32_t key_length() const { return pack_length(); }
343
277
virtual enum_field_types type() const =0;
344
virtual enum_field_types real_type() const;
345
virtual int cmp_max(const unsigned char *a, const unsigned char *b, uint32_t max_len);
278
virtual enum_field_types real_type() const { return type(); }
279
inline int cmp(const unsigned char *str) { return cmp(ptr,str); }
280
virtual int cmp_max(const unsigned char *a, const unsigned char *b,
281
uint32_t max_len __attribute__((unused)))
282
{ return cmp(a, b); }
346
283
virtual int cmp(const unsigned char *,const unsigned char *)=0;
347
int cmp_internal(const unsigned char *str) { return cmp(ptr,str); }
348
284
virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
349
uint32_t max_length=UINT32_MAX);
350
virtual int cmp_offset(uint32_t row_offset);
351
virtual int cmp_binary_offset(uint32_t row_offset);
352
virtual int key_cmp(const unsigned char *a,const unsigned char *b);
353
virtual int key_cmp(const unsigned char *str, uint32_t length);
354
virtual uint32_t decimals() const;
285
uint32_t __attribute__((unused)) max_length=UINT32_MAX)
286
{ return memcmp(a,b,pack_length()); }
287
virtual int cmp_offset(uint32_t row_offset)
288
{ return cmp(ptr,ptr+row_offset); }
289
virtual int cmp_binary_offset(uint32_t row_offset)
290
{ return cmp_binary(ptr, ptr+row_offset); };
291
virtual int key_cmp(const unsigned char *a,const unsigned char *b)
292
{ return cmp(a, b); }
293
virtual int key_cmp(const unsigned char *str, uint32_t length __attribute__((unused)))
294
{ return cmp(ptr,str); }
295
virtual uint32_t decimals() const { return 0; }
357
297
Caller beware: sql_type can change str.Ptr, so check
358
298
ptr() to see if it changed if you are using your own buffer
359
299
in str and restore it with set() if needed
361
301
virtual void sql_type(String &str) const =0;
364
virtual uint32_t size_of() const =0;
366
bool is_null(ptrdiff_t row_offset= 0) const;
367
bool is_real_null(ptrdiff_t row_offset= 0) const;
368
bool is_null_in_record(const unsigned char *record) const;
369
bool is_null_in_record_with_offset(ptrdiff_t offset) const;
370
void set_null(ptrdiff_t row_offset= 0);
371
void set_notnull(ptrdiff_t row_offset= 0);
372
bool maybe_null(void) const;
373
bool real_maybe_null(void) const;
375
virtual void make_field(SendField *);
302
virtual uint32_t size_of() const =0; // For new field
303
inline bool is_null(my_ptrdiff_t row_offset= 0)
304
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
305
inline bool is_real_null(my_ptrdiff_t row_offset= 0)
306
{ return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
307
inline bool is_null_in_record(const unsigned char *record)
311
return test(record[(uint32_t) (null_ptr -table->record[0])] &
314
inline bool is_null_in_record_with_offset(my_ptrdiff_t offset)
318
return test(null_ptr[offset] & null_bit);
320
inline void set_null(my_ptrdiff_t row_offset= 0)
321
{ if (null_ptr) null_ptr[row_offset]|= null_bit; }
322
inline void set_notnull(my_ptrdiff_t row_offset= 0)
323
{ if (null_ptr) null_ptr[row_offset]&= (unsigned char) ~null_bit; }
324
inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
325
inline bool real_maybe_null(void) { return null_ptr != 0; }
328
LAST_NULL_BYTE_UNDEF= 0
332
Find the position of the last null byte for the field.
338
Return a pointer to the last byte of the null bytes where the
339
field conceptually is placed.
342
The position of the last null byte relative to the beginning of
343
the record. If the field does not use any bits of the null
344
bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
346
size_t last_null_byte() const {
347
size_t bytes= do_last_null_byte();
348
assert(bytes <= table->getNullBytes());
352
virtual void make_field(Send_field *);
376
353
virtual void sort_string(unsigned char *buff,uint32_t length)=0;
377
354
virtual bool optimize_range(uint32_t idx, uint32_t part);
379
* Returns true for fields which, when compared with constant
380
* items, can be casted to int64_t. In this case we will at 'fix_fields'
381
* stage cast the constant items to int64_ts and at the execution stage
382
* use field->val_int() for comparison. Used to optimize clauses like
383
* 'a_column BETWEEN date_const AND date_const'.
385
virtual bool can_be_compared_as_int64_t() const
356
This should be true for fields which, when compared with constant
357
items, can be casted to int64_t. In this case we will at 'fix_fields'
358
stage cast the constant items to int64_ts and at the execution stage
359
use field->val_int() for comparison. Used to optimize clauses like
360
'a_column BETWEEN date_const, date_const'.
362
virtual bool can_be_compared_as_int64_t() const { return false; }
389
363
virtual void free() {}
390
virtual Field *new_field(memory::Root *root,
364
virtual Field *new_field(MEM_ROOT *root, Table *new_table,
393
virtual Field *new_key_field(memory::Root *root, Table *new_table,
394
unsigned char *new_ptr,
395
unsigned char *new_null_ptr,
366
virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
367
unsigned char *new_ptr, unsigned char *new_null_ptr,
396
368
uint32_t new_null_bit);
397
/** This is used to generate a field in Table from TableShare */
398
Field *clone(memory::Root *mem_root, Table *new_table);
399
void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
369
Field *clone(MEM_ROOT *mem_root, Table *new_table);
370
inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
402
null_ptr= null_ptr_arg;
403
null_bit= null_bit_arg;
372
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
405
void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
406
virtual void move_field_offset(ptrdiff_t ptr_diff)
374
inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
375
virtual void move_field_offset(my_ptrdiff_t ptr_diff)
408
ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
377
ptr=ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
410
null_ptr= ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
412
virtual void get_image(unsigned char *buff, uint32_t length, const CHARSET_INFO * const)
414
memcpy(buff,ptr,length);
416
virtual void get_image(std::basic_string<unsigned char> &buff, uint32_t length, const CHARSET_INFO * const)
418
buff.append(ptr,length);
420
virtual void set_image(const unsigned char *buff,uint32_t length, const CHARSET_INFO * const)
422
memcpy(ptr,buff,length);
426
* Copy a field part into an output buffer.
430
* This function makes a copy of field part of size equal to or
431
* less than "length" parameter value.
432
* For fields of string types (VARCHAR, TEXT) the rest of buffer
433
* is padded by zero byte.
435
* @param output buffer
436
* @param output buffer size
440
* For variable length character fields (i.e. UTF-8) the "length"
441
* parameter means a number of output buffer bytes as if all field
442
* characters have maximal possible size (mbmaxlen). In the other words,
443
* "length" parameter is a number of characters multiplied by
444
* field_charset->mbmaxlen.
447
* Number of copied bytes (excluding padded zero bytes -- see above).
449
virtual uint32_t get_key_image(unsigned char *buff, uint32_t length)
451
get_image(buff, length, &my_charset_bin);
454
virtual uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length)
379
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
381
virtual void get_image(unsigned char *buff, uint32_t length,
382
const CHARSET_INFO * const cs __attribute__((unused)))
383
{ memcpy(buff,ptr,length); }
384
virtual void set_image(const unsigned char *buff,uint32_t length,
385
const CHARSET_INFO * const cs __attribute__((unused)))
386
{ memcpy(ptr,buff,length); }
390
Copy a field part into an output buffer.
393
Field::get_key_image()
394
buff [out] output buffer
395
length output buffer size
396
type itMBR for geometry blobs, otherwise itRAW
399
This function makes a copy of field part of size equal to or
400
less than "length" parameter value.
401
For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
402
is padded by zero byte.
405
For variable length character fields (i.e. UTF-8) the "length"
406
parameter means a number of output buffer bytes as if all field
407
characters have maximal possible size (mbmaxlen). In the other words,
408
"length" parameter is a number of characters multiplied by
409
field_charset->mbmaxlen.
412
Number of copied bytes (excluding padded zero bytes -- see above).
415
virtual uint32_t get_key_image(unsigned char *buff, uint32_t length,
416
imagetype type __attribute__((unused)))
456
418
get_image(buff, length, &my_charset_bin);
459
421
virtual void set_key_image(const unsigned char *buff,uint32_t length)
461
set_image(buff,length, &my_charset_bin);
463
int64_t val_int_offset(uint32_t row_offset)
466
int64_t tmp=val_int();
471
int64_t val_int_internal(const unsigned char *new_ptr)
422
{ set_image(buff,length, &my_charset_bin); }
423
inline int64_t val_int_offset(uint32_t row_offset)
426
int64_t tmp=val_int();
430
inline int64_t val_int(const unsigned char *new_ptr)
473
432
unsigned char *old_ptr= ptr;
474
ptr= const_cast<unsigned char*>(new_ptr);
475
int64_t return_value= val_int();
433
int64_t return_value;
434
ptr= (unsigned char*) new_ptr;
435
return_value= val_int();
477
437
return return_value;
480
String *val_str_internal(String *str, const unsigned char *new_ptr)
439
inline String *val_str(String *str, const unsigned char *new_ptr)
482
441
unsigned char *old_ptr= ptr;
483
ptr= const_cast<unsigned char*>(new_ptr);
484
val_str_internal(str);
442
ptr= (unsigned char*) new_ptr;
490
Pack the field into a format suitable for storage and transfer.
492
To implement packing functionality, only the virtual function
493
should be overridden. The other functions are just convenience
494
functions and hence should not be overridden.
496
The value of <code>low_byte_first</code> is dependent on how the
497
packed data is going to be used: for local use, e.g., temporary
498
store on disk or in memory, use the native format since that is
499
faster. For data that is going to be transfered to other machines
500
(e.g., when writing data to the binary log), data should always be
501
stored in little-endian format.
503
@note The default method for packing fields just copy the raw bytes
504
of the record into the destination, but never more than
505
<code>max_length</code> characters.
508
Pointer to memory area where representation of field should be put.
511
Pointer to memory area where record representation of field is
515
Maximum length of the field, as given in the column definition. For
516
example, for <code>CHAR(1000)</code>, the <code>max_length</code>
517
is 1000. This information is sometimes needed to decide how to pack
520
@param low_byte_first
521
@c true if integers should be stored little-endian, @c false if
522
native format should be used. Note that for little-endian machines,
523
the value of this flag is a moot point since the native format is
526
virtual unsigned char *pack(unsigned char *to,
527
const unsigned char *from,
529
bool low_byte_first);
531
unsigned char *pack(unsigned char *to, const unsigned char *from);
534
Unpack a field from row data.
536
This method is used to unpack a field from a master whose size of
537
the field is less than that of the slave.
539
The <code>param_data</code> parameter is a two-byte integer (stored
540
in the least significant 16 bits of the unsigned integer) usually
541
consisting of two parts: the real type in the most significant byte
542
and a original pack length in the least significant byte.
544
The exact layout of the <code>param_data</code> field is given by
545
the <code>Table_map_log_event::save_field_metadata()</code>.
547
This is the default method for unpacking a field. It just copies
548
the memory block in byte order (of original pack length bytes or
549
length of field, whichever is smaller).
551
@param to Destination of the data
552
@param from Source of the data
553
@param param_data Real type and original pack length of the field
556
@param low_byte_first
557
If this flag is @c true, all composite entities (e.g., lengths)
558
should be unpacked in little-endian format; otherwise, the entities
559
are unpacked in native order.
561
@return New pointer into memory based on from + length of the data
563
virtual const unsigned char *unpack(unsigned char* to,
564
const unsigned char *from,
566
bool low_byte_first);
568
@overload Field::unpack(unsigned char*, const unsigned char*,
571
const unsigned char *unpack(unsigned char* to,
572
const unsigned char *from);
574
virtual unsigned char *pack_key(unsigned char* to,
575
const unsigned char *from,
579
return pack(to, from, max_length, low_byte_first);
581
virtual const unsigned char *unpack_key(unsigned char* to,
582
const unsigned char *from,
447
virtual bool send_binary(Protocol *protocol);
449
virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
450
uint32_t max_length, bool low_byte_first);
452
@overload Field::pack(unsigned char*, const unsigned char*, uint32_t, bool)
454
unsigned char *pack(unsigned char *to, const unsigned char *from)
456
unsigned char *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
460
virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
461
uint32_t param_data, bool low_byte_first);
463
@overload Field::unpack(unsigned char*, const unsigned char*, uint32_t, bool)
465
const unsigned char *unpack(unsigned char* to, const unsigned char *from)
467
const unsigned char *result= unpack(to, from, 0U, table->s->db_low_byte_first);
471
virtual unsigned char *pack_key(unsigned char* to, const unsigned char *from,
472
uint32_t max_length, bool low_byte_first)
474
return pack(to, from, max_length, low_byte_first);
476
virtual unsigned char *pack_key_from_key_image(unsigned char* to, const unsigned char *from,
477
uint32_t max_length, bool low_byte_first)
479
return pack(to, from, max_length, low_byte_first);
481
virtual const unsigned char *unpack_key(unsigned char* to, const unsigned char *from,
482
uint32_t max_length, bool low_byte_first)
586
484
return unpack(to, from, max_length, low_byte_first);
486
virtual uint32_t packed_col_length(const unsigned char *to __attribute__((unused)),
588
489
virtual uint32_t max_packed_col_length(uint32_t max_length)
490
{ return max_length;}
593
uint32_t offset(const unsigned char *record)
492
virtual int pack_cmp(const unsigned char *a,const unsigned char *b,
493
uint32_t key_length_arg __attribute__((unused)),
494
bool insert_or_update __attribute__((unused)))
496
virtual int pack_cmp(const unsigned char *b,
497
uint32_t key_length_arg __attribute__((unused)),
498
bool insert_or_update __attribute__((unused)))
499
{ return cmp(ptr,b); }
500
uint32_t offset(unsigned char *record)
595
502
return (uint32_t) (ptr - record);
597
504
void copy_from_tmp(int offset);
598
uint32_t fill_cache_field(CacheField *copy);
599
virtual bool get_date(type::Time <ime,uint32_t fuzzydate) const;
600
virtual bool get_time(type::Time <ime) const;
505
uint32_t fill_cache_field(struct st_cache_field *copy);
506
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
507
virtual bool get_time(DRIZZLE_TIME *ltime);
601
508
virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
602
509
virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
603
510
virtual bool has_charset(void) const { return false; }
604
virtual void set_charset(const CHARSET_INFO * const)
511
virtual void set_charset(const CHARSET_INFO * const charset_arg __attribute__((unused)))
606
513
virtual enum Derivation derivation(void) const
608
return DERIVATION_IMPLICIT;
610
virtual void set_derivation(enum Derivation)
613
Produce warning or note about data saved into field.
615
@param level - level of message (Note/Warning/Error)
616
@param code - error code of message to be produced
617
@param cuted_increment - whenever we should increase cut fields count or not
620
This function won't produce warning and increase cut fields counter
621
if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
623
if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
624
This allows us to avoid notes in optimisation, like convert_constant_item().
627
1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
631
bool set_warning(DRIZZLE_ERROR::enum_warning_level,
632
drizzled::error_t code,
514
{ return DERIVATION_IMPLICIT; }
515
virtual void set_derivation(enum Derivation derivation_arg __attribute__((unused)))
517
bool set_warning(DRIZZLE_ERROR::enum_warning_level, unsigned int code,
633
518
int cuted_increment);
635
Produce warning or note about datetime string data saved into field.
637
@param level level of message (Note/Warning/Error)
638
@param code error code of message to be produced
639
@param str string value which we tried to save
640
@param str_length length of string which we tried to save
641
@param ts_type type of datetime value (datetime/date/time)
642
@param cuted_increment whenever we should increase cut fields count or not
645
This function will always produce some warning but won't increase cut
646
fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
649
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
650
drizzled::error_t code,
653
type::timestamp_t ts_type,
654
int cuted_increment);
656
Produce warning or note about integer datetime value saved into field.
658
@param level level of message (Note/Warning/Error)
659
@param code error code of message to be produced
660
@param nr numeric value which we tried to save
661
@param ts_type type of datetime value (datetime/date/time)
662
@param cuted_increment whenever we should increase cut fields count or not
665
This function will always produce some warning but won't increase cut
666
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
669
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
670
drizzled::error_t code,
672
type::timestamp_t ts_type,
673
int cuted_increment);
675
Produce warning or note about double datetime data saved into field.
677
@param level level of message (Note/Warning/Error)
678
@param code error code of message to be produced
679
@param nr double value which we tried to save
680
@param ts_type type of datetime value (datetime/date/time)
683
This function will always produce some warning but won't increase cut
684
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
687
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
688
const drizzled::error_t code,
690
type::timestamp_t ts_type);
691
bool check_overflow(int op_result)
519
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code,
520
const char *str, uint32_t str_len,
521
enum enum_drizzle_timestamp_type ts_type, int cuted_increment);
522
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code,
523
int64_t nr, enum enum_drizzle_timestamp_type ts_type,
524
int cuted_increment);
525
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint32_t code,
526
double nr, enum enum_drizzle_timestamp_type ts_type);
527
inline bool check_overflow(int op_result)
693
529
return (op_result == E_DEC_OVERFLOW);
696
Process decimal library return codes and issue warnings for overflow and
699
@param op_result decimal library return code (E_DEC_* see include/decimal.h)
702
E_DEC_OVERFLOW there was overflow
703
E_DEC_TRUNCATED there was truncation
705
0 no error or there was some other error except overflow or truncation
707
531
int warn_if_overflow(int op_result);
708
void init(Table *table_arg);
532
void init(Table *table_arg)
534
orig_table= table= table_arg;
535
table_name= &table_arg->alias;
710
538
/* maximum possible display length */
711
539
virtual uint32_t max_display_length()= 0;
713
virtual uint32_t is_equal(CreateField *new_field);
715
Conversion from decimal to int64_t with checking overflow and
716
setting correct value (min/max) in case of overflow.
718
@param val value which have to be converted
719
@param unsigned_flag type of integer in which we convert val
720
@param err variable to pass error code
723
value converted from val
725
int64_t convert_decimal2int64_t(const type::Decimal *val,
541
virtual uint32_t is_equal(Create_field *new_field);
542
/* convert decimal to int64_t with overflow check */
543
int64_t convert_decimal2int64_t(const my_decimal *val, bool unsigned_flag,
728
545
/* The max. number of characters */
729
uint32_t char_length() const
546
inline uint32_t char_length() const
731
548
return field_length / charset()->mbmaxlen;
734
enum column_format_type column_format() const
551
inline enum column_format_type column_format() const
736
553
return (enum column_format_type)
737
554
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
741
virtual void hash(uint32_t *nr, uint32_t *nr2) const;
742
friend bool reopen_table(Session *,Table *,bool);
744
friend class CopyField;
558
virtual void hash(uint32_t *nr, uint32_t *nr2);
559
friend bool reopen_table(THD *,Table *,bool);
560
friend int cre_myisam(char * name, register Table *form, uint32_t options,
561
uint64_t auto_increment_value);
562
friend class Copy_field;
745
563
friend class Item_avg_field;
746
564
friend class Item_std_field;
747
565
friend class Item_sum_num;
754
572
friend class Item_sum_max;
755
573
friend class Item_func_group_concat;
757
bool isReadSet() const;
759
void setReadSet(bool arg= true);
760
void setWriteSet(bool arg= true);
764
void pack_num(uint64_t arg, unsigned char *destination= NULL);
765
void pack_num(uint32_t arg, unsigned char *destination= NULL);
766
uint64_t unpack_num(uint64_t &destination, const unsigned char *arg= NULL) const;
767
uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
577
Primitive for implementing last_null_byte().
583
Primitive for the implementation of the last_null_byte()
584
function. This represents the inheritance interface and can be
585
overridden by subclasses.
587
virtual size_t do_last_null_byte() const;
590
Retrieve the field metadata for fields.
592
This default implementation returns 0 and saves 0 in the metadata_ptr
595
@param metadata_ptr First byte of field metadata
597
@returns 0 no bytes written.
599
virtual int do_save_field_metadata(unsigned char *metadata_ptr __attribute__((unused)))
604
Create field class for CREATE TABLE
772
inline bool isDateTime(const enum_field_types &arg)
607
class Create_field :public Sql_alloc
610
const char *field_name;
611
const char *change; // If done with alter table
612
const char *after; // Put column after this one
613
LEX_STRING comment; // Comment for field
614
Item *def; // Default value
615
enum enum_field_types sql_type;
617
At various stages in execution this can be length of field in bytes or
618
max number of characters.
622
The value of `length' as set by parser: is the number of characters
623
for most of the types, or of bytes for BLOBs or numeric types.
625
uint32_t char_length;
626
uint32_t decimals, flags, pack_length, key_length;
627
Field::utype unireg_check;
628
TYPELIB *interval; // Which interval to use
629
TYPELIB *save_interval; // Temporary copy for the above
630
// Used only for UCS2 intervals
631
List<String> interval_list;
632
const CHARSET_INFO *charset;
633
Field *field; // For alter table
635
uint8_t row,col,sc_length,interval_id; // For rea_create_table
636
uint32_t offset,pack_flag;
638
/* Virtual column expression statement */
639
virtual_column_info *vcol_info;
641
Indication that the field is phycically stored in tables
642
rather than just generated on SQL queries.
643
As of now, FALSE can only be set for generated-only virtual columns.
647
Create_field() :after(0) {}
648
Create_field(Field *field, Field *orig_field);
649
/* Used to make a clone of this object for ALTER/CREATE TABLE */
650
Create_field *clone(MEM_ROOT *mem_root) const
651
{ return new (mem_root) Create_field(*this); }
652
void create_length_to_internal_length(void);
654
inline enum column_format_type column_format() const
776
case DRIZZLE_TYPE_DATE:
777
case DRIZZLE_TYPE_DATETIME:
778
case DRIZZLE_TYPE_MICROTIME:
779
case DRIZZLE_TYPE_TIME:
780
case DRIZZLE_TYPE_TIMESTAMP:
783
case DRIZZLE_TYPE_BLOB:
784
case DRIZZLE_TYPE_BOOLEAN:
785
case DRIZZLE_TYPE_DECIMAL:
786
case DRIZZLE_TYPE_DOUBLE:
787
case DRIZZLE_TYPE_ENUM:
788
case DRIZZLE_TYPE_LONG:
789
case DRIZZLE_TYPE_LONGLONG:
790
case DRIZZLE_TYPE_NULL:
791
case DRIZZLE_TYPE_UUID:
792
case DRIZZLE_TYPE_VARCHAR:
656
return (enum column_format_type)
657
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
802
std::ostream& operator<<(std::ostream& output, const Field &field);
804
} /* namespace drizzled */
806
/** @TODO Why is this in the middle of the file???*/
807
#include <drizzled/create_field.h>
813
* A class for sending field information to a client.
817
* Send_field is basically a stripped-down POD class for
818
* representing basic information about a field...
660
/* Init for a tmp table field. To be extended if need be. */
661
void init_for_tmp_table(enum_field_types sql_type_arg,
662
uint32_t max_length, uint32_t decimals,
663
bool maybe_null, bool is_unsigned);
665
bool init(THD *thd, char *field_name, enum_field_types type, char *length,
666
char *decimals, uint32_t type_modifier, Item *default_value,
667
Item *on_update_value, LEX_STRING *comment, char *change,
668
List<String> *interval_list, const CHARSET_INFO * const cs,
669
uint32_t uint_geom_type,
670
enum column_format_type column_format,
671
virtual_column_info *vcol_info);
676
A class for sending info to the client
823
681
const char *db_name;
824
const char *table_name;
825
const char *org_table_name;
826
const char *col_name;
827
const char *org_col_name;
682
const char *table_name,*org_table_name;
683
const char *col_name,*org_col_name;
685
uint32_t charsetnr, flags, decimals;
832
686
enum_field_types type;
692
A class for quick copying data to fields
695
class Copy_field :public Sql_alloc {
697
Convenience definition of a copy function returned by
700
typedef void Copy_func(Copy_field*);
701
Copy_func *get_copy_func(Field *to, Field *from);
703
unsigned char *from_ptr,*to_ptr;
704
unsigned char *from_null_ptr,*to_null_ptr;
706
uint32_t from_bit,to_bit;
707
uint32_t from_length,to_length;
708
Field *from_field,*to_field;
709
String tmp; // For items
713
void set(Field *to,Field *from,bool save); // Field to field
714
void set(unsigned char *to,Field *from); // Field to string
715
void (*do_copy)(Copy_field *);
716
void (*do_copy2)(Copy_field *); // Used to handle null values
720
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
721
unsigned char *null_pos, unsigned char null_bit,
722
uint32_t pack_flag, enum_field_types field_type,
723
const CHARSET_INFO * cs,
724
Field::utype unireg_check,
725
TYPELIB *interval, const char *field_name);
836
726
uint32_t pack_length_to_packflag(uint32_t type);
727
enum_field_types get_blob_type_from_length(uint32_t length);
837
728
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
838
729
int set_field_to_null(Field *field);
839
730
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
842
* Tests if the given string contains important data:
843
* not spaces for character string, or any data for binary string.
845
* @param pointer to the character set to use
846
* @param String to test
850
* false - If string does not have important data
852
* true - If string has some important data
734
test_if_important_data(const CHARSET_INFO * const cs,
854
bool test_if_important_data(const CHARSET_INFO * const cs,
858
} /* namespace drizzled */
860
#endif /* DRIZZLED_FIELD_H */
741
#include <drizzled/field/str.h>
742
#include <drizzled/field/longstr.h>
743
#include <drizzled/field/num.h>
744
#include <drizzled/field/blob.h>
745
#include <drizzled/field/enum.h>
746
#include <drizzled/field/null.h>
747
#include <drizzled/field/date.h>
748
#include <drizzled/field/fdecimal.h>
749
#include <drizzled/field/real.h>
750
#include <drizzled/field/double.h>
751
#include <drizzled/field/long.h>
752
#include <drizzled/field/int64_t.h>
753
#include <drizzled/field/num.h>
754
#include <drizzled/field/timetype.h>
755
#include <drizzled/field/timestamp.h>
756
#include <drizzled/field/datetime.h>
757
#include <drizzled/field/fstring.h>
758
#include <drizzled/field/varstring.h>
761
The following are for the interface with the .frm file
764
#define FIELDFLAG_DECIMAL 1
765
#define FIELDFLAG_BINARY 1 // Shares same flag
766
#define FIELDFLAG_NUMBER 2
767
#define FIELDFLAG_DECIMAL_POSITION 4
768
#define FIELDFLAG_PACK 120 // Bits used for packing
769
#define FIELDFLAG_INTERVAL 256 // mangled with decimals!
770
#define FIELDFLAG_BITFIELD 512 // mangled with decimals!
771
#define FIELDFLAG_BLOB 1024 // mangled with decimals!
772
#define FIELDFLAG_GEOM 2048 // mangled with decimals!
774
#define FIELDFLAG_TREAT_BIT_AS_CHAR 4096 /* use Field_bit_as_char */
776
#define FIELDFLAG_LEFT_FULLSCREEN 8192
777
#define FIELDFLAG_RIGHT_FULLSCREEN 16384
778
#define FIELDFLAG_FORMAT_NUMBER 16384 // predit: ###,,## in output
779
#define FIELDFLAG_NO_DEFAULT 16384 /* sql */
780
#define FIELDFLAG_SUM ((uint32_t) 32768)// predit: +#fieldflag
781
#define FIELDFLAG_MAYBE_NULL ((uint32_t) 32768)// sql
782
#define FIELDFLAG_HEX_ESCAPE ((uint32_t) 0x10000)
783
#define FIELDFLAG_PACK_SHIFT 3
784
#define FIELDFLAG_DEC_SHIFT 8
785
#define FIELDFLAG_MAX_DEC 31
786
#define FIELDFLAG_NUM_SCREEN_TYPE 0x7F01
787
#define FIELDFLAG_ALFA_SCREEN_TYPE 0x7800
789
#define MTYP_TYPENR(type) (type & 127) /* Remove bits from type */
791
#define f_is_dec(x) ((x) & FIELDFLAG_DECIMAL)
792
#define f_is_num(x) ((x) & FIELDFLAG_NUMBER)
793
#define f_is_decimal_precision(x) ((x) & FIELDFLAG_DECIMAL_POSITION)
794
#define f_is_packed(x) ((x) & FIELDFLAG_PACK)
795
#define f_packtype(x) (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
796
#define f_decimals(x) ((uint8_t) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
797
#define f_is_alpha(x) (!f_is_num(x))
798
#define f_is_binary(x) ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
799
#define f_is_enum(x) (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
800
#define f_is_bitfield(x) (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
801
#define f_is_blob(x) (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
802
#define f_is_equ(x) ((x) & (1+2+FIELDFLAG_PACK+31*256))
803
#define f_settype(x) (((int) x) << FIELDFLAG_PACK_SHIFT)
804
#define f_maybe_null(x) (x & FIELDFLAG_MAYBE_NULL)
805
#define f_no_default(x) (x & FIELDFLAG_NO_DEFAULT)
806
#define f_bit_as_char(x) ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
807
#define f_is_hex_escape(x) ((x) & FIELDFLAG_HEX_ESCAPE)
810
check_string_copy_error(Field_str *field,
811
const char *well_formed_error_pos,
812
const char *cannot_convert_error_pos,
814
const CHARSET_INFO * const cs);
817
class Field_tiny :public Field_num {
819
Field_tiny(unsigned char *ptr_arg, uint32_t len_arg, unsigned char *null_ptr_arg,
820
unsigned char null_bit_arg,
821
enum utype unireg_check_arg, const char *field_name_arg,
822
bool zero_arg, bool unsigned_arg)
823
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
824
unireg_check_arg, field_name_arg,
825
0, zero_arg,unsigned_arg)
827
enum Item_result result_type () const { return INT_RESULT; }
828
enum_field_types type() const { return DRIZZLE_TYPE_TINY;}
829
enum ha_base_keytype key_type() const
830
{ return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
831
int store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
832
int store(double nr);
833
int store(int64_t nr, bool unsigned_val);
834
int reset(void) { ptr[0]=0; return 0; }
835
double val_real(void);
836
int64_t val_int(void);
837
String *val_str(String*,String *);
838
bool send_binary(Protocol *protocol);
839
int cmp(const unsigned char *,const unsigned char *);
840
void sort_string(unsigned char *buff,uint32_t length);
841
uint32_t pack_length() const { return 1; }
842
void sql_type(String &str) const;
843
uint32_t max_display_length() { return 4; }
845
virtual unsigned char *pack(unsigned char* to, const unsigned char *from,
846
uint32_t max_length __attribute__((unused)),
847
bool low_byte_first __attribute__((unused)))
853
virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
854
uint32_t param_data __attribute__((unused)),
855
bool low_byte_first __attribute__((unused)))