field.h 49 KB
Newer Older
unknown's avatar
unknown committed
1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
unknown's avatar
unknown committed
2

unknown's avatar
unknown committed
3 4 5 6
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
unknown's avatar
unknown committed
7

unknown's avatar
unknown committed
8 9 10 11
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
unknown's avatar
unknown committed
12

unknown's avatar
unknown committed
13 14 15 16 17 18
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


/*
unknown's avatar
unknown committed
19 20
  Because of the function new_field() all field classes that have static
  variables must declare the size_of() member function.
unknown's avatar
unknown committed
21 22 23 24 25 26 27 28 29
*/

#ifdef __GNUC__
#pragma interface			/* gcc class implementation */
#endif

#define NOT_FIXED_DEC			31

class Send_field;
30
class Protocol;
unknown's avatar
unknown committed
31
struct st_cache_field;
32
void field_conv(Field *to,Field *from);
unknown's avatar
unknown committed
33

34 35
class Field
{
unknown's avatar
unknown committed
36
  Field(const Item &);				/* Prevent use of these */
unknown's avatar
unknown committed
37 38
  void operator=(Field &);
public:
unknown's avatar
unknown committed
39
  static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); }
40
  static void operator delete(void *ptr_arg, size_t size) {
41
#ifdef SAFEMALLOC
42 43 44
    bfill(ptr_arg, size, 0x8F);
#endif
  }
unknown's avatar
unknown committed
45

46 47
  char		*ptr;			// Position to field in record
  uchar		*null_ptr;		// Byte where null_bit is
48 49 50 51
  /*
    Note that you can use table->in_use as replacement for current_thd member 
    only inside of val_*() and store() members (e.g. you can't use it in cons)
  */
52
  struct st_table *table;		// Pointer for table
53
  struct st_table *orig_table;		// Pointer to original table
unknown's avatar
unknown committed
54
  const char	*table_name,*field_name;
55
  LEX_STRING	comment;
56
  ulong		query_id;		// For quick test of used fields
unknown's avatar
unknown committed
57
  /* Field is part of the following keys */
58
  key_map	key_start,part_of_key,part_of_sortkey;
59 60 61 62 63 64 65 66
  /* 
    We use three additional unireg types for TIMESTAMP to overcome limitation 
    of current binary format of .frm file. We'd like to be able to support 
    NOW() as default and on update value for such fields but unable to hold 
    this info anywhere except unireg_check field. This issue will be resolved
    in more clean way with transition to new text based .frm format.
    See also comment for Field_timestamp::Field_timestamp().
  */
unknown's avatar
unknown committed
67 68
  enum utype  { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
		CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
69 70
                BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
                TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
unknown's avatar
unknown committed
71 72 73 74 75 76
  enum geometry_type
  {
    GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3,
    GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6,
    GEOM_GEOMETRYCOLLECTION = 7
  };
unknown's avatar
unknown committed
77
  enum imagetype { itRAW, itMBR};
unknown's avatar
unknown committed
78 79 80 81 82 83 84 85 86 87 88
  enum field_cast_enum
  {
    FIELD_CAST_STOP, FIELD_CAST_DECIMAL, FIELD_CAST_TINY, FIELD_CAST_SHORT,
    FIELD_CAST_MEDIUM, FIELD_CAST_LONG, FIELD_CAST_LONGLONG,
    FIELD_CAST_FLOAT, FIELD_CAST_DOUBLE,
    FIELD_CAST_NULL,
    FIELD_CAST_TIMESTAMP, FIELD_CAST_YEAR, FIELD_CAST_DATE, FIELD_CAST_NEWDATE,
    FIELD_CAST_TIME, FIELD_CAST_DATETIME,
    FIELD_CAST_STRING, FIELD_CAST_VARSTRING, FIELD_CAST_BLOB,
    FIELD_CAST_GEOM, FIELD_CAST_ENUM, FIELD_CAST_SET
  };
unknown's avatar
unknown committed
89

unknown's avatar
unknown committed
90
  utype		unireg_check;
91
  uint32	field_length;		// Length of field
unknown's avatar
unknown committed
92
  uint16	flags;
93
  uchar		null_bit;		// Bit used to test null bit
unknown's avatar
unknown committed
94 95

  Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,uchar null_bit_arg,
unknown's avatar
unknown committed
96 97 98
	utype unireg_check_arg, const char *field_name_arg,
	struct st_table *table_arg);
  virtual ~Field() {}
unknown's avatar
unknown committed
99
  /* Store functions returns 1 on overflow and -1 on fatal error */
100 101 102
  virtual int  store(const char *to,uint length,CHARSET_INFO *cs)=0;
  virtual int  store(double nr)=0;
  virtual int  store(longlong nr)=0;
unknown's avatar
unknown committed
103 104 105
  virtual void store_time(TIME *ltime,timestamp_type t_type);
  virtual double val_real(void)=0;
  virtual longlong val_int(void)=0;
unknown's avatar
unknown committed
106 107 108
  inline String *val_str(String *str) { return val_str(str, str); }
  /*
     val_str(buf1, buf2) gets two buffers and should use them as follows:
109 110 111 112 113 114 115 116 117 118
     if it needs a temp buffer to convert result to string - use buf1
       example Field_tiny::val_str()
     if the value exists as a string already - use buf2
       example Field_string::val_str()
     consequently, buf2 may be created as 'String buf;' - no memory
     will be allocated for it. buf1 will be allocated to hold a
     value if it's too small. Using allocated buffer for buf2 may result in
     an unnecessary free (and later, may be an alloc).
     This trickery is used to decrease a number of malloc calls.
  */
unknown's avatar
unknown committed
119 120 121
  virtual String *val_str(String*,String *)=0;
  virtual Item_result result_type () const=0;
  virtual Item_result cmp_type () const { return result_type(); }
122
  bool eq(Field *field) { return ptr == field->ptr && null_ptr == field->null_ptr; }
unknown's avatar
unknown committed
123 124 125 126
  virtual bool eq_def(Field *field);
  virtual uint32 pack_length() const { return (uint32) field_length; }
  virtual void reset(void) { bzero(ptr,pack_length()); }
  virtual void reset_fields() {}
unknown's avatar
unknown committed
127 128
  virtual void set_default()
  {
unknown's avatar
unknown committed
129 130
    my_ptrdiff_t offset = (my_ptrdiff_t) (table->default_values -
					  table->record[0]);
unknown's avatar
SCRUM  
unknown committed
131
    memcpy(ptr, ptr + offset, pack_length());
132 133
    if (null_ptr)
      *null_ptr= ((*null_ptr & (uchar) ~null_bit) |
unknown's avatar
SCRUM  
unknown committed
134
		  null_ptr[offset] & null_bit);
unknown's avatar
unknown committed
135
  }
unknown's avatar
unknown committed
136 137 138 139 140 141 142 143
  virtual bool binary() const { return 1; }
  virtual bool zero_pack() const { return 1; }
  virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
  virtual uint32 key_length() const { return pack_length(); }
  virtual enum_field_types type() const =0;
  virtual enum_field_types real_type() const { return type(); }
  inline  int cmp(const char *str) { return cmp(ptr,str); }
  virtual int cmp(const char *,const char *)=0;
unknown's avatar
unknown committed
144
  virtual int cmp_binary(const char *a,const char *b, uint32 max_length=~0L)
