field.h 62.9 KB
Newer Older
1
/* Copyright (C) 2000-2006 MySQL AB
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3 4
   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
5
   the Free Software Foundation; version 2 of the License.
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6

bk@work.mysql.com's avatar
bk@work.mysql.com committed
7 8 9 10
   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.
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
11

bk@work.mysql.com's avatar
bk@work.mysql.com committed
12 13 14 15 16 17
   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 */


/*
18 19
  Because of the function new_field() all field classes that have static
  variables must declare the size_of() member function.
bk@work.mysql.com's avatar
bk@work.mysql.com committed
20 21
*/

22
#ifdef USE_PRAGMA_INTERFACE
bk@work.mysql.com's avatar
bk@work.mysql.com committed
23 24 25 26
#pragma interface			/* gcc class implementation */
#endif

#define NOT_FIXED_DEC			31
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
27
#define DATETIME_DEC                     6
bk@work.mysql.com's avatar
bk@work.mysql.com committed
28 29

class Send_field;
30
class Protocol;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
31
struct st_cache_field;
32
int field_conv(Field *to,Field *from);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
33

34 35 36 37 38 39 40 41 42 43 44
inline uint get_enum_pack_length(int elements)
{
  return elements < 256 ? 1 : 2;
}

inline uint get_set_pack_length(int elements)
{
  uint len= (elements + 7) / 8;
  return len > 4 ? 8 : len;
}

45 46
class Field
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
47
  Field(const Item &);				/* Prevent use of these */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
48 49
  void operator=(Field &);
public:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
50
  static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
51
  static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
52

53 54
  char		*ptr;			// Position to field in record
  uchar		*null_ptr;		// Byte where null_bit is
55 56 57 58
  /*
    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)
  */
59
  struct st_table *table;		// Pointer for table
60
  struct st_table *orig_table;		// Pointer to original table
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
61
  const char	**table_name, *field_name;
62
  LEX_STRING	comment;
63
  query_id_t	query_id;		// For quick test of used fields
salle@geopard.online.bg's avatar
salle@geopard.online.bg committed
64
  /* Field is part of the following keys */
65
  key_map	key_start,part_of_key,part_of_sortkey;
66 67 68 69 70 71 72 73
  /* 
    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().
  */
74 75
  enum utype  { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
		CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
76 77
                BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
                TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
78 79 80 81 82 83
  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
  };
84
  enum imagetype { itRAW, itMBR};
85

86
  utype		unireg_check;
87
  uint32	field_length;		// Length of field
88
  uint          field_index;            // field number in fields array
89
  uint16	flags;
90
  uchar		null_bit;		// Bit used to test null bit
91 92

  Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
93 94 95
	utype unireg_check_arg, const char *field_name_arg,
	struct st_table *table_arg);
  virtual ~Field() {}
monty@mysql.com's avatar
monty@mysql.com committed
96
  /* Store functions returns 1 on overflow and -1 on fatal error */
97 98
  virtual int  store(const char *to,uint length,CHARSET_INFO *cs)=0;
  virtual int  store(double nr)=0;
99
  virtual int  store(longlong nr, bool unsigned_val)=0;
100
  virtual int  store_decimal(const my_decimal *d)=0;
101
  virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
102 103
  virtual double val_real(void)=0;
  virtual longlong val_int(void)=0;
104
  virtual my_decimal *val_decimal(my_decimal *);
serg@serg.mylan's avatar
serg@serg.mylan committed
105 106 107
  inline String *val_str(String *str) { return val_str(str, str); }
  /*
     val_str(buf1, buf2) gets two buffers and should use them as follows:
108 109 110 111 112 113 114 115 116 117
     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.
  */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
118
  virtual String *val_str(String*,String *)=0;
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
119
  String *val_int_as_str(String *val_buffer, my_bool unsigned_flag);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
120 121
  virtual Item_result result_type () const=0;
  virtual Item_result cmp_type () const { return result_type(); }
122
  virtual Item_result cast_to_int_type () const { return result_type(); }
123
  static bool type_can_have_key_part(enum_field_types);
124 125
  static enum_field_types field_type_merge(enum_field_types, enum_field_types);
  static Item_result result_merge_type(enum_field_types);
126
  virtual bool eq(Field *field)
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
127 128 129 130
  {
    return (ptr == field->ptr && null_ptr == field->null_ptr &&
            null_bit == field->null_bit);
  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
131
  virtual bool eq_def(Field *field);
132 133 134 135 136 137
  
  /*
    pack_length() returns size (in bytes) used to store field data in memory
    (i.e. it returns the maximum size of the field in a row of the table,
    which is located in RAM).
  */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
138
  virtual uint32 pack_length() const { return (uint32) field_length; }
139 140 141 142 143 144

  /*
    pack_length_in_rec() returns size (in bytes) used to store field data on
    storage (i.e. it returns the maximal size of the field in a row of the
    table, which is located on disk).
  */
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
145
  virtual uint32 pack_length_in_rec() const { return pack_length(); }
146 147 148 149 150

  /*
    data_length() return the "real size" of the data in memory.
  */
  virtual uint32 data_length(const char *from) { return pack_length(); }
151
  virtual uint32 sort_length() const { return pack_length(); }
152
  virtual int reset(void) { bzero(ptr,pack_length()); return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
153
  virtual void reset_fields() {}
154 155
  virtual void set_default()
  {
156
    my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values -
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
157
					  table->record[0]);
158
    memcpy(ptr, ptr + l_offset, pack_length());
159 160
    if (null_ptr)
      *null_ptr= ((*null_ptr & (uchar) ~null_bit) |
161
		  null_ptr[l_offset] & null_bit);
162
  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
163 164 165 166 167 168 169 170
  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;
171
  virtual int cmp_binary(const char *a,const char *b, uint32 max_length=~0L)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
172
  { return memcmp(a,b,pack_length()); }
173 174 175
  virtual int cmp_offset(uint row_offset)
  { return cmp(ptr,ptr+row_offset); }
  virtual int cmp_binary_offset(uint row_offset)
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
176
  { return cmp_binary(ptr, ptr+row_offset); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
177 178 179 180 181
  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; }
salle@geopard.online.bg's avatar
salle@geopard.online.bg committed
182 183 184 185 186
  /*
    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
  */
187
  virtual void sql_type(String &str) const =0;
188
  virtual uint size_of() const =0;		// For new field
bk@work.mysql.com's avatar
bk@work.mysql.com committed
189 190 191 192
  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; }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
193 194 195 196 197 198 199
  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);
  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
200 201 202
  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)
203
    { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
204 205
  inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
  inline bool real_maybe_null(void) { return null_ptr != 0; }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
206
  virtual void make_field(Send_field *);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
207
  virtual void sort_string(char *buff,uint length)=0;
208
  virtual bool optimize_range(uint idx, uint part);
209 210 211 212 213 214 215 216
  /*
    This should be true for fields which, when compared with constant
    items, can be casted to longlong. In this case we will at 'fix_fields'
    stage cast the constant items to longlongs and at the execution stage
    use field->val_int() for comparison.  Used to optimize clauses like
    'a_column BETWEEN date_const, date_const'.
  */
  virtual bool can_be_compared_as_longlong() const { return FALSE; }
217
  virtual void free() {}
218 219
  virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table,
                           bool keep_type);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
