00001 /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 00018 /* 00019 Because of the function new_field() all field classes that have static 00020 variables must declare the size_of() member function. 00021 */ 00022 00023 #ifdef USE_PRAGMA_INTERFACE 00024 #pragma interface /* gcc class implementation */ 00025 #endif 00026 00027 #define NOT_FIXED_DEC 31 00028 #define DATETIME_DEC 6 00029 00030 class Send_field; 00031 class Protocol; 00032 class create_field; 00033 struct st_cache_field; 00034 void field_conv(Field *to,Field *from); 00035 00036 inline uint get_enum_pack_length(int elements) 00037 { 00038 return elements < 256 ? 1 : 2; 00039 } 00040 00041 inline uint get_set_pack_length(int elements) 00042 { 00043 uint len= (elements + 7) / 8; 00044 return len > 4 ? 8 : len; 00045 } 00046 00047 class Field 00048 { 00049 Field(const Item &); /* Prevent use of these */ 00050 void operator=(Field &); 00051 public: 00052 static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); } 00053 static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); } 00054 00055 char *ptr; // Position to field in record 00056 uchar *null_ptr; // Byte where null_bit is 00057 /* 00058 Note that you can use table->in_use as replacement for current_thd member 00059 only inside of val_*() and store() members (e.g. you can't use it in cons) 00060 */ 00061 struct st_table *table; // Pointer for table 00062 struct st_table *orig_table; // Pointer to original table 00063 const char **table_name, *field_name; 00064 LEX_STRING comment; 00065 /* Field is part of the following keys */ 00066 key_map key_start, part_of_key, part_of_key_not_clustered; 00067 key_map part_of_sortkey; 00068 /* 00069 We use three additional unireg types for TIMESTAMP to overcome limitation 00070 of current binary format of .frm file. We'd like to be able to support 00071 NOW() as default and on update value for such fields but unable to hold 00072 this info anywhere except unireg_check field. This issue will be resolved 00073 in more clean way with transition to new text based .frm format. 00074 See also comment for Field_timestamp::Field_timestamp(). 00075 */ 00076 enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL, 00077 CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD, 00078 BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD, 00079 TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD}; 00080 enum geometry_type 00081 { 00082 GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3, 00083 GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6, 00084 GEOM_GEOMETRYCOLLECTION = 7 00085 }; 00086 enum imagetype { itRAW, itMBR}; 00087 00088 utype unireg_check; 00089 uint32 field_length; // Length of field 00090 uint32 flags; 00091 uint16 field_index; // field number in fields array 00092 uchar null_bit; // Bit used to test null bit 00093 00094 Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,uchar null_bit_arg, 00095 utype unireg_check_arg, const char *field_name_arg); 00096 virtual ~Field() {} 00097 /* Store functions returns 1 on overflow and -1 on fatal error */ 00098 virtual int store(const char *to,uint length,CHARSET_INFO *cs)=0; 00099 virtual int store(double nr)=0; 00100 virtual int store(longlong nr, bool unsigned_val)=0; 00101 virtual int store_decimal(const my_decimal *d)=0; 00102 virtual int store_time(TIME *ltime, timestamp_type t_type); 00103 virtual double val_real(void)=0; 00104 virtual longlong val_int(void)=0; 00105 virtual my_decimal *val_decimal(my_decimal *); 00106 inline String *val_str(String *str) { return val_str(str, str); } 00107 /* 00108 val_str(buf1, buf2) gets two buffers and should use them as follows: 00109 if it needs a temp buffer to convert result to string - use buf1 00110 example Field_tiny::val_str() 00111 if the value exists as a string already - use buf2 00112 example Field_string::val_str() 00113 consequently, buf2 may be created as 'String buf;' - no memory 00114 will be allocated for it. buf1 will be allocated to hold a 00115 value if it's too small. Using allocated buffer for buf2 may result in 00116 an unnecessary free (and later, may be an alloc). 00117 This trickery is used to decrease a number of malloc calls. 00118 */ 00119 virtual String *val_str(String*,String *)=0; 00120 String *val_int_as_str(String *val_buffer, my_bool unsigned_flag); 00121 /* 00122 str_needs_quotes() returns TRUE if the value returned by val_str() needs 00123 to be quoted when used in constructing an SQL query. 00124 */ 00125 virtual bool str_needs_quotes() { return FALSE; } 00126 virtual Item_result result_type () const=0; 00127 virtual Item_result cmp_type () const { return result_type(); } 00128 virtual Item_result cast_to_int_type () const { return result_type(); } 00129 static bool type_can_have_key_part(enum_field_types); 00130 static enum_field_types field_type_merge(enum_field_types, enum_field_types); 00131 static Item_result result_merge_type(enum_field_types); 00132 virtual bool eq(Field *field) 00133 { 00134 return (ptr == field->ptr && null_ptr == field->null_ptr && 00135 null_bit == field->null_bit); 00136 } 00137 virtual bool eq_def(Field *field); 00138 00139 /* 00140 pack_length() returns size (in bytes) used to store field data in memory 00141 (i.e. it returns the maximum size of the field in a row of the table, 00142 which is located in RAM). 00143 */ 00144 virtual uint32 pack_length() const { return (uint32) field_length; } 00145 00146 /* 00147 pack_length_in_rec() returns size (in bytes) used to store field data on 00148 storage (i.e. it returns the maximal size of the field in a row of the 00149 table, which is located on disk). 00150 */ 00151 virtual uint32 pack_length_in_rec() const { return pack_length(); } 00152 00153 /* 00154 data_length() return the "real size" of the data in memory. 00155 */ 00156 virtual uint32 data_length(const char *from) { return pack_length(); } 00157 virtual uint32 sort_length() const { return pack_length(); } 00158 virtual void reset(void) { bzero(ptr,pack_length()); } 00159 virtual void reset_fields() {} 00160 virtual void set_default() 00161 { 00162 my_ptrdiff_t offset = (my_ptrdiff_t) (table->s->default_values - 00163 table->record[0]); 00164 memcpy(ptr, ptr + offset, pack_length()); 00165 if (null_ptr) 00166 *null_ptr= ((*null_ptr & (uchar) ~null_bit) | 00167 null_ptr[offset] & null_bit); 00168 } 00169 virtual bool binary() const { return 1; } 00170 virtual bool zero_pack() const { return 1; } 00171 virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } 00172 virtual uint32 key_length() const { return pack_length(); } 00173 virtual enum_field_types type() const =0; 00174 virtual enum_field_types real_type() const { return type(); } 00175 inline int cmp(const char *str) { return cmp(ptr,str); } 00176 virtual int cmp_max(const char *a, const char *b, uint max_len) 00177 { return cmp(a, b); } 00178 virtual int cmp(const char *,const char *)=0; 00179 virtual int cmp_binary(const char *a,const char *b, uint32 max_length=~0L) 00180 { return memcmp(a,b,pack_length()); } 00181 virtual int cmp_offset(uint row_offset) 00182 { return cmp(ptr,ptr+row_offset); } 00183 virtual int cmp_binary_offset(uint row_offset) 00184 { return cmp_binary(ptr, ptr+row_offset); }; 00185 virtual int key_cmp(const byte *a,const byte *b) 00186 { return cmp((char*) a,(char*) b); } 00187 virtual int key_cmp(const byte *str, uint length) 00188 { return cmp(ptr,(char*) str); } 00189 virtual uint decimals() const { return 0; } 00190 /* 00191 Caller beware: sql_type can change str.Ptr, so check 00192 ptr() to see if it changed if you are using your own buffer 00193 in str and restore it with set() if needed 00194 */ 00195 virtual void sql_type(String &str) const =0; 00196 virtual uint size_of() const =0; // For new field 00197 inline bool is_null(uint row_offset=0) 00198 { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; } 00199 inline bool is_real_null(uint row_offset=0) 00200 { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; } 00201 inline bool is_null_in_record(const uchar *record) 00202 { 00203 if (!null_ptr) 00204 return 0; 00205 return test(record[(uint) (null_ptr - (uchar*) table->record[0])] & 00206 null_bit); 00207 } 00208 inline bool is_null_in_record_with_offset(my_ptrdiff_t offset) 00209 { 00210 if (!null_ptr) 00211 return 0; 00212 return test(null_ptr[offset] & null_bit); 00213 } 00214 inline void set_null(int row_offset=0) 00215 { if (null_ptr) null_ptr[row_offset]|= null_bit; } 00216 inline void set_notnull(int row_offset=0) 00217 { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; } 00218 inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; } 00219 inline bool real_maybe_null(void) { return null_ptr != 0; } 00220 virtual void make_field(Send_field *); 00221 virtual void sort_string(char *buff,uint length)=0; 00222 virtual bool optimize_range(uint idx, uint part); 00223 /* 00224 This should be true for fields which, when compared with constant 00225 items, can be casted to longlong. In this case we will at 'fix_fields' 00226 stage cast the constant items to longlongs and at the execution stage 00227 use field->val_int() for comparison. Used to optimize clauses like 00228 'a_column BETWEEN date_const, date_const'. 00229 */ 00230 virtual bool can_be_compared_as_longlong() const { return FALSE; } 00231 virtual void free() {} 00232 virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table, 00233 bool keep_type); 00234 virtual Field *new_key_field(MEM_ROOT *root, struct st_table *new_table, 00235 char *new_ptr, uchar *new_null_ptr, 00236 uint new_null_bit); 00237 Field *clone(MEM_ROOT *mem_root, struct st_table *new_table); 00238 inline void move_field(char *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg) 00239 { 00240 ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg; 00241 } 00242 inline void move_field(char *ptr_arg) { ptr=ptr_arg; } 00243 virtual void move_field_offset(my_ptrdiff_t ptr_diff) 00244 { 00245 ptr=ADD_TO_PTR(ptr,ptr_diff,char*); 00246 if (null_ptr) 00247 null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*); 00248 } 00249 inline void get_image(char *buff,uint length, CHARSET_INFO *cs) 00250 { memcpy(buff,ptr,length); } 00251 inline void set_image(char *buff,uint length, CHARSET_INFO *cs) 00252 { memcpy(ptr,buff,length); } 00253 virtual void get_key_image(char *buff, uint length, imagetype type) 00254 { get_image(buff,length, &my_charset_bin); } 00255 virtual void set_key_image(char *buff,uint length) 00256 { set_image(buff,length, &my_charset_bin); } 00257 inline longlong val_int_offset(uint row_offset) 00258 { 00259 ptr+=row_offset; 00260 longlong tmp=val_int(); 00261 ptr-=row_offset; 00262 return tmp; 00263 } 00264 inline longlong val_int(char *new_ptr) 00265 { 00266 char *old_ptr= ptr; 00267 longlong return_value; 00268 ptr= new_ptr; 00269 return_value= val_int(); 00270 ptr= old_ptr; 00271 return return_value; 00272 } 00273 inline String *val_str(String *str, char *new_ptr) 00274 { 00275 char *old_ptr= ptr; 00276 ptr= new_ptr; 00277 val_str(str); 00278 ptr= old_ptr; 00279 return str; 00280 } 00281 virtual bool send_binary(Protocol *protocol); 00282 virtual char *pack(char* to, const char *from, uint max_length=~(uint) 0) 00283 { 00284 uint32 length=pack_length(); 00285 memcpy(to,from,length); 00286 return to+length; 00287 } 00288 virtual const char *unpack(char* to, const char *from) 00289 { 00290 uint length=pack_length(); 00291 memcpy(to,from,length); 00292 return from+length; 00293 } 00294 virtual char *pack_key(char* to, const char *from, uint max_length) 00295 { 00296 return pack(to,from,max_length); 00297 } 00298 virtual char *pack_key_from_key_image(char* to, const char *from, 00299 uint max_length) 00300 { 00301 return pack(to,from,max_length); 00302 } 00303 virtual const char *unpack_key(char* to, const char *from, uint max_length) 00304 { 00305 return unpack(to,from); 00306 } 00307 virtual uint packed_col_length(const char *to, uint length) 00308 { return length;} 00309 virtual uint max_packed_col_length(uint max_length) 00310 { return max_length;} 00311 00312 virtual int pack_cmp(const char *a,const char *b, uint key_length_arg, 00313 my_bool insert_or_update) 00314 { return cmp(a,b); } 00315 virtual int pack_cmp(const char *b, uint key_length_arg, 00316 my_bool insert_or_update) 00317 { return cmp(ptr,b); } 00318 uint offset(); // Should be inline ... 00319 void copy_from_tmp(int offset); 00320 uint fill_cache_field(struct st_cache_field *copy); 00321 virtual bool get_date(TIME *ltime,uint fuzzydate); 00322 virtual bool get_time(TIME *ltime); 00323 virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; } 00324 virtual CHARSET_INFO *sort_charset(void) const { return charset(); } 00325 virtual bool has_charset(void) const { return FALSE; } 00326 virtual void set_charset(CHARSET_INFO *charset) { } 00327 bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code, 00328 int cuted_increment); 00329 bool check_int(const char *str, int length, const char *int_end, 00330 CHARSET_INFO *cs); 00331 void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, 00332 const char *str, uint str_len, 00333 timestamp_type ts_type, int cuted_increment); 00334 void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, 00335 longlong nr, timestamp_type ts_type, 00336 int cuted_increment); 00337 void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code, 00338 double nr, timestamp_type ts_type); 00339 inline bool check_overflow(int op_result) 00340 { 00341 return (op_result == E_DEC_OVERFLOW); 00342 } 00343 int warn_if_overflow(int op_result); 00344 void init(TABLE *table_arg) 00345 { 00346 orig_table= table= table_arg; 00347 table_name= &table_arg->alias; 00348 } 00349 00350 /* maximum possible display length */ 00351 virtual uint32 max_length()= 0; 00352 00353 virtual uint is_equal(create_field *new_field); 00354 /* convert decimal to longlong with overflow check */ 00355 longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag, 00356 int *err); 00357 /* The max. number of characters */ 00358 inline uint32 char_length() const 00359 { 00360 return field_length / charset()->mbmaxlen; 00361 } 00362 00363 /* Hash value */ 00364 virtual void hash(ulong *nr, ulong *nr2); 00365 friend bool reopen_table(THD *,struct st_table *,bool); 00366 friend int cre_myisam(my_string name, register TABLE *form, uint options, 00367 ulonglong auto_increment_value); 00368 friend class Copy_field; 00369 friend class Item_avg_field; 00370 friend class Item_std_field; 00371 friend class Item_sum_num; 00372 friend class Item_sum_sum; 00373 friend class Item_sum_str; 00374 friend class Item_sum_count; 00375 friend class Item_sum_avg; 00376 friend class Item_sum_std; 00377 friend class Item_sum_min; 00378 friend class Item_sum_max; 00379 friend class Item_func_group_concat; 00380 }; 00381 00382 00383 class Field_num :public Field { 00384 public: 00385 const uint8 dec; 00386 bool zerofill,unsigned_flag; // Purify cannot handle bit fields 00387 Field_num(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, 00388 uchar null_bit_arg, utype unireg_check_arg, 00389 const char *field_name_arg, 00390 uint8 dec_arg, bool zero_arg, bool unsigned_arg); 00391 Item_result result_type () const { return REAL_RESULT; } 00392 void prepend_zeros(String *value); 00393 void add_zerofill_and_unsigned(String &res) const; 00394 friend class create_field; 00395 void make_field(Send_field *); 00396 uint decimals() const { return (uint) dec; } 00397 uint size_of() const { return sizeof(*this); } 00398 bool eq_def(Field *field); 00399 int store_decimal(const my_decimal *); 00400 my_decimal *val_decimal(my_decimal *); 00401 uint is_equal(create_field *new_field); 00402 }; 00403 00404 00405 class Field_str :public Field { 00406 protected: 00407 CHARSET_INFO *field_charset; 00408 public: 00409 Field_str(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, 00410 uchar null_bit_arg, utype unireg_check_arg, 00411 const char *field_name_arg, CHARSET_INFO *charset); 00412 Item_result result_type () const { return STRING_RESULT; } 00413 uint decimals() const { return NOT_FIXED_DEC; } 00414 int store(double nr); 00415 int store(longlong nr, bool unsigned_val)=0; 00416 int store_decimal(const my_decimal *); 00417 int store(const char *to,uint length,CHARSET_INFO *cs)=0; 00418 uint size_of() const { return sizeof(*this); } 00419 CHARSET_INFO *charset(void) const { return field_charset; } 00420 void set_charset(CHARSET_INFO *charset) { field_charset=charset; } 00421 bool binary() const { return field_charset == &my_charset_bin; } 00422 uint32 max_length() { return field_length; } 00423 friend class create_field; 00424 my_decimal *val_decimal(my_decimal *); 00425 virtual bool str_needs_quotes() { return TRUE; } 00426 uint is_equal(create_field *new_field); 00427 }; 00428 00429 00430 /* base class for Field_string, Field_varstring and Field_blob */ 00431 00432 class Field_longstr :public Field_str 00433 { 00434 public: 00435 Field_longstr(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00436 uchar null_bit_arg, utype unireg_check_arg, 00437 const char *field_name_arg, CHARSET_INFO *charset) 00438 :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, 00439 field_name_arg, charset) 00440 {} 00441 00442 int store_decimal(const my_decimal *d); 00443 }; 00444 00445 /* base class for float and double and decimal (old one) */ 00446 class Field_real :public Field_num { 00447 public: 00448 Field_real(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00449 uchar null_bit_arg, utype unireg_check_arg, 00450 const char *field_name_arg, 00451 uint8 dec_arg, bool zero_arg, bool unsigned_arg) 00452 :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, 00453 field_name_arg, dec_arg, zero_arg, unsigned_arg) 00454 {} 00455 int store_decimal(const my_decimal *); 00456 my_decimal *val_decimal(my_decimal *); 00457 }; 00458 00459 00460 class Field_decimal :public Field_real { 00461 public: 00462 Field_decimal(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00463 uchar null_bit_arg, 00464 enum utype unireg_check_arg, const char *field_name_arg, 00465 uint8 dec_arg,bool zero_arg,bool unsigned_arg) 00466 :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 00467 unireg_check_arg, field_name_arg, 00468 dec_arg, zero_arg, unsigned_arg) 00469 {} 00470 enum_field_types type() const { return FIELD_TYPE_DECIMAL;} 00471 enum ha_base_keytype key_type() const 00472 { return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; } 00473 void reset(void); 00474 int store(const char *to,uint length,CHARSET_INFO *charset); 00475 int store(double nr); 00476 int store(longlong nr, bool unsigned_val); 00477 double val_real(void); 00478 longlong val_int(void); 00479 String *val_str(String*,String *); 00480 int cmp(const char *,const char*); 00481 void sort_string(char *buff,uint length); 00482 void overflow(bool negative); 00483 bool zero_pack() const { return 0; } 00484 void sql_type(String &str) const; 00485 uint32 max_length() { return field_length; } 00486 }; 00487 00488 00489 /* New decimal/numeric field which use fixed point arithmetic */ 00490 class Field_new_decimal :public Field_num { 00491 public: 00492 /* The maximum number of decimal digits can be stored */ 00493 uint precision; 00494 uint bin_size; 00495 /* 00496 Constructors take max_length of the field as a parameter - not the 00497 precision as the number of decimal digits allowed. 00498 So for example we need to count length from precision handling 00499 CREATE TABLE ( DECIMAL(x,y)) 00500 */ 00501 Field_new_decimal(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00502 uchar null_bit_arg, 00503 enum utype unireg_check_arg, const char *field_name_arg, 00504 uint8 dec_arg, bool zero_arg, bool unsigned_arg); 00505 Field_new_decimal(uint32 len_arg, bool maybe_null_arg, 00506 const char *field_name_arg, uint8 dec_arg, 00507 bool unsigned_arg); 00508 enum_field_types type() const { return FIELD_TYPE_NEWDECIMAL;} 00509 enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } 00510 Item_result result_type () const { return DECIMAL_RESULT; } 00511 void reset(void); 00512 bool store_value(const my_decimal *decimal_value); 00513 void set_value_on_overflow(my_decimal *decimal_value, bool sign); 00514 int store(const char *to, uint length, CHARSET_INFO *charset); 00515 int store(double nr); 00516 int store(longlong nr, bool unsigned_val); 00517 int store_decimal(const my_decimal *); 00518 double val_real(void); 00519 longlong val_int(void); 00520 my_decimal *val_decimal(my_decimal *); 00521 String *val_str(String*, String *); 00522 int cmp(const char *, const char*); 00523 void sort_string(char *buff, uint length); 00524 bool zero_pack() const { return 0; } 00525 void sql_type(String &str) const; 00526 uint32 max_length() { return field_length; } 00527 uint size_of() const { return sizeof(*this); } 00528 uint32 pack_length() const { return (uint32) bin_size; } 00529 uint is_equal(create_field *new_field); 00530 }; 00531 00532 00533 class Field_tiny :public Field_num { 00534 public: 00535 Field_tiny(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00536 uchar null_bit_arg, 00537 enum utype unireg_check_arg, const char *field_name_arg, 00538 bool zero_arg, bool unsigned_arg) 00539 :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 00540 unireg_check_arg, field_name_arg, 00541 0, zero_arg,unsigned_arg) 00542 {} 00543 enum Item_result result_type () const { return INT_RESULT; } 00544 enum_field_types type() const { return FIELD_TYPE_TINY;} 00545 enum ha_base_keytype key_type() const 00546 { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; } 00547 int store(const char *to,uint length,CHARSET_INFO *charset); 00548 int store(double nr); 00549 int store(longlong nr, bool unsigned_val); 00550 void reset(void) { ptr[0]=0; } 00551 double val_real(void); 00552 longlong val_int(void); 00553 String *val_str(String*,String *); 00554 bool send_binary(Protocol *protocol); 00555 int cmp(const char *,const char*); 00556 void sort_string(char *buff,uint length); 00557 uint32 pack_length() const { return 1; } 00558 void sql_type(String &str) const; 00559 uint32 max_length() { return 4; } 00560 }; 00561 00562 00563 class Field_short :public Field_num { 00564 public: 00565 Field_short(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00566 uchar null_bit_arg, 00567 enum utype unireg_check_arg, const char *field_name_arg, 00568 bool zero_arg, bool unsigned_arg) 00569 :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 00570 unireg_check_arg, field_name_arg, 00571 0, zero_arg,unsigned_arg) 00572 {} 00573 Field_short(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, 00574 bool unsigned_arg) 00575 :Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0, 00576 NONE, field_name_arg, 0, 0, unsigned_arg) 00577 {} 00578 enum Item_result result_type () const { return INT_RESULT; } 00579 enum_field_types type() const { return FIELD_TYPE_SHORT;} 00580 enum ha_base_keytype key_type() const 00581 { return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;} 00582 int store(const char *to,uint length,CHARSET_INFO *charset); 00583 int store(double nr); 00584 int store(longlong nr, bool unsigned_val); 00585 void reset(void) { ptr[0]=ptr[1]=0; } 00586 double val_real(void); 00587 longlong val_int(void); 00588 String *val_str(String*,String *); 00589 bool send_binary(Protocol *protocol); 00590 int cmp(const char *,const char*); 00591 void sort_string(char *buff,uint length); 00592 uint32 pack_length() const { return 2; } 00593 void sql_type(String &str) const; 00594 uint32 max_length() { return 6; } 00595 }; 00596 00597 00598 class Field_medium :public Field_num { 00599 public: 00600 Field_medium(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00601 uchar null_bit_arg, 00602 enum utype unireg_check_arg, const char *field_name_arg, 00603 bool zero_arg, bool unsigned_arg) 00604 :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 00605 unireg_check_arg, field_name_arg, 00606 0, zero_arg,unsigned_arg) 00607 {} 00608 enum Item_result result_type () const { return INT_RESULT; } 00609 enum_field_types type() const { return FIELD_TYPE_INT24;} 00610 enum ha_base_keytype key_type() const 00611 { return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; } 00612 int store(const char *to,uint length,CHARSET_INFO *charset); 00613 int store(double nr); 00614 int store(longlong nr, bool unsigned_val); 00615 void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; } 00616 double val_real(void); 00617 longlong val_int(void); 00618 String *val_str(String*,String *); 00619 bool send_binary(Protocol *protocol); 00620 int cmp(const char *,const char*); 00621 void sort_string(char *buff,uint length); 00622 uint32 pack_length() const { return 3; } 00623 void sql_type(String &str) const; 00624 uint32 max_length() { return 8; } 00625 }; 00626 00627 00628 class Field_long :public Field_num { 00629 public: 00630 Field_long(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00631 uchar null_bit_arg, 00632 enum utype unireg_check_arg, const char *field_name_arg, 00633 bool zero_arg, bool unsigned_arg) 00634 :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 00635 unireg_check_arg, field_name_arg, 00636 0, zero_arg,unsigned_arg) 00637 {} 00638 Field_long(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, 00639 bool unsigned_arg) 00640 :Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0, 00641 NONE, field_name_arg,0,0,unsigned_arg) 00642 {} 00643 enum Item_result result_type () const { return INT_RESULT; } 00644 enum_field_types type() const { return FIELD_TYPE_LONG;} 00645 enum ha_base_keytype key_type() const 00646 { return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; } 00647 int store(const char *to,uint length,CHARSET_INFO *charset); 00648 int store(double nr); 00649 int store(longlong nr, bool unsigned_val); 00650 void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; } 00651 double val_real(void); 00652 longlong val_int(void); 00653 bool send_binary(Protocol *protocol); 00654 String *val_str(String*,String *); 00655 int cmp(const char *,const char*); 00656 void sort_string(char *buff,uint length); 00657 uint32 pack_length() const { return 4; } 00658 void sql_type(String &str) const; 00659 uint32 max_length() { return 11; } 00660 }; 00661 00662 00663 #ifdef HAVE_LONG_LONG 00664 class Field_longlong :public Field_num { 00665 public: 00666 Field_longlong(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00667 uchar null_bit_arg, 00668 enum utype unireg_check_arg, const char *field_name_arg, 00669 bool zero_arg, bool unsigned_arg) 00670 :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 00671 unireg_check_arg, field_name_arg, 00672 0, zero_arg,unsigned_arg) 00673 {} 00674 Field_longlong(uint32 len_arg,bool maybe_null_arg, 00675 const char *field_name_arg, 00676 bool unsigned_arg) 00677 :Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0, 00678 NONE, field_name_arg,0,0,unsigned_arg) 00679 {} 00680 enum Item_result result_type () const { return INT_RESULT; } 00681 enum_field_types type() const { return FIELD_TYPE_LONGLONG;} 00682 enum ha_base_keytype key_type() const 00683 { return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; } 00684 int store(const char *to,uint length,CHARSET_INFO *charset); 00685 int store(double nr); 00686 int store(longlong nr, bool unsigned_val); 00687 void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; } 00688 double val_real(void); 00689 longlong val_int(void); 00690 String *val_str(String*,String *); 00691 bool send_binary(Protocol *protocol); 00692 int cmp(const char *,const char*); 00693 void sort_string(char *buff,uint length); 00694 uint32 pack_length() const { return 8; } 00695 void sql_type(String &str) const; 00696 bool can_be_compared_as_longlong() const { return TRUE; } 00697 uint32 max_length() { return 20; } 00698 }; 00699 #endif 00700 00701 00702 class Field_float :public Field_real { 00703 public: 00704 Field_float(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00705 uchar null_bit_arg, 00706 enum utype unireg_check_arg, const char *field_name_arg, 00707 uint8 dec_arg,bool zero_arg,bool unsigned_arg) 00708 :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 00709 unireg_check_arg, field_name_arg, 00710 dec_arg, zero_arg, unsigned_arg) 00711 {} 00712 Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg, 00713 uint8 dec_arg) 00714 :Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0, 00715 NONE, field_name_arg, dec_arg, 0, 0) 00716 {} 00717 enum_field_types type() const { return FIELD_TYPE_FLOAT;} 00718 enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; } 00719 int store(const char *to,uint length,CHARSET_INFO *charset); 00720 int store(double nr); 00721 int store(longlong nr, bool unsigned_val); 00722 void reset(void) { bzero(ptr,sizeof(float)); } 00723 double val_real(void); 00724 longlong val_int(void); 00725 String *val_str(String*,String *); 00726 bool send_binary(Protocol *protocol); 00727 int cmp(const char *,const char*); 00728 void sort_string(char *buff,uint length); 00729 uint32 pack_length() const { return sizeof(float); } 00730 void sql_type(String &str) const; 00731 uint32 max_length() { return 24; } 00732 }; 00733 00734 00735 class Field_double :public Field_real { 00736 public: 00737 Field_double(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00738 uchar null_bit_arg, 00739 enum utype unireg_check_arg, const char *field_name_arg, 00740 uint8 dec_arg,bool zero_arg,bool unsigned_arg) 00741 :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 00742 unireg_check_arg, field_name_arg, 00743 dec_arg, zero_arg, unsigned_arg) 00744 {} 00745 Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg, 00746 uint8 dec_arg) 00747 :Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0, 00748 NONE, field_name_arg, dec_arg, 0, 0) 00749 {} 00750 enum_field_types type() const { return FIELD_TYPE_DOUBLE;} 00751 enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; } 00752 int store(const char *to,uint length,CHARSET_INFO *charset); 00753 int store(double nr); 00754 int store(longlong nr, bool unsigned_val); 00755 void reset(void) { bzero(ptr,sizeof(double)); } 00756 double val_real(void); 00757 longlong val_int(void); 00758 String *val_str(String*,String *); 00759 bool send_binary(Protocol *protocol); 00760 int cmp(const char *,const char*); 00761 void sort_string(char *buff,uint length); 00762 uint32 pack_length() const { return sizeof(double); } 00763 void sql_type(String &str) const; 00764 uint32 max_length() { return 53; } 00765 }; 00766 00767 00768 /* Everything saved in this will disappear. It will always return NULL */ 00769 00770 class Field_null :public Field_str { 00771 static uchar null[1]; 00772 public: 00773 Field_null(char *ptr_arg, uint32 len_arg, 00774 enum utype unireg_check_arg, const char *field_name_arg, 00775 CHARSET_INFO *cs) 00776 :Field_str(ptr_arg, len_arg, null, 1, 00777 unireg_check_arg, field_name_arg, cs) 00778 {} 00779 enum_field_types type() const { return FIELD_TYPE_NULL;} 00780 int store(const char *to, uint length, CHARSET_INFO *cs) 00781 { null[0]=1; return 0; } 00782 int store(double nr) { null[0]=1; return 0; } 00783 int store(longlong nr, bool unsigned_val) { null[0]=1; return 0; } 00784 int store_decimal(const my_decimal *d) { null[0]=1; return 0; } 00785 void reset(void) {} 00786 double val_real(void) { return 0.0;} 00787 longlong val_int(void) { return 0;} 00788 my_decimal *val_decimal(my_decimal *) { return 0; } 00789 String *val_str(String *value,String *value2) 00790 { value2->length(0); return value2;} 00791 int cmp(const char *a, const char *b) { return 0;} 00792 void sort_string(char *buff, uint length) {} 00793 uint32 pack_length() const { return 0; } 00794 void sql_type(String &str) const; 00795 uint size_of() const { return sizeof(*this); } 00796 uint32 max_length() { return 4; } 00797 }; 00798 00799 00800 class Field_timestamp :public Field_str { 00801 public: 00802 Field_timestamp(char *ptr_arg, uint32 len_arg, 00803 uchar *null_ptr_arg, uchar null_bit_arg, 00804 enum utype unireg_check_arg, const char *field_name_arg, 00805 TABLE_SHARE *share, CHARSET_INFO *cs); 00806 Field_timestamp(bool maybe_null_arg, const char *field_name_arg, 00807 CHARSET_INFO *cs); 00808 enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;} 00809 enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } 00810 enum Item_result cmp_type () const { return INT_RESULT; } 00811 int store(const char *to,uint length,CHARSET_INFO *charset); 00812 int store(double nr); 00813 int store(longlong nr, bool unsigned_val); 00814 void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; } 00815 double val_real(void); 00816 longlong val_int(void); 00817 String *val_str(String*,String *); 00818 bool send_binary(Protocol *protocol); 00819 int cmp(const char *,const char*); 00820 void sort_string(char *buff,uint length); 00821 uint32 pack_length() const { return 4; } 00822 void sql_type(String &str) const; 00823 bool can_be_compared_as_longlong() const { return TRUE; } 00824 bool zero_pack() const { return 0; } 00825 void set_time(); 00826 virtual void set_default() 00827 { 00828 if (table->timestamp_field == this && 00829 unireg_check != TIMESTAMP_UN_FIELD) 00830 set_time(); 00831 else 00832 Field::set_default(); 00833 } 00834 /* Get TIMESTAMP field value as seconds since begging of Unix Epoch */ 00835 inline long get_timestamp(my_bool *null_value) 00836 { 00837 if ((*null_value= is_null())) 00838 return 0; 00839 #ifdef WORDS_BIGENDIAN 00840 if (table && table->s->db_low_byte_first) 00841 return sint4korr(ptr); 00842 #endif 00843 long tmp; 00844 longget(tmp,ptr); 00845 return tmp; 00846 } 00847 bool get_date(TIME *ltime,uint fuzzydate); 00848 bool get_time(TIME *ltime); 00849 timestamp_auto_set_type get_auto_set_type() const; 00850 }; 00851 00852 00853 class Field_year :public Field_tiny { 00854 public: 00855 Field_year(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 00856 uchar null_bit_arg, 00857 enum utype unireg_check_arg, const char *field_name_arg) 00858 :Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 00859 unireg_check_arg, field_name_arg, 1, 1) 00860 {} 00861 enum_field_types type() const { return FIELD_TYPE_YEAR;} 00862 int store(const char *to,uint length,CHARSET_INFO *charset); 00863 int store(double nr); 00864 int store(longlong nr, bool unsigned_val); 00865 double val_real(void); 00866 longlong val_int(void); 00867 String *val_str(String*,String *); 00868 bool send_binary(Protocol *protocol); 00869 void sql_type(String &str) const; 00870 bool can_be_compared_as_longlong() const { return TRUE; } 00871 }; 00872 00873 00874 class Field_date :public Field_str { 00875 public: 00876 Field_date(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, 00877 enum utype unireg_check_arg, const char *field_name_arg, 00878 CHARSET_INFO *cs) 00879 :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg, 00880 unireg_check_arg, field_name_arg, cs) 00881 {} 00882 Field_date(bool maybe_null_arg, const char *field_name_arg, 00883 CHARSET_INFO *cs) 00884 :Field_str((char*) 0,10, maybe_null_arg ? (uchar*) "": 0,0, 00885 NONE, field_name_arg, cs) {} 00886 enum_field_types type() const { return FIELD_TYPE_DATE;} 00887 enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } 00888 enum Item_result cmp_type () const { return INT_RESULT; } 00889 int store(const char *to,uint length,CHARSET_INFO *charset); 00890 int store(double nr); 00891 int store(longlong nr, bool unsigned_val); 00892 void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; } 00893 double val_real(void); 00894 longlong val_int(void); 00895 String *val_str(String*,String *); 00896 bool send_binary(Protocol *protocol); 00897 int cmp(const char *,const char*); 00898 void sort_string(char *buff,uint length); 00899 uint32 pack_length() const { return 4; } 00900 void sql_type(String &str) const; 00901 bool can_be_compared_as_longlong() const { return TRUE; } 00902 bool zero_pack() const { return 1; } 00903 }; 00904 00905 00906 class Field_newdate :public Field_str { 00907 public: 00908 Field_newdate(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, 00909 enum utype unireg_check_arg, const char *field_name_arg, 00910 CHARSET_INFO *cs) 00911 :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg, 00912 unireg_check_arg, field_name_arg, cs) 00913 {} 00914 enum_field_types type() const { return FIELD_TYPE_DATE;} 00915 enum_field_types real_type() const { return FIELD_TYPE_NEWDATE; } 00916 enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; } 00917 enum Item_result cmp_type () const { return INT_RESULT; } 00918 int store(const char *to,uint length,CHARSET_INFO *charset); 00919 int store(double nr); 00920 int store(longlong nr, bool unsigned_val); 00921 int store_time(TIME *ltime, timestamp_type type); 00922 void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; } 00923 double val_real(void); 00924 longlong val_int(void); 00925 String *val_str(String*,String *); 00926 bool send_binary(Protocol *protocol); 00927 int cmp(const char *,const char*); 00928 void sort_string(char *buff,uint length); 00929 uint32 pack_length() const { return 3; } 00930 void sql_type(String &str) const; 00931 bool can_be_compared_as_longlong() const { return TRUE; } 00932 bool zero_pack() const { return 1; } 00933 bool get_date(TIME *ltime,uint fuzzydate); 00934 bool get_time(TIME *ltime); 00935 }; 00936 00937 00938 class Field_time :public Field_str { 00939 public: 00940 Field_time(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, 00941 enum utype unireg_check_arg, const char *field_name_arg, 00942 CHARSET_INFO *cs) 00943 :Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg, 00944 unireg_check_arg, field_name_arg, cs) 00945 {} 00946 Field_time(bool maybe_null_arg, const char *field_name_arg, 00947 CHARSET_INFO *cs) 00948 :Field_str((char*) 0,8, maybe_null_arg ? (uchar*) "": 0,0, 00949 NONE, field_name_arg, cs) {} 00950 enum_field_types type() const { return FIELD_TYPE_TIME;} 00951 enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; } 00952 enum Item_result cmp_type () const { return INT_RESULT; } 00953 int store_time(TIME *ltime, timestamp_type type); 00954 int store(const char *to,uint length,CHARSET_INFO *charset); 00955 int store(double nr); 00956 int store(longlong nr, bool unsigned_val); 00957 void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; } 00958 double val_real(void); 00959 longlong val_int(void); 00960 String *val_str(String*,String *); 00961 bool get_date(TIME *ltime, uint fuzzydate); 00962 bool send_binary(Protocol *protocol); 00963 bool get_time(TIME *ltime); 00964 int cmp(const char *,const char*); 00965 void sort_string(char *buff,uint length); 00966 uint32 pack_length() const { return 3; } 00967 void sql_type(String &str) const; 00968 bool can_be_compared_as_longlong() const { return TRUE; } 00969 bool zero_pack() const { return 1; } 00970 }; 00971 00972 00973 class Field_datetime :public Field_str { 00974 public: 00975 Field_datetime(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, 00976 enum utype unireg_check_arg, const char *field_name_arg, 00977 CHARSET_INFO *cs) 00978 :Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg, 00979 unireg_check_arg, field_name_arg, cs) 00980 {} 00981 Field_datetime(bool maybe_null_arg, const char *field_name_arg, 00982 CHARSET_INFO *cs) 00983 :Field_str((char*) 0,19, maybe_null_arg ? (uchar*) "": 0,0, 00984 NONE, field_name_arg, cs) {} 00985 enum_field_types type() const { return FIELD_TYPE_DATETIME;} 00986 #ifdef HAVE_LONG_LONG 00987 enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; } 00988 #endif 00989 enum Item_result cmp_type () const { return INT_RESULT; } 00990 uint decimals() const { return DATETIME_DEC; } 00991 int store(const char *to,uint length,CHARSET_INFO *charset); 00992 int store(double nr); 00993 int store(longlong nr, bool unsigned_val); 00994 int store_time(TIME *ltime, timestamp_type type); 00995 void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; } 00996 double val_real(void); 00997 longlong val_int(void); 00998 String *val_str(String*,String *); 00999 bool send_binary(Protocol *protocol); 01000 int cmp(const char *,const char*); 01001 void sort_string(char *buff,uint length); 01002 uint32 pack_length() const { return 8; } 01003 void sql_type(String &str) const; 01004 bool can_be_compared_as_longlong() const { return TRUE; } 01005 bool zero_pack() const { return 1; } 01006 bool get_date(TIME *ltime,uint fuzzydate); 01007 bool get_time(TIME *ltime); 01008 }; 01009 01010 01011 class Field_string :public Field_longstr { 01012 public: 01013 bool can_alter_field_type; 01014 Field_string(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg, 01015 uchar null_bit_arg, 01016 enum utype unireg_check_arg, const char *field_name_arg, 01017 CHARSET_INFO *cs) 01018 :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 01019 unireg_check_arg, field_name_arg, cs), 01020 can_alter_field_type(1) {}; 01021 Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, 01022 CHARSET_INFO *cs) 01023 :Field_longstr((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0, 01024 NONE, field_name_arg, cs), 01025 can_alter_field_type(1) {}; 01026 01027 enum_field_types type() const 01028 { 01029 return ((can_alter_field_type && orig_table && 01030 orig_table->s->db_create_options & HA_OPTION_PACK_RECORD && 01031 field_length >= 4) && 01032 orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ? 01033 MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING); 01034 } 01035 enum ha_base_keytype key_type() const 01036 { return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; } 01037 bool zero_pack() const { return 0; } 01038 void reset(void) { charset()->cset->fill(charset(),ptr,field_length,' '); } 01039 int store(const char *to,uint length,CHARSET_INFO *charset); 01040 int store(longlong nr, bool unsigned_val); 01041 int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */ 01042 double val_real(void); 01043 longlong val_int(void); 01044 String *val_str(String*,String *); 01045 my_decimal *val_decimal(my_decimal *); 01046 int cmp(const char *,const char*); 01047 void sort_string(char *buff,uint length); 01048 void sql_type(String &str) const; 01049 char *pack(char *to, const char *from, uint max_length=~(uint) 0); 01050 const char *unpack(char* to, const char *from); 01051 int pack_cmp(const char *a,const char *b,uint key_length, 01052 my_bool insert_or_update); 01053 int pack_cmp(const char *b,uint key_length,my_bool insert_or_update); 01054 uint packed_col_length(const char *to, uint length); 01055 uint max_packed_col_length(uint max_length); 01056 uint size_of() const { return sizeof(*this); } 01057 enum_field_types real_type() const { return FIELD_TYPE_STRING; } 01058 bool has_charset(void) const 01059 { return charset() == &my_charset_bin ? FALSE : TRUE; } 01060 Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type); 01061 }; 01062 01063 01064 class Field_varstring :public Field_longstr { 01065 public: 01066 /* Store number of bytes used to store length (1 or 2) */ 01067 uint32 length_bytes; 01068 Field_varstring(char *ptr_arg, 01069 uint32 len_arg, uint length_bytes_arg, 01070 uchar *null_ptr_arg, uchar null_bit_arg, 01071 enum utype unireg_check_arg, const char *field_name_arg, 01072 TABLE_SHARE *share, CHARSET_INFO *cs) 01073 :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 01074 unireg_check_arg, field_name_arg, cs), 01075 length_bytes(length_bytes_arg) 01076 { 01077 share->varchar_fields++; 01078 } 01079 Field_varstring(uint32 len_arg,bool maybe_null_arg, 01080 const char *field_name_arg, 01081 TABLE_SHARE *share, CHARSET_INFO *cs) 01082 :Field_longstr((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0, 01083 NONE, field_name_arg, cs), 01084 length_bytes(len_arg < 256 ? 1 :2) 01085 { 01086 share->varchar_fields++; 01087 } 01088 01089 enum_field_types type() const { return MYSQL_TYPE_VARCHAR; } 01090 enum ha_base_keytype key_type() const; 01091 bool zero_pack() const { return 0; } 01092 void reset(void) { bzero(ptr,field_length+length_bytes); } 01093 uint32 pack_length() const { return (uint32) field_length+length_bytes; } 01094 uint32 key_length() const { return (uint32) field_length; } 01095 uint32 sort_length() const 01096 { 01097 return (uint32) field_length + (field_charset == &my_charset_bin ? 01098 length_bytes : 0); 01099 } 01100 int store(const char *to,uint length,CHARSET_INFO *charset); 01101 int store(longlong nr, bool unsigned_val); 01102 int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */ 01103 double val_real(void); 01104 longlong val_int(void); 01105 String *val_str(String*,String *); 01106 my_decimal *val_decimal(my_decimal *); 01107 int cmp_max(const char *, const char *, uint max_length); 01108 int cmp(const char *a,const char*b) 01109 { 01110 return cmp_max(a, b, ~0L); 01111 } 01112 void sort_string(char *buff,uint length); 01113 void get_key_image(char *buff,uint length, imagetype type); 01114 void set_key_image(char *buff,uint length); 01115 void sql_type(String &str) const; 01116 char *pack(char *to, const char *from, uint max_length=~(uint) 0); 01117 char *pack_key(char *to, const char *from, uint max_length); 01118 char *pack_key_from_key_image(char* to, const char *from, uint max_length); 01119 const char *unpack(char* to, const char *from); 01120 const char *unpack_key(char* to, const char *from, uint max_length); 01121 int pack_cmp(const char *a, const char *b, uint key_length, 01122 my_bool insert_or_update); 01123 int pack_cmp(const char *b, uint key_length,my_bool insert_or_update); 01124 int cmp_binary(const char *a,const char *b, uint32 max_length=~0L); 01125 int key_cmp(const byte *,const byte*); 01126 int key_cmp(const byte *str, uint length); 01127 uint packed_col_length(const char *to, uint length); 01128 uint max_packed_col_length(uint max_length); 01129 uint32 data_length(const char *from); 01130 uint size_of() const { return sizeof(*this); } 01131 enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; } 01132 bool has_charset(void) const 01133 { return charset() == &my_charset_bin ? FALSE : TRUE; } 01134 Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type); 01135 Field *new_key_field(MEM_ROOT *root, struct st_table *new_table, 01136 char *new_ptr, uchar *new_null_ptr, 01137 uint new_null_bit); 01138 uint is_equal(create_field *new_field); 01139 void hash(ulong *nr, ulong *nr2); 01140 }; 01141 01142 01143 class Field_blob :public Field_longstr { 01144 protected: 01145 uint packlength; 01146 String value; // For temporaries 01147 public: 01148 Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, 01149 enum utype unireg_check_arg, const char *field_name_arg, 01150 TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs); 01151 Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, 01152 CHARSET_INFO *cs) 01153 :Field_longstr((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0, 01154 NONE, field_name_arg, cs), 01155 packlength(4) 01156 { 01157 flags|= BLOB_FLAG; 01158 } 01159 Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, 01160 CHARSET_INFO *cs, bool set_packlength) 01161 :Field_longstr((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0, 01162 NONE, field_name_arg, cs) 01163 { 01164 flags|= BLOB_FLAG; 01165 packlength= 4; 01166 if (set_packlength) 01167 { 01168 uint32 char_length= len_arg/cs->mbmaxlen; 01169 packlength= char_length <= 255 ? 1 : 01170 char_length <= 65535 ? 2 : 01171 char_length <= 16777215 ? 3 : 4; 01172 } 01173 } 01174 enum_field_types type() const { return FIELD_TYPE_BLOB;} 01175 enum ha_base_keytype key_type() const 01176 { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; } 01177 int store(const char *to,uint length,CHARSET_INFO *charset); 01178 int store(double nr); 01179 int store(longlong nr, bool unsigned_val); 01180 double val_real(void); 01181 longlong val_int(void); 01182 String *val_str(String*,String *); 01183 my_decimal *val_decimal(my_decimal *); 01184 int cmp_max(const char *, const char *, uint max_length); 01185 int cmp(const char *a,const char*b) 01186 { return cmp_max(a, b, ~0L); } 01187 int cmp(const char *a, uint32 a_length, const char *b, uint32 b_length); 01188 int cmp_binary(const char *a,const char *b, uint32 max_length=~0L); 01189 int key_cmp(const byte *,const byte*); 01190 int key_cmp(const byte *str, uint length); 01191 uint32 key_length() const { return 0; } 01192 void sort_string(char *buff,uint length); 01193 uint32 pack_length() const 01194 { return (uint32) (packlength+table->s->blob_ptr_size); } 01195 uint32 sort_length() const; 01196 inline uint32 max_data_length() const 01197 { 01198 return (uint32) (((ulonglong) 1 << (packlength*8)) -1); 01199 } 01200 void reset(void) { bzero(ptr, packlength+sizeof(char*)); } 01201 void reset_fields() { bzero((char*) &value,sizeof(value)); } 01202 void store_length(uint32 number); 01203 inline uint32 get_length(uint row_offset=0) 01204 { return get_length(ptr+row_offset); } 01205 uint32 get_length(const char *ptr); 01206 void put_length(char *pos, uint32 length); 01207 inline void get_ptr(char **str) 01208 { 01209 memcpy_fixed(str,ptr+packlength,sizeof(char*)); 01210 } 01211 inline void get_ptr(char **str, uint row_offset) 01212 { 01213 memcpy_fixed(str,ptr+packlength+row_offset,sizeof(char*)); 01214 } 01215 inline void set_ptr(char *length,char *data) 01216 { 01217 memcpy(ptr,length,packlength); 01218 memcpy_fixed(ptr+packlength,&data,sizeof(char*)); 01219 } 01220 inline void set_ptr(uint32 length,char *data) 01221 { 01222 store_length(length); 01223 memcpy_fixed(ptr+packlength,&data,sizeof(char*)); 01224 } 01225 void get_key_image(char *buff,uint length, imagetype type); 01226 void set_key_image(char *buff,uint length); 01227 void sql_type(String &str) const; 01228 inline bool copy() 01229 { char *tmp; 01230 get_ptr(&tmp); 01231 if (value.copy(tmp,get_length(),charset())) 01232 { 01233 Field_blob::reset(); 01234 return 1; 01235 } 01236 tmp=(char*) value.ptr(); memcpy_fixed(ptr+packlength,&tmp,sizeof(char*)); 01237 return 0; 01238 } 01239 char *pack(char *to, const char *from, uint max_length= ~(uint) 0); 01240 char *pack_key(char *to, const char *from, uint max_length); 01241 char *pack_key_from_key_image(char* to, const char *from, uint max_length); 01242 const char *unpack(char *to, const char *from); 01243 const char *unpack_key(char* to, const char *from, uint max_length); 01244 int pack_cmp(const char *a, const char *b, uint key_length, 01245 my_bool insert_or_update); 01246 int pack_cmp(const char *b, uint key_length,my_bool insert_or_update); 01247 uint packed_col_length(const char *col_ptr, uint length); 01248 uint max_packed_col_length(uint max_length); 01249 void free() { value.free(); } 01250 inline void clear_temporary() { bzero((char*) &value,sizeof(value)); } 01251 friend void field_conv(Field *to,Field *from); 01252 uint size_of() const { return sizeof(*this); } 01253 bool has_charset(void) const 01254 { return charset() == &my_charset_bin ? FALSE : TRUE; } 01255 uint32 max_length(); 01256 }; 01257 01258 01259 #ifdef HAVE_SPATIAL 01260 class Field_geom :public Field_blob { 01261 public: 01262 enum geometry_type geom_type; 01263 01264 Field_geom(char *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg, 01265 enum utype unireg_check_arg, const char *field_name_arg, 01266 TABLE_SHARE *share, uint blob_pack_length, 01267 enum geometry_type geom_type_arg) 01268 :Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, 01269 field_name_arg, share, blob_pack_length, &my_charset_bin) 01270 { geom_type= geom_type_arg; } 01271 Field_geom(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg, 01272 TABLE_SHARE *share, enum geometry_type geom_type_arg) 01273 :Field_blob(len_arg, maybe_null_arg, field_name_arg, &my_charset_bin) 01274 { geom_type= geom_type_arg; } 01275 enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY2; } 01276 enum_field_types type() const { return FIELD_TYPE_GEOMETRY; } 01277 void sql_type(String &str) const; 01278 int store(const char *to, uint length, CHARSET_INFO *charset); 01279 int store(double nr); 01280 int store(longlong nr, bool unsigned_val); 01281 int store_decimal(const my_decimal *); 01282 void get_key_image(char *buff,uint length,imagetype type); 01283 uint size_of() const { return sizeof(*this); } 01284 }; 01285 #endif /*HAVE_SPATIAL*/ 01286 01287 01288 class Field_enum :public Field_str { 01289 protected: 01290 uint packlength; 01291 public: 01292 TYPELIB *typelib; 01293 Field_enum(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 01294 uchar null_bit_arg, 01295 enum utype unireg_check_arg, const char *field_name_arg, 01296 uint packlength_arg, 01297 TYPELIB *typelib_arg, 01298 CHARSET_INFO *charset_arg) 01299 :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 01300 unireg_check_arg, field_name_arg, charset_arg), 01301 packlength(packlength_arg),typelib(typelib_arg) 01302 { 01303 flags|=ENUM_FLAG; 01304 } 01305 enum_field_types type() const { return FIELD_TYPE_STRING; } 01306 enum Item_result cmp_type () const { return INT_RESULT; } 01307 enum Item_result cast_to_int_type () const { return INT_RESULT; } 01308 enum ha_base_keytype key_type() const; 01309 int store(const char *to,uint length,CHARSET_INFO *charset); 01310 int store(double nr); 01311 int store(longlong nr, bool unsigned_val); 01312 void reset() { bzero(ptr,packlength); } 01313 double val_real(void); 01314 longlong val_int(void); 01315 String *val_str(String*,String *); 01316 int cmp(const char *,const char*); 01317 void sort_string(char *buff,uint length); 01318 uint32 pack_length() const { return (uint32) packlength; } 01319 void store_type(ulonglong value); 01320 void sql_type(String &str) const; 01321 uint size_of() const { return sizeof(*this); } 01322 enum_field_types real_type() const { return FIELD_TYPE_ENUM; } 01323 virtual bool zero_pack() const { return 0; } 01324 bool optimize_range(uint idx, uint part) { return 0; } 01325 bool eq_def(Field *field); 01326 bool has_charset(void) const { return TRUE; } 01327 /* enum and set are sorted as integers */ 01328 CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; } 01329 }; 01330 01331 01332 class Field_set :public Field_enum { 01333 public: 01334 Field_set(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 01335 uchar null_bit_arg, 01336 enum utype unireg_check_arg, const char *field_name_arg, 01337 uint32 packlength_arg, 01338 TYPELIB *typelib_arg, CHARSET_INFO *charset_arg) 01339 :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 01340 unireg_check_arg, field_name_arg, 01341 packlength_arg, 01342 typelib_arg,charset_arg) 01343 { 01344 flags=(flags & ~ENUM_FLAG) | SET_FLAG; 01345 } 01346 int store(const char *to,uint length,CHARSET_INFO *charset); 01347 int store(double nr) { return Field_set::store((longlong) nr, FALSE); } 01348 int store(longlong nr, bool unsigned_val); 01349 virtual bool zero_pack() const { return 1; } 01350 String *val_str(String*,String *); 01351 void sql_type(String &str) const; 01352 enum_field_types real_type() const { return FIELD_TYPE_SET; } 01353 bool has_charset(void) const { return TRUE; } 01354 }; 01355 01356 01357 /* 01358 Note: 01359 To use Field_bit::cmp_binary() you need to copy the bits stored in 01360 the beginning of the record (the NULL bytes) to each memory you 01361 want to compare (where the arguments point). 01362 01363 This is the reason: 01364 - Field_bit::cmp_binary() is only implemented in the base class 01365 (Field::cmp_binary()). 01366 - Field::cmp_binary() currenly use pack_length() to calculate how 01367 long the data is. 01368 - pack_length() includes size of the bits stored in the NULL bytes 01369 of the record. 01370 */ 01371 class Field_bit :public Field { 01372 public: 01373 uchar *bit_ptr; // position in record where 'uneven' bits store 01374 uchar bit_ofs; // offset to 'uneven' high bits 01375 uint bit_len; // number of 'uneven' high bits 01376 uint bytes_in_rec; 01377 Field_bit(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 01378 uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg, 01379 enum utype unireg_check_arg, const char *field_name_arg); 01380 enum_field_types type() const { return FIELD_TYPE_BIT; } 01381 enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; } 01382 uint32 key_length() const { return (uint32) (field_length + 7) / 8; } 01383 uint32 max_length() { return field_length; } 01384 uint size_of() const { return sizeof(*this); } 01385 Item_result result_type () const { return INT_RESULT; } 01386 void reset(void) { bzero(ptr, bytes_in_rec); } 01387 int store(const char *to, uint length, CHARSET_INFO *charset); 01388 int store(double nr); 01389 int store(longlong nr, bool unsigned_val); 01390 int store_decimal(const my_decimal *); 01391 double val_real(void); 01392 longlong val_int(void); 01393 String *val_str(String*, String *); 01394 virtual bool str_needs_quotes() { return TRUE; } 01395 my_decimal *val_decimal(my_decimal *); 01396 int cmp(const char *a, const char *b) 01397 { return cmp_binary(a, b); } 01398 int cmp_binary_offset(uint row_offset) 01399 { return cmp_offset(row_offset); } 01400 int cmp_max(const char *a, const char *b, uint max_length); 01401 int key_cmp(const byte *a, const byte *b) 01402 { return cmp_binary((char *) a, (char *) b); } 01403 int key_cmp(const byte *str, uint length); 01404 int cmp_offset(uint row_offset); 01405 void get_key_image(char *buff, uint length, imagetype type); 01406 void set_key_image(char *buff, uint length) 01407 { Field_bit::store(buff, length, &my_charset_bin); } 01408 void sort_string(char *buff, uint length) 01409 { get_key_image(buff, length, itRAW); } 01410 uint32 pack_length() const { return (uint32) (field_length + 7) / 8; } 01411 uint32 pack_length_in_rec() const { return bytes_in_rec; } 01412 void sql_type(String &str) const; 01413 char *pack(char *to, const char *from, uint max_length=~(uint) 0); 01414 const char *unpack(char* to, const char *from); 01415 Field *new_key_field(MEM_ROOT *root, struct st_table *new_table, 01416 char *new_ptr, uchar *new_null_ptr, 01417 uint new_null_bit); 01418 void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg) 01419 { 01420 bit_ptr= bit_ptr_arg; 01421 bit_ofs= bit_ofs_arg; 01422 } 01423 bool eq(Field *field) 01424 { 01425 return (Field::eq(field) && 01426 field->type() == type() && 01427 bit_ptr == ((Field_bit *)field)->bit_ptr && 01428 bit_ofs == ((Field_bit *)field)->bit_ofs); 01429 } 01430 void move_field_offset(my_ptrdiff_t ptr_diff) 01431 { 01432 Field::move_field_offset(ptr_diff); 01433 bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*); 01434 } 01435 }; 01436 01437 01438 class Field_bit_as_char: public Field_bit { 01439 public: 01440 Field_bit_as_char(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, 01441 uchar null_bit_arg, 01442 enum utype unireg_check_arg, const char *field_name_arg); 01443 enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } 01444 uint size_of() const { return sizeof(*this); } 01445 int store(const char *to, uint length, CHARSET_INFO *charset); 01446 int store(double nr) { return Field_bit::store(nr); } 01447 int store(longlong nr, bool unsigned_val) 01448 { return Field_bit::store(nr, unsigned_val); } 01449 void sql_type(String &str) const; 01450 }; 01451 01452 01453 /* 01454 Create field class for CREATE TABLE 01455 */ 01456 01457 class create_field :public Sql_alloc 01458 { 01459 public: 01460 const char *field_name; 01461 const char *change; // If done with alter table 01462 const char *after; // Put column after this one 01463 LEX_STRING comment; // Comment for field 01464 Item *def; // Default value 01465 enum enum_field_types sql_type; 01466 /* 01467 At various stages in execution this can be length of field in bytes or 01468 max number of characters. 01469 */ 01470 ulong length; 01471 /* 01472 The value of `length' as set by parser: is the number of characters 01473 for most of the types, or of bytes for BLOBs or numeric types. 01474 */ 01475 uint32 char_length; 01476 uint decimals, flags, pack_length, key_length; 01477 Field::utype unireg_check; 01478 TYPELIB *interval; // Which interval to use 01479 List<String> interval_list; 01480 CHARSET_INFO *charset; 01481 Field::geometry_type geom_type; 01482 Field *field; // For alter table 01483 01484 uint8 row,col,sc_length,interval_id; // For rea_create_table 01485 uint offset,pack_flag; 01486 create_field() :after(0) {} 01487 create_field(Field *field, Field *orig_field); 01488 void create_length_to_internal_length(void); 01489 01490 /* Init for a tmp table field. To be extended if need be. */ 01491 void init_for_tmp_table(enum_field_types sql_type_arg, 01492 uint32 max_length, uint32 decimals, 01493 bool maybe_null, bool is_unsigned); 01494 01495 bool init(THD *thd, char *field_name, enum_field_types type, char *length, 01496 char *decimals, uint type_modifier, Item *default_value, 01497 Item *on_update_value, LEX_STRING *comment, char *change, 01498 List<String> *interval_list, CHARSET_INFO *cs, 01499 uint uint_geom_type); 01500 }; 01501 01502 01503 /* 01504 A class for sending info to the client 01505 */ 01506 01507 class Send_field { 01508 public: 01509 const char *db_name; 01510 const char *table_name,*org_table_name; 01511 const char *col_name,*org_col_name; 01512 ulong length; 01513 uint charsetnr, flags, decimals; 01514 enum_field_types type; 01515 Send_field() {} 01516 }; 01517 01518 01519 /* 01520 A class for quick copying data to fields 01521 */ 01522 01523 class Copy_field :public Sql_alloc { 01524 void (*get_copy_func(Field *to,Field *from))(Copy_field *); 01525 public: 01526 char *from_ptr,*to_ptr; 01527 uchar *from_null_ptr,*to_null_ptr; 01528 my_bool *null_row; 01529 uint from_bit,to_bit; 01530 uint from_length,to_length; 01531 Field *from_field,*to_field; 01532 String tmp; // For items 01533 01534 Copy_field() {} 01535 ~Copy_field() {} 01536 void set(Field *to,Field *from,bool save); // Field to field 01537 void set(char *to,Field *from); // Field to string 01538 void (*do_copy)(Copy_field *); 01539 void (*do_copy2)(Copy_field *); // Used to handle null values 01540 }; 01541 01542 01543 Field *make_field(TABLE_SHARE *share, char *ptr, uint32 field_length, 01544 uchar *null_pos, uchar null_bit, 01545 uint pack_flag, enum_field_types field_type, 01546 CHARSET_INFO *cs, 01547 Field::geometry_type geom_type, 01548 Field::utype unireg_check, 01549 TYPELIB *interval, const char *field_name); 01550 uint pack_length_to_packflag(uint type); 01551 enum_field_types get_blob_type_from_length(ulong length); 01552 uint32 calc_pack_length(enum_field_types type,uint32 length); 01553 int set_field_to_null(Field *field); 01554 int set_field_to_null_with_conversions(Field *field, bool no_conversions); 01555 01556 /* 01557 The following are for the interface with the .frm file 01558 */ 01559 01560 #define FIELDFLAG_DECIMAL 1 01561 #define FIELDFLAG_BINARY 1 // Shares same flag 01562 #define FIELDFLAG_NUMBER 2 01563 #define FIELDFLAG_ZEROFILL 4 01564 #define FIELDFLAG_PACK 120 // Bits used for packing 01565 #define FIELDFLAG_INTERVAL 256 // mangled with decimals! 01566 #define FIELDFLAG_BITFIELD 512 // mangled with decimals! 01567 #define FIELDFLAG_BLOB 1024 // mangled with decimals! 01568 #define FIELDFLAG_GEOM 2048 // mangled with decimals! 01569 01570 #define FIELDFLAG_TREAT_BIT_AS_CHAR 4096 /* use Field_bit_as_char */ 01571 01572 #define FIELDFLAG_LEFT_FULLSCREEN 8192 01573 #define FIELDFLAG_RIGHT_FULLSCREEN 16384 01574 #define FIELDFLAG_FORMAT_NUMBER 16384 // predit: ###,,## in output 01575 #define FIELDFLAG_NO_DEFAULT 16384 /* sql */ 01576 #define FIELDFLAG_SUM ((uint) 32768)// predit: +#fieldflag 01577 #define FIELDFLAG_MAYBE_NULL ((uint) 32768)// sql 01578 #define FIELDFLAG_PACK_SHIFT 3 01579 #define FIELDFLAG_DEC_SHIFT 8 01580 #define FIELDFLAG_MAX_DEC 31 01581 #define FIELDFLAG_NUM_SCREEN_TYPE 0x7F01 01582 #define FIELDFLAG_ALFA_SCREEN_TYPE 0x7800 01583 01584 #define MTYP_TYPENR(type) (type & 127) /* Remove bits from type */ 01585 01586 #define f_is_dec(x) ((x) & FIELDFLAG_DECIMAL) 01587 #define f_is_num(x) ((x) & FIELDFLAG_NUMBER) 01588 #define f_is_zerofill(x) ((x) & FIELDFLAG_ZEROFILL) 01589 #define f_is_packed(x) ((x) & FIELDFLAG_PACK) 01590 #define f_packtype(x) (((x) >> FIELDFLAG_PACK_SHIFT) & 15) 01591 #define f_decimals(x) ((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC)) 01592 #define f_is_alpha(x) (!f_is_num(x)) 01593 #define f_is_binary(x) ((x) & FIELDFLAG_BINARY) // 4.0- compatibility 01594 #define f_is_enum(x) (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL) 01595 #define f_is_bitfield(x) (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD) 01596 #define f_is_blob(x) (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB) 01597 #define f_is_geom(x) (((x) & (FIELDFLAG_GEOM | FIELDFLAG_NUMBER)) == FIELDFLAG_GEOM) 01598 #define f_is_equ(x) ((x) & (1+2+FIELDFLAG_PACK+31*256)) 01599 #define f_settype(x) (((int) x) << FIELDFLAG_PACK_SHIFT) 01600 #define f_maybe_null(x) (x & FIELDFLAG_MAYBE_NULL) 01601 #define f_no_default(x) (x & FIELDFLAG_NO_DEFAULT) 01602 #define f_bit_as_char(x) ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
1.4.7