unknown's avatar
unknown committed
145 146 147 148 149 150 151 152 153 154
  { return memcmp(a,b,pack_length()); }
  virtual int cmp_offset(uint row_offset)
  { return memcmp(ptr,ptr+row_offset,pack_length()); }
  virtual int cmp_binary_offset(uint row_offset)
  { return memcmp(ptr,ptr+row_offset,pack_length()); }
  virtual int key_cmp(const byte *a,const byte *b)
  { return cmp((char*) a,(char*) b); }
  virtual int key_cmp(const byte *str, uint length)
  { return cmp(ptr,(char*) str); }
  virtual uint decimals() const { return 0; }
unknown's avatar
unknown committed
155 156 157 158 159
  /*
    Caller beware: sql_type can change str.Ptr, so check
    ptr() to see if it changed if you are using your own buffer
    in str and restore it with set() if needed
  */
160
  virtual void sql_type(String &str) const =0;
161
  virtual uint size_of() const =0;		// For new field
unknown's avatar
unknown committed
162 163 164 165
  inline bool is_null(uint row_offset=0)
  { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
  inline bool is_real_null(uint row_offset=0)
    { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
unknown's avatar
unknown committed
166 167 168 169 170 171 172
  inline bool is_null_in_record(const uchar *record)
  {
    if (!null_ptr)
      return 0;
    return test(record[(uint) (null_ptr - (uchar*) table->record[0])] &
		null_bit);
  }
unknown's avatar
unknown committed
173 174 175
  inline void set_null(int row_offset=0)
    { if (null_ptr) null_ptr[row_offset]|= null_bit; }
  inline void set_notnull(int row_offset=0)
unknown's avatar
unknown committed
176
    { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
unknown's avatar
unknown committed
177 178 179 180
  inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
  inline bool real_maybe_null(void) { return null_ptr != 0; }
  virtual void make_field(Send_field *)=0;
  virtual void sort_string(char *buff,uint length)=0;
181
  virtual bool optimize_range(uint idx, uint part);
unknown's avatar
unknown committed
182
  virtual bool store_for_compare() { return 0; }
183
  virtual void free() {}
unknown's avatar
unknown committed
184 185 186 187
  Field *new_field(MEM_ROOT *root, struct st_table *new_table)
  {
    Field *tmp= (Field*) memdup_root(root,(char*) this,size_of());
    if (tmp)
unknown's avatar
unknown committed
188
    {
189 190
      if (tmp->table->maybe_null)
	tmp->flags&= ~NOT_NULL_FLAG;
191
      tmp->table= new_table;
unknown's avatar
unknown committed
192 193 194
      tmp->key_start.init(0);
      tmp->part_of_key.init(0);
      tmp->part_of_sortkey.init(0);
unknown's avatar
unknown committed
195
      tmp->unireg_check=Field::NONE;
196
      tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG |
unknown's avatar
unknown committed
197
		    ZEROFILL_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
198
#ifdef PROBABLY_WRONG
199
      tmp->table_name= new_table->table_name;
200
#endif
unknown's avatar
unknown committed
201
      tmp->reset_fields();
unknown's avatar
unknown committed
202
    }
unknown's avatar
unknown committed
203 204 205 206 207 208
    return tmp;
  }
  inline void move_field(char *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
  {
    ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
  }
unknown's avatar
unknown committed
209 210 211 212 213 214 215
  inline void move_field(char *ptr_arg) { ptr=ptr_arg; }
  inline void move_field(my_ptrdiff_t ptr_diff)
  {
    ptr=ADD_TO_PTR(ptr,ptr_diff,char*);
    if (null_ptr)
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
  }
unknown's avatar
unknown committed
216
  inline void get_image(char *buff,uint length, CHARSET_INFO *cs)
unknown's avatar
unknown committed
217
    { memcpy(buff,ptr,length); }
unknown's avatar
unknown committed
218
  inline void set_image(char *buff,uint length, CHARSET_INFO *cs)
unknown's avatar
unknown committed
219
    { memcpy(ptr,buff,length); }
220 221
  virtual void get_key_image(char *buff,uint length, CHARSET_INFO *cs,
			     imagetype type)
unknown's avatar
unknown committed
222 223 224
    { get_image(buff,length,cs); }
  virtual void set_key_image(char *buff,uint length, CHARSET_INFO *cs)
    { set_image(buff,length,cs); }
unknown's avatar
unknown committed
225 226 227 228 229 230 231
  inline longlong val_int_offset(uint row_offset)
    {
      ptr+=row_offset;
      longlong tmp=val_int();
      ptr-=row_offset;
      return tmp;
    }
unknown's avatar
unknown committed
232
  virtual bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
233 234
  virtual char *pack(char* to, const char *from, uint max_length=~(uint) 0)
  {
unknown's avatar
unknown committed
235
    uint32 length=pack_length();
unknown's avatar
unknown committed
236 237 238 239 240 241 242 243 244
    memcpy(to,from,length);
    return to+length;
  }
  virtual const char *unpack(char* to, const char *from)
  {
    uint length=pack_length();
    memcpy(to,from,length);
    return from+length;
  }
245 246 247 248 249 250
  virtual char *pack_key(char* to, const char *from, uint max_length)
  {
    return pack(to,from,max_length);
  }
  virtual char *pack_key_from_key_image(char* to, const char *from,
					uint max_length)
unknown's avatar
unknown committed
251 252 253
  {
    return pack(to,from,max_length);
  }
254 255 256 257
  virtual const char *unpack_key(char* to, const char *from, uint max_length)
  {
    return unpack(to,from);
  }
258 259
  virtual uint packed_col_length(const char *to, uint length)
  { return length;}
unknown's avatar
unknown committed
260
  virtual uint max_packed_col_length(uint max_length)
261
  { return max_length;}
unknown's avatar
unknown committed
262 263 264

  virtual int pack_cmp(const char *a,const char *b, uint key_length_arg)
  { return cmp(a,b); }
265 266
  virtual int pack_cmp(const char *b, uint key_length_arg)
  { return cmp(ptr,b); }
267
  uint offset();			// Should be inline ...
unknown's avatar
unknown committed
268 269
  void copy_from_tmp(int offset);
  uint fill_cache_field(struct st_cache_field *copy);
270
  virtual bool get_date(TIME *ltime,uint fuzzydate);
unknown's avatar
unknown committed
271
  virtual bool get_time(TIME *ltime);
unknown's avatar
unknown committed
272
  virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
273
  virtual bool has_charset(void) const { return FALSE; }
unknown's avatar
unknown committed
274
  virtual void set_charset(CHARSET_INFO *charset) { }
275 276 277 278 279 280 281 282 283 284
  bool set_warning(const unsigned int level, const unsigned int code, 
                   int cuted_increment);
  void set_datetime_warning(const uint level, const uint code, 
                            const char *str, uint str_len,
                            timestamp_type ts_type, int cuted_increment);
  void set_datetime_warning(const uint level, const uint code, 
                            longlong nr, timestamp_type ts_type,
                            int cuted_increment);
  void set_datetime_warning(const uint level, const uint code, 
                            double nr, timestamp_type ts_type);
unknown's avatar
unknown committed
285 286
  virtual field_cast_enum field_cast_type()= 0;
  bool field_cast_compatible(field_cast_enum type);
unknown's avatar
unknown committed
287 288
  /* maximum possible display length */
  virtual uint32 max_length()= 0;
unknown's avatar
unknown committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302
  friend bool reopen_table(THD *,struct st_table *,bool);
  friend int cre_myisam(my_string name, register TABLE *form, uint options,
			ulonglong auto_increment_value);
  friend class Copy_field;
  friend class Item_avg_field;
  friend class Item_std_field;
  friend class Item_sum_num;
  friend class Item_sum_sum;
  friend class Item_sum_str;
  friend class Item_sum_count;
  friend class Item_sum_avg;
  friend class Item_sum_std;
  friend class Item_sum_min;
  friend class Item_sum_max;
303
  friend class Item_func_group_concat;
unknown's avatar
unknown committed
304 305 306 307 308 309
};


class Field_num :public Field {
public:
  const uint8 dec;
310
  bool zerofill,unsigned_flag;	// Purify cannot handle bit fields
unknown's avatar
unknown committed
311
  Field_num(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
312
	    uchar null_bit_arg, utype unireg_check_arg,
unknown's avatar
unknown committed
313 314
	    const char *field_name_arg,
	    struct st_table *table_arg,
unknown's avatar
unknown committed
315
	    uint8 dec_arg,bool zero_arg,bool unsigned_arg)
unknown's avatar
unknown committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329
    :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	   unireg_check_arg, field_name_arg, table_arg),
     dec(dec_arg),zerofill(zero_arg),unsigned_flag(unsigned_arg)
    {
      if (zerofill)
	flags|=ZEROFILL_FLAG;
      if (unsigned_flag)
	flags|=UNSIGNED_FLAG;
    }
  Item_result result_type () const { return REAL_RESULT; }
  void prepend_zeros(String *value);
  void add_zerofill_and_unsigned(String &res) const;
  friend class create_field;
  void make_field(Send_field *);
unknown's avatar
unknown committed
330
  uint decimals() const { return (uint) dec; }
unknown's avatar
unknown committed
331 332 333 334 335 336
  uint size_of() const { return sizeof(*this); }
  bool eq_def(Field *field);
};


class Field_str :public Field {
337 338
protected:
  CHARSET_INFO *field_charset;
339
  double ceiling; // for ::store(double nr)
unknown's avatar
unknown committed
340
public:
unknown's avatar
unknown committed
341
  Field_str(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
342
	    uchar null_bit_arg, utype unireg_check_arg,
unknown's avatar
unknown committed
343
	    const char *field_name_arg,
344
	    struct st_table *table_arg,CHARSET_INFO *charset)
unknown's avatar
unknown committed
345
    :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
346
	   unireg_check_arg, field_name_arg, table_arg), ceiling(0.0)
unknown's avatar
unknown committed
347
    {
unknown's avatar
unknown committed
348
      field_charset=charset;
349
      if (charset->state & MY_CS_BINSORT)
unknown's avatar
unknown committed
350 351
        flags|=BINARY_FLAG;
    }
unknown's avatar
unknown committed
352 353
  Item_result result_type () const { return STRING_RESULT; }
  uint decimals() const { return NOT_FIXED_DEC; }
unknown's avatar
unknown committed
354 355
  int  store(double nr);
  int  store(const char *to,uint length,CHARSET_INFO *cs)=0;
unknown's avatar
unknown committed
356 357
  void make_field(Send_field *);
  uint size_of() const { return sizeof(*this); }
unknown's avatar
unknown committed
358 359
  CHARSET_INFO *charset(void) const { return field_charset; }
  void set_charset(CHARSET_INFO *charset) { field_charset=charset; }
360
  bool binary() const { return field_charset->state & MY_CS_BINSORT ? 1 : 0; }
unknown's avatar
unknown committed
361
  uint32 max_length() { return field_length; }
unknown's avatar
unknown committed
362
  friend class create_field;
unknown's avatar
unknown committed
363 364 365 366 367 368
};


class Field_decimal :public Field_num {
public:
  Field_decimal(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
369
		uchar null_bit_arg,
unknown's avatar
unknown committed
370 371
		enum utype unireg_check_arg, const char *field_name_arg,
		struct st_table *table_arg,
unknown's avatar
unknown committed
372
		uint8 dec_arg,bool zero_arg,bool unsigned_arg)
unknown's avatar
unknown committed
373 374 375 376 377 378
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       dec_arg, zero_arg,unsigned_arg)
    {}
  enum_field_types type() const { return FIELD_TYPE_DECIMAL;}
  enum ha_base_keytype key_type() const
379
  { return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
unknown's avatar
unknown committed
380
  void reset(void);
381 382 383
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
unknown's avatar
unknown committed
384 385 386 387 388 389 390 391
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  void overflow(bool negative);
  bool zero_pack() const { return 0; }
  void sql_type(String &str) const;
unknown's avatar
unknown committed
392
  uint32 max_length() { return field_length; }
unknown's avatar
unknown committed
393
  field_cast_enum field_cast_type() { return FIELD_CAST_DECIMAL; }
unknown's avatar
unknown committed
394 395 396 397 398 399
};


class Field_tiny :public Field_num {
public:
  Field_tiny(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
400
	     uchar null_bit_arg,
unknown's avatar
unknown committed
401 402 403 404 405 406 407 408 409 410 411
	     enum utype unireg_check_arg, const char *field_name_arg,
	     struct st_table *table_arg,
	     bool zero_arg, bool unsigned_arg)
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       0, zero_arg,unsigned_arg)
    {}
  enum Item_result result_type () const { return INT_RESULT; }
  enum_field_types type() const { return FIELD_TYPE_TINY;}
  enum ha_base_keytype key_type() const
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
412 413 414
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
415
  void reset(void) { ptr[0]=0; }
unknown's avatar
unknown committed
416 417 418
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
419
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
420 421 422 423
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 1; }
  void sql_type(String &str) const;