220 221 222
  virtual Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
                               char *new_ptr, uchar *new_null_ptr,
                               uint new_null_bit);
serg@sergbook.mylan's avatar
serg@sergbook.mylan committed
223
  inline void move_field(char *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
224 225 226
  {
    ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
227
  inline void move_field(char *ptr_arg) { ptr=ptr_arg; }
228
  virtual inline void move_field(my_ptrdiff_t ptr_diff)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
229 230 231 232 233
  {
    ptr=ADD_TO_PTR(ptr,ptr_diff,char*);
    if (null_ptr)
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
  }
234
  inline void get_image(char *buff,uint length, CHARSET_INFO *cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
235
    { memcpy(buff,ptr,length); }
236
  inline void set_image(char *buff,uint length, CHARSET_INFO *cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
237
    { memcpy(ptr,buff,length); }
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265


  /*
    Copy a field part into an output buffer.

    SYNOPSIS
      Field::get_key_image()
      buff   [out] output buffer
      length       output buffer size
      type         itMBR for geometry blobs, otherwise itRAW

    DESCRIPTION
      This function makes a copy of field part of size equal to or
      less than "length" parameter value.
      For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
      is padded by zero byte.

    NOTES
      For variable length character fields (i.e. UTF-8) the "length"
      parameter means a number of output buffer bytes as if all field
      characters have maximal possible size (mbmaxlen). In the other words,
      "length" parameter is a number of characters multiplied by
      field_charset->mbmaxlen.

    RETURN
      Number of copied bytes (excluding padded zero bytes -- see above).
  */

266
  virtual uint get_key_image(char *buff, uint length, imagetype type)
267
  {
268
    get_image(buff, length, &my_charset_bin);
269 270
    return length;
  }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
271 272
  virtual void set_key_image(char *buff,uint length)
    { set_image(buff,length, &my_charset_bin); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
273 274 275 276 277 278 279
  inline longlong val_int_offset(uint row_offset)
    {
      ptr+=row_offset;
      longlong tmp=val_int();
      ptr-=row_offset;
      return tmp;
    }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
280 281 282 283 284 285 286 287 288

  inline String *val_str(String *str, char *new_ptr)
  {
    char *old_ptr= ptr;
    ptr= new_ptr;
    val_str(str);
    ptr= old_ptr;
    return str;
  }
289
  virtual bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
290 291
  virtual char *pack(char* to, const char *from, uint max_length=~(uint) 0)
  {
292
    uint32 length=pack_length();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
293 294 295 296 297 298 299 300 301
    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;
  }
302 303 304 305 306 307
  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)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
308 309 310
  {
    return pack(to,from,max_length);
  }
311 312 313 314
  virtual const char *unpack_key(char* to, const char *from, uint max_length)
  {
    return unpack(to,from);
  }
315 316
  virtual uint packed_col_length(const char *to, uint length)
  { return length;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
317
  virtual uint max_packed_col_length(uint max_length)
318
  { return max_length;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
319

jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
320 321
  virtual int pack_cmp(const char *a,const char *b, uint key_length_arg,
                       my_bool insert_or_update)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
322
  { return cmp(a,b); }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
323 324
  virtual int pack_cmp(const char *b, uint key_length_arg,
                       my_bool insert_or_update)
325
  { return cmp(ptr,b); }
326
  uint offset();			// Should be inline ...
bk@work.mysql.com's avatar
bk@work.mysql.com committed
327 328
  void copy_from_tmp(int offset);
  uint fill_cache_field(struct st_cache_field *copy);
329 330
  virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
  virtual bool get_time(MYSQL_TIME *ltime);
331
  virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
332
  virtual CHARSET_INFO *sort_charset(void) const { return charset(); }
333
  virtual bool has_charset(void) const { return FALSE; }
334
  virtual void set_charset(CHARSET_INFO *charset_arg) { }
335 336
  virtual enum Derivation derivation(void) const
  { return DERIVATION_IMPLICIT; }
337
  virtual void set_derivation(enum Derivation derivation_arg) { }
338
  bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
339
                   int cuted_increment);
340
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, 
341 342
                            const char *str, uint str_len,
                            timestamp_type ts_type, int cuted_increment);
343
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, 
344 345
                            longlong nr, timestamp_type ts_type,
                            int cuted_increment);
346
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code, 
347
                            double nr, timestamp_type ts_type);
348 349 350 351 352
  inline bool check_overflow(int op_result)
  {
    return (op_result == E_DEC_OVERFLOW);
  }
  int warn_if_overflow(int op_result);
353
  /* maximum possible display length */
354
  virtual uint32 max_display_length()= 0;
355 356 357
  /* convert decimal to longlong with overflow check */
  longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
                                    int *err);
358
  /* The max. number of characters */
359
  inline uint32 char_length() const
360 361 362 363
  {
    return field_length / charset()->mbmaxlen;
  }

bk@work.mysql.com's avatar
bk@work.mysql.com committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377
  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;
378
  friend class Item_func_group_concat;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
379 380 381 382 383 384
};


class Field_num :public Field {
public:
  const uint8 dec;
385
  bool zerofill,unsigned_flag;	// Purify cannot handle bit fields
bk@work.mysql.com's avatar
bk@work.mysql.com committed
386
  Field_num(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
387
	    uchar null_bit_arg, utype unireg_check_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
388 389
	    const char *field_name_arg,
	    struct st_table *table_arg,
390
            uint8 dec_arg, bool zero_arg, bool unsigned_arg);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
391 392 393 394 395
  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 *);
396
  uint decimals() const { return (uint) dec; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
397 398
  uint size_of() const { return sizeof(*this); }
  bool eq_def(Field *field);
399 400
  int store_decimal(const my_decimal *);
  my_decimal *val_decimal(my_decimal *);
401 402 403 404 405
  int check_int(CHARSET_INFO *cs, const char *str, int length,
                const char *int_end, int error);
  bool get_int(CHARSET_INFO *cs, const char *from, uint len, 
               longlong *rnd, ulonglong unsigned_max, 
               longlong signed_min, longlong signed_max);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
406 407 408 409
};


