61
61
Note that you can use table->in_use as replacement for current_thd member
62
62
only inside of val_*() and store() members (e.g. you can't use it in cons)
64
Table *table; // Pointer for table
65
Table *orig_table; // Pointer to original table
64
struct st_table *table; // Pointer for table
65
struct st_table *orig_table; // Pointer to original table
66
66
const char **table_name, *field_name;
67
67
LEX_STRING comment;
68
68
/* Field is part of the following keys */
103
103
const char *field_name_arg);
104
104
virtual ~Field() {}
105
105
/* Store functions returns 1 on overflow and -1 on fatal error */
106
virtual int store(const char *to, uint length, const CHARSET_INFO * const cs)=0;
106
virtual int store(const char *to, uint length,CHARSET_INFO *cs)=0;
107
107
virtual int store(double nr)=0;
108
108
virtual int store(int64_t nr, bool unsigned_val)=0;
109
109
virtual int store_decimal(const my_decimal *d)=0;
110
virtual int store_time(DRIZZLE_TIME *ltime, timestamp_type t_type);
111
int store(const char *to, uint length, const CHARSET_INFO * const cs,
110
virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
111
int store(const char *to, uint length, CHARSET_INFO *cs,
112
112
enum_check_fields check_level);
113
113
virtual double val_real(void)=0;
114
114
virtual int64_t val_int(void)=0;
119
119
if it needs a temp buffer to convert result to string - use buf1
120
120
example Field_tiny::val_str()
121
121
if the value exists as a string already - use buf2
122
example Field_varstring::val_str() (???)
122
example Field_string::val_str()
123
123
consequently, buf2 may be created as 'String buf;' - no memory
124
124
will be allocated for it. buf1 will be allocated to hold a
125
125
value if it's too small. Using allocated buffer for buf2 may result in
127
127
This trickery is used to decrease a number of malloc calls.
129
129
virtual String *val_str(String*,String *)=0;
130
String *val_int_as_str(String *val_buffer, bool unsigned_flag);
130
String *val_int_as_str(String *val_buffer, my_bool unsigned_flag);
132
132
str_needs_quotes() returns true if the value returned by val_str() needs
133
133
to be quoted when used in constructing an SQL query.
171
171
metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
173
173
Note: While most classes that override this method return pack_length(),
174
the classes Field_varstring, and Field_blob return
174
the classes Field_string, Field_varstring, and Field_blob return
175
175
field_length + 1, field_length, and pack_length_no_ptr() respectfully.
177
177
virtual uint row_pack_length() { return 0; }
201
201
return pack_length();
204
virtual int reset(void) { memset(ptr, 0, pack_length()); return 0; }
204
virtual int reset(void) { bzero(ptr,pack_length()); return 0; }
205
205
virtual void reset_fields() {}
206
206
virtual void set_default()
208
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
208
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values - table->record[0]);
209
209
memcpy(ptr, ptr + l_offset, pack_length());
211
211
*null_ptr= ((*null_ptr & (uchar) ~null_bit) | (null_ptr[l_offset] & null_bit));
222
222
{ return cmp(a, b); }
223
223
virtual int cmp(const uchar *,const uchar *)=0;
224
224
virtual int cmp_binary(const uchar *a,const uchar *b,
225
uint32_t __attribute__((unused)) max_length=UINT32_MAX)
225
uint32_t __attribute__((unused)) max_length=~0)
226
226
{ return memcmp(a,b,pack_length()); }
227
227
virtual int cmp_offset(uint row_offset)
228
228
{ return cmp(ptr,ptr+row_offset); }
302
302
virtual bool can_be_compared_as_int64_t() const { return false; }
303
303
virtual void free() {}
304
virtual Field *new_field(MEM_ROOT *root, Table *new_table,
304
virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table,
306
virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
306
virtual Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
307
307
uchar *new_ptr, uchar *new_null_ptr,
308
308
uint new_null_bit);
309
Field *clone(MEM_ROOT *mem_root, Table *new_table);
309
Field *clone(MEM_ROOT *mem_root, struct st_table *new_table);
310
310
inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
312
312
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
319
319
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
321
321
virtual void get_image(uchar *buff, uint length,
322
const CHARSET_INFO * const cs __attribute__((unused)))
322
CHARSET_INFO *cs __attribute__((unused)))
323
323
{ memcpy(buff,ptr,length); }
324
324
virtual void set_image(const uchar *buff,uint length,
325
const CHARSET_INFO * const cs __attribute__((unused)))
325
CHARSET_INFO *cs __attribute__((unused)))
326
326
{ memcpy(ptr,buff,length); }
432
432
virtual int pack_cmp(const uchar *a,const uchar *b,
433
433
uint key_length_arg __attribute__((unused)),
434
bool insert_or_update __attribute__((unused)))
434
my_bool insert_or_update __attribute__((unused)))
435
435
{ return cmp(a,b); }
436
436
virtual int pack_cmp(const uchar *b,
437
437
uint key_length_arg __attribute__((unused)),
438
bool insert_or_update __attribute__((unused)))
438
my_bool insert_or_update __attribute__((unused)))
439
439
{ return cmp(ptr,b); }
440
440
uint offset(uchar *record)
444
444
void copy_from_tmp(int offset);
445
445
uint fill_cache_field(struct st_cache_field *copy);
446
virtual bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
447
virtual bool get_time(DRIZZLE_TIME *ltime);
448
virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
449
virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
446
virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
447
virtual bool get_time(MYSQL_TIME *ltime);
448
virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
449
virtual CHARSET_INFO *sort_charset(void) const { return charset(); }
450
450
virtual bool has_charset(void) const { return false; }
451
virtual void set_charset(const CHARSET_INFO * const charset_arg __attribute__((unused)))
451
virtual void set_charset(CHARSET_INFO *charset_arg __attribute__((unused)))
453
453
virtual enum Derivation derivation(void) const
454
454
{ return DERIVATION_IMPLICIT; }
455
455
virtual void set_derivation(enum Derivation derivation_arg __attribute__((unused)))
457
bool set_warning(DRIZZLE_ERROR::enum_warning_level, unsigned int code,
457
bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
458
458
int cuted_increment);
459
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint code,
459
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code,
460
460
const char *str, uint str_len,
461
461
timestamp_type ts_type, int cuted_increment);
462
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint code,
462
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code,
463
463
int64_t nr, timestamp_type ts_type,
464
464
int cuted_increment);
465
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint code,
465
void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code,
466
466
double nr, timestamp_type ts_type);
467
467
inline bool check_overflow(int op_result)
469
469
return (op_result == E_DEC_OVERFLOW);
471
471
int warn_if_overflow(int op_result);
472
void init(Table *table_arg)
472
void init(TABLE *table_arg)
474
474
orig_table= table= table_arg;
475
475
table_name= &table_arg->alias;
498
virtual void hash(uint32_t *nr, uint32_t *nr2);
499
friend bool reopen_table(THD *,Table *,bool);
500
friend int cre_myisam(char * name, register Table *form, uint options,
498
virtual void hash(ulong *nr, ulong *nr2);
499
friend bool reopen_table(THD *,struct st_table *,bool);
500
friend int cre_myisam(char * name, register TABLE *form, uint options,
501
501
uint64_t auto_increment_value);
502
502
friend class Copy_field;
503
503
friend class Item_avg_field;
560
560
int store_decimal(const my_decimal *);
561
561
my_decimal *val_decimal(my_decimal *);
562
562
uint is_equal(Create_field *new_field);
563
int check_int(const CHARSET_INFO * const cs, const char *str, int length,
563
int check_int(CHARSET_INFO *cs, const char *str, int length,
564
564
const char *int_end, int error);
565
bool get_int(const CHARSET_INFO * const cs, const char *from, uint len,
565
bool get_int(CHARSET_INFO *cs, const char *from, uint len,
566
566
int64_t *rnd, uint64_t unsigned_max,
567
567
int64_t signed_min, int64_t signed_max);
572
572
class Field_str :public Field {
574
const CHARSET_INFO *field_charset;
574
CHARSET_INFO *field_charset;
575
575
enum Derivation field_derivation;
577
577
Field_str(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
578
578
uchar null_bit_arg, utype unireg_check_arg,
579
const char *field_name_arg, const CHARSET_INFO * const charset);
579
const char *field_name_arg, CHARSET_INFO *charset);
580
580
Item_result result_type () const { return STRING_RESULT; }
581
581
uint decimals() const { return NOT_FIXED_DEC; }
582
582
int store(double nr);
583
583
int store(int64_t nr, bool unsigned_val)=0;
584
584
int store_decimal(const my_decimal *);
585
int store(const char *to,uint length, const CHARSET_INFO * const cs)=0;
585
int store(const char *to,uint length,CHARSET_INFO *cs)=0;
586
586
uint size_of() const { return sizeof(*this); }
587
const CHARSET_INFO *charset(void) const { return field_charset; }
588
void set_charset(const CHARSET_INFO * const charset_arg) { field_charset= charset_arg; }
587
CHARSET_INFO *charset(void) const { return field_charset; }
588
void set_charset(CHARSET_INFO *charset_arg) { field_charset= charset_arg; }
589
589
enum Derivation derivation(void) const { return field_derivation; }
590
590
virtual void set_derivation(enum Derivation derivation_arg)
591
591
{ field_derivation= derivation_arg; }
609
609
Field_longstr(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
610
610
uchar null_bit_arg, utype unireg_check_arg,
611
const char *field_name_arg, const CHARSET_INFO * const charset_arg)
611
const char *field_name_arg, CHARSET_INFO *charset_arg)
612
612
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
613
613
field_name_arg, charset_arg)
620
620
/* base class for float and double and decimal (old one) */
621
621
class Field_real :public Field_num {
625
625
Field_real(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
626
626
uchar null_bit_arg, utype unireg_check_arg,
656
656
enum_field_types type() const { return DRIZZLE_TYPE_TINY;}
657
657
enum ha_base_keytype key_type() const
658
658
{ return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
659
int store(const char *to,uint length, const CHARSET_INFO * const charset);
659
int store(const char *to,uint length,CHARSET_INFO *charset);
660
660
int store(double nr);
661
661
int store(int64_t nr, bool unsigned_val);
662
662
int reset(void) { ptr[0]=0; return 0; }
698
698
enum utype unireg_check_arg, const char *field_name_arg,
699
699
uint packlength_arg,
700
700
TYPELIB *typelib_arg,
701
const CHARSET_INFO * const charset_arg)
701
CHARSET_INFO *charset_arg)
702
702
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
703
703
unireg_check_arg, field_name_arg, charset_arg),
704
704
packlength(packlength_arg),typelib(typelib_arg)
706
706
flags|=ENUM_FLAG;
708
Field *new_field(MEM_ROOT *root, Table *new_table, bool keep_type);
709
enum_field_types type() const { return DRIZZLE_TYPE_ENUM; }
708
Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
709
enum_field_types type() const { return DRIZZLE_TYPE_STRING; }
710
710
enum Item_result cmp_type () const { return INT_RESULT; }
711
711
enum Item_result cast_to_int_type () const { return INT_RESULT; }
712
712
enum ha_base_keytype key_type() const;
713
int store(const char *to,uint length, const CHARSET_INFO * const charset);
713
int store(const char *to,uint length,CHARSET_INFO *charset);
714
714
int store(double nr);
715
715
int store(int64_t nr, bool unsigned_val);
716
716
double val_real(void);
733
733
bool eq_def(Field *field);
734
734
bool has_charset(void) const { return true; }
735
735
/* enum and set are sorted as integers */
736
const CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
736
CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
738
738
int do_save_field_metadata(uchar *first_byte);
767
767
TYPELIB *save_interval; // Temporary copy for the above
768
768
// Used only for UCS2 intervals
769
769
List<String> interval_list;
770
const CHARSET_INFO *charset;
770
CHARSET_INFO *charset;
771
771
Field *field; // For alter table
773
773
uint8_t row,col,sc_length,interval_id; // For rea_create_table
793
793
bool init(THD *thd, char *field_name, enum_field_types type, char *length,
794
794
char *decimals, uint type_modifier, Item *default_value,
795
795
Item *on_update_value, LEX_STRING *comment, char *change,
796
List<String> *interval_list, const CHARSET_INFO * const cs,
796
List<String> *interval_list, CHARSET_INFO *cs,
797
797
uint uint_geom_type,
798
798
enum column_format_type column_format);
847
847
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32_t field_length,
848
848
uchar *null_pos, uchar null_bit,
849
849
uint pack_flag, enum_field_types field_type,
850
const CHARSET_INFO * cs,
851
851
Field::utype unireg_check,
852
852
TYPELIB *interval, const char *field_name);
853
853
uint pack_length_to_packflag(uint type);
854
enum_field_types get_blob_type_from_length(uint32_t length);
854
enum_field_types get_blob_type_from_length(ulong length);
855
855
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
856
856
int set_field_to_null(Field *field);
857
857
int set_field_to_null_with_conversions(Field *field, bool no_conversions);