unknown's avatar
unknown committed
424
  uint32 max_length() { return 4; }
unknown's avatar
unknown committed
425
  field_cast_enum field_cast_type() { return FIELD_CAST_TINY; }
unknown's avatar
unknown committed
426 427 428 429 430 431
};


class Field_short :public Field_num {
public:
  Field_short(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
432
	      uchar null_bit_arg,
unknown's avatar
unknown committed
433 434 435 436 437 438 439
	      enum utype unireg_check_arg, const char *field_name_arg,
	      struct st_table *table_arg,
	      bool zero_arg, bool unsigned_arg)
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       0, zero_arg,unsigned_arg)
    {}
440 441 442 443 444
  Field_short(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
	      struct st_table *table_arg,bool unsigned_arg)
    :Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
	       NONE, field_name_arg, table_arg,0,0,unsigned_arg)
    {}
unknown's avatar
unknown committed
445 446 447 448
  enum Item_result result_type () const { return INT_RESULT; }
  enum_field_types type() const { return FIELD_TYPE_SHORT;}
  enum ha_base_keytype key_type() const
    { return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;}
449 450 451
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
452
  void reset(void) { ptr[0]=ptr[1]=0; }
unknown's avatar
unknown committed
453 454 455
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
456
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
457 458 459 460
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 2; }
  void sql_type(String &str) const;
unknown's avatar
unknown committed
461
  uint32 max_length() { return 6; }
unknown's avatar
unknown committed
462
  field_cast_enum field_cast_type() { return FIELD_CAST_SHORT; }
unknown's avatar
unknown committed
463 464 465 466 467 468
};


class Field_medium :public Field_num {
public:
  Field_medium(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
469
	      uchar null_bit_arg,
unknown's avatar
unknown committed
470 471 472 473 474 475 476 477 478 479 480
	      enum utype unireg_check_arg, const char *field_name_arg,
	      struct st_table *table_arg,
	      bool zero_arg, bool unsigned_arg)
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       0, zero_arg,unsigned_arg)
    {}
  enum Item_result result_type () const { return INT_RESULT; }
  enum_field_types type() const { return FIELD_TYPE_INT24;}
  enum ha_base_keytype key_type() const
    { return unsigned_flag ? HA_KEYTYPE_UINT24 : HA_KEYTYPE_INT24; }
481 482 483
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int store(longlong nr);
484
  void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; }
unknown's avatar
unknown committed
485 486 487
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
488
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
489 490 491 492
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 3; }
  void sql_type(String &str) const;