class Field_str :public Field {
410 411
protected:
  CHARSET_INFO *field_charset;
412
  enum Derivation field_derivation;
serg@serg.mylan's avatar
serg@serg.mylan committed
413
public:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
414
  Field_str(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
415
	    uchar null_bit_arg, utype unireg_check_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
416
	    const char *field_name_arg,
417
            struct st_table *table_arg, CHARSET_INFO *charset);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
418 419
  Item_result result_type () const { return STRING_RESULT; }
  uint decimals() const { return NOT_FIXED_DEC; }
serg@serg.mylan's avatar
serg@serg.mylan committed
420
  int  store(double nr);
421
  int  store(longlong nr, bool unsigned_val)=0;
422
  int  store_decimal(const my_decimal *);
serg@serg.mylan's avatar
serg@serg.mylan committed
423
  int  store(const char *to,uint length,CHARSET_INFO *cs)=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
424
  uint size_of() const { return sizeof(*this); }
425
  CHARSET_INFO *charset(void) const { return field_charset; }
426
  void set_charset(CHARSET_INFO *charset_arg) { field_charset= charset_arg; }
427 428 429
  enum Derivation derivation(void) const { return field_derivation; }
  virtual void set_derivation(enum Derivation derivation_arg)
  { field_derivation= derivation_arg; }
430
  bool binary() const { return field_charset == &my_charset_bin; }
431
  uint32 max_display_length() { return field_length; }
432
  friend class create_field;
433 434 435
  my_decimal *val_decimal(my_decimal *);
};

436 437 438

/* base class for Field_string, Field_varstring and Field_blob */

439 440 441 442 443 444
class Field_longstr :public Field_str
{
public:
  Field_longstr(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
                uchar null_bit_arg, utype unireg_check_arg,
                const char *field_name_arg,
445
                struct st_table *table_arg, CHARSET_INFO *charset_arg)
446
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
447
               field_name_arg, table_arg, charset_arg)
448 449 450 451 452 453 454 455
    {}

  int store_decimal(const my_decimal *d);
};

/* base class for float and double and decimal (old one) */
class Field_real :public Field_num {
public:
456
  my_bool not_fixed;
457 458 459 460 461 462 463

  Field_real(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
             uchar null_bit_arg, utype unireg_check_arg,
             const char *field_name_arg,
             struct st_table *table_arg,
             uint8 dec_arg, bool zero_arg, bool unsigned_arg)
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
464 465
               field_name_arg, table_arg, dec_arg, zero_arg, unsigned_arg),
    not_fixed(dec_arg >= NOT_FIXED_DEC)
466 467 468 469 470
    {}


  int store_decimal(const my_decimal *);
  my_decimal *val_decimal(my_decimal *);
471
  int truncate(double *nr, double max_length);
472
  uint32 max_display_length() { return field_length; }
473
  uint size_of() const { return sizeof(*this); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
474 475 476
};


477
class Field_decimal :public Field_real {
bk@work.mysql.com's avatar
bk@work.mysql.com committed
478 479
public:
  Field_decimal(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
480
		uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
481 482
		enum utype unireg_check_arg, const char *field_name_arg,
		struct st_table *table_arg,
483
		uint8 dec_arg,bool zero_arg,bool unsigned_arg)
484 485 486
    :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
                unireg_check_arg, field_name_arg, table_arg,
                dec_arg, zero_arg, unsigned_arg)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
487 488 489
    {}
  enum_field_types type() const { return FIELD_TYPE_DECIMAL;}
  enum ha_base_keytype key_type() const
490
  { return zerofill ? HA_KEYTYPE_BINARY : HA_KEYTYPE_NUM; }
491 492 493
  int reset(void);
  int store(const char *to,uint length,CHARSET_INFO *charset);
  int store(double nr);
494
  int store(longlong nr, bool unsigned_val);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
495 496 497 498 499 500 501 502 503 504 505
  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;
};


506 507 508
/* New decimal/numeric field which use fixed point arithmetic */
class Field_new_decimal :public Field_num {
public:
509 510
  /* The maximum number of decimal digits can be stored */
  uint precision;
511
  uint bin_size;
monty@mysql.com's avatar
monty@mysql.com committed
512 513 514 515 516 517
  /*
    Constructors take max_length of the field as a parameter - not the
    precision as the number of decimal digits allowed.
    So for example we need to count length from precision handling
    CREATE TABLE ( DECIMAL(x,y)) 
  */
518 519 520 521 522 523 524
  Field_new_decimal(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
                    uchar null_bit_arg,
                    enum utype unireg_check_arg, const char *field_name_arg,
                    struct st_table *table_arg,
                    uint8 dec_arg, bool zero_arg, bool unsigned_arg);
  Field_new_decimal(uint32 len_arg, bool maybe_null_arg,
                    const char *field_name_arg,
525 526
                    struct st_table *table_arg, uint8 dec_arg,
                    bool unsigned_arg);
527 528 529
  enum_field_types type() const { return FIELD_TYPE_NEWDECIMAL;}
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
  Item_result result_type () const { return DECIMAL_RESULT; }
530
  int  reset(void);
531 532 533 534
  bool store_value(const my_decimal *decimal_value);
  void set_value_on_overflow(my_decimal *decimal_value, bool sign);
  int  store(const char *to, uint length, CHARSET_INFO *charset);
  int  store(double nr);
535
  int  store(longlong nr, bool unsigned_val);
536
  int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
537 538 539 540 541 542 543 544 545
  int  store_decimal(const my_decimal *);
  double val_real(void);
  longlong val_int(void);
  my_decimal *val_decimal(my_decimal *);
  String *val_str(String*, String *);
  int cmp(const char *, const char*);
  void sort_string(char *buff, uint length);
  bool zero_pack() const { return 0; }
  void sql_type(String &str) const;
546
  uint32 max_display_length() { return field_length; }
547 548 549 550 551
  uint size_of() const { return sizeof(*this); } 
  uint32 pack_length() const { return (uint32) bin_size; }
};