unknown's avatar
unknown committed
493
  uint32 max_length() { return 8; }
unknown's avatar
unknown committed
494
  field_cast_enum field_cast_type() { return FIELD_CAST_MEDIUM; }
unknown's avatar
unknown committed
495 496 497 498 499 500
};


class Field_long :public Field_num {
public:
  Field_long(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
501
	     uchar null_bit_arg,
unknown's avatar
unknown committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
	     enum utype unireg_check_arg, const char *field_name_arg,
	     struct st_table *table_arg,
	     bool zero_arg, bool unsigned_arg)
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       0, zero_arg,unsigned_arg)
    {}
  Field_long(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
	     struct st_table *table_arg,bool unsigned_arg)
    :Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
	       NONE, field_name_arg, table_arg,0,0,unsigned_arg)
    {}
  enum Item_result result_type () const { return INT_RESULT; }
  enum_field_types type() const { return FIELD_TYPE_LONG;}
  enum ha_base_keytype key_type() const
    { return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; }
518 519 520
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
521
  void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; }
unknown's avatar
unknown committed
522 523
  double val_real(void);
  longlong val_int(void);
524
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
525 526 527 528 529
  String *val_str(String*,String *);
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 4; }
  void sql_type(String &str) const;
unknown's avatar
unknown committed
530
  uint32 max_length() { return 11; }
unknown's avatar
unknown committed
531
  field_cast_enum field_cast_type() { return FIELD_CAST_LONG; }
unknown's avatar
unknown committed
532 533 534 535 536 537 538
};


#ifdef HAVE_LONG_LONG
class Field_longlong :public Field_num {
public:
  Field_longlong(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
539
	      uchar null_bit_arg,
unknown's avatar
unknown committed
540 541 542 543 544 545 546
	      enum utype unireg_check_arg, const char *field_name_arg,
	      struct st_table *table_arg,
	      bool zero_arg, bool unsigned_arg)
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       0, zero_arg,unsigned_arg)
    {}
547 548 549
  Field_longlong(uint32 len_arg,bool maybe_null_arg,
		 const char *field_name_arg,
		 struct st_table *table_arg, bool unsigned_arg)
unknown's avatar
unknown committed
550
    :Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
551
	       NONE, field_name_arg, table_arg,0,0,unsigned_arg)
unknown's avatar
unknown committed
552 553 554 555 556
    {}
  enum Item_result result_type () const { return INT_RESULT; }
  enum_field_types type() const { return FIELD_TYPE_LONGLONG;}
  enum ha_base_keytype key_type() const
    { return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
557 558 559
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
560
  void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; }
unknown's avatar
unknown committed
561 562 563
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
564
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
565 566 567 568
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 8; }
  void sql_type(String &str) const;
569
  bool store_for_compare() { return 1; }
unknown's avatar
unknown committed
570
  uint32 max_length() { return 20; }
unknown's avatar
unknown committed
571
  field_cast_enum field_cast_type() { return FIELD_CAST_LONGLONG; }
unknown's avatar
unknown committed
572 573 574 575 576 577
};
#endif

class Field_float :public Field_num {
public:
  Field_float(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
578
	      uchar null_bit_arg,
unknown's avatar
unknown committed
579 580
	      enum utype unireg_check_arg, const char *field_name_arg,
	      struct st_table *table_arg,
unknown's avatar
unknown committed
581
	      uint8 dec_arg,bool zero_arg,bool unsigned_arg)
unknown's avatar
unknown committed
582 583 584 585
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       dec_arg, zero_arg,unsigned_arg)
    {}
586 587 588 589 590
  Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
	      struct st_table *table_arg, uint8 dec_arg)
    :Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
	       NONE, field_name_arg, table_arg,dec_arg,0,0)
    {}
unknown's avatar
unknown committed
591 592
  enum_field_types type() const { return FIELD_TYPE_FLOAT;}
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
593 594 595
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
596
  void reset(void) { bzero(ptr,sizeof(float)); }
unknown's avatar
unknown committed
597 598 599
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
600
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
601 602 603 604
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return sizeof(float); }
  void sql_type(String &str) const;
unknown's avatar
unknown committed
605
  uint32 max_length() { return 24; }
unknown's avatar
unknown committed
606
  field_cast_enum field_cast_type() { return FIELD_CAST_FLOAT; }
unknown's avatar
unknown committed
607 608 609 610 611 612
};


class Field_double :public Field_num {
public:
  Field_double(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
613
	       uchar null_bit_arg,
unknown's avatar
unknown committed
614 615
	       enum utype unireg_check_arg, const char *field_name_arg,
	       struct st_table *table_arg,
unknown's avatar
unknown committed
616
	       uint8 dec_arg,bool zero_arg,bool unsigned_arg)
unknown's avatar
unknown committed
617 618 619 620 621
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
	       unireg_check_arg, field_name_arg, table_arg,
	       dec_arg, zero_arg,unsigned_arg)
    {}
  Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
unknown's avatar
unknown committed
622
	       struct st_table *table_arg, uint8 dec_arg)
unknown's avatar
unknown committed
623 624 625 626 627
    :Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
	       NONE, field_name_arg, table_arg,dec_arg,0,0)
    {}
  enum_field_types type() const { return FIELD_TYPE_DOUBLE;}
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
628 629 630
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
631
  void reset(void) { bzero(ptr,sizeof(double)); }
unknown's avatar
unknown committed
632 633 634
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
635
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
636 637 638 639
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return sizeof(double); }
  void sql_type(String &str) const;
unknown's avatar
unknown committed
640
  uint32 max_length() { return 53; }
unknown's avatar
unknown committed
641
  field_cast_enum field_cast_type() { return FIELD_CAST_DOUBLE; }
unknown's avatar
unknown committed
642 643 644 645 646 647 648 649 650 651
};


/* Everything saved in this will disapper. It will always return NULL */

class Field_null :public Field_str {
  static uchar null[1];
public:
  Field_null(char *ptr_arg, uint32 len_arg,
	     enum utype unireg_check_arg, const char *field_name_arg,
652
	     struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
653
    :Field_str(ptr_arg, len_arg, null, 1,
654
	       unireg_check_arg, field_name_arg, table_arg, cs)
unknown's avatar
unknown committed
655 656
    {}
  enum_field_types type() const { return FIELD_TYPE_NULL;}
657 658
  int  store(const char *to, uint length, CHARSET_INFO *cs)
  { null[0]=1; return 0; }
659 660
  int  store(double nr)   { null[0]=1; return 0; }
  int  store(longlong nr) { null[0]=1; return 0; }
661
  void reset(void)	  {}
unknown's avatar
unknown committed
662 663 664 665 666 667 668
  double val_real(void)		{ return 0.0;}
  longlong val_int(void)	{ return 0;}
  String *val_str(String *value,String *value2)
  { value2->length(0); return value2;}
  int cmp(const char *a, const char *b) { return 0;}
  void sort_string(char *buff, uint length)  {}
  uint32 pack_length() const { return 0; }
669
  void sql_type(String &str) const;
unknown's avatar
unknown committed
670
  uint size_of() const { return sizeof(*this); }
unknown's avatar
unknown committed
671
  uint32 max_length() { return 4; }
unknown's avatar
unknown committed
672
  field_cast_enum field_cast_type() { return FIELD_CAST_NULL; }
unknown's avatar
unknown committed
673 674 675
};


676
class Field_timestamp :public Field_str {
unknown's avatar
unknown committed
677 678 679
public:
  Field_timestamp(char *ptr_arg, uint32 len_arg,
		  enum utype unireg_check_arg, const char *field_name_arg,
680 681
		  struct st_table *table_arg,
		  CHARSET_INFO *cs);
unknown's avatar
unknown committed
682 683
  enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;}
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
684
  enum Item_result cmp_type () const { return INT_RESULT; }
685 686 687
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
688
  void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; }