bk@work.mysql.com's avatar
bk@work.mysql.com committed
552 553 554
class Field_tiny :public Field_num {
public:
  Field_tiny(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
555
	     uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
556 557 558 559 560 561 562 563 564 565 566
	     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; }
567 568
  int store(const char *to,uint length,CHARSET_INFO *charset);
  int store(double nr);
569
  int store(longlong nr, bool unsigned_val);
570
  int reset(void) { ptr[0]=0; return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
571 572 573
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
574
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
575 576 577 578
  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;
579
  uint32 max_display_length() { return 4; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
580 581 582 583 584 585
};


class Field_short :public Field_num {
public:
  Field_short(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
586
	      uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
587 588 589 590 591 592 593
	      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)
    {}
594 595 596 597 598
  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)
    {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
599 600 601 602
  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;}
603 604
  int store(const char *to,uint length,CHARSET_INFO *charset);
  int store(double nr);
605
  int store(longlong nr, bool unsigned_val);
606
  int reset(void) { ptr[0]=ptr[1]=0; return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
607 608 609
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
610
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
611 612 613 614
  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;
615
  uint32 max_display_length() { return 6; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
616 617 618 619 620 621
};


class Field_medium :public Field_num {
public:
  Field_medium(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
622
	      uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
623 624 625 626 627 628 629 630 631 632 633
	      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; }
634 635
  int store(const char *to,uint length,CHARSET_INFO *charset);
  int store(double nr);
636
  int store(longlong nr, bool unsigned_val);
637
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
638 639 640
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
641
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
642 643 644 645
  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;
646
  uint32 max_display_length() { return 8; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
647 648 649 650 651 652
};


class Field_long :public Field_num {
public:
  Field_long(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
653
	     uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
	     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; }
670 671
  int store(const char *to,uint length,CHARSET_INFO *charset);
  int store(double nr);
672
  int store(longlong nr, bool unsigned_val);
673
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
674 675
  double val_real(void);
  longlong val_int(void);
676
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
677 678 679 680 681
  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;
682
  uint32 max_display_length() { return 11; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
683 684 685 686 687 688 689
};


#ifdef HAVE_LONG_LONG
class Field_longlong :public Field_num {
public:
  Field_longlong(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
690
	      uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
691 692 693 694 695 696 697
	      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)
    {}
698 699 700
  Field_longlong(uint32 len_arg,bool maybe_null_arg,
		 const char *field_name_arg,
		 struct st_table *table_arg, bool unsigned_arg)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
701
    :Field_num((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
702
	       NONE, field_name_arg, table_arg,0,0,unsigned_arg)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
703 704 705 706 707
    {}
  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; }
708 709
  int store(const char *to,uint length,CHARSET_INFO *charset);
  int store(double nr);
710
  int store(longlong nr, bool unsigned_val);
711 712 713 714 715
  int reset(void)
  {
    ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
    return 0;
  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
716 717 718
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
719
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
720 721 722 723
  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;
724
  bool can_be_compared_as_longlong() const { return TRUE; }
725
  uint32 max_display_length() { return 20; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
726 727 728
};
#endif

729 730

class Field_float :public Field_real {
bk@work.mysql.com's avatar
bk@work.mysql.com committed
731 732
public:
  Field_float(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
733
	      uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
734 735
	      enum utype unireg_check_arg, const char *field_name_arg,
	      struct st_table *table_arg,
736 737 738 739
              uint8 dec_arg,bool zero_arg,bool unsigned_arg)
    :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
                unireg_check_arg, field_name_arg, table_arg,
                dec_arg, zero_arg, unsigned_arg)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
740
    {}
741 742
  Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
	      struct st_table *table_arg, uint8 dec_arg)
743 744
    :Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
                NONE, field_name_arg, table_arg, dec_arg, 0, 0)
745
    {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
746 747
  enum_field_types type() const { return FIELD_TYPE_FLOAT;}
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
748 749
  int store(const char *to,uint length,CHARSET_INFO *charset);
  int store(double nr);
750
  int store(longlong nr, bool unsigned_val);
751
  int reset(void) { bzero(ptr,sizeof(float)); return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
752 753 754
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
755
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
756 757 758 759 760 761 762
  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;
};


763
class Field_double :public Field_real {
bk@work.mysql.com's avatar
bk@work.mysql.com committed
764 765
public:
  Field_double(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
766
	       uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
767 768
	       enum utype unireg_check_arg, const char *field_name_arg,
	       struct st_table *table_arg,
769
	       uint8 dec_arg,bool zero_arg,bool unsigned_arg)
770 771
    :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
                unireg_check_arg, field_name_arg, table_arg,
772
                dec_arg, zero_arg, unsigned_arg)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
773 774
    {}
  Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
775
	       struct st_table *table_arg, uint8 dec_arg)
776
    :Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
777
                NONE, field_name_arg, table_arg, dec_arg, 0, 0)
778 779
    {}
  Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
780
	       struct st_table *table_arg, uint8 dec_arg, my_bool not_fixed_arg)
781
    :Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
782 783
                NONE, field_name_arg, table_arg, dec_arg, 0, 0)
    {not_fixed= not_fixed_arg; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
784 785
  enum_field_types type() const { return FIELD_TYPE_DOUBLE;}
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
786 787
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
788
  int  store(longlong nr, bool unsigned_val);
789
  int reset(void) { bzero(ptr,sizeof(double)); return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
790 791 792
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
793
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
794 795 796 797 798 799 800
  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;
};


801
/* Everything saved in this will disappear. It will always return NULL */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
802 803 804 805 806 807

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,
808
	     struct st_table *table_arg, CHARSET_INFO *cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
809
    :Field_str(ptr_arg, len_arg, null, 1,
810
	       unireg_check_arg, field_name_arg, table_arg, cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
811 812
    {}
  enum_field_types type() const { return FIELD_TYPE_NULL;}
813 814
  int  store(const char *to, uint length, CHARSET_INFO *cs)
  { null[0]=1; return 0; }
815
  int store(double nr)   { null[0]=1; return 0; }
816 817
  int store(longlong nr, bool unsigned_val) { null[0]=1; return 0; }
  int store_decimal(const my_decimal *d)  { null[0]=1; return 0; }
818
  int reset(void)	  { return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
819 820
  double val_real(void)		{ return 0.0;}
  longlong val_int(void)	{ return 0;}
821
  my_decimal *val_decimal(my_decimal *) { return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
822 823 824 825 826
  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; }
827
  void sql_type(String &str) const;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
828
  uint size_of() const { return sizeof(*this); }
829
  uint32 max_display_length() { return 4; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
830 831 832
};


833
class Field_timestamp :public Field_str {
bk@work.mysql.com's avatar
bk@work.mysql.com committed
834 835
public:
  Field_timestamp(char *ptr_arg, uint32 len_arg,
836
                  uchar *null_ptr_arg, uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
837
		  enum utype unireg_check_arg, const char *field_name_arg,
838 839
		  struct st_table *table_arg,
		  CHARSET_INFO *cs);
840 841
  Field_timestamp(bool maybe_null_arg, const char *field_name_arg,
		 struct st_table *table_arg, CHARSET_INFO *cs);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
842 843
  enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;}
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
844
  enum Item_result cmp_type () const { return INT_RESULT; }
845 846
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
847
  int  store(longlong nr, bool unsigned_val);
848
  int  reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
849 850 851
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
852
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
853 854 855 856
  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;
857
  bool can_be_compared_as_longlong() const { return TRUE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
858 859
  bool zero_pack() const { return 0; }
  void set_time();
860 861
  virtual void set_default()
  {
862 863
    if (table->timestamp_field == this &&
        unireg_check != TIMESTAMP_UN_FIELD)
864 865 866
      set_time();
    else
      Field::set_default();
867
  }
868 869
  /* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
  inline long get_timestamp(my_bool *null_value)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
870
  {
871 872
    if ((*null_value= is_null()))
      return 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
873
#ifdef WORDS_BIGENDIAN
evgen@moonbone.local's avatar
evgen@moonbone.local committed
874
    if (table && table->s->db_low_byte_first)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
875 876 877 878 879 880
      return sint4korr(ptr);
#endif
    long tmp;
    longget(tmp,ptr);
    return tmp;
  }
881 882
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
  bool get_time(MYSQL_TIME *ltime);
883
  timestamp_auto_set_type get_auto_set_type() const;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
884 885 886 887 888 889
};


class Field_year :public Field_tiny {
public:
  Field_year(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
890
	     uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
891 892 893 894 895 896
	     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;}
897 898
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
899
  int  store(longlong nr, bool unsigned_val);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
900 901 902
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
903
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
904
  void sql_type(String &str) const;
905
  bool can_be_compared_as_longlong() const { return TRUE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
906 907 908 909 910
};


class Field_date :public Field_str {
public:
911
  Field_date(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
912
	     enum utype unireg_check_arg, const char *field_name_arg,
913
	     struct st_table *table_arg, CHARSET_INFO *cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
914
    :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
915
	       unireg_check_arg, field_name_arg, table_arg, cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
916
    {}
917
  Field_date(bool maybe_null_arg, const char *field_name_arg,
918
		 struct st_table *table_arg, CHARSET_INFO *cs)
919
    :Field_str((char*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
920
	       NONE, field_name_arg, table_arg, cs) {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
921 922 923
  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; }
924 925
  int store(const char *to,uint length,CHARSET_INFO *charset);
  int store(double nr);
926
  int store(longlong nr, bool unsigned_val);
927
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
928 929 930
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
931
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
932 933 934 935
  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;
936
  bool can_be_compared_as_longlong() const { return TRUE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
937 938 939 940 941
  bool zero_pack() const { return 1; }
};

class Field_newdate :public Field_str {
public:
942
  Field_newdate(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
943
		enum utype unireg_check_arg, const char *field_name_arg,
944
		struct st_table *table_arg, CHARSET_INFO *cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
945
    :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
946
	       unireg_check_arg, field_name_arg, table_arg, cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
947 948 949 950 951
    {}
  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; }
952 953
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
954
  int  store(longlong nr, bool unsigned_val);
955
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
956
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
957 958 959
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
960
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
961 962 963 964
  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;
965
  bool can_be_compared_as_longlong() const { return TRUE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
966
  bool zero_pack() const { return 1; }
967 968
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
  bool get_time(MYSQL_TIME *ltime);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
969 970 971 972 973
};


class Field_time :public Field_str {
public:
974
  Field_time(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
975
	     enum utype unireg_check_arg, const char *field_name_arg,
976
	     struct st_table *table_arg, CHARSET_INFO *cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
977
    :Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
978
	       unireg_check_arg, field_name_arg, table_arg, cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
979
    {}
980
  Field_time(bool maybe_null_arg, const char *field_name_arg,
981
		 struct st_table *table_arg, CHARSET_INFO *cs)
982
    :Field_str((char*) 0,8, maybe_null_arg ? (uchar*) "": 0,0,
983
	       NONE, field_name_arg, table_arg, cs) {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
984 985 986
  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; }
987
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
988 989
  int store(const char *to,uint length,CHARSET_INFO *charset);
  int store(double nr);
990
  int store(longlong nr, bool unsigned_val);
991
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
992 993 994
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
995
  bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
996
  bool send_binary(Protocol *protocol);
997
  bool get_time(MYSQL_TIME *ltime);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
998 999 1000 1001
  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;
1002
  bool can_be_compared_as_longlong() const { return TRUE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1003 1004 1005 1006 1007 1008
  bool zero_pack() const { return 1; }
};


class Field_datetime :public Field_str {
public:
1009
  Field_datetime(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1010
		 enum utype unireg_check_arg, const char *field_name_arg,
1011
		 struct st_table *table_arg, CHARSET_INFO *cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1012
    :Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
1013
	       unireg_check_arg, field_name_arg, table_arg, cs)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1014
    {}
1015
  Field_datetime(bool maybe_null_arg, const char *field_name_arg,
1016
		 struct st_table *table_arg, CHARSET_INFO *cs)
1017
    :Field_str((char*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
1018
	       NONE, field_name_arg, table_arg, cs) {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1019 1020 1021 1022 1023
  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; }
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
1024
  uint decimals() const { return DATETIME_DEC; }
1025 1026
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
1027
  int  store(longlong nr, bool unsigned_val);
1028
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
1029 1030 1031 1032 1033
  int reset(void)
  {
    ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
    return 0;
  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1034 1035 1036
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
1037
  bool send_binary(Protocol *protocol);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1038 1039 1040 1041
  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;
1042
  bool can_be_compared_as_longlong() const { return TRUE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1043
  bool zero_pack() const { return 1; }
1044 1045
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
  bool get_time(MYSQL_TIME *ltime);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1046 1047 1048
};


1049
class Field_string :public Field_longstr {
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1050
public:
1051
  bool can_alter_field_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1052
  Field_string(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
1053
	       uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1054
	       enum utype unireg_check_arg, const char *field_name_arg,
1055
	       struct st_table *table_arg, CHARSET_INFO *cs)
1056
    :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1057 1058
                   unireg_check_arg, field_name_arg, table_arg, cs),
     can_alter_field_type(1) {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1059
  Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1060 1061
               struct st_table *table_arg, CHARSET_INFO *cs)
    :Field_longstr((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
1062 1063
                   NONE, field_name_arg, table_arg, cs),
     can_alter_field_type(1) {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1064 1065 1066

  enum_field_types type() const
  {
1067
    return ((can_alter_field_type && orig_table &&
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1068 1069 1070 1071
             orig_table->s->db_create_options & HA_OPTION_PACK_RECORD &&
	     field_length >= 4) &&
            orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ?
	    MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1072 1073
  }
  enum ha_base_keytype key_type() const
1074
    { return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1075
  bool zero_pack() const { return 0; }
1076 1077
  int reset(void)
  {
1078 1079
    charset()->cset->fill(charset(),ptr,field_length,
                          (has_charset() ? ' ' : 0));
1080 1081 1082
    return 0;
  }
  int store(const char *to,uint length,CHARSET_INFO *charset);
1083
  int store(longlong nr, bool unsigned_val);
1084
  int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1085 1086 1087
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
1088
  my_decimal *val_decimal(my_decimal *);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1089 1090 1091 1092 1093
  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);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1094 1095 1096
  int pack_cmp(const char *a,const char *b,uint key_length,
               my_bool insert_or_update);
  int pack_cmp(const char *b,uint key_length,my_bool insert_or_update);
1097
  uint packed_col_length(const char *to, uint length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1098 1099 1100
  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; }
1101 1102
  bool has_charset(void) const
  { return charset() == &my_charset_bin ? FALSE : TRUE; }
1103
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
1104
  virtual uint get_key_image(char *buff,uint length, imagetype type);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1105 1106 1107
};


1108
class Field_varstring :public Field_longstr {
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1109
public:
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1110 1111 1112 1113 1114
  /* Store number of bytes used to store length (1 or 2) */
  uint32 length_bytes;
  Field_varstring(char *ptr_arg,
                  uint32 len_arg, uint length_bytes_arg,
                  uchar *null_ptr_arg,
1115
		  uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1116
		  enum utype unireg_check_arg, const char *field_name_arg,
1117
		  struct st_table *table_arg, CHARSET_INFO *cs)
1118 1119 1120
    :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
                   unireg_check_arg, field_name_arg, table_arg, cs),
     length_bytes(length_bytes_arg)
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1121 1122 1123 1124
  {
    if (table)
      table->s->varchar_fields++;
  }
monty@mysql.com's avatar
monty@mysql.com committed
1125
  Field_varstring(uint32 len_arg,bool maybe_null_arg,
1126 1127 1128 1129 1130
                  const char *field_name_arg,
                  struct st_table *table_arg, CHARSET_INFO *cs)
    :Field_longstr((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
                   NONE, field_name_arg, table_arg, cs),
     length_bytes(len_arg < 256 ? 1 :2)
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1131 1132 1133 1134
  {
    if (table)
      table->s->varchar_fields++;
  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1135

jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1136 1137
  enum_field_types type() const { return MYSQL_TYPE_VARCHAR; }
  enum ha_base_keytype key_type() const;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1138
  bool zero_pack() const { return 0; }
1139
  int  reset(void) { bzero(ptr,field_length+length_bytes); return 0; }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1140
  uint32 pack_length() const { return (uint32) field_length+length_bytes; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1141
  uint32 key_length() const { return (uint32) field_length; }
1142 1143 1144 1145 1146
  uint32 sort_length() const
  {
    return (uint32) field_length + (field_charset == &my_charset_bin ?
                                    length_bytes : 0);
  }
1147
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1148
  int  store(longlong nr, bool unsigned_val);
1149
  int  store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1150 1151 1152
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
1153
  my_decimal *val_decimal(my_decimal *);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1154 1155
  int cmp(const char *,const char*);
  void sort_string(char *buff,uint length);
1156
  uint get_key_image(char *buff,uint length, imagetype type);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1157
  void set_key_image(char *buff,uint length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1158 1159
  void sql_type(String &str) const;
  char *pack(char *to, const char *from, uint max_length=~(uint) 0);
1160
  char *pack_key(char *to, const char *from, uint max_length);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1161
  char *pack_key_from_key_image(char* to, const char *from, uint max_length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1162
  const char *unpack(char* to, const char *from);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1163 1164 1165 1166 1167 1168 1169
  const char *unpack_key(char* to, const char *from, uint max_length);
  int pack_cmp(const char *a, const char *b, uint key_length,
               my_bool insert_or_update);
  int pack_cmp(const char *b, uint key_length,my_bool insert_or_update);
  int cmp_binary(const char *a,const char *b, uint32 max_length=~0L);
  int key_cmp(const byte *,const byte*);
  int key_cmp(const byte *str, uint length);
1170
  uint packed_col_length(const char *to, uint length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1171
  uint max_packed_col_length(uint max_length);
1172
  uint32 data_length(const char *from);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1173
  uint size_of() const { return sizeof(*this); }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1174
  enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
1175 1176
  bool has_charset(void) const
  { return charset() == &my_charset_bin ? FALSE : TRUE; }
1177
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1178 1179 1180
  Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
                       char *new_ptr, uchar *new_null_ptr,
                       uint new_null_bit);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1181 1182 1183
};


1184
class Field_blob :public Field_longstr {
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1185
protected:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1186
  uint packlength;
1187
  String value;				// For temporaries
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1188
public:
1189
  Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1190 1191
	     enum utype unireg_check_arg, const char *field_name_arg,
	     struct st_table *table_arg,uint blob_pack_length,
1192
	     CHARSET_INFO *cs);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1193
  Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1194
	     struct st_table *table_arg, CHARSET_INFO *cs)
1195 1196
    :Field_longstr((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
                   NONE, field_name_arg, table_arg, cs),
hf@deer.(none)'s avatar
hf@deer.(none) committed
1197
    packlength(4)
monty@mysql.com's avatar
monty@mysql.com committed
1198 1199 1200
  {
    flags|= BLOB_FLAG;
  }
1201 1202 1203 1204 1205 1206 1207 1208 1209
  Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
	     struct st_table *table_arg, CHARSET_INFO *cs, bool set_packlength)
    :Field_longstr((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
                   NONE, field_name_arg, table_arg, cs)
  {
    flags|= BLOB_FLAG;
    packlength= 4;
    if (set_packlength)
    {
1210 1211 1212 1213
      uint32 l_char_length= len_arg/cs->mbmaxlen;
      packlength= l_char_length <= 255 ? 1 :
                  l_char_length <= 65535 ? 2 :
                  l_char_length <= 16777215 ? 3 : 4;
1214 1215
    }
  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1216 1217
  enum_field_types type() const { return FIELD_TYPE_BLOB;}
  enum ha_base_keytype key_type() const
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1218
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
1219 1220
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
1221
  int  store(longlong nr, bool unsigned_val);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1222 1223 1224
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*,String *);
1225
  my_decimal *val_decimal(my_decimal *);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1226
  int cmp(const char *,const char*);
1227 1228
  int cmp(const char *a, uint32 a_length, const char *b, uint32 b_length);
  int cmp_binary(const char *a,const char *b, uint32 max_length=~0L);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1229 1230 1231 1232
  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);
1233
  uint32 pack_length() const
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1234
  { return (uint32) (packlength+table->s->blob_ptr_size); }
1235
  uint32 sort_length() const;
1236
  inline uint32 max_data_length() const
1237
  {
1238
    return (uint32) (((ulonglong) 1 << (packlength*8)) -1);
1239
  }
1240
  int reset(void) { bzero(ptr, packlength+sizeof(char*)); return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1241
  void reset_fields() { bzero((char*) &value,sizeof(value)); }
1242 1243
  void store_length(uint32 number);
  inline uint32 get_length(uint row_offset=0)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1244
  { return get_length(ptr+row_offset); }
1245
  uint32 get_length(const char *ptr);
1246
  void put_length(char *pos, uint32 length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1247 1248 1249 1250 1251 1252 1253 1254 1255
  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*));
    }
1256
  inline void set_ptr(uint32 length,char *data)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1257 1258 1259 1260
    {
      store_length(length);
      memcpy_fixed(ptr+packlength,&data,sizeof(char*));
    }
1261
  uint get_key_image(char *buff,uint length, imagetype type);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1262
  void set_key_image(char *buff,uint length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1263 1264 1265 1266
  void sql_type(String &str) const;
  inline bool copy()
  { char *tmp;
    get_ptr(&tmp);
1267
    if (value.copy(tmp,get_length(),charset()))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1268 1269 1270 1271 1272 1273 1274
    {
      Field_blob::reset();
      return 1;
    }
    tmp=(char*) value.ptr(); memcpy_fixed(ptr+packlength,&tmp,sizeof(char*));
    return 0;
  }
1275 1276 1277
  char *pack(char *to, const char *from, uint max_length= ~(uint) 0);
  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);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1278
  const char *unpack(char *to, const char *from);
1279
  const char *unpack_key(char* to, const char *from, uint max_length);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1280 1281 1282
  int pack_cmp(const char *a, const char *b, uint key_length,
               my_bool insert_or_update);
  int pack_cmp(const char *b, uint key_length,my_bool insert_or_update);
1283 1284
  uint packed_col_length(const char *col_ptr, uint length);
  uint max_packed_col_length(uint max_length);
1285
  void free() { value.free(); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1286
  inline void clear_temporary() { bzero((char*) &value,sizeof(value)); }
1287
  friend int field_conv(Field *to,Field *from);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1288
  uint size_of() const { return sizeof(*this); }
1289
  bool has_charset(void) const
1290
  { return charset() == &my_charset_bin ? FALSE : TRUE; }
1291
  uint32 max_display_length();
1292 1293
};

jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1294

hf@deer.(none)'s avatar
hf@deer.(none) committed
1295
#ifdef HAVE_SPATIAL
1296 1297
class Field_geom :public Field_blob {
public:
1298
  enum geometry_type geom_type;
1299

1300 1301
  Field_geom(char *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
	     enum utype unireg_check_arg, const char *field_name_arg,
1302 1303
	     struct st_table *table_arg,uint blob_pack_length,
	     enum geometry_type geom_type_arg)
1304
     :Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, 
1305 1306
                 field_name_arg, table_arg, blob_pack_length,&my_charset_bin)
  { geom_type= geom_type_arg; }
1307
  Field_geom(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
1308
	     struct st_table *table_arg, enum geometry_type geom_type_arg)
1309
     :Field_blob(len_arg, maybe_null_arg, field_name_arg,
1310 1311
                 table_arg, &my_charset_bin)
  { geom_type= geom_type_arg; }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1312
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY2; }
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1313
  enum_field_types type() const { return FIELD_TYPE_GEOMETRY; }
1314
  void sql_type(String &str) const;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1315
  int  store(const char *to, uint length, CHARSET_INFO *charset);
1316
  int  store(double nr);
1317
  int  store(longlong nr, bool unsigned_val);
1318
  int  store_decimal(const my_decimal *);
1319
  uint get_key_image(char *buff,uint length,imagetype type);
1320
  uint size_of() const { return sizeof(*this); }
1321
  int  reset(void) { return !maybe_null() || Field_blob::reset(); }
1322
};
hf@deer.(none)'s avatar
hf@deer.(none) committed
1323
#endif /*HAVE_SPATIAL*/
1324

jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1325

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1326 1327 1328 1329 1330 1331
class Field_enum :public Field_str {
protected:
  uint packlength;
public:
  TYPELIB *typelib;
  Field_enum(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1332
		 uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1333 1334
		 enum utype unireg_check_arg, const char *field_name_arg,
		 struct st_table *table_arg,uint packlength_arg,
1335 1336
		 TYPELIB *typelib_arg,
		 CHARSET_INFO *charset_arg)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1337
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1338
	       unireg_check_arg, field_name_arg, table_arg, charset_arg),
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1339
    packlength(packlength_arg),typelib(typelib_arg)
1340
  {
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1341
      flags|=ENUM_FLAG;
1342
  }
1343
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1344 1345
  enum_field_types type() const { return FIELD_TYPE_STRING; }
  enum Item_result cmp_type () const { return INT_RESULT; }
1346
  enum Item_result cast_to_int_type () const { return INT_RESULT; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1347
  enum ha_base_keytype key_type() const;
1348 1349
  int  store(const char *to,uint length,CHARSET_INFO *charset);
  int  store(double nr);
1350
  int  store(longlong nr, bool unsigned_val);
1351
  int reset() { bzero(ptr,packlength); return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
  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; }
1363
  bool optimize_range(uint idx, uint part) { return 0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1364
  bool eq_def(Field *field);
1365
  bool has_charset(void) const { return TRUE; }
1366 1367
  /* enum and set are sorted as integers */
  CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1368 1369 1370 1371 1372 1373
};


class Field_set :public Field_enum {
public:
  Field_set(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1374
	    uchar null_bit_arg,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1375 1376
	    enum utype unireg_check_arg, const char *field_name_arg,
	    struct st_table *table_arg,uint32 packlength_arg,
1377
	    TYPELIB *typelib_arg, CHARSET_INFO *charset_arg)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1378 1379 1380
    :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
		    unireg_check_arg, field_name_arg,
		    table_arg, packlength_arg,
1381
		    typelib_arg,charset_arg)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1382 1383 1384
    {
      flags=(flags & ~ENUM_FLAG) | SET_FLAG;
    }
1385
  int  store(const char *to,uint length,CHARSET_INFO *charset);
1386 1387
  int  store(double nr) { return Field_set::store((longlong) nr, FALSE); }
  int  store(longlong nr, bool unsigned_val);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1388 1389 1390 1391
  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; }
1392
  bool has_charset(void) const { return TRUE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1393 1394 1395
};


jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1396 1397 1398 1399 1400
class Field_bit :public Field {
public:
  uchar *bit_ptr;     // position in record where 'uneven' bits store
  uchar bit_ofs;      // offset to 'uneven' high bits
  uint bit_len;       // number of 'uneven' high bits
1401
  uint bytes_in_rec;
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1402 1403 1404 1405 1406 1407
  Field_bit(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
            uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
            enum utype unireg_check_arg, const char *field_name_arg,
            struct st_table *table_arg);
  enum_field_types type() const { return FIELD_TYPE_BIT; }
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
1408
  uint32 key_length() const { return (uint32) (field_length + 7) / 8; }
1409
  uint32 max_display_length() { return field_length; }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1410 1411
  uint size_of() const { return sizeof(*this); }
  Item_result result_type () const { return INT_RESULT; }
1412
  int reset(void) { bzero(ptr, bytes_in_rec); return 0; }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1413 1414
  int store(const char *to, uint length, CHARSET_INFO *charset);
  int store(double nr);
1415
  int store(longlong nr, bool unsigned_val);
1416
  int store_decimal(const my_decimal *);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1417 1418 1419
  double val_real(void);
  longlong val_int(void);
  String *val_str(String*, String *);
1420
  my_decimal *val_decimal(my_decimal *);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1421 1422 1423 1424 1425 1426
  int cmp(const char *a, const char *b)
  { return cmp_binary(a, b); }
  int key_cmp(const byte *a, const byte *b)
  { return cmp_binary((char *) a, (char *) b); }
  int key_cmp(const byte *str, uint length);
  int cmp_offset(uint row_offset);
1427 1428
  int cmp_binary_offset(uint row_offset)
  { return cmp_offset(row_offset); }
1429
  uint get_key_image(char *buff, uint length, imagetype type);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1430 1431 1432 1433
  void set_key_image(char *buff, uint length)
  { Field_bit::store(buff, length, &my_charset_bin); }
  void sort_string(char *buff, uint length)
  { get_key_image(buff, length, itRAW); }
1434 1435
  uint32 pack_length() const { return (uint32) (field_length + 7) / 8; }
  uint32 pack_length_in_rec() const { return bytes_in_rec; }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1436 1437 1438 1439 1440 1441
  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);
  Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
                       char *new_ptr, uchar *new_null_ptr,
                       uint new_null_bit);
1442 1443 1444 1445 1446
  inline void move_field(my_ptrdiff_t ptr_diff)
  {
    Field::move_field(ptr_diff);
    bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*);
  }
ramil@mysql.com's avatar
ramil@mysql.com committed
1447 1448 1449 1450 1451
  void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg)
  {
    bit_ptr= bit_ptr_arg;
    bit_ofs= bit_ofs_arg;
  }
1452 1453 1454 1455 1456 1457 1458
  bool eq(Field *field)
  {
    return (Field::eq(field) &&
            field->type() == type() &&
            bit_ptr == ((Field_bit *)field)->bit_ptr &&
            bit_ofs == ((Field_bit *)field)->bit_ofs);
  }
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1459 1460
};

1461

1462 1463 1464
class Field_bit_as_char: public Field_bit {
public:
  Field_bit_as_char(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1465
                    uchar null_bit_arg,
1466 1467 1468
                    enum utype unireg_check_arg, const char *field_name_arg,
                    struct st_table *table_arg);
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
ramil@mysql.com's avatar
ramil@mysql.com committed
1469
  uint size_of() const { return sizeof(*this); }
1470 1471
  int store(const char *to, uint length, CHARSET_INFO *charset);
  int store(double nr) { return Field_bit::store(nr); }
1472 1473
  int store(longlong nr, bool unsigned_val)
  { return Field_bit::store(nr, unsigned_val); }
1474 1475 1476 1477
  void sql_type(String &str) const;
};


bk@work.mysql.com's avatar
bk@work.mysql.com committed
1478
/*
salle@geopard.online.bg's avatar
salle@geopard.online.bg committed
1479
  Create field class for CREATE TABLE
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1480 1481
*/

1482 1483
class create_field :public Sql_alloc
{
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1484 1485
public:
  const char *field_name;
1486 1487
  const char *change;			// If done with alter table
  const char *after;			// Put column after this one
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1488
  LEX_STRING comment;			// Comment for field
1489
  Item	*def;				// Default value
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1490
  enum	enum_field_types sql_type;
1491 1492 1493 1494
  /*
    At various stages in execution this can be length of field in bytes or
    max number of characters. 
  */
sergefp@mysql.com's avatar
sergefp@mysql.com committed
1495
  ulong length;
sergefp@mysql.com's avatar
sergefp@mysql.com committed
1496
  /*
1497 1498
    The value of `length' as set by parser: is the number of characters
    for most of the types, or of bytes for BLOBs or numeric types.
sergefp@mysql.com's avatar
sergefp@mysql.com committed
1499
  */
1500
  uint32 char_length;
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1501
  uint  decimals, flags, pack_length, key_length;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1502
  Field::utype unireg_check;
1503
  TYPELIB *interval;			// Which interval to use
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
1504 1505
  TYPELIB *save_interval;               // Temporary copy for the above
                                        // Used only for UCS2 intervals
1506
  List<String> interval_list;
1507
  CHARSET_INFO *charset;
1508
  Field::geometry_type geom_type;
1509
  Field *field;				// For alter table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1510

1511
  uint8 row,col,sc_length,interval_id;	// For rea_create_table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1512 1513
  uint	offset,pack_flag;
  create_field() :after(0) {}
1514
  create_field(Field *field, Field *orig_field);
1515
  void create_length_to_internal_length(void);
1516 1517 1518 1519 1520