unknown's avatar
unknown committed
689 690 691
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
692
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
693 694 695 696 697 698 699
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 4; }
  void sql_type(String &str) const;
  bool store_for_compare() { return 1; }
  bool zero_pack() const { return 0; }
  void set_time();
unknown's avatar
unknown committed
700 701
  virtual void set_default()
  {
702 703
    if (table->timestamp_field == this &&
        unireg_check != TIMESTAMP_UN_FIELD)
704 705 706
      set_time();
    else
      Field::set_default();
unknown's avatar
unknown committed
707
  }
unknown's avatar
unknown committed
708 709 710 711 712 713 714 715 716 717
  inline long get_timestamp()
  {
#ifdef WORDS_BIGENDIAN
    if (table->db_low_byte_first)
      return sint4korr(ptr);
#endif
    long tmp;
    longget(tmp,ptr);
    return tmp;
  }
718
  bool get_date(TIME *ltime,uint fuzzydate);
unknown's avatar
unknown committed
719
  bool get_time(TIME *ltime);
unknown's avatar
unknown committed
720
  field_cast_enum field_cast_type() { return FIELD_CAST_TIMESTAMP; }
721
  void set_timestamp_offsets();
unknown's avatar
unknown committed
722 723 724 725 726 727
};


class Field_year :public Field_tiny {
public:
  Field_year(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
728
	     uchar null_bit_arg,
unknown's avatar
unknown committed
729 730 731 732 733 734
	     enum utype unireg_check_arg, const char *field_name_arg,
	     struct st_table *table_arg)
    :Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
		unireg_check_arg, field_name_arg, table_arg, 1, 1)
    {}
  enum_field_types type() const { return FIELD_TYPE_YEAR;}
735 736 737
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
unknown's avatar
unknown committed
738 739 740
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
741
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
742
  void sql_type(String &str) const;
743
  bool store_for_compare() { return 1; }
unknown's avatar
unknown committed
744
  field_cast_enum field_cast_type() { return FIELD_CAST_YEAR; }
unknown's avatar
unknown committed
745 746 747 748 749
};


class Field_date :public Field_str {
public:
unknown's avatar
unknown committed
750
  Field_date(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
unknown's avatar
unknown committed
751
	     enum utype unireg_check_arg, const char *field_name_arg,
752
	     struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
753
    :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
754
	       unireg_check_arg, field_name_arg, table_arg, cs)
unknown's avatar
unknown committed
755
    {}
756
  Field_date(bool maybe_null_arg, const char *field_name_arg,
757
		 struct st_table *table_arg, CHARSET_INFO *cs)
758
    :Field_str((char*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
759
	       NONE, field_name_arg, table_arg, cs) {}
unknown's avatar
unknown committed
760 761 762
  enum_field_types type() const { return FIELD_TYPE_DATE;}
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
  enum Item_result cmp_type () const { return INT_RESULT; }
763 764 765
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
766
  void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; }
unknown's avatar
unknown committed
767 768 769
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
770
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
771 772 773 774 775 776
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 4; }
  void sql_type(String &str) const;
  bool store_for_compare() { return 1; }
  bool zero_pack() const { return 1; }
unknown's avatar
unknown committed
777
  field_cast_enum field_cast_type() { return FIELD_CAST_DATE; }
unknown's avatar
unknown committed
778 779 780 781
};

class Field_newdate :public Field_str {
public:
unknown's avatar
unknown committed
782
  Field_newdate(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
unknown's avatar
unknown committed
783
		enum utype unireg_check_arg, const char *field_name_arg,
784
		struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
785
    :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
786
	       unireg_check_arg, field_name_arg, table_arg, cs)
unknown's avatar
unknown committed
787 788 789 790 791
    {}
  enum_field_types type() const { return FIELD_TYPE_DATE;}
  enum_field_types real_type() const { return FIELD_TYPE_NEWDATE; }
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; }
  enum Item_result cmp_type () const { return INT_RESULT; }
792 793 794
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
unknown's avatar
unknown committed
795
  void store_time(TIME *ltime,timestamp_type type);
796
  void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; }
unknown's avatar
unknown committed
797 798 799
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
800
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
801 802 803 804 805 806
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 3; }
  void sql_type(String &str) const;
  bool store_for_compare() { return 1; }
  bool zero_pack() const { return 1; }
807
  bool get_date(TIME *ltime,uint fuzzydate);
unknown's avatar
unknown committed
808
  bool get_time(TIME *ltime);
unknown's avatar
unknown committed
809
  field_cast_enum field_cast_type() { return FIELD_CAST_NEWDATE; }
unknown's avatar
unknown committed
810 811 812 813 814
};


class Field_time :public Field_str {
public:
unknown's avatar
unknown committed
815
  Field_time(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
unknown's avatar
unknown committed
816
	     enum utype unireg_check_arg, const char *field_name_arg,
817
	     struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
818
    :Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
819
	       unireg_check_arg, field_name_arg, table_arg, cs)
unknown's avatar
unknown committed
820
    {}
821
  Field_time(bool maybe_null_arg, const char *field_name_arg,
822
		 struct st_table *table_arg, CHARSET_INFO *cs)
823
    :Field_str((char*) 0,8, maybe_null_arg ? (uchar*) "": 0,0,
824
	       NONE, field_name_arg, table_arg, cs) {}
unknown's avatar
unknown committed
825 826 827
  enum_field_types type() const { return FIELD_TYPE_TIME;}
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
  enum Item_result cmp_type () const { return INT_RESULT; }
828 829 830
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
831
  void reset(void) { ptr[0]=ptr[1]=ptr[2]=0; }
unknown's avatar
unknown committed
832 833 834
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
unknown's avatar
unknown committed
835
  bool get_date(TIME *ltime, uint fuzzydate);
836
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
837 838 839 840 841 842 843
  bool get_time(TIME *ltime);
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 3; }
  void sql_type(String &str) const;
  bool store_for_compare() { return 1; }
  bool zero_pack() const { return 1; }
unknown's avatar
unknown committed
844
  field_cast_enum field_cast_type() { return FIELD_CAST_TIME; }
unknown's avatar
unknown committed
845 846 847 848 849
};


class Field_datetime :public Field_str {
public:
unknown's avatar
unknown committed
850
  Field_datetime(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
unknown's avatar
unknown committed
851
		 enum utype unireg_check_arg, const char *field_name_arg,
852
		 struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
853
    :Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
854
	       unireg_check_arg, field_name_arg, table_arg, cs)
unknown's avatar
unknown committed
855
    {}
856
  Field_datetime(bool maybe_null_arg, const char *field_name_arg,
857
		 struct st_table *table_arg, CHARSET_INFO *cs)
858
    :Field_str((char*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
859
	       NONE, field_name_arg, table_arg, cs) {}
unknown's avatar
unknown committed
860 861 862 863 864
  enum_field_types type() const { return FIELD_TYPE_DATETIME;}
#ifdef HAVE_LONG_LONG
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
#endif
  enum Item_result cmp_type () const { return INT_RESULT; }
865 866 867
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
unknown's avatar
unknown committed
868
  void store_time(TIME *ltime,timestamp_type type);
869
  void reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; }
unknown's avatar
unknown committed
870 871 872
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
873
  bool send_binary(Protocol *protocol);
unknown's avatar
unknown committed
874 875 876 877 878 879
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return 8; }
  void sql_type(String &str) const;
  bool store_for_compare() { return 1; }
  bool zero_pack() const { return 1; }