  /* Init for a tmp table field. To be extended if need be. */
  void init_for_tmp_table(enum_field_types sql_type_arg,
                          uint32 max_length, uint32 decimals,
                          bool maybe_null, bool is_unsigned);
1521 1522 1523 1524 1525 1526

  bool init(THD *thd, char *field_name, enum_field_types type, char *length,
            char *decimals, uint type_modifier, Item *default_value,
            Item *on_update_value, LEX_STRING *comment, char *change,
            List<String> *interval_list, CHARSET_INFO *cs,
            uint uint_geom_type);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1527 1528 1529 1530
};


/*
salle@geopard.online.bg's avatar
salle@geopard.online.bg committed
1531
  A class for sending info to the client
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1532 1533 1534 1535
*/

class Send_field {
 public:
1536 1537 1538
  const char *db_name;
  const char *table_name,*org_table_name;
  const char *col_name,*org_col_name;
1539 1540
  ulong length;
  uint charsetnr, flags, decimals;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1541 1542 1543 1544 1545 1546
  enum_field_types type;
  Send_field() {}
};


/*
1547
  A class for quick copying data to fields
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
*/

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;
1559
  String tmp;					// For items
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1560 1561 1562

  Copy_field() {}
  ~Copy_field() {}
1563 1564
  void set(Field *to,Field *from,bool save);	// Field to field 
  void set(char *to,Field *from);		// Field to string
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1565
  void (*do_copy)(Copy_field *);
1566
  void (*do_copy2)(Copy_field *);		// Used to handle null values
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1567 1568 1569 1570
};


Field *make_field(char *ptr, uint32 field_length,
1571
		  uchar *null_pos, uchar null_bit,
1572
		  uint pack_flag, enum_field_types field_type,
1573
		  CHARSET_INFO *cs,
1574
		  Field::geometry_type geom_type,
1575
		  Field::utype unireg_check,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1576 1577 1578
		  TYPELIB *interval, const char *field_name,
		  struct st_table *table);
uint pack_length_to_packflag(uint type);
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1579
enum_field_types get_blob_type_from_length(ulong length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1580
uint32 calc_pack_length(enum_field_types type,uint32 length);
hf@deer.(none)'s avatar
hf@deer.(none) committed
1581 1582
int set_field_to_null(Field *field);
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1583 1584

/*
1585
  The following are for the interface with the .frm file
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1586 1587 1588
*/

#define FIELDFLAG_DECIMAL		1
1589
#define FIELDFLAG_BINARY		1	// Shares same flag
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1590 1591
#define FIELDFLAG_NUMBER		2
#define FIELDFLAG_ZEROFILL		4
1592
#define FIELDFLAG_PACK			120	// Bits used for packing
1593 1594 1595 1596
#define FIELDFLAG_INTERVAL		256     // mangled with decimals!
#define FIELDFLAG_BITFIELD		512	// mangled with decimals!
#define FIELDFLAG_BLOB			1024	// mangled with decimals!
#define FIELDFLAG_GEOM			2048    // mangled with decimals!
1597

1598 1599
#define FIELDFLAG_TREAT_BIT_AS_CHAR     4096    /* use Field_bit_as_char */

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1600 1601
#define FIELDFLAG_LEFT_FULLSCREEN	8192
#define FIELDFLAG_RIGHT_FULLSCREEN	16384
1602
#define FIELDFLAG_FORMAT_NUMBER		16384	// predit: ###,,## in output
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1603
#define FIELDFLAG_NO_DEFAULT		16384   /* sql */
1604 1605
#define FIELDFLAG_SUM			((uint) 32768)// predit: +#fieldflag
#define FIELDFLAG_MAYBE_NULL		((uint) 32768)// sql
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618
#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 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)
1619
#define f_decimals(x)		((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1620
#define f_is_alpha(x)		(!f_is_num(x))
1621
#define f_is_binary(x)          ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
1622 1623
#define f_is_enum(x)            (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
#define f_is_bitfield(x)        (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1624
#define f_is_blob(x)		(((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
1625
#define f_is_geom(x)		(((x) & (FIELDFLAG_GEOM | FIELDFLAG_NUMBER)) == FIELDFLAG_GEOM)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1626 1627 1628
#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)
jimw@mysql.com's avatar
Merge  
jimw@mysql.com committed
1629
#define f_no_default(x)		(x & FIELDFLAG_NO_DEFAULT)
1630
#define f_bit_as_char(x)        ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)