880
  bool get_date(TIME *ltime,uint fuzzydate);
unknown's avatar
unknown committed
881
  bool get_time(TIME *ltime);
unknown's avatar
unknown committed
882
  field_cast_enum field_cast_type() { return FIELD_CAST_DATETIME; }
unknown's avatar
unknown committed
883 884 885 886 887 888
};


class Field_string :public Field_str {
public:
  Field_string(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
unknown's avatar
unknown committed
889
	       uchar null_bit_arg,
unknown's avatar
unknown committed
890
	       enum utype unireg_check_arg, const char *field_name_arg,
891
	       struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
892
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
893
	       unireg_check_arg, field_name_arg, table_arg,cs) {};
unknown's avatar
unknown committed
894
  Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
895
	       struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
896
    :Field_str((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0,0,
897
	       NONE, field_name_arg, table_arg, cs) {};
unknown's avatar
unknown committed
898 899 900 901 902 903 904 905

  enum_field_types type() const
  {
    return ((table && table->db_create_options & HA_OPTION_PACK_RECORD &&
	     field_length >= 4) ?
	    FIELD_TYPE_VAR_STRING : FIELD_TYPE_STRING);
  }
  enum ha_base_keytype key_type() const
906
    { return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
unknown's avatar
unknown committed
907
  bool zero_pack() const { return 0; }
908
  void reset(void) { charset()->cset->fill(charset(),ptr,field_length,' '); }
909 910
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(longlong nr);
unknown's avatar
unknown committed
911 912 913 914 915 916 917 918 919
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  void sql_type(String &str) const;
  char *pack(char *to, const char *from, uint max_length=~(uint) 0);
  const char *unpack(char* to, const char *from);
  int pack_cmp(const char *a,const char *b,uint key_length);
920
  int pack_cmp(const char *b,uint key_length);
921
  uint packed_col_length(const char *to, uint length);
unknown's avatar
unknown committed
922 923 924
  uint max_packed_col_length(uint max_length);
  uint size_of() const { return sizeof(*this); }
  enum_field_types real_type() const { return FIELD_TYPE_STRING; }
925 926
  bool has_charset(void) const
  { return charset() == &my_charset_bin ? FALSE : TRUE; }
unknown's avatar
unknown committed
927
  field_cast_enum field_cast_type() { return FIELD_CAST_STRING; }
unknown's avatar
unknown committed
928 929 930 931 932 933
};


class Field_varstring :public Field_str {
public:
  Field_varstring(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
unknown's avatar
unknown committed
934
		  uchar null_bit_arg,
unknown's avatar
unknown committed
935
		  enum utype unireg_check_arg, const char *field_name_arg,
936
		  struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
937
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unknown's avatar
unknown committed
938 939
	       unireg_check_arg, field_name_arg, table_arg, cs)
  {}
unknown's avatar
unknown committed
940 941 942
  Field_varstring(uint32 len_arg,bool maybe_null_arg,
		  const char *field_name_arg,
		  struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
943
    :Field_str((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0,0,
unknown's avatar
unknown committed
944 945
	       NONE, field_name_arg, table_arg, cs)
  {}
unknown's avatar
unknown committed
946 947 948

  enum_field_types type() const { return FIELD_TYPE_VAR_STRING; }
  enum ha_base_keytype key_type() const
949
    { return binary() ? HA_KEYTYPE_VARBINARY : HA_KEYTYPE_VARTEXT; }
unknown's avatar
unknown committed
950 951 952 953
  bool zero_pack() const { return 0; }
  void reset(void) { bzero(ptr,field_length+2); }
  uint32 pack_length() const { return (uint32) field_length+2; }
  uint32 key_length() const { return (uint32) field_length; }
954 955
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(longlong nr);
unknown's avatar
unknown committed
956 957 958 959 960
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
unknown's avatar
unknown committed
961 962
  void get_key_image(char *buff,uint length, CHARSET_INFO *cs, imagetype type);
  void set_key_image(char *buff,uint length, CHARSET_INFO *cs);
unknown's avatar
unknown committed
963 964 965 966
  void sql_type(String &str) const;
  char *pack(char *to, const char *from, uint max_length=~(uint) 0);
  const char *unpack(char* to, const char *from);
  int pack_cmp(const char *a, const char *b, uint key_length);
967
  int pack_cmp(const char *b, uint key_length);
968
  uint packed_col_length(const char *to, uint length);
unknown's avatar
unknown committed
969 970 971
  uint max_packed_col_length(uint max_length);
  uint size_of() const { return sizeof(*this); }
  enum_field_types real_type() const { return FIELD_TYPE_VAR_STRING; }
972 973
  bool has_charset(void) const
  { return charset() == &my_charset_bin ? FALSE : TRUE; }
unknown's avatar
unknown committed
974
  field_cast_enum field_cast_type() { return FIELD_CAST_VARSTRING; }
unknown's avatar
unknown committed
975 976 977 978
};


class Field_blob :public Field_str {
unknown's avatar
unknown committed
979
protected:
unknown's avatar
unknown committed
980
  uint packlength;
981
  String value;				// For temporaries
unknown's avatar
unknown committed
982
public:
unknown's avatar
unknown committed
983
  Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
unknown's avatar
unknown committed
984 985
	     enum utype unireg_check_arg, const char *field_name_arg,
	     struct st_table *table_arg,uint blob_pack_length,
986
	     CHARSET_INFO *cs);
unknown's avatar
unknown committed
987
  Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
988
	     struct st_table *table_arg, CHARSET_INFO *cs)
unknown's avatar
unknown committed
989
    :Field_str((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0,0,
990
	       NONE, field_name_arg, table_arg, cs),
unknown's avatar
unknown committed
991
    packlength(4)
unknown's avatar
unknown committed
992 993 994
  {
    flags|= BLOB_FLAG;
  }
unknown's avatar
unknown committed
995 996
  enum_field_types type() const { return FIELD_TYPE_BLOB;}
  enum ha_base_keytype key_type() const
997
    { return binary() ? HA_KEYTYPE_VARBINARY : HA_KEYTYPE_VARTEXT; }
998 999 1000
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
unknown's avatar
unknown committed
1001 1002 1003 1004
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
  int cmp(const char *,const char*);
unknown's avatar
unknown committed
1005
  int cmp(const char *a, uint32 a_length, const char *b, uint32 b_length);
unknown's avatar
unknown committed
1006
  int cmp_offset(uint offset);
unknown's avatar
unknown committed
1007
  int cmp_binary(const char *a,const char *b, uint32 max_length=~0L);
unknown's avatar
unknown committed
1008 1009 1010 1011 1012
  int cmp_binary_offset(uint row_offset);
  int key_cmp(const byte *,const byte*);
  int key_cmp(const byte *str, uint length);
  uint32 key_length() const { return 0; }
  void sort_string(char *buff,uint length);
unknown's avatar
unknown committed
1013 1014
  uint32 pack_length() const
  { return (uint32) (packlength+table->blob_ptr_size); }
1015
  inline uint32 max_data_length() const
1016
  {
1017
    return (uint32) (((ulonglong) 1 << (packlength*8)) -1);
1018
  }
unknown's avatar
unknown committed
1019
  void reset(void) { bzero(ptr, packlength+sizeof(char*)); }
unknown's avatar
unknown committed
1020
  void reset_fields() { bzero((char*) &value,sizeof(value)); }
unknown's avatar
unknown committed
1021 1022
  void store_length(uint32 number);
  inline uint32 get_length(uint row_offset=0)
unknown's avatar
unknown committed
1023
  { return get_length(ptr+row_offset); }
unknown's avatar
unknown committed
1024
  uint32 get_length(const char *ptr);
1025
  void put_length(char *pos, uint32 length);
unknown's avatar
unknown committed
1026 1027 1028 1029 1030 1031 1032 1033 1034
  inline void get_ptr(char **str)
    {
      memcpy_fixed(str,ptr+packlength,sizeof(char*));
    }
  inline void set_ptr(char *length,char *data)
    {
      memcpy(ptr,length,packlength);
      memcpy_fixed(ptr+packlength,&data,sizeof(char*));
    }
unknown's avatar
unknown committed
1035
  inline void set_ptr(uint32 length,char *data)
unknown's avatar
unknown committed
1036 1037 1038 1039
    {
      store_length(length);
      memcpy_fixed(ptr+packlength,&data,sizeof(char*));
    }
unknown's avatar
unknown committed
1040 1041
  void get_key_image(char *buff,uint length, CHARSET_INFO *cs, imagetype type);
  void set_key_image(char *buff,uint length, CHARSET_INFO *cs);
unknown's avatar
unknown committed
1042 1043 1044 1045
  void sql_type(String &str) const;
  inline bool copy()
  { char *tmp;
    get_ptr(&tmp);
1046
    if (value.copy(tmp,get_length(),charset()))
unknown's avatar
unknown committed
1047 1048 1049 1050 1051 1052 1053
    {
      Field_blob::reset();
      return 1;
    }
    tmp=(char*) value.ptr(); memcpy_fixed(ptr+packlength,&tmp,sizeof(char*));
    return 0;
  }
1054 1055 1056 1057
  char *pack(char *to, const char *from, uint max_length= ~(uint) 0);
  const char *unpack(char *to, const char *from);
  char *pack_key(char *to, const char *from, uint max_length);
  char *pack_key_from_key_image(char* to, const char *from, uint max_length);
1058
  const char *unpack_key(char* to, const char *from, uint max_length);
unknown's avatar
unknown committed
1059
  int pack_cmp(const char *a, const char *b, uint key_length);
1060
  int pack_cmp(const char *b, uint key_length);
1061 1062
  uint packed_col_length(const char *col_ptr, uint length);
  uint max_packed_col_length(uint max_length);
1063
  void free() { value.free(); }
unknown's avatar
unknown committed
1064 1065 1066
  inline void clear_temporary() { bzero((char*) &value,sizeof(value)); }
  friend void field_conv(Field *to,Field *from);
  uint size_of() const { return sizeof(*this); }
1067
  bool has_charset(void) const
1068
  { return charset() == &my_charset_bin ? FALSE : TRUE; }
unknown's avatar
unknown committed
1069
  field_cast_enum field_cast_type() { return FIELD_CAST_BLOB; }
unknown's avatar
unknown committed
1070
  uint32 max_length();
unknown's avatar
unknown committed
1071 1072
};

unknown's avatar
unknown committed
1073
#ifdef HAVE_SPATIAL
unknown's avatar
unknown committed
1074 1075
class Field_geom :public Field_blob {
public:
unknown's avatar
unknown committed
1076
  enum geometry_type geom_type;
1077

unknown's avatar
unknown committed
1078 1079
  Field_geom(char *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
	     enum utype unireg_check_arg, const char *field_name_arg,
unknown's avatar
unknown committed
1080 1081
	     struct st_table *table_arg,uint blob_pack_length,
	     enum geometry_type geom_type_arg)
unknown's avatar
unknown committed
1082
     :Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, 
unknown's avatar
unknown committed
1083 1084
                 field_name_arg, table_arg, blob_pack_length,&my_charset_bin)
  { geom_type= geom_type_arg; }
unknown's avatar
unknown committed
1085
  Field_geom(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
unknown's avatar
unknown committed
1086
	     struct st_table *table_arg, enum geometry_type geom_type_arg)
unknown's avatar
unknown committed
1087
     :Field_blob(len_arg, maybe_null_arg, field_name_arg,
unknown's avatar
unknown committed
1088 1089
                 table_arg, &my_charset_bin)
  { geom_type= geom_type_arg; }
unknown's avatar
unknown committed
1090
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY; }
unknown's avatar
unknown committed
1091
  enum_field_types type() const { return FIELD_TYPE_GEOMETRY; }
unknown's avatar
unknown committed
1092
  void sql_type(String &str) const;
unknown's avatar
unknown committed
1093 1094 1095
  int  store(const char *to, uint length, CHARSET_INFO *charset);
  int  store(double nr) { return 1; }
  int  store(longlong nr) { return 1; }
unknown's avatar
unknown committed
1096

unknown's avatar
unknown committed
1097 1098
  void get_key_image(char *buff,uint length, CHARSET_INFO *cs,imagetype type);
  void set_key_image(char *buff,uint length, CHARSET_INFO *cs);
unknown's avatar
unknown committed
1099
  field_cast_enum field_cast_type() { return FIELD_CAST_GEOM; }
unknown's avatar
unknown committed
1100
};
unknown's avatar
unknown committed
1101
#endif /*HAVE_SPATIAL*/
unknown's avatar
unknown committed
1102

unknown's avatar
unknown committed
1103 1104 1105 1106 1107 1108
class Field_enum :public Field_str {
protected:
  uint packlength;
public:
  TYPELIB *typelib;
  Field_enum(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
1109
		 uchar null_bit_arg,
unknown's avatar
unknown committed
1110 1111
		 enum utype unireg_check_arg, const char *field_name_arg,
		 struct st_table *table_arg,uint packlength_arg,
1112 1113
		 TYPELIB *typelib_arg,
		 CHARSET_INFO *charset_arg)
unknown's avatar
unknown committed
1114
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1115
	       unireg_check_arg, field_name_arg, table_arg, charset_arg),
unknown's avatar
unknown committed
1116
    packlength(packlength_arg),typelib(typelib_arg)
unknown's avatar
unknown committed
1117
  {
unknown's avatar
unknown committed
1118
      flags|=ENUM_FLAG;
unknown's avatar
unknown committed
1119
  }
unknown's avatar
unknown committed
1120 1121 1122
  enum_field_types type() const { return FIELD_TYPE_STRING; }
  enum Item_result cmp_type () const { return INT_RESULT; }
  enum ha_base_keytype key_type() const;
1123 1124 1125
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
  int  store(longlong nr);
1126
  void reset() { bzero(ptr,packlength); }
unknown's avatar
unknown committed
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
  uint32 pack_length() const { return (uint32) packlength; }
  void store_type(ulonglong value);
  void sql_type(String &str) const;
  uint size_of() const { return sizeof(*this); }
  enum_field_types real_type() const { return FIELD_TYPE_ENUM; }
  virtual bool zero_pack() const { return 0; }
1138
  bool optimize_range(uint idx, uint part) { return 0; }
unknown's avatar
unknown committed
1139
  bool eq_def(Field *field);
1140
  bool has_charset(void) const { return TRUE; }
unknown's avatar
unknown committed
1141
  field_cast_enum field_cast_type() { return FIELD_CAST_ENUM; }
unknown's avatar
unknown committed
1142 1143 1144 1145 1146 1147
};


class Field_set :public Field_enum {
public:
  Field_set(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
unknown's avatar
unknown committed
1148
	    uchar null_bit_arg,
unknown's avatar
unknown committed
1149 1150
	    enum utype unireg_check_arg, const char *field_name_arg,
	    struct st_table *table_arg,uint32 packlength_arg,
1151
	    TYPELIB *typelib_arg, CHARSET_INFO *charset_arg)
unknown's avatar
unknown committed
1152 1153 1154
    :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
		    unireg_check_arg, field_name_arg,
		    table_arg, packlength_arg,
1155
		    typelib_arg,charset_arg)
unknown's avatar
unknown committed
1156 1157 1158
    {
      flags=(flags & ~ENUM_FLAG) | SET_FLAG;
    }
1159 1160 1161
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr) { return Field_set::store((longlong) nr); }
  int  store(longlong nr);
unknown's avatar
unknown committed
1162 1163 1164 1165
  virtual bool zero_pack() const { return 1; }
  String *val_str(String*,String *);
  void sql_type(String &str) const;
  enum_field_types real_type() const { return FIELD_TYPE_SET; }
1166
  bool has_charset(void) const { return TRUE; }
unknown's avatar
unknown committed
1167
  field_cast_enum field_cast_type() { return FIELD_CAST_SET; }
unknown's avatar
unknown committed
1168 1169 1170 1171
};


/*
unknown's avatar
unknown committed
1172
  Create field class for CREATE TABLE
unknown's avatar
unknown committed
1173 1174 1175 1176 1177
*/

class create_field :public Sql_alloc {
public:
  const char *field_name;
1178 1179
  const char *change;			// If done with alter table
  const char *after;			// Put column after this one
unknown's avatar
unknown committed
1180
  LEX_STRING comment;			// Comment for field
1181
  Item	*def;				// Default value
unknown's avatar
unknown committed
1182 1183 1184 1185
  enum	enum_field_types sql_type;
  uint32 length;
  uint decimals,flags,pack_length;
  Field::utype unireg_check;
1186
  TYPELIB *interval;			// Which interval to use
1187
  CHARSET_INFO *charset;
unknown's avatar
unknown committed
1188
  Field::geometry_type geom_type;
1189
  Field *field;				// For alter table
unknown's avatar
unknown committed
1190

1191
  uint8 row,col,sc_length,interval_id;	// For rea_create_table
unknown's avatar
unknown committed
1192 1193
  uint	offset,pack_flag;
  create_field() :after(0) {}
1194
  create_field(Field *field, Field *orig_field);
1195
  void create_length_to_internal_length(void);
unknown's avatar
unknown committed
1196 1197 1198 1199
};


/*
unknown's avatar
unknown committed
1200
  A class for sending info to the client
unknown's avatar
unknown committed
1201 1202 1203 1204
*/

class Send_field {
 public:
unknown's avatar
unknown committed
1205 1206 1207
  const char *db_name;
  const char *table_name,*org_table_name;
  const char *col_name,*org_col_name;
1208 1209
  ulong length;
  uint charsetnr, flags, decimals;
unknown's avatar
unknown committed
1210 1211 1212 1213 1214 1215
  enum_field_types type;
  Send_field() {}
};


/*
1216
  A class for quick copying data to fields
unknown's avatar
unknown committed
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
*/

class Copy_field :public Sql_alloc {
  void (*get_copy_func(Field *to,Field *from))(Copy_field *);
public:
  char *from_ptr,*to_ptr;
  uchar *from_null_ptr,*to_null_ptr;
  my_bool *null_row;
  uint	from_bit,to_bit;
  uint from_length,to_length;
  Field *from_field,*to_field;
1228
  String tmp;					// For items
unknown's avatar
unknown committed
1229 1230 1231

  Copy_field() {}
  ~Copy_field() {}
1232 1233
  void set(Field *to,Field *from,bool save);	// Field to field 
  void set(char *to,Field *from);		// Field to string
unknown's avatar
unknown committed
1234
  void (*do_copy)(Copy_field *);
1235
  void (*do_copy2)(Copy_field *);		// Used to handle null values
unknown's avatar
unknown committed
1236 1237 1238 1239
};


Field *make_field(char *ptr, uint32 field_length,
unknown's avatar
unknown committed
1240
		  uchar *null_pos, uchar null_bit,
1241
		  uint pack_flag, enum_field_types field_type,
1242
		  CHARSET_INFO *cs,
unknown's avatar
unknown committed
1243
		  Field::geometry_type geom_type,
1244
		  Field::utype unireg_check,
unknown's avatar
unknown committed
1245 1246 1247 1248
		  TYPELIB *interval, const char *field_name,
		  struct st_table *table);
uint pack_length_to_packflag(uint type);
uint32 calc_pack_length(enum_field_types type,uint32 length);
unknown's avatar
unknown committed
1249 1250
int set_field_to_null(Field *field);
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
1251 1252
bool test_if_int(const char *str, int length, const char *int_end,
		 CHARSET_INFO *cs);
unknown's avatar
unknown committed
1253 1254

/*
1255
  The following are for the interface with the .frm file
unknown's avatar
unknown committed
1256 1257 1258
*/

#define FIELDFLAG_DECIMAL		1
1259
#define FIELDFLAG_BINARY		1	// Shares same flag
unknown's avatar
unknown committed
1260 1261
#define FIELDFLAG_NUMBER		2
#define FIELDFLAG_ZEROFILL		4
1262
#define FIELDFLAG_PACK			120	// Bits used for packing
unknown's avatar
unknown committed
1263
#define FIELDFLAG_INTERVAL		256
1264 1265
#define FIELDFLAG_BITFIELD		512	// mangled with dec!
#define FIELDFLAG_BLOB			1024	// mangled with dec!
unknown's avatar
unknown committed
1266 1267
#define FIELDFLAG_GEOM			2048

unknown's avatar
unknown committed
1268 1269
#define FIELDFLAG_LEFT_FULLSCREEN	8192
#define FIELDFLAG_RIGHT_FULLSCREEN	16384
1270 1271 1272
#define FIELDFLAG_FORMAT_NUMBER		16384	// predit: ###,,## in output
#define FIELDFLAG_SUM			((uint) 32768)// predit: +#fieldflag
#define FIELDFLAG_MAYBE_NULL		((uint) 32768)// sql
unknown's avatar
unknown committed
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
#define FIELDFLAG_PACK_SHIFT		3
#define FIELDFLAG_DEC_SHIFT		8
#define FIELDFLAG_MAX_DEC		31
#define FIELDFLAG_NUM_SCREEN_TYPE	0x7F01
#define FIELDFLAG_ALFA_SCREEN_TYPE	0x7800

#define FIELD_SORT_REVERSE		16384

#define MTYP_TYPENR(type) (type & 127)	/* Remove bits from type */

#define f_is_dec(x)		((x) & FIELDFLAG_DECIMAL)
#define f_is_num(x)		((x) & FIELDFLAG_NUMBER)
#define f_is_zerofill(x)	((x) & FIELDFLAG_ZEROFILL)
#define f_is_packed(x)		((x) & FIELDFLAG_PACK)
#define f_packtype(x)		(((x) >> FIELDFLAG_PACK_SHIFT) & 15)
unknown's avatar
unknown committed
1288
#define f_decimals(x)		((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
unknown's avatar
unknown committed
1289
#define f_is_alpha(x)		(!f_is_num(x))
1290 1291
#define f_is_binary(x)          ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
#define f_is_enum(x)            ((x) & FIELDFLAG_INTERVAL)
unknown's avatar
unknown committed
1292 1293
#define f_is_bitfield(x)	((x) & FIELDFLAG_BITFIELD)
#define f_is_blob(x)		(((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
unknown's avatar
unknown committed
1294
#define f_is_geom(x)		((x) & FIELDFLAG_GEOM)
unknown's avatar
unknown committed
1295 1296 1297
#define f_is_equ(x)		((x) & (1+2+FIELDFLAG_PACK+31*256))
#define f_settype(x)		(((int) x) << FIELDFLAG_PACK_SHIFT)
#define f_maybe_null(x)		(x & FIELDFLAG_MAYBE_NULL)