~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/field.h

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
19
16
 
20
17
/*
21
18
  Because of the function new_field() all field classes that have static
22
19
  variables must declare the size_of() member function.
23
20
*/
24
21
 
25
 
#ifndef DRIZZLED_FIELD_H
26
 
#define DRIZZLED_FIELD_H
27
 
 
28
 
#include "drizzled/sql_error.h"
29
 
#include "drizzled/decimal.h"
30
 
#include "drizzled/key_map.h"
31
 
#include "drizzled/sql_bitmap.h"
32
 
#include "drizzled/sql_list.h"
33
 
#include "drizzled/structs.h"
34
 
#include "drizzled/charset_info.h"
35
 
#include "drizzled/item_result.h"
36
 
 
37
 
#include <string>
38
 
#include <vector>
39
 
 
40
 
namespace drizzled
41
 
{
 
22
#ifdef USE_PRAGMA_INTERFACE
 
23
#pragma interface                       /* gcc class implementation */
 
24
#endif
42
25
 
43
26
#define DATETIME_DEC                     6
44
 
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
45
 
 
46
 
#ifdef DEBUG
47
 
#define ASSERT_COLUMN_MARKED_FOR_READ assert(!table || (table->read_set == NULL || isReadSet()))
48
 
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(!table || (table->write_set == NULL || isWriteSet()))
49
 
#else
50
 
#define ASSERT_COLUMN_MARKED_FOR_READ
51
 
#define ASSERT_COLUMN_MARKED_FOR_WRITE
52
 
#endif
53
 
 
54
 
typedef struct st_typelib TYPELIB;
55
 
 
56
 
const uint32_t max_field_size= (uint32_t) 4294967295U;
57
 
 
58
 
class SendField;
59
 
class CreateField;
60
 
class TableShare;
61
 
class Field;
 
27
const uint32 max_field_size= (uint32) 4294967295U;
 
28
 
 
29
class Send_field;
 
30
class Protocol;
 
31
class Create_field;
62
32
struct st_cache_field;
63
 
 
64
33
int field_conv(Field *to,Field *from);
65
34
 
66
 
inline uint32_t get_enum_pack_length(int elements)
 
35
inline uint get_enum_pack_length(int elements)
67
36
{
68
37
  return elements < 256 ? 1 : 2;
69
38
}
70
39
 
71
 
/**
72
 
 * Class representing a Field in a Table
73
 
 *
74
 
 * @details
75
 
 *
76
 
 * The value stored in the Field object is stored in the
77
 
 * unsigned char pointer member variable called ptr.  The
78
 
 * val_xxx() methods retrieve this raw byte value and
79
 
 * convert the byte into the appropriate output (int, decimal, etc).
80
 
 *
81
 
 * The store_xxx() methods take various input and convert
82
 
 * the input into the raw bytes stored in the ptr member variable.
83
 
 */
 
40
inline uint get_set_pack_length(int elements)
 
41
{
 
42
  uint len= (elements + 7) / 8;
 
43
  return len > 4 ? 8 : len;
 
44
}
 
45
 
84
46
class Field
85
47
{
86
 
  /* Prevent use of these */
87
 
  Field(const Field&);
 
48
  Field(const Item &);                          /* Prevent use of these */
88
49
  void operator=(Field &);
89
50
public:
90
 
  unsigned char *ptr; /**< Position to field in record. Stores raw field value */
91
 
  unsigned char *null_ptr; /**< Byte where null_bit is */
92
 
 
93
 
  /**
94
 
   * Pointer to the Table object containing this Field
95
 
   *
96
 
   * @note You can use table->in_use as replacement for current_session member
97
 
   * only inside of val_*() and store() members (e.g. you can't use it in cons)
98
 
   */
99
 
  Table *table;
100
 
  Table *orig_table; /**< Pointer to the original Table. @TODO What is "the original table"? */
101
 
  const char **table_name; /**< Pointer to the name of the table. @TODO This is redundant with Table::table_name. */
102
 
  const char *field_name; /**< Name of the field */
103
 
  LEX_STRING comment; /**< A comment about the field */
104
 
 
105
 
  /** The field is part of the following keys */
106
 
  key_map       key_start;
107
 
  key_map part_of_key;
108
 
  key_map part_of_key_not_clustered;
109
 
  key_map part_of_sortkey;
110
 
 
 
51
  static void *operator new(size_t size) {return sql_alloc(size); }
 
52
  static void operator delete(void *ptr_arg __attribute__((__unused__)),
 
53
                              size_t size __attribute__((__unused__)))
 
54
  { TRASH(ptr_arg, size); }
 
55
 
 
56
  uchar         *ptr;                   // Position to field in record
 
57
  uchar         *null_ptr;              // Byte where null_bit is
111
58
  /*
112
 
    We use three additional unireg types for TIMESTAMP for hysterical
113
 
    raisins and limitations in the MySQL FRM file format.
114
 
 
115
 
    A good TODO is to clean this up as we can support just about
116
 
    anything in the table proto message now.
117
 
  */
118
 
  enum utype
119
 
  {
120
 
    NONE,
121
 
    NEXT_NUMBER,
122
 
    TIMESTAMP_OLD_FIELD,
123
 
    TIMESTAMP_DN_FIELD,
124
 
    TIMESTAMP_UN_FIELD,
125
 
    TIMESTAMP_DNUN_FIELD
126
 
  };
127
 
 
128
 
  utype unireg_check;
129
 
  uint32_t field_length; /**< Length of this field in bytes */
130
 
  uint32_t flags;
131
 
  uint16_t field_index; /**< Index of this Field in Table::fields array */
132
 
  unsigned char null_bit; /**< Bit used to test null bit */
 
59
    Note that you can use table->in_use as replacement for current_thd member 
 
60
    only inside of val_*() and store() members (e.g. you can't use it in cons)
 
61
  */
 
62
  struct st_table *table;               // Pointer for table
 
63
  struct st_table *orig_table;          // Pointer to original table
 
64
  const char    **table_name, *field_name;
 
65
  LEX_STRING    comment;
 
66
  /* Field is part of the following keys */
 
67
  key_map       key_start, part_of_key, part_of_key_not_clustered;
 
68
  key_map       part_of_sortkey;
 
69
  /* 
 
70
    We use three additional unireg types for TIMESTAMP to overcome limitation 
 
71
    of current binary format of .frm file. We'd like to be able to support 
 
72
    NOW() as default and on update value for such fields but unable to hold 
 
73
    this info anywhere except unireg_check field. This issue will be resolved
 
74
    in more clean way with transition to new text based .frm format.
 
75
    See also comment for Field_timestamp::Field_timestamp().
 
76
  */
 
77
  enum utype  { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
 
78
                CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
 
79
                BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
 
80
                TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
 
81
  enum imagetype { itRAW, itMBR};
 
82
 
 
83
  utype         unireg_check;
 
84
  uint32        field_length;           // Length of field
 
85
  uint32        flags;
 
86
  uint16        field_index;            // field number in fields array
 
87
  uchar         null_bit;               // Bit used to test null bit
133
88
  /**
134
89
     If true, this field was created in create_tmp_field_from_item from a NULL
135
90
     value. This means that the type of the field is just a guess, and the type
137
92
 
138
93
     @see create_tmp_field_from_item
139
94
     @see Item_type_holder::get_real_type
 
95
 
140
96
   */
141
97
  bool is_created_from_null_item;
142
98
 
143
 
  static void *operator new(size_t size);
144
 
  static void *operator new(size_t size, memory::Root *mem_root);
145
 
  static void operator delete(void *, size_t)
146
 
  { }
147
 
 
148
 
  Field(unsigned char *ptr_arg,
149
 
        uint32_t length_arg,
150
 
        unsigned char *null_ptr_arg,
151
 
        unsigned char null_bit_arg,
152
 
        utype unireg_check_arg,
 
99
  Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
 
100
        uchar null_bit_arg, utype unireg_check_arg,
153
101
        const char *field_name_arg);
154
102
  virtual ~Field() {}
155
103
  /* Store functions returns 1 on overflow and -1 on fatal error */
156
 
  virtual int store(const char *to,
157
 
                    uint32_t length,
158
 
                    const CHARSET_INFO * const cs)=0;
159
 
  virtual int store(double nr)=0;
160
 
  virtual int store(int64_t nr, bool unsigned_val)=0;
161
 
  virtual int store_decimal(const my_decimal *d)=0;
162
 
  int store(const char *to,
163
 
            uint32_t length,
164
 
            const CHARSET_INFO * const cs,
 
104
  virtual int  store(const char *to, uint length,CHARSET_INFO *cs)=0;
 
105
  virtual int  store(double nr)=0;
 
106
  virtual int  store(longlong nr, bool unsigned_val)=0;
 
107
  virtual int  store_decimal(const my_decimal *d)=0;
 
108
  virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
 
109
  int store(const char *to, uint length, CHARSET_INFO *cs,
165
110
            enum_check_fields check_level);
166
 
  /**
167
 
    This is called when storing a date in a string.
168
 
 
169
 
    @note
170
 
      Needs to be changed if/when we want to support different time formats.
171
 
  */
172
 
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
173
111
  virtual double val_real(void)=0;
174
 
  virtual int64_t val_int(void)=0;
 
112
  virtual longlong val_int(void)=0;
175
113
  virtual my_decimal *val_decimal(my_decimal *);
176
 
  inline String *val_str(String *str)
177
 
  {
178
 
    return val_str(str, str);
179
 
  }
 
114
  inline String *val_str(String *str) { return val_str(str, str); }
180
115
  /*
181
116
     val_str(buf1, buf2) gets two buffers and should use them as follows:
182
117
     if it needs a temp buffer to convert result to string - use buf1
183
118
       example Field_tiny::val_str()
184
119
     if the value exists as a string already - use buf2
185
 
       example Field_varstring::val_str() (???)
 
120
       example Field_string::val_str()
186
121
     consequently, buf2 may be created as 'String buf;' - no memory
187
122
     will be allocated for it. buf1 will be allocated to hold a
188
123
     value if it's too small. Using allocated buffer for buf2 may result in
189
124
     an unnecessary free (and later, may be an alloc).
190
125
     This trickery is used to decrease a number of malloc calls.
191
126
  */
192
 
  virtual String *val_str(String*, String *)=0;
 
127
  virtual String *val_str(String*,String *)=0;
 
128
  String *val_int_as_str(String *val_buffer, my_bool unsigned_flag);
193
129
  /*
194
130
   str_needs_quotes() returns true if the value returned by val_str() needs
195
131
   to be quoted when used in constructing an SQL query.
198
134
  virtual Item_result result_type () const=0;
199
135
  virtual Item_result cmp_type () const { return result_type(); }
200
136
  virtual Item_result cast_to_int_type () const { return result_type(); }
201
 
  /**
202
 
     Check whether a field type can be partially indexed by a key.
203
 
 
204
 
     This is a static method, rather than a virtual function, because we need
205
 
     to check the type of a non-Field in alter_table().
206
 
 
207
 
     @param type  field type
208
 
 
209
 
     @retval
210
 
       true  Type can have a prefixed key
211
 
     @retval
212
 
       false Type can not have a prefixed key
213
 
  */
214
137
  static bool type_can_have_key_part(enum_field_types);
215
 
  /**
216
 
    Return type of which can carry value of both given types in UNION result.
217
 
 
218
 
    @param a  type for merging
219
 
    @param b  type for merging
220
 
 
221
 
    @retval
222
 
      type of field
223
 
  */
224
138
  static enum_field_types field_type_merge(enum_field_types, enum_field_types);
225
 
 
226
 
  /**
227
 
     Detect Item_result by given field type of UNION merge result.
228
 
 
229
 
     @param field_type  given field type
230
 
 
231
 
     @return
232
 
       Item_result (type of internal MySQL expression result)
233
 
  */
234
139
  static Item_result result_merge_type(enum_field_types);
235
 
 
236
 
  virtual bool eq(Field *field);
237
 
  /**
238
 
   * Returns true if the fields are equally defined
239
 
   *
240
 
   * @retval
241
 
   *  true  This Field is equally defined to supplied Field
242
 
   * @retval
243
 
   *  false This Field is NOT equally defined to supplied Field
244
 
   */
 
140
  virtual bool eq(Field *field)
 
141
  {
 
142
    return (ptr == field->ptr && null_ptr == field->null_ptr &&
 
143
            null_bit == field->null_bit);
 
144
  }
245
145
  virtual bool eq_def(Field *field);
246
 
 
247
 
  /**
248
 
   * Returns size (in bytes) used to store field data in memory
249
 
   * (i.e. it returns the maximum size of the field in a row of the table,
250
 
   * which is located in RAM).
251
 
   */
252
 
  virtual uint32_t pack_length() const;
253
 
 
254
 
  /**
255
 
   * Returns size (in bytes) used to store field data on
256
 
   * storage (i.e. it returns the maximal size of the field in a row of the
257
 
   * table, which is located on disk).
258
 
   */
259
 
  virtual uint32_t pack_length_in_rec() const;
260
 
 
261
 
  /**
262
 
   * Return the "real size" of the data in memory.
263
 
   * For varstrings, this does _not_ include the length bytes.
264
 
   */
265
 
  virtual uint32_t data_length();
266
 
  /**
267
 
   * Returns the number of bytes actually used to store the data
268
 
   * of the field. So for a varstring it includes both lenght byte(s) and
269
 
   * string data, and anything after data_length() bytes are unused.
270
 
   */
271
 
  virtual uint32_t used_length();
272
 
  virtual uint32_t sort_length() const;
 
146
  
 
147
  /*
 
148
    pack_length() returns size (in bytes) used to store field data in memory
 
149
    (i.e. it returns the maximum size of the field in a row of the table,
 
150
    which is located in RAM).
 
151
  */
 
152
  virtual uint32 pack_length() const { return (uint32) field_length; }
 
153
 
 
154
  /*
 
155
    pack_length_in_rec() returns size (in bytes) used to store field data on
 
156
    storage (i.e. it returns the maximal size of the field in a row of the
 
157
    table, which is located on disk).
 
158
  */
 
159
  virtual uint32 pack_length_in_rec() const { return pack_length(); }
 
160
  virtual int compatible_field_size(uint field_metadata);
 
161
  virtual uint pack_length_from_metadata(uint field_metadata)
 
162
  { return field_metadata; }
 
163
  /*
 
164
    This method is used to return the size of the data in a row-based
 
165
    replication row record. The default implementation of returning 0 is
 
166
    designed to allow fields that do not use metadata to return true (1)
 
167
    from compatible_field_size() which uses this function in the comparison.
 
168
    The default value for field metadata for fields that do not have 
 
169
    metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
 
170
 
 
171
    Note: While most classes that override this method return pack_length(),
 
172
    the classes Field_string, Field_varstring, and Field_blob return 
 
173
    field_length + 1, field_length, and pack_length_no_ptr() respectfully.
 
174
  */
 
175
  virtual uint row_pack_length() { return 0; }
 
176
  virtual int save_field_metadata(uchar *first_byte)
 
177
  { return do_save_field_metadata(first_byte); }
 
178
 
 
179
  /*
 
180
    data_length() return the "real size" of the data in memory.
 
181
    For varstrings, this does _not_ include the length bytes.
 
182
  */
 
183
  virtual uint32 data_length() { return pack_length(); }
 
184
  /*
 
185
    used_length() returns the number of bytes actually used to store the data
 
186
    of the field. So for a varstring it includes both lenght byte(s) and
 
187
    string data, and anything after data_length() bytes are unused.
 
188
  */
 
189
  virtual uint32 used_length() { return pack_length(); }
 
190
  virtual uint32 sort_length() const { return pack_length(); }
273
191
 
274
192
  /**
275
193
     Get the maximum size of the data in packed format.
277
195
     @return Maximum data length of the field when packed using the
278
196
     Field::pack() function.
279
197
   */
280
 
  virtual uint32_t max_data_length() const;
281
 
  virtual int reset(void);
282
 
  virtual void reset_fields();
283
 
  virtual void set_default();
284
 
  virtual bool binary() const;
285
 
  virtual bool zero_pack() const;
286
 
  virtual enum ha_base_keytype key_type() const;
287
 
  virtual uint32_t key_length() const;
 
198
  virtual uint32 max_data_length() const {
 
199
    return pack_length();
 
200
  };
 
201
 
 
202
  virtual int reset(void) { bzero(ptr,pack_length()); return 0; }
 
203
  virtual void reset_fields() {}
 
204
  virtual void set_default()
 
205
  {
 
206
    my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values - table->record[0]);
 
207
    memcpy(ptr, ptr + l_offset, pack_length());
 
208
    if (null_ptr)
 
209
      *null_ptr= ((*null_ptr & (uchar) ~null_bit) | (null_ptr[l_offset] & null_bit));
 
210
  }
 
211
  virtual bool binary() const { return 1; }
 
212
  virtual bool zero_pack() const { return 1; }
 
213
  virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
 
214
  virtual uint32 key_length() const { return pack_length(); }
288
215
  virtual enum_field_types type() const =0;
289
 
  virtual enum_field_types real_type() const;
290
 
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
291
 
  virtual int cmp_max(const unsigned char *a, const unsigned char *b,
292
 
                      uint32_t max_len);
293
 
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
294
 
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
295
 
                         uint32_t max_length=UINT32_MAX);
296
 
  virtual int cmp_offset(uint32_t row_offset);
297
 
  virtual int cmp_binary_offset(uint32_t row_offset);
298
 
  virtual int key_cmp(const unsigned char *a,const unsigned char *b);
299
 
  virtual int key_cmp(const unsigned char *str, uint32_t length);
300
 
  virtual uint32_t decimals() const;
301
 
 
 
216
  virtual enum_field_types real_type() const { return type(); }
 
217
  inline  int cmp(const uchar *str) { return cmp(ptr,str); }
 
218
  virtual int cmp_max(const uchar *a, const uchar *b,
 
219
                      uint max_len __attribute__((__unused__)))
 
220
    { return cmp(a, b); }
 
221
  virtual int cmp(const uchar *,const uchar *)=0;
 
222
  virtual int cmp_binary(const uchar *a,const uchar *b,
 
223
                         uint32  __attribute__((__unused__)) max_length=~0)
 
224
  { return memcmp(a,b,pack_length()); }
 
225
  virtual int cmp_offset(uint row_offset)
 
226
  { return cmp(ptr,ptr+row_offset); }
 
227
  virtual int cmp_binary_offset(uint row_offset)
 
228
  { return cmp_binary(ptr, ptr+row_offset); };
 
229
  virtual int key_cmp(const uchar *a,const uchar *b)
 
230
  { return cmp(a, b); }
 
231
  virtual int key_cmp(const uchar *str, uint length __attribute__((__unused__)))
 
232
  { return cmp(ptr,str); }
 
233
  virtual uint decimals() const { return 0; }
302
234
  /*
303
235
    Caller beware: sql_type can change str.Ptr, so check
304
236
    ptr() to see if it changed if you are using your own buffer
305
237
    in str and restore it with set() if needed
306
238
  */
307
239
  virtual void sql_type(String &str) const =0;
308
 
 
309
 
  // For new field
310
 
  virtual uint32_t size_of() const =0;
311
 
 
312
 
  bool is_null(ptrdiff_t row_offset= 0);
313
 
  bool is_real_null(ptrdiff_t row_offset= 0);
314
 
  bool is_null_in_record(const unsigned char *record);
315
 
  bool is_null_in_record_with_offset(ptrdiff_t offset);
316
 
  void set_null(ptrdiff_t row_offset= 0);
317
 
  void set_notnull(ptrdiff_t row_offset= 0);
318
 
  bool maybe_null(void);
319
 
  bool real_maybe_null(void);
320
 
 
321
 
  virtual void make_field(SendField *);
322
 
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
323
 
  virtual bool optimize_range(uint32_t idx, uint32_t part);
324
 
  /**
325
 
   * Returns true for fields which, when compared with constant
326
 
   * items, can be casted to int64_t. In this case we will at 'fix_fields'
327
 
   * stage cast the constant items to int64_ts and at the execution stage
328
 
   * use field->val_int() for comparison.  Used to optimize clauses like
329
 
   * 'a_column BETWEEN date_const AND date_const'.
 
240
  virtual uint size_of() const =0;              // For new field
 
241
  inline bool is_null(my_ptrdiff_t row_offset= 0)
 
242
  { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
 
243
  inline bool is_real_null(my_ptrdiff_t row_offset= 0)
 
244
    { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
 
245
  inline bool is_null_in_record(const uchar *record)
 
246
  {
 
247
    if (!null_ptr)
 
248
      return 0;
 
249
    return test(record[(uint) (null_ptr -table->record[0])] &
 
250
                null_bit);
 
251
  }
 
252
  inline bool is_null_in_record_with_offset(my_ptrdiff_t offset)
 
253
  {
 
254
    if (!null_ptr)
 
255
      return 0;
 
256
    return test(null_ptr[offset] & null_bit);
 
257
  }
 
258
  inline void set_null(my_ptrdiff_t row_offset= 0)
 
259
    { if (null_ptr) null_ptr[row_offset]|= null_bit; }
 
260
  inline void set_notnull(my_ptrdiff_t row_offset= 0)
 
261
    { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
 
262
  inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
 
263
  inline bool real_maybe_null(void) { return null_ptr != 0; }
 
264
 
 
265
  enum {
 
266
    LAST_NULL_BYTE_UNDEF= 0
 
267
  };
 
268
 
 
269
  /*
 
270
    Find the position of the last null byte for the field.
 
271
 
 
272
    SYNOPSIS
 
273
      last_null_byte()
 
274
 
 
275
    DESCRIPTION
 
276
      Return a pointer to the last byte of the null bytes where the
 
277
      field conceptually is placed.
 
278
 
 
279
    RETURN VALUE
 
280
      The position of the last null byte relative to the beginning of
 
281
      the record. If the field does not use any bits of the null
 
282
      bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
330
283
   */
331
 
  virtual bool can_be_compared_as_int64_t() const
332
 
  {
333
 
    return false;
 
284
  size_t last_null_byte() const {
 
285
    size_t bytes= do_last_null_byte();
 
286
    assert(bytes <= table->s->null_bytes);
 
287
    return bytes;
334
288
  }
 
289
 
 
290
  virtual void make_field(Send_field *);
 
291
  virtual void sort_string(uchar *buff,uint length)=0;
 
292
  virtual bool optimize_range(uint idx, uint part);
 
293
  /*
 
294
    This should be true for fields which, when compared with constant
 
295
    items, can be casted to longlong. In this case we will at 'fix_fields'
 
296
    stage cast the constant items to longlongs and at the execution stage
 
297
    use field->val_int() for comparison.  Used to optimize clauses like
 
298
    'a_column BETWEEN date_const, date_const'.
 
299
  */
 
300
  virtual bool can_be_compared_as_longlong() const { return false; }
335
301
  virtual void free() {}
336
 
  virtual Field *new_field(memory::Root *root,
337
 
                           Table *new_table,
 
302
  virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table,
338
303
                           bool keep_type);
339
 
  virtual Field *new_key_field(memory::Root *root, Table *new_table,
340
 
                               unsigned char *new_ptr,
341
 
                               unsigned char *new_null_ptr,
342
 
                               uint32_t new_null_bit);
343
 
  /** This is used to generate a field in Table from TableShare */
344
 
  Field *clone(memory::Root *mem_root, Table *new_table);
345
 
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
 
304
  virtual Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
 
305
                               uchar *new_ptr, uchar *new_null_ptr,
 
306
                               uint new_null_bit);
 
307
  Field *clone(MEM_ROOT *mem_root, struct st_table *new_table);
 
308
  inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
346
309
  {
347
 
    ptr= ptr_arg;
348
 
    null_ptr= null_ptr_arg;
349
 
    null_bit= null_bit_arg;
 
310
    ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
350
311
  }
351
 
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
352
 
  virtual void move_field_offset(ptrdiff_t ptr_diff)
 
312
  inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; }
 
313
  virtual void move_field_offset(my_ptrdiff_t ptr_diff)
353
314
  {
354
 
    ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
 
315
    ptr=ADD_TO_PTR(ptr,ptr_diff, uchar*);
355
316
    if (null_ptr)
356
 
      null_ptr= ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
357
 
  }
358
 
  virtual void get_image(unsigned char *buff, uint32_t length, const CHARSET_INFO * const)
359
 
  {
360
 
    memcpy(buff,ptr,length);
361
 
  }
362
 
  virtual void get_image(std::basic_string<unsigned char> &buff, uint32_t length, const CHARSET_INFO * const)
363
 
  {
364
 
    buff.append(ptr,length);
365
 
  }
366
 
  virtual void set_image(const unsigned char *buff,uint32_t length, const CHARSET_INFO * const)
367
 
  {
368
 
    memcpy(ptr,buff,length);
369
 
  }
370
 
 
371
 
  /**
372
 
   * Copy a field part into an output buffer.
373
 
   *
374
 
   * @details
375
 
   *
376
 
   * This function makes a copy of field part of size equal to or
377
 
   * less than "length" parameter value.
378
 
   * For fields of string types (VARCHAR, TEXT) the rest of buffer
379
 
   * is padded by zero byte.
380
 
   *
381
 
   * @param output buffer
382
 
   * @param output buffer size
383
 
   *
384
 
   * @note
385
 
   *
386
 
   * For variable length character fields (i.e. UTF-8) the "length"
387
 
   * parameter means a number of output buffer bytes as if all field
388
 
   * characters have maximal possible size (mbmaxlen). In the other words,
389
 
   * "length" parameter is a number of characters multiplied by
390
 
   * field_charset->mbmaxlen.
391
 
   *
392
 
   * @retval
393
 
   *   Number of copied bytes (excluding padded zero bytes -- see above).
394
 
   */
395
 
  virtual uint32_t get_key_image(unsigned char *buff, uint32_t length)
396
 
  {
397
 
    get_image(buff, length, &my_charset_bin);
398
 
    return length;
399
 
  }
400
 
  virtual uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length)
401
 
  {
402
 
    get_image(buff, length, &my_charset_bin);
403
 
    return length;
404
 
  }
405
 
  virtual void set_key_image(const unsigned char *buff,uint32_t length)
406
 
  {
407
 
    set_image(buff,length, &my_charset_bin);
408
 
  }
409
 
  inline int64_t val_int_offset(uint32_t row_offset)
410
 
  {
411
 
    ptr+=row_offset;
412
 
    int64_t tmp=val_int();
413
 
    ptr-=row_offset;
414
 
    return tmp;
415
 
  }
416
 
 
417
 
  inline int64_t val_int(const unsigned char *new_ptr)
418
 
  {
419
 
    unsigned char *old_ptr= ptr;
420
 
    int64_t return_value;
421
 
    ptr= const_cast<unsigned char*>(new_ptr);
 
317
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
 
318
  }
 
319
  virtual void get_image(uchar *buff, uint length,
 
320
                         CHARSET_INFO *cs __attribute__((__unused__)))
 
321
    { memcpy(buff,ptr,length); }
 
322
  virtual void set_image(const uchar *buff,uint length,
 
323
                         CHARSET_INFO *cs __attribute__((__unused__)))
 
324
    { memcpy(ptr,buff,length); }
 
325
 
 
326
 
 
327
  /*
 
328
    Copy a field part into an output buffer.
 
329
 
 
330
    SYNOPSIS
 
331
      Field::get_key_image()
 
332
      buff   [out] output buffer
 
333
      length       output buffer size
 
334
      type         itMBR for geometry blobs, otherwise itRAW
 
335
 
 
336
    DESCRIPTION
 
337
      This function makes a copy of field part of size equal to or
 
338
      less than "length" parameter value.
 
339
      For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
 
340
      is padded by zero byte.
 
341
 
 
342
    NOTES
 
343
      For variable length character fields (i.e. UTF-8) the "length"
 
344
      parameter means a number of output buffer bytes as if all field
 
345
      characters have maximal possible size (mbmaxlen). In the other words,
 
346
      "length" parameter is a number of characters multiplied by
 
347
      field_charset->mbmaxlen.
 
348
 
 
349
    RETURN
 
350
      Number of copied bytes (excluding padded zero bytes -- see above).
 
351
  */
 
352
 
 
353
  virtual uint get_key_image(uchar *buff, uint length,
 
354
                             imagetype type __attribute__((__unused__)))
 
355
  {
 
356
    get_image(buff, length, &my_charset_bin);
 
357
    return length;
 
358
  }
 
359
  virtual void set_key_image(const uchar *buff,uint length)
 
360
    { set_image(buff,length, &my_charset_bin); }
 
361
  inline longlong val_int_offset(uint row_offset)
 
362
    {
 
363
      ptr+=row_offset;
 
364
      longlong tmp=val_int();
 
365
      ptr-=row_offset;
 
366
      return tmp;
 
367
    }
 
368
  inline longlong val_int(const uchar *new_ptr)
 
369
  {
 
370
    uchar *old_ptr= ptr;
 
371
    longlong return_value;
 
372
    ptr= (uchar*) new_ptr;
422
373
    return_value= val_int();
423
374
    ptr= old_ptr;
424
375
    return return_value;
425
376
  }
426
 
  inline String *val_str(String *str, const unsigned char *new_ptr)
 
377
  inline String *val_str(String *str, const uchar *new_ptr)
427
378
  {
428
 
    unsigned char *old_ptr= ptr;
429
 
    ptr= const_cast<unsigned char*>(new_ptr);
 
379
    uchar *old_ptr= ptr;
 
380
    ptr= (uchar*) new_ptr;
430
381
    val_str(str);
431
382
    ptr= old_ptr;
432
383
    return str;
433
384
  }
434
 
 
435
 
  /**
436
 
    Pack the field into a format suitable for storage and transfer.
437
 
 
438
 
    To implement packing functionality, only the virtual function
439
 
    should be overridden. The other functions are just convenience
440
 
    functions and hence should not be overridden.
441
 
 
442
 
    The value of <code>low_byte_first</code> is dependent on how the
443
 
    packed data is going to be used: for local use, e.g., temporary
444
 
    store on disk or in memory, use the native format since that is
445
 
    faster. For data that is going to be transfered to other machines
446
 
    (e.g., when writing data to the binary log), data should always be
447
 
    stored in little-endian format.
448
 
 
449
 
    @note The default method for packing fields just copy the raw bytes
450
 
    of the record into the destination, but never more than
451
 
    <code>max_length</code> characters.
452
 
 
453
 
    @param to
454
 
    Pointer to memory area where representation of field should be put.
455
 
 
456
 
    @param from
457
 
    Pointer to memory area where record representation of field is
458
 
    stored.
459
 
 
460
 
    @param max_length
461
 
    Maximum length of the field, as given in the column definition. For
462
 
    example, for <code>CHAR(1000)</code>, the <code>max_length</code>
463
 
    is 1000. This information is sometimes needed to decide how to pack
464
 
    the data.
465
 
 
466
 
    @param low_byte_first
467
 
    @c true if integers should be stored little-endian, @c false if
468
 
    native format should be used. Note that for little-endian machines,
469
 
    the value of this flag is a moot point since the native format is
470
 
    little-endian.
471
 
  */
472
 
  virtual unsigned char *pack(unsigned char *to,
473
 
                              const unsigned char *from,
474
 
                              uint32_t max_length,
475
 
                              bool low_byte_first);
476
 
 
477
 
  unsigned char *pack(unsigned char *to, const unsigned char *from);
478
 
 
479
 
  /**
480
 
    Unpack a field from row data.
481
 
 
482
 
    This method is used to unpack a field from a master whose size of
483
 
    the field is less than that of the slave.
484
 
 
485
 
    The <code>param_data</code> parameter is a two-byte integer (stored
486
 
    in the least significant 16 bits of the unsigned integer) usually
487
 
    consisting of two parts: the real type in the most significant byte
488
 
    and a original pack length in the least significant byte.
489
 
 
490
 
    The exact layout of the <code>param_data</code> field is given by
491
 
    the <code>Table_map_log_event::save_field_metadata()</code>.
492
 
 
493
 
    This is the default method for unpacking a field. It just copies
494
 
    the memory block in byte order (of original pack length bytes or
495
 
    length of field, whichever is smaller).
496
 
 
497
 
    @param   to         Destination of the data
498
 
    @param   from       Source of the data
499
 
    @param   param_data Real type and original pack length of the field
500
 
                        data
501
 
 
502
 
    @param low_byte_first
503
 
    If this flag is @c true, all composite entities (e.g., lengths)
504
 
    should be unpacked in little-endian format; otherwise, the entities
505
 
    are unpacked in native order.
506
 
 
507
 
    @return  New pointer into memory based on from + length of the data
508
 
  */
509
 
  virtual const unsigned char *unpack(unsigned char* to,
510
 
                                      const unsigned char *from,
511
 
                                      uint32_t param_data,
512
 
                                      bool low_byte_first);
513
 
  /**
514
 
     @overload Field::unpack(unsigned char*, const unsigned char*,
515
 
                             uint32_t, bool)
516
 
  */
517
 
  const unsigned char *unpack(unsigned char* to,
518
 
                              const unsigned char *from);
519
 
 
520
 
  virtual unsigned char *pack_key(unsigned char* to,
521
 
                                  const unsigned char *from,
522
 
                                  uint32_t max_length,
523
 
                                  bool low_byte_first)
524
 
  {
525
 
    return pack(to, from, max_length, low_byte_first);
526
 
  }
527
 
  virtual const unsigned char *unpack_key(unsigned char* to,
528
 
                                          const unsigned char *from,
529
 
                                          uint32_t max_length,
530
 
                                          bool low_byte_first)
 
385
  virtual bool send_binary(Protocol *protocol);
 
386
 
 
387
  virtual uchar *pack(uchar *to, const uchar *from,
 
388
                      uint max_length, bool low_byte_first);
 
389
  /**
 
390
     @overload Field::pack(uchar*, const uchar*, uint, bool)
 
391
  */
 
392
  uchar *pack(uchar *to, const uchar *from)
 
393
  {
 
394
    uchar *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
 
395
    return(result);
 
396
  }
 
397
 
 
398
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
399
                              uint param_data, bool low_byte_first);
 
400
  /**
 
401
     @overload Field::unpack(uchar*, const uchar*, uint, bool)
 
402
  */
 
403
  const uchar *unpack(uchar* to, const uchar *from)
 
404
  {
 
405
    const uchar *result= unpack(to, from, 0U, table->s->db_low_byte_first);
 
406
    return(result);
 
407
  }
 
408
 
 
409
  virtual uchar *pack_key(uchar* to, const uchar *from,
 
410
                          uint max_length, bool low_byte_first)
 
411
  {
 
412
    return pack(to, from, max_length, low_byte_first);
 
413
  }
 
414
  virtual uchar *pack_key_from_key_image(uchar* to, const uchar *from,
 
415
                                        uint max_length, bool low_byte_first)
 
416
  {
 
417
    return pack(to, from, max_length, low_byte_first);
 
418
  }
 
419
  virtual const uchar *unpack_key(uchar* to, const uchar *from,
 
420
                                  uint max_length, bool low_byte_first)
531
421
  {
532
422
    return unpack(to, from, max_length, low_byte_first);
533
423
  }
534
 
  virtual uint32_t max_packed_col_length(uint32_t max_length)
535
 
  {
536
 
    return max_length;
537
 
  }
 
424
  virtual uint packed_col_length(const uchar *to __attribute__((__unused__)),
 
425
                                 uint length)
 
426
  { return length;}
 
427
  virtual uint max_packed_col_length(uint max_length)
 
428
  { return max_length;}
538
429
 
539
 
  inline uint32_t offset(unsigned char *record)
 
430
  virtual int pack_cmp(const uchar *a,const uchar *b,
 
431
                       uint key_length_arg __attribute__((__unused__)),
 
432
                       my_bool insert_or_update __attribute__((__unused__)))
 
433
  { return cmp(a,b); }
 
434
  virtual int pack_cmp(const uchar *b,
 
435
                       uint key_length_arg __attribute__((__unused__)),
 
436
                       my_bool insert_or_update __attribute__((__unused__)))
 
437
  { return cmp(ptr,b); }
 
438
  uint offset(uchar *record)
540
439
  {
541
 
    return (uint32_t) (ptr - record);
 
440
    return (uint) (ptr - record);
542
441
  }
543
442
  void copy_from_tmp(int offset);
544
 
  uint32_t fill_cache_field(struct st_cache_field *copy);
545
 
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
546
 
  virtual bool get_time(DRIZZLE_TIME *ltime);
547
 
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
548
 
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
 
443
  uint fill_cache_field(struct st_cache_field *copy);
 
444
  virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
445
  virtual bool get_time(MYSQL_TIME *ltime);
 
446
  virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
 
447
  virtual CHARSET_INFO *sort_charset(void) const { return charset(); }
549
448
  virtual bool has_charset(void) const { return false; }
550
 
  virtual void set_charset(const CHARSET_INFO * const)
551
 
  {}
 
449
  virtual void set_charset(CHARSET_INFO *charset_arg __attribute__((__unused__)))
 
450
  { }
552
451
  virtual enum Derivation derivation(void) const
553
 
  {
554
 
    return DERIVATION_IMPLICIT;
555
 
  }
556
 
  virtual void set_derivation(enum Derivation)
557
 
  {}
558
 
  /**
559
 
    Produce warning or note about data saved into field.
560
 
 
561
 
    @param level            - level of message (Note/Warning/Error)
562
 
    @param code             - error code of message to be produced
563
 
    @param cuted_increment  - whenever we should increase cut fields count or not
564
 
 
565
 
    @note
566
 
      This function won't produce warning and increase cut fields counter
567
 
      if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
568
 
 
569
 
      if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
570
 
      This allows us to avoid notes in optimisation, like convert_constant_item().
571
 
 
572
 
    @retval
573
 
      1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
574
 
    @retval
575
 
      0 otherwise
576
 
  */
577
 
  bool set_warning(DRIZZLE_ERROR::enum_warning_level,
578
 
                   unsigned int code,
 
452
  { return DERIVATION_IMPLICIT; }
 
453
  virtual void set_derivation(enum Derivation derivation_arg __attribute__((__unused__)))
 
454
  { }
 
455
  bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
579
456
                   int cuted_increment);
580
 
  /**
581
 
    Produce warning or note about datetime string data saved into field.
582
 
 
583
 
    @param level            level of message (Note/Warning/Error)
584
 
    @param code             error code of message to be produced
585
 
    @param str              string value which we tried to save
586
 
    @param str_length       length of string which we tried to save
587
 
    @param ts_type          type of datetime value (datetime/date/time)
588
 
    @param cuted_increment  whenever we should increase cut fields count or not
589
 
 
590
 
    @note
591
 
      This function will always produce some warning but won't increase cut
592
 
      fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
593
 
      thread.
594
 
  */
595
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
596
 
                            uint32_t code,
597
 
                            const char *str,
598
 
                            uint32_t str_len,
599
 
                            enum enum_drizzle_timestamp_type ts_type,
600
 
                            int cuted_increment);
601
 
  /**
602
 
    Produce warning or note about integer datetime value saved into field.
603
 
 
604
 
    @param level            level of message (Note/Warning/Error)
605
 
    @param code             error code of message to be produced
606
 
    @param nr               numeric value which we tried to save
607
 
    @param ts_type          type of datetime value (datetime/date/time)
608
 
    @param cuted_increment  whenever we should increase cut fields count or not
609
 
 
610
 
    @note
611
 
      This function will always produce some warning but won't increase cut
612
 
      fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
613
 
      thread.
614
 
  */
615
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
616
 
                            uint32_t code,
617
 
                            int64_t nr,
618
 
                            enum enum_drizzle_timestamp_type ts_type,
619
 
                            int cuted_increment);
620
 
  /**
621
 
    Produce warning or note about double datetime data saved into field.
622
 
 
623
 
    @param level            level of message (Note/Warning/Error)
624
 
    @param code             error code of message to be produced
625
 
    @param nr               double value which we tried to save
626
 
    @param ts_type          type of datetime value (datetime/date/time)
627
 
 
628
 
    @note
629
 
      This function will always produce some warning but won't increase cut
630
 
      fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
631
 
      thread.
632
 
  */
633
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
634
 
                            const uint32_t code,
635
 
                            double nr,
636
 
                            enum enum_drizzle_timestamp_type ts_type);
 
457
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, 
 
458
                            const char *str, uint str_len,
 
459
                            timestamp_type ts_type, int cuted_increment);
 
460
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, 
 
461
                            longlong nr, timestamp_type ts_type,
 
462
                            int cuted_increment);
 
463
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code, 
 
464
                            double nr, timestamp_type ts_type);
637
465
  inline bool check_overflow(int op_result)
638
466
  {
639
467
    return (op_result == E_DEC_OVERFLOW);
640
468
  }
641
 
  /**
642
 
    Process decimal library return codes and issue warnings for overflow and
643
 
    truncation.
644
 
 
645
 
    @param op_result  decimal library return code (E_DEC_* see include/decimal.h)
646
 
 
647
 
    @retval
648
 
      E_DEC_OVERFLOW   there was overflow
649
 
      E_DEC_TRUNCATED  there was truncation
650
 
    @retval
651
 
      0  no error or there was some other error except overflow or truncation
652
 
  */
653
469
  int warn_if_overflow(int op_result);
654
 
  void init(Table *table_arg);
 
470
  void init(TABLE *table_arg)
 
471
  {
 
472
    orig_table= table= table_arg;
 
473
    table_name= &table_arg->alias;
 
474
  }
655
475
 
656
476
  /* maximum possible display length */
657
 
  virtual uint32_t max_display_length()= 0;
658
 
 
659
 
  virtual uint32_t is_equal(CreateField *new_field);
660
 
  /**
661
 
    Conversion from decimal to int64_t with checking overflow and
662
 
    setting correct value (min/max) in case of overflow.
663
 
 
664
 
    @param val             value which have to be converted
665
 
    @param unsigned_flag   type of integer in which we convert val
666
 
    @param err             variable to pass error code
667
 
 
668
 
    @return
669
 
      value converted from val
670
 
  */
671
 
  int64_t convert_decimal2int64_t(const my_decimal *val,
672
 
                                  bool unsigned_flag,
673
 
                                  int *err);
 
477
  virtual uint32 max_display_length()= 0;
 
478
 
 
479
  virtual uint is_equal(Create_field *new_field);
 
480
  /* convert decimal to longlong with overflow check */
 
481
  longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
 
482
                                    int *err);
674
483
  /* The max. number of characters */
675
 
  inline uint32_t char_length() const
 
484
  inline uint32 char_length() const
676
485
  {
677
486
    return field_length / charset()->mbmaxlen;
678
487
  }
684
493
  }
685
494
 
686
495
  /* Hash value */
687
 
  virtual void hash(uint32_t *nr, uint32_t *nr2);
688
 
  friend bool reopen_table(Session *,Table *,bool);
689
 
 
690
 
  friend class CopyField;
 
496
  virtual void hash(ulong *nr, ulong *nr2);
 
497
  friend bool reopen_table(THD *,struct st_table *,bool);
 
498
  friend int cre_myisam(char * name, register TABLE *form, uint options,
 
499
                        uint64_t auto_increment_value);
 
500
  friend class Copy_field;
691
501
  friend class Item_avg_field;
692
502
  friend class Item_std_field;
693
503
  friend class Item_sum_num;
700
510
  friend class Item_sum_max;
701
511
  friend class Item_func_group_concat;
702
512
 
703
 
  bool isReadSet();
704
 
  bool isWriteSet();
705
 
  void setReadSet(bool arg= true);
706
 
  void setWriteSet(bool arg= true);
707
 
};
708
 
 
709
 
} /* namespace drizzled */
710
 
 
711
 
/** @TODO Why is this in the middle of the file???*/
712
 
#include "drizzled/create_field.h"
713
 
 
714
 
namespace drizzled
715
 
{
 
513
private:
 
514
  /*
 
515
    Primitive for implementing last_null_byte().
 
516
 
 
517
    SYNOPSIS
 
518
      do_last_null_byte()
 
519
 
 
520
    DESCRIPTION
 
521
      Primitive for the implementation of the last_null_byte()
 
522
      function. This represents the inheritance interface and can be
 
523
      overridden by subclasses.
 
524
   */
 
525
  virtual size_t do_last_null_byte() const;
716
526
 
717
527
/**
718
 
 * A class for sending field information to a client.
719
 
 *
720
 
 * @details
721
 
 *
722
 
 * Send_field is basically a stripped-down POD class for
723
 
 * representing basic information about a field...
724
 
 */
725
 
class SendField
726
 
{
727
 
public:
 
528
   Retrieve the field metadata for fields.
 
529
 
 
530
   This default implementation returns 0 and saves 0 in the metadata_ptr
 
531
   value.
 
532
 
 
533
   @param   metadata_ptr   First byte of field metadata
 
534
 
 
535
   @returns 0 no bytes written.
 
536
*/
 
537
  virtual int do_save_field_metadata(uchar *metadata_ptr __attribute__((__unused__)))
 
538
  { return 0; }
 
539
};
 
540
 
 
541
 
 
542
class Field_num :public Field {
 
543
public:
 
544
  const uint8 dec;
 
545
  bool zerofill,unsigned_flag;  // Purify cannot handle bit fields
 
546
  Field_num(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
 
547
            uchar null_bit_arg, utype unireg_check_arg,
 
548
            const char *field_name_arg,
 
549
            uint8 dec_arg, bool zero_arg, bool unsigned_arg);
 
550
  Item_result result_type () const { return REAL_RESULT; }
 
551
  void prepend_zeros(String *value);
 
552
  void add_zerofill_and_unsigned(String &res) const;
 
553
  friend class Create_field;
 
554
  void make_field(Send_field *);
 
555
  uint decimals() const { return (uint) dec; }
 
556
  uint size_of() const { return sizeof(*this); }
 
557
  bool eq_def(Field *field);
 
558
  int store_decimal(const my_decimal *);
 
559
  my_decimal *val_decimal(my_decimal *);
 
560
  uint is_equal(Create_field *new_field);
 
561
  int check_int(CHARSET_INFO *cs, const char *str, int length,
 
562
                const char *int_end, int error);
 
563
  bool get_int(CHARSET_INFO *cs, const char *from, uint len, 
 
564
               longlong *rnd, uint64_t unsigned_max, 
 
565
               longlong signed_min, longlong signed_max);
 
566
};
 
567
 
 
568
 
 
569
class Field_str :public Field {
 
570
protected:
 
571
  CHARSET_INFO *field_charset;
 
572
  enum Derivation field_derivation;
 
573
public:
 
574
  Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
 
575
            uchar null_bit_arg, utype unireg_check_arg,
 
576
            const char *field_name_arg, CHARSET_INFO *charset);
 
577
  Item_result result_type () const { return STRING_RESULT; }
 
578
  uint decimals() const { return NOT_FIXED_DEC; }
 
579
  int  store(double nr);
 
580
  int  store(longlong nr, bool unsigned_val)=0;
 
581
  int  store_decimal(const my_decimal *);
 
582
  int  store(const char *to,uint length,CHARSET_INFO *cs)=0;
 
583
  uint size_of() const { return sizeof(*this); }
 
584
  CHARSET_INFO *charset(void) const { return field_charset; }
 
585
  void set_charset(CHARSET_INFO *charset_arg) { field_charset= charset_arg; }
 
586
  enum Derivation derivation(void) const { return field_derivation; }
 
587
  virtual void set_derivation(enum Derivation derivation_arg)
 
588
  { field_derivation= derivation_arg; }
 
589
  bool binary() const { return field_charset == &my_charset_bin; }
 
590
  uint32 max_display_length() { return field_length; }
 
591
  friend class Create_field;
 
592
  my_decimal *val_decimal(my_decimal *);
 
593
  virtual bool str_needs_quotes() { return true; }
 
594
  bool compare_str_field_flags(Create_field *new_field, uint32 flags);
 
595
  uint is_equal(Create_field *new_field);
 
596
};
 
597
 
 
598
 
 
599
/* base class for Field_string, Field_varstring and Field_blob */
 
600
 
 
601
class Field_longstr :public Field_str
 
602
{
 
603
protected:
 
604
  int report_if_important_data(const char *ptr, const char *end);
 
605
public:
 
606
  Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
607
                uchar null_bit_arg, utype unireg_check_arg,
 
608
                const char *field_name_arg, CHARSET_INFO *charset_arg)
 
609
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
 
610
               field_name_arg, charset_arg)
 
611
    {}
 
612
 
 
613
  int store_decimal(const my_decimal *d);
 
614
  uint32 max_data_length() const;
 
615
};
 
616
 
 
617
/* base class for float and double and decimal (old one) */
 
618
class Field_real :public Field_num {
 
619
public:
 
620
  my_bool not_fixed;
 
621
 
 
622
  Field_real(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
623
             uchar null_bit_arg, utype unireg_check_arg,
 
624
             const char *field_name_arg,
 
625
             uint8 dec_arg, bool zero_arg, bool unsigned_arg)
 
626
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
 
627
               field_name_arg, dec_arg, zero_arg, unsigned_arg),
 
628
    not_fixed(dec_arg >= NOT_FIXED_DEC)
 
629
    {}
 
630
  int store_decimal(const my_decimal *);
 
631
  my_decimal *val_decimal(my_decimal *);
 
632
  int truncate(double *nr, double max_length);
 
633
  uint32 max_display_length() { return field_length; }
 
634
  uint size_of() const { return sizeof(*this); }
 
635
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
636
                              uint param_data, bool low_byte_first);
 
637
  virtual uchar *pack(uchar* to, const uchar *from,
 
638
                      uint max_length, bool low_byte_first);
 
639
};
 
640
 
 
641
 
 
642
/* New decimal/numeric field which use fixed point arithmetic */
 
643
class Field_new_decimal :public Field_num {
 
644
private:
 
645
  int do_save_field_metadata(uchar *first_byte);
 
646
public:
 
647
  /* The maximum number of decimal digits can be stored */
 
648
  uint precision;
 
649
  uint bin_size;
 
650
  /*
 
651
    Constructors take max_length of the field as a parameter - not the
 
652
    precision as the number of decimal digits allowed.
 
653
    So for example we need to count length from precision handling
 
654
    CREATE TABLE ( DECIMAL(x,y)) 
 
655
  */
 
656
  Field_new_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
657
                    uchar null_bit_arg,
 
658
                    enum utype unireg_check_arg, const char *field_name_arg,
 
659
                    uint8 dec_arg, bool zero_arg, bool unsigned_arg);
 
660
  Field_new_decimal(uint32 len_arg, bool maybe_null_arg,
 
661
                    const char *field_name_arg, uint8 dec_arg,
 
662
                    bool unsigned_arg);
 
663
  enum_field_types type() const { return MYSQL_TYPE_NEWDECIMAL;}
 
664
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
 
665
  Item_result result_type () const { return DECIMAL_RESULT; }
 
666
  int  reset(void);
 
667
  bool store_value(const my_decimal *decimal_value);
 
668
  void set_value_on_overflow(my_decimal *decimal_value, bool sign);
 
669
  int  store(const char *to, uint length, CHARSET_INFO *charset);
 
670
  int  store(double nr);
 
671
  int  store(longlong nr, bool unsigned_val);
 
672
  int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
 
673
  int  store_decimal(const my_decimal *);
 
674
  double val_real(void);
 
675
  longlong val_int(void);
 
676
  my_decimal *val_decimal(my_decimal *);
 
677
  String *val_str(String*, String *);
 
678
  int cmp(const uchar *, const uchar *);
 
679
  void sort_string(uchar *buff, uint length);
 
680
  bool zero_pack() const { return 0; }
 
681
  void sql_type(String &str) const;
 
682
  uint32 max_display_length() { return field_length; }
 
683
  uint size_of() const { return sizeof(*this); } 
 
684
  uint32 pack_length() const { return (uint32) bin_size; }
 
685
  uint pack_length_from_metadata(uint field_metadata);
 
686
  uint row_pack_length() { return pack_length(); }
 
687
  int compatible_field_size(uint field_metadata);
 
688
  uint is_equal(Create_field *new_field);
 
689
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
690
                              uint param_data, bool low_byte_first);
 
691
};
 
692
 
 
693
 
 
694
class Field_tiny :public Field_num {
 
695
public:
 
696
  Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
697
             uchar null_bit_arg,
 
698
             enum utype unireg_check_arg, const char *field_name_arg,
 
699
             bool zero_arg, bool unsigned_arg)
 
700
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
701
               unireg_check_arg, field_name_arg,
 
702
               0, zero_arg,unsigned_arg)
 
703
    {}
 
704
  enum Item_result result_type () const { return INT_RESULT; }
 
705
  enum_field_types type() const { return MYSQL_TYPE_TINY;}
 
706
  enum ha_base_keytype key_type() const
 
707
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
 
708
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
709
  int store(double nr);
 
710
  int store(longlong nr, bool unsigned_val);
 
711
  int reset(void) { ptr[0]=0; return 0; }
 
712
  double val_real(void);
 
713
  longlong val_int(void);
 
714
  String *val_str(String*,String *);
 
715
  bool send_binary(Protocol *protocol);
 
716
  int cmp(const uchar *,const uchar *);
 
717
  void sort_string(uchar *buff,uint length);
 
718
  uint32 pack_length() const { return 1; }
 
719
  void sql_type(String &str) const;
 
720
  uint32 max_display_length() { return 4; }
 
721
 
 
722
  virtual uchar *pack(uchar* to, const uchar *from,
 
723
                      uint max_length __attribute__((__unused__)),
 
724
                      bool low_byte_first __attribute__((__unused__)))
 
725
  {
 
726
    *to= *from;
 
727
    return to + 1;
 
728
  }
 
729
 
 
730
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
731
                              uint param_data __attribute__((__unused__)),
 
732
                              bool low_byte_first __attribute__((__unused__)))
 
733
  {
 
734
    *to= *from;
 
735
    return from + 1;
 
736
  }
 
737
};
 
738
 
 
739
 
 
740
class Field_short :public Field_num {
 
741
public:
 
742
  Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
743
              uchar null_bit_arg,
 
744
              enum utype unireg_check_arg, const char *field_name_arg,
 
745
              bool zero_arg, bool unsigned_arg)
 
746
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
747
               unireg_check_arg, field_name_arg,
 
748
               0, zero_arg,unsigned_arg)
 
749
    {}
 
750
  Field_short(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
 
751
              bool unsigned_arg)
 
752
    :Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
 
753
               NONE, field_name_arg, 0, 0, unsigned_arg)
 
754
    {}
 
755
  enum Item_result result_type () const { return INT_RESULT; }
 
756
  enum_field_types type() const { return MYSQL_TYPE_SHORT;}
 
757
  enum ha_base_keytype key_type() const
 
758
    { return unsigned_flag ? HA_KEYTYPE_USHORT_INT : HA_KEYTYPE_SHORT_INT;}
 
759
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
760
  int store(double nr);
 
761
  int store(longlong nr, bool unsigned_val);
 
762
  int reset(void) { ptr[0]=ptr[1]=0; return 0; }
 
763
  double val_real(void);
 
764
  longlong val_int(void);
 
765
  String *val_str(String*,String *);
 
766
  bool send_binary(Protocol *protocol);
 
767
  int cmp(const uchar *,const uchar *);
 
768
  void sort_string(uchar *buff,uint length);
 
769
  uint32 pack_length() const { return 2; }
 
770
  void sql_type(String &str) const;
 
771
  uint32 max_display_length() { return 6; }
 
772
 
 
773
  virtual uchar *pack(uchar* to, const uchar *from,
 
774
                      uint max_length __attribute__((__unused__)),
 
775
                      bool low_byte_first __attribute__((__unused__)))
 
776
  {
 
777
    int16 val;
 
778
#ifdef WORDS_BIGENDIAN
 
779
    if (table->s->db_low_byte_first)
 
780
      val = sint2korr(from);
 
781
    else
 
782
#endif
 
783
      shortget(val, from);
 
784
 
 
785
#ifdef WORDS_BIGENDIAN
 
786
    if (low_byte_first)
 
787
      int2store(to, val);
 
788
    else
 
789
#endif
 
790
      shortstore(to, val);
 
791
    return to + sizeof(val);
 
792
  }
 
793
 
 
794
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
795
                              uint param_data __attribute__((__unused__)),
 
796
                              bool low_byte_first __attribute__((__unused__)))
 
797
  {
 
798
    int16 val;
 
799
#ifdef WORDS_BIGENDIAN
 
800
    if (low_byte_first)
 
801
      val = sint2korr(from);
 
802
    else
 
803
#endif
 
804
      shortget(val, from);
 
805
 
 
806
#ifdef WORDS_BIGENDIAN
 
807
    if (table->s->db_low_byte_first)
 
808
      int2store(to, val);
 
809
    else
 
810
#endif
 
811
      shortstore(to, val);
 
812
    return from + sizeof(val);
 
813
  }
 
814
};
 
815
 
 
816
class Field_long :public Field_num {
 
817
public:
 
818
  Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
819
             uchar null_bit_arg,
 
820
             enum utype unireg_check_arg, const char *field_name_arg,
 
821
             bool zero_arg, bool unsigned_arg)
 
822
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
823
               unireg_check_arg, field_name_arg,
 
824
               0, zero_arg,unsigned_arg)
 
825
    {}
 
826
  Field_long(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
 
827
             bool unsigned_arg)
 
828
    :Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
 
829
               NONE, field_name_arg,0,0,unsigned_arg)
 
830
    {}
 
831
  enum Item_result result_type () const { return INT_RESULT; }
 
832
  enum_field_types type() const { return MYSQL_TYPE_LONG;}
 
833
  enum ha_base_keytype key_type() const
 
834
    { return unsigned_flag ? HA_KEYTYPE_ULONG_INT : HA_KEYTYPE_LONG_INT; }
 
835
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
836
  int store(double nr);
 
837
  int store(longlong nr, bool unsigned_val);
 
838
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
 
839
  double val_real(void);
 
840
  longlong val_int(void);
 
841
  bool send_binary(Protocol *protocol);
 
842
  String *val_str(String*,String *);
 
843
  int cmp(const uchar *,const uchar *);
 
844
  void sort_string(uchar *buff,uint length);
 
845
  uint32 pack_length() const { return 4; }
 
846
  void sql_type(String &str) const;
 
847
  uint32 max_display_length() { return MY_INT32_NUM_DECIMAL_DIGITS; }
 
848
  virtual uchar *pack(uchar* to, const uchar *from,
 
849
                      uint max_length __attribute__((__unused__)),
 
850
                      bool low_byte_first __attribute__((__unused__)))
 
851
  {
 
852
    int32 val;
 
853
#ifdef WORDS_BIGENDIAN
 
854
    if (table->s->db_low_byte_first)
 
855
      val = sint4korr(from);
 
856
    else
 
857
#endif
 
858
      longget(val, from);
 
859
 
 
860
#ifdef WORDS_BIGENDIAN
 
861
    if (low_byte_first)
 
862
      int4store(to, val);
 
863
    else
 
864
#endif
 
865
      longstore(to, val);
 
866
    return to + sizeof(val);
 
867
  }
 
868
 
 
869
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
870
                              uint param_data __attribute__((__unused__)),
 
871
                              bool low_byte_first __attribute__((__unused__)))
 
872
  {
 
873
    int32 val;
 
874
#ifdef WORDS_BIGENDIAN
 
875
    if (low_byte_first)
 
876
      val = sint4korr(from);
 
877
    else
 
878
#endif
 
879
      longget(val, from);
 
880
 
 
881
#ifdef WORDS_BIGENDIAN
 
882
    if (table->s->db_low_byte_first)
 
883
      int4store(to, val);
 
884
    else
 
885
#endif
 
886
      longstore(to, val);
 
887
    return from + sizeof(val);
 
888
  }
 
889
};
 
890
 
 
891
 
 
892
class Field_longlong :public Field_num {
 
893
public:
 
894
  Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
895
              uchar null_bit_arg,
 
896
              enum utype unireg_check_arg, const char *field_name_arg,
 
897
              bool zero_arg, bool unsigned_arg)
 
898
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
899
               unireg_check_arg, field_name_arg,
 
900
               0, zero_arg,unsigned_arg)
 
901
    {}
 
902
  Field_longlong(uint32 len_arg,bool maybe_null_arg,
 
903
                 const char *field_name_arg,
 
904
                  bool unsigned_arg)
 
905
    :Field_num((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0,0,
 
906
               NONE, field_name_arg,0,0,unsigned_arg)
 
907
    {}
 
908
  enum Item_result result_type () const { return INT_RESULT; }
 
909
  enum_field_types type() const { return MYSQL_TYPE_LONGLONG;}
 
910
  enum ha_base_keytype key_type() const
 
911
    { return unsigned_flag ? HA_KEYTYPE_ULONGLONG : HA_KEYTYPE_LONGLONG; }
 
912
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
913
  int store(double nr);
 
914
  int store(longlong nr, bool unsigned_val);
 
915
  int reset(void)
 
916
  {
 
917
    ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
 
918
    return 0;
 
919
  }
 
920
  double val_real(void);
 
921
  longlong val_int(void);
 
922
  String *val_str(String*,String *);
 
923
  bool send_binary(Protocol *protocol);
 
924
  int cmp(const uchar *,const uchar *);
 
925
  void sort_string(uchar *buff,uint length);
 
926
  uint32 pack_length() const { return 8; }
 
927
  void sql_type(String &str) const;
 
928
  bool can_be_compared_as_longlong() const { return true; }
 
929
  uint32 max_display_length() { return 20; }
 
930
  virtual uchar *pack(uchar* to, const uchar *from,
 
931
                      uint max_length __attribute__((__unused__)),
 
932
                      bool low_byte_first __attribute__((__unused__)))
 
933
  {
 
934
    int64 val;
 
935
#ifdef WORDS_BIGENDIAN
 
936
    if (table->s->db_low_byte_first)
 
937
      val = sint8korr(from);
 
938
    else
 
939
#endif
 
940
      longlongget(val, from);
 
941
 
 
942
#ifdef WORDS_BIGENDIAN
 
943
    if (low_byte_first)
 
944
      int8store(to, val);
 
945
    else
 
946
#endif
 
947
      longlongstore(to, val);
 
948
    return to + sizeof(val);
 
949
  }
 
950
 
 
951
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
952
                              uint param_data __attribute__((__unused__)),
 
953
                              bool low_byte_first __attribute__((__unused__)))
 
954
  {
 
955
    int64 val;
 
956
#ifdef WORDS_BIGENDIAN
 
957
    if (low_byte_first)
 
958
      val = sint8korr(from);
 
959
    else
 
960
#endif
 
961
      longlongget(val, from);
 
962
 
 
963
#ifdef WORDS_BIGENDIAN
 
964
    if (table->s->db_low_byte_first)
 
965
      int8store(to, val);
 
966
    else
 
967
#endif
 
968
      longlongstore(to, val);
 
969
    return from + sizeof(val);
 
970
  }
 
971
};
 
972
 
 
973
class Field_float :public Field_real {
 
974
public:
 
975
  Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
976
              uchar null_bit_arg,
 
977
              enum utype unireg_check_arg, const char *field_name_arg,
 
978
              uint8 dec_arg,bool zero_arg,bool unsigned_arg)
 
979
    :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
980
                unireg_check_arg, field_name_arg,
 
981
                dec_arg, zero_arg, unsigned_arg)
 
982
    {}
 
983
  Field_float(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
 
984
              uint8 dec_arg)
 
985
    :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, (uint) 0,
 
986
                NONE, field_name_arg, dec_arg, 0, 0)
 
987
    {}
 
988
  enum_field_types type() const { return MYSQL_TYPE_FLOAT;}
 
989
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_FLOAT; }
 
990
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
991
  int store(double nr);
 
992
  int store(longlong nr, bool unsigned_val);
 
993
  int reset(void) { bzero(ptr,sizeof(float)); return 0; }
 
994
  double val_real(void);
 
995
  longlong val_int(void);
 
996
  String *val_str(String*,String *);
 
997
  bool send_binary(Protocol *protocol);
 
998
  int cmp(const uchar *,const uchar *);
 
999
  void sort_string(uchar *buff,uint length);
 
1000
  uint32 pack_length() const { return sizeof(float); }
 
1001
  uint row_pack_length() { return pack_length(); }
 
1002
  void sql_type(String &str) const;
 
1003
private:
 
1004
  int do_save_field_metadata(uchar *first_byte);
 
1005
};
 
1006
 
 
1007
 
 
1008
class Field_double :public Field_real {
 
1009
public:
 
1010
  Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
1011
               uchar null_bit_arg,
 
1012
               enum utype unireg_check_arg, const char *field_name_arg,
 
1013
               uint8 dec_arg,bool zero_arg,bool unsigned_arg)
 
1014
    :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1015
                unireg_check_arg, field_name_arg,
 
1016
                dec_arg, zero_arg, unsigned_arg)
 
1017
    {}
 
1018
  Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
 
1019
               uint8 dec_arg)
 
1020
    :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
 
1021
                NONE, field_name_arg, dec_arg, 0, 0)
 
1022
    {}
 
1023
  Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
 
1024
               uint8 dec_arg, my_bool not_fixed_arg)
 
1025
    :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
 
1026
                NONE, field_name_arg, dec_arg, 0, 0)
 
1027
    {not_fixed= not_fixed_arg; }
 
1028
  enum_field_types type() const { return MYSQL_TYPE_DOUBLE;}
 
1029
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
 
1030
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1031
  int  store(double nr);
 
1032
  int  store(longlong nr, bool unsigned_val);
 
1033
  int reset(void) { bzero(ptr,sizeof(double)); return 0; }
 
1034
  double val_real(void);
 
1035
  longlong val_int(void);
 
1036
  String *val_str(String*,String *);
 
1037
  bool send_binary(Protocol *protocol);
 
1038
  int cmp(const uchar *,const uchar *);
 
1039
  void sort_string(uchar *buff,uint length);
 
1040
  uint32 pack_length() const { return sizeof(double); }
 
1041
  uint row_pack_length() { return pack_length(); }
 
1042
  void sql_type(String &str) const;
 
1043
private:
 
1044
  int do_save_field_metadata(uchar *first_byte);
 
1045
};
 
1046
 
 
1047
 
 
1048
/* Everything saved in this will disappear. It will always return NULL */
 
1049
 
 
1050
class Field_null :public Field_str {
 
1051
  static uchar null[1];
 
1052
public:
 
1053
  Field_null(uchar *ptr_arg, uint32 len_arg,
 
1054
             enum utype unireg_check_arg, const char *field_name_arg,
 
1055
             CHARSET_INFO *cs)
 
1056
    :Field_str(ptr_arg, len_arg, null, 1,
 
1057
               unireg_check_arg, field_name_arg, cs)
 
1058
    {}
 
1059
  enum_field_types type() const { return MYSQL_TYPE_NULL;}
 
1060
  int  store(const char *to __attribute__((__unused__)),
 
1061
             uint length __attribute__((__unused__)),
 
1062
             CHARSET_INFO *cs __attribute__((__unused__)))
 
1063
  { null[0]=1; return 0; }
 
1064
  int store(double nr __attribute__((__unused__)))
 
1065
  { null[0]=1; return 0; }
 
1066
  int store(longlong nr __attribute__((__unused__)),
 
1067
            bool unsigned_val __attribute__((__unused__)))
 
1068
  { null[0]=1; return 0; }
 
1069
  int store_decimal(const my_decimal *d __attribute__((__unused__)))
 
1070
  { null[0]=1; return 0; }
 
1071
  int reset(void)
 
1072
  { return 0; }
 
1073
  double val_real(void)
 
1074
  { return 0.0;}
 
1075
  longlong val_int(void)
 
1076
  { return 0;}
 
1077
  my_decimal *val_decimal(my_decimal *) { return 0; }
 
1078
  String *val_str(String *value __attribute__((__unused__)),
 
1079
                  String *value2)
 
1080
  { value2->length(0); return value2;}
 
1081
  int cmp(const uchar *a __attribute__((__unused__)),
 
1082
          const uchar *b __attribute__((__unused__))) { return 0;}
 
1083
  void sort_string(uchar *buff __attribute__((__unused__)),
 
1084
                   uint length __attribute__((__unused__)))  {}
 
1085
  uint32 pack_length() const { return 0; }
 
1086
  void sql_type(String &str) const;
 
1087
  uint size_of() const { return sizeof(*this); }
 
1088
  uint32 max_display_length() { return 4; }
 
1089
};
 
1090
 
 
1091
 
 
1092
class Field_timestamp :public Field_str {
 
1093
public:
 
1094
  Field_timestamp(uchar *ptr_arg, uint32 len_arg,
 
1095
                  uchar *null_ptr_arg, uchar null_bit_arg,
 
1096
                  enum utype unireg_check_arg, const char *field_name_arg,
 
1097
                  TABLE_SHARE *share, CHARSET_INFO *cs);
 
1098
  Field_timestamp(bool maybe_null_arg, const char *field_name_arg,
 
1099
                  CHARSET_INFO *cs);
 
1100
  enum_field_types type() const { return MYSQL_TYPE_TIMESTAMP;}
 
1101
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
 
1102
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1103
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1104
  int  store(double nr);
 
1105
  int  store(longlong nr, bool unsigned_val);
 
1106
  int  reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
 
1107
  double val_real(void);
 
1108
  longlong val_int(void);
 
1109
  String *val_str(String*,String *);
 
1110
  bool send_binary(Protocol *protocol);
 
1111
  int cmp(const uchar *,const uchar *);
 
1112
  void sort_string(uchar *buff,uint length);
 
1113
  uint32 pack_length() const { return 4; }
 
1114
  void sql_type(String &str) const;
 
1115
  bool can_be_compared_as_longlong() const { return true; }
 
1116
  bool zero_pack() const { return 0; }
 
1117
  void set_time();
 
1118
  virtual void set_default()
 
1119
  {
 
1120
    if (table->timestamp_field == this &&
 
1121
        unireg_check != TIMESTAMP_UN_FIELD)
 
1122
      set_time();
 
1123
    else
 
1124
      Field::set_default();
 
1125
  }
 
1126
  /* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
 
1127
  inline long get_timestamp(my_bool *null_value)
 
1128
  {
 
1129
    if ((*null_value= is_null()))
 
1130
      return 0;
 
1131
#ifdef WORDS_BIGENDIAN
 
1132
    if (table && table->s->db_low_byte_first)
 
1133
      return sint4korr(ptr);
 
1134
#endif
 
1135
    long tmp;
 
1136
    longget(tmp,ptr);
 
1137
    return tmp;
 
1138
  }
 
1139
  inline void store_timestamp(my_time_t timestamp)
 
1140
  {
 
1141
#ifdef WORDS_BIGENDIAN
 
1142
    if (table && table->s->db_low_byte_first)
 
1143
    {
 
1144
      int4store(ptr,timestamp);
 
1145
    }
 
1146
    else
 
1147
#endif
 
1148
      longstore(ptr,(uint32) timestamp);
 
1149
  }
 
1150
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
1151
  bool get_time(MYSQL_TIME *ltime);
 
1152
  timestamp_auto_set_type get_auto_set_type() const;
 
1153
};
 
1154
 
 
1155
 
 
1156
class Field_year :public Field_tiny {
 
1157
public:
 
1158
  Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
1159
             uchar null_bit_arg,
 
1160
             enum utype unireg_check_arg, const char *field_name_arg)
 
1161
    :Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1162
                unireg_check_arg, field_name_arg, 1, 1)
 
1163
    {}
 
1164
  enum_field_types type() const { return MYSQL_TYPE_YEAR;}
 
1165
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1166
  int  store(double nr);
 
1167
  int  store(longlong nr, bool unsigned_val);
 
1168
  double val_real(void);
 
1169
  longlong val_int(void);
 
1170
  String *val_str(String*,String *);
 
1171
  bool send_binary(Protocol *protocol);
 
1172
  void sql_type(String &str) const;
 
1173
  bool can_be_compared_as_longlong() const { return true; }
 
1174
};
 
1175
 
 
1176
 
 
1177
class Field_newdate :public Field_str {
 
1178
public:
 
1179
  Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
 
1180
                enum utype unireg_check_arg, const char *field_name_arg,
 
1181
                CHARSET_INFO *cs)
 
1182
    :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
 
1183
               unireg_check_arg, field_name_arg, cs)
 
1184
    {}
 
1185
  Field_newdate(bool maybe_null_arg, const char *field_name_arg,
 
1186
                CHARSET_INFO *cs)
 
1187
    :Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
 
1188
               NONE, field_name_arg, cs) {}
 
1189
  enum_field_types type() const { return MYSQL_TYPE_NEWDATE;}
 
1190
  enum_field_types real_type() const { return MYSQL_TYPE_NEWDATE; }
 
1191
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; }
 
1192
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1193
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1194
  int  store(double nr);
 
1195
  int  store(longlong nr, bool unsigned_val);
 
1196
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
 
1197
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
 
1198
  double val_real(void);
 
1199
  longlong val_int(void);
 
1200
  String *val_str(String*,String *);
 
1201
  bool send_binary(Protocol *protocol);
 
1202
  int cmp(const uchar *,const uchar *);
 
1203
  void sort_string(uchar *buff,uint length);
 
1204
  uint32 pack_length() const { return 3; }
 
1205
  void sql_type(String &str) const;
 
1206
  bool can_be_compared_as_longlong() const { return true; }
 
1207
  bool zero_pack() const { return 1; }
 
1208
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
1209
  bool get_time(MYSQL_TIME *ltime);
 
1210
};
 
1211
 
 
1212
 
 
1213
class Field_time :public Field_str {
 
1214
public:
 
1215
  Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
 
1216
             enum utype unireg_check_arg, const char *field_name_arg,
 
1217
             CHARSET_INFO *cs)
 
1218
    :Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
 
1219
               unireg_check_arg, field_name_arg, cs)
 
1220
    {}
 
1221
  Field_time(bool maybe_null_arg, const char *field_name_arg,
 
1222
             CHARSET_INFO *cs)
 
1223
    :Field_str((uchar*) 0,8, maybe_null_arg ? (uchar*) "": 0,0,
 
1224
               NONE, field_name_arg, cs) {}
 
1225
  enum_field_types type() const { return MYSQL_TYPE_TIME;}
 
1226
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
 
1227
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1228
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
 
1229
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
1230
  int store(double nr);
 
1231
  int store(longlong nr, bool unsigned_val);
 
1232
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
 
1233
  double val_real(void);
 
1234
  longlong val_int(void);
 
1235
  String *val_str(String*,String *);
 
1236
  bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
 
1237
  bool send_binary(Protocol *protocol);
 
1238
  bool get_time(MYSQL_TIME *ltime);
 
1239
  int cmp(const uchar *,const uchar *);
 
1240
  void sort_string(uchar *buff,uint length);
 
1241
  uint32 pack_length() const { return 3; }
 
1242
  void sql_type(String &str) const;
 
1243
  bool can_be_compared_as_longlong() const { return true; }
 
1244
  bool zero_pack() const { return 1; }
 
1245
};
 
1246
 
 
1247
 
 
1248
class Field_datetime :public Field_str {
 
1249
public:
 
1250
  Field_datetime(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
 
1251
                 enum utype unireg_check_arg, const char *field_name_arg,
 
1252
                 CHARSET_INFO *cs)
 
1253
    :Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
 
1254
               unireg_check_arg, field_name_arg, cs)
 
1255
    {}
 
1256
  Field_datetime(bool maybe_null_arg, const char *field_name_arg,
 
1257
                 CHARSET_INFO *cs)
 
1258
    :Field_str((uchar*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
 
1259
               NONE, field_name_arg, cs) {}
 
1260
  enum_field_types type() const { return MYSQL_TYPE_DATETIME;}
 
1261
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
 
1262
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1263
  uint decimals() const { return DATETIME_DEC; }
 
1264
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1265
  int  store(double nr);
 
1266
  int  store(longlong nr, bool unsigned_val);
 
1267
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
 
1268
  int reset(void)
 
1269
  {
 
1270
    ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
 
1271
    return 0;
 
1272
  }
 
1273
  double val_real(void);
 
1274
  longlong val_int(void);
 
1275
  String *val_str(String*,String *);
 
1276
  bool send_binary(Protocol *protocol);
 
1277
  int cmp(const uchar *,const uchar *);
 
1278
  void sort_string(uchar *buff,uint length);
 
1279
  uint32 pack_length() const { return 8; }
 
1280
  void sql_type(String &str) const;
 
1281
  bool can_be_compared_as_longlong() const { return true; }
 
1282
  bool zero_pack() const { return 1; }
 
1283
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
1284
  bool get_time(MYSQL_TIME *ltime);
 
1285
};
 
1286
 
 
1287
 
 
1288
class Field_string :public Field_longstr {
 
1289
public:
 
1290
  bool can_alter_field_type;
 
1291
  Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
 
1292
               uchar null_bit_arg,
 
1293
               enum utype unireg_check_arg, const char *field_name_arg,
 
1294
               CHARSET_INFO *cs)
 
1295
    :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1296
                   unireg_check_arg, field_name_arg, cs),
 
1297
     can_alter_field_type(1) {};
 
1298
  Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
 
1299
               CHARSET_INFO *cs)
 
1300
    :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
1301
                   NONE, field_name_arg, cs),
 
1302
     can_alter_field_type(1) {};
 
1303
 
 
1304
  enum_field_types type() const
 
1305
  {
 
1306
    return  MYSQL_TYPE_STRING;
 
1307
  }
 
1308
  enum ha_base_keytype key_type() const
 
1309
    { return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
 
1310
  bool zero_pack() const { return 0; }
 
1311
  int reset(void)
 
1312
  {
 
1313
    charset()->cset->fill(charset(),(char*) ptr, field_length,
 
1314
                          (has_charset() ? ' ' : 0));
 
1315
    return 0;
 
1316
  }
 
1317
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
1318
  int store(longlong nr, bool unsigned_val);
 
1319
  int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
 
1320
  double val_real(void);
 
1321
  longlong val_int(void);
 
1322
  String *val_str(String*,String *);
 
1323
  my_decimal *val_decimal(my_decimal *);
 
1324
  int cmp(const uchar *,const uchar *);
 
1325
  void sort_string(uchar *buff,uint length);
 
1326
  void sql_type(String &str) const;
 
1327
  virtual uchar *pack(uchar *to, const uchar *from,
 
1328
                      uint max_length, bool low_byte_first);
 
1329
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
1330
                              uint param_data, bool low_byte_first);
 
1331
  uint pack_length_from_metadata(uint field_metadata)
 
1332
  { return (field_metadata & 0x00ff); }
 
1333
  uint row_pack_length() { return (field_length + 1); }
 
1334
  int pack_cmp(const uchar *a,const uchar *b,uint key_length,
 
1335
               my_bool insert_or_update);
 
1336
  int pack_cmp(const uchar *b,uint key_length,my_bool insert_or_update);
 
1337
  uint packed_col_length(const uchar *to, uint length);
 
1338
  uint max_packed_col_length(uint max_length);
 
1339
  uint size_of() const { return sizeof(*this); }
 
1340
  enum_field_types real_type() const { return MYSQL_TYPE_STRING; }
 
1341
  bool has_charset(void) const
 
1342
  { return charset() == &my_charset_bin ? false : true; }
 
1343
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
 
1344
  virtual uint get_key_image(uchar *buff,uint length, imagetype type);
 
1345
private:
 
1346
  int do_save_field_metadata(uchar *first_byte);
 
1347
};
 
1348
 
 
1349
 
 
1350
class Field_varstring :public Field_longstr {
 
1351
public:
 
1352
  /*
 
1353
    The maximum space available in a Field_varstring, in bytes. See
 
1354
    length_bytes.
 
1355
  */
 
1356
  static const uint MAX_SIZE;
 
1357
  /* Store number of bytes used to store length (1 or 2) */
 
1358
  uint32 length_bytes;
 
1359
  Field_varstring(uchar *ptr_arg,
 
1360
                  uint32 len_arg, uint length_bytes_arg,
 
1361
                  uchar *null_ptr_arg, uchar null_bit_arg,
 
1362
                  enum utype unireg_check_arg, const char *field_name_arg,
 
1363
                  TABLE_SHARE *share, CHARSET_INFO *cs)
 
1364
    :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1365
                   unireg_check_arg, field_name_arg, cs),
 
1366
     length_bytes(length_bytes_arg)
 
1367
  {
 
1368
    share->varchar_fields++;
 
1369
  }
 
1370
  Field_varstring(uint32 len_arg,bool maybe_null_arg,
 
1371
                  const char *field_name_arg,
 
1372
                  TABLE_SHARE *share, CHARSET_INFO *cs)
 
1373
    :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
1374
                   NONE, field_name_arg, cs),
 
1375
     length_bytes(len_arg < 256 ? 1 :2)
 
1376
  {
 
1377
    share->varchar_fields++;
 
1378
  }
 
1379
 
 
1380
  enum_field_types type() const { return MYSQL_TYPE_VARCHAR; }
 
1381
  enum ha_base_keytype key_type() const;
 
1382
  uint row_pack_length() { return field_length; }
 
1383
  bool zero_pack() const { return 0; }
 
1384
  int  reset(void) { bzero(ptr,field_length+length_bytes); return 0; }
 
1385
  uint32 pack_length() const { return (uint32) field_length+length_bytes; }
 
1386
  uint32 key_length() const { return (uint32) field_length; }
 
1387
  uint32 sort_length() const
 
1388
  {
 
1389
    return (uint32) field_length + (field_charset == &my_charset_bin ?
 
1390
                                    length_bytes : 0);
 
1391
  }
 
1392
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1393
  int  store(longlong nr, bool unsigned_val);
 
1394
  int  store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
 
1395
  double val_real(void);
 
1396
  longlong val_int(void);
 
1397
  String *val_str(String*,String *);
 
1398
  my_decimal *val_decimal(my_decimal *);
 
1399
  int cmp_max(const uchar *, const uchar *, uint max_length);
 
1400
  int cmp(const uchar *a,const uchar *b)
 
1401
  {
 
1402
    return cmp_max(a, b, ~0L);
 
1403
  }
 
1404
  void sort_string(uchar *buff,uint length);
 
1405
  uint get_key_image(uchar *buff,uint length, imagetype type);
 
1406
  void set_key_image(const uchar *buff,uint length);
 
1407
  void sql_type(String &str) const;
 
1408
  virtual uchar *pack(uchar *to, const uchar *from,
 
1409
                      uint max_length, bool low_byte_first);
 
1410
  uchar *pack_key(uchar *to, const uchar *from, uint max_length, bool low_byte_first);
 
1411
  uchar *pack_key_from_key_image(uchar* to, const uchar *from,
 
1412
                                 uint max_length, bool low_byte_first);
 
1413
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
1414
                              uint param_data, bool low_byte_first);
 
1415
  const uchar *unpack_key(uchar* to, const uchar *from,
 
1416
                          uint max_length, bool low_byte_first);
 
1417
  int pack_cmp(const uchar *a, const uchar *b, uint key_length,
 
1418
               my_bool insert_or_update);
 
1419
  int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
 
1420
  int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
 
1421
  int key_cmp(const uchar *,const uchar*);
 
1422
  int key_cmp(const uchar *str, uint length);
 
1423
  uint packed_col_length(const uchar *to, uint length);
 
1424
  uint max_packed_col_length(uint max_length);
 
1425
  uint32 data_length();
 
1426
  uint32 used_length();
 
1427
  uint size_of() const { return sizeof(*this); }
 
1428
  enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
 
1429
  bool has_charset(void) const
 
1430
  { return charset() == &my_charset_bin ? false : true; }
 
1431
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
 
1432
  Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
 
1433
                       uchar *new_ptr, uchar *new_null_ptr,
 
1434
                       uint new_null_bit);
 
1435
  uint is_equal(Create_field *new_field);
 
1436
  void hash(ulong *nr, ulong *nr2);
 
1437
private:
 
1438
  int do_save_field_metadata(uchar *first_byte);
 
1439
};
 
1440
 
 
1441
 
 
1442
class Field_blob :public Field_longstr {
 
1443
protected:
 
1444
  uint packlength;
 
1445
  String value;                         // For temporaries
 
1446
public:
 
1447
  Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
 
1448
             enum utype unireg_check_arg, const char *field_name_arg,
 
1449
             TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs);
 
1450
  Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
 
1451
             CHARSET_INFO *cs)
 
1452
    :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
1453
                   NONE, field_name_arg, cs),
 
1454
    packlength(4)
 
1455
  {
 
1456
    flags|= BLOB_FLAG;
 
1457
  }
 
1458
  Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
 
1459
             CHARSET_INFO *cs, bool set_packlength)
 
1460
    :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
1461
                   NONE, field_name_arg, cs)
 
1462
  {
 
1463
    flags|= BLOB_FLAG;
 
1464
    packlength= 4;
 
1465
    if (set_packlength)
 
1466
    {
 
1467
      uint32 l_char_length= len_arg/cs->mbmaxlen;
 
1468
      packlength= l_char_length <= 255 ? 1 :
 
1469
                  l_char_length <= 65535 ? 2 :
 
1470
                  l_char_length <= 16777215 ? 3 : 4;
 
1471
    }
 
1472
  }
 
1473
  Field_blob(uint32 packlength_arg)
 
1474
    :Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
 
1475
    packlength(packlength_arg) {}
 
1476
  enum_field_types type() const { return MYSQL_TYPE_BLOB;}
 
1477
  enum ha_base_keytype key_type() const
 
1478
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
 
1479
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1480
  int  store(double nr);
 
1481
  int  store(longlong nr, bool unsigned_val);
 
1482
  double val_real(void);
 
1483
  longlong val_int(void);
 
1484
  String *val_str(String*,String *);
 
1485
  my_decimal *val_decimal(my_decimal *);
 
1486
  int cmp_max(const uchar *, const uchar *, uint max_length);
 
1487
  int cmp(const uchar *a,const uchar *b)
 
1488
    { return cmp_max(a, b, ~0L); }
 
1489
  int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length);
 
1490
  int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
 
1491
  int key_cmp(const uchar *,const uchar*);
 
1492
  int key_cmp(const uchar *str, uint length);
 
1493
  uint32 key_length() const { return 0; }
 
1494
  void sort_string(uchar *buff,uint length);
 
1495
  uint32 pack_length() const
 
1496
  { return (uint32) (packlength+table->s->blob_ptr_size); }
 
1497
 
 
1498
  /**
 
1499
     Return the packed length without the pointer size added. 
 
1500
 
 
1501
     This is used to determine the size of the actual data in the row
 
1502
     buffer.
 
1503
 
 
1504
     @returns The length of the raw data itself without the pointer.
 
1505
  */
 
1506
  uint32 pack_length_no_ptr() const
 
1507
  { return (uint32) (packlength); }
 
1508
  uint row_pack_length() { return pack_length_no_ptr(); }
 
1509
  uint32 sort_length() const;
 
1510
  virtual uint32 max_data_length() const
 
1511
  {
 
1512
    return (uint32) (((uint64_t) 1 << (packlength*8)) -1);
 
1513
  }
 
1514
  int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; }
 
1515
  void reset_fields() { bzero((uchar*) &value,sizeof(value)); }
 
1516
#ifndef WORDS_BIGENDIAN
 
1517
  static
 
1518
#endif
 
1519
  void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number, bool low_byte_first);
 
1520
  void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number)
 
1521
  {
 
1522
    store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
 
1523
  }
 
1524
  inline void store_length(uint32 number)
 
1525
  {
 
1526
    store_length(ptr, packlength, number);
 
1527
  }
 
1528
 
 
1529
  /**
 
1530
     Return the packed length plus the length of the data. 
 
1531
 
 
1532
     This is used to determine the size of the data plus the 
 
1533
     packed length portion in the row data.
 
1534
 
 
1535
     @returns The length in the row plus the size of the data.
 
1536
  */
 
1537
  uint32 get_packed_size(const uchar *ptr_arg, bool low_byte_first)
 
1538
    {return packlength + get_length(ptr_arg, packlength, low_byte_first);}
 
1539
 
 
1540
  inline uint32 get_length(uint row_offset= 0)
 
1541
  { return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); }
 
1542
  uint32 get_length(const uchar *ptr, uint packlength, bool low_byte_first);
 
1543
  uint32 get_length(const uchar *ptr_arg)
 
1544
  { return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); }
 
1545
  void put_length(uchar *pos, uint32 length);
 
1546
  inline void get_ptr(uchar **str)
 
1547
    {
 
1548
      memcpy_fixed((uchar*) str,ptr+packlength,sizeof(uchar*));
 
1549
    }
 
1550
  inline void get_ptr(uchar **str, uint row_offset)
 
1551
    {
 
1552
      memcpy_fixed((uchar*) str,ptr+packlength+row_offset,sizeof(char*));
 
1553
    }
 
1554
  inline void set_ptr(uchar *length, uchar *data)
 
1555
    {
 
1556
      memcpy(ptr,length,packlength);
 
1557
      memcpy_fixed(ptr+packlength,&data,sizeof(char*));
 
1558
    }
 
1559
  void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data)
 
1560
    {
 
1561
      uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
 
1562
      store_length(ptr_ofs, packlength, length);
 
1563
      memcpy_fixed(ptr_ofs+packlength,&data,sizeof(char*));
 
1564
    }
 
1565
  inline void set_ptr(uint32 length, uchar *data)
 
1566
    {
 
1567
      set_ptr_offset(0, length, data);
 
1568
    }
 
1569
  uint get_key_image(uchar *buff,uint length, imagetype type);
 
1570
  void set_key_image(const uchar *buff,uint length);
 
1571
  void sql_type(String &str) const;
 
1572
  inline bool copy()
 
1573
  {
 
1574
    uchar *tmp;
 
1575
    get_ptr(&tmp);
 
1576
    if (value.copy((char*) tmp, get_length(), charset()))
 
1577
    {
 
1578
      Field_blob::reset();
 
1579
      return 1;
 
1580
    }
 
1581
    tmp=(uchar*) value.ptr();
 
1582
    memcpy_fixed(ptr+packlength,&tmp,sizeof(char*));
 
1583
    return 0;
 
1584
  }
 
1585
  virtual uchar *pack(uchar *to, const uchar *from,
 
1586
                      uint max_length, bool low_byte_first);
 
1587
  uchar *pack_key(uchar *to, const uchar *from,
 
1588
                  uint max_length, bool low_byte_first);
 
1589
  uchar *pack_key_from_key_image(uchar* to, const uchar *from,
 
1590
                                 uint max_length, bool low_byte_first);
 
1591
  virtual const uchar *unpack(uchar *to, const uchar *from,
 
1592
                              uint param_data, bool low_byte_first);
 
1593
  const uchar *unpack_key(uchar* to, const uchar *from,
 
1594
                          uint max_length, bool low_byte_first);
 
1595
  int pack_cmp(const uchar *a, const uchar *b, uint key_length,
 
1596
               my_bool insert_or_update);
 
1597
  int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
 
1598
  uint packed_col_length(const uchar *col_ptr, uint length);
 
1599
  uint max_packed_col_length(uint max_length);
 
1600
  void free() { value.free(); }
 
1601
  inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); }
 
1602
  friend int field_conv(Field *to,Field *from);
 
1603
  uint size_of() const { return sizeof(*this); }
 
1604
  bool has_charset(void) const
 
1605
  { return charset() == &my_charset_bin ? false : true; }
 
1606
  uint32 max_display_length();
 
1607
  uint is_equal(Create_field *new_field);
 
1608
  inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
 
1609
  inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
 
1610
private:
 
1611
  int do_save_field_metadata(uchar *first_byte);
 
1612
};
 
1613
 
 
1614
 
 
1615
class Field_enum :public Field_str {
 
1616
protected:
 
1617
  uint packlength;
 
1618
public:
 
1619
  TYPELIB *typelib;
 
1620
  Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
1621
             uchar null_bit_arg,
 
1622
             enum utype unireg_check_arg, const char *field_name_arg,
 
1623
             uint packlength_arg,
 
1624
             TYPELIB *typelib_arg,
 
1625
             CHARSET_INFO *charset_arg)
 
1626
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1627
               unireg_check_arg, field_name_arg, charset_arg),
 
1628
    packlength(packlength_arg),typelib(typelib_arg)
 
1629
  {
 
1630
      flags|=ENUM_FLAG;
 
1631
  }
 
1632
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
 
1633
  enum_field_types type() const { return MYSQL_TYPE_STRING; }
 
1634
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1635
  enum Item_result cast_to_int_type () const { return INT_RESULT; }
 
1636
  enum ha_base_keytype key_type() const;
 
1637
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1638
  int  store(double nr);
 
1639
  int  store(longlong nr, bool unsigned_val);
 
1640
  double val_real(void);
 
1641
  longlong val_int(void);
 
1642
  String *val_str(String*,String *);
 
1643
  int cmp(const uchar *,const uchar *);
 
1644
  void sort_string(uchar *buff,uint length);
 
1645
  uint32 pack_length() const { return (uint32) packlength; }
 
1646
  void store_type(uint64_t value);
 
1647
  void sql_type(String &str) const;
 
1648
  uint size_of() const { return sizeof(*this); }
 
1649
  enum_field_types real_type() const { return MYSQL_TYPE_ENUM; }
 
1650
  uint pack_length_from_metadata(uint field_metadata)
 
1651
  { return (field_metadata & 0x00ff); }
 
1652
  uint row_pack_length() { return pack_length(); }
 
1653
  virtual bool zero_pack() const { return 0; }
 
1654
  bool optimize_range(uint idx __attribute__((__unused__)),
 
1655
                      uint part __attribute__((__unused__)))
 
1656
  { return 0; }
 
1657
  bool eq_def(Field *field);
 
1658
  bool has_charset(void) const { return true; }
 
1659
  /* enum and set are sorted as integers */
 
1660
  CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
 
1661
private:
 
1662
  int do_save_field_metadata(uchar *first_byte);
 
1663
};
 
1664
 
 
1665
 
 
1666
class Field_set :public Field_enum {
 
1667
public:
 
1668
  Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
1669
            uchar null_bit_arg,
 
1670
            enum utype unireg_check_arg, const char *field_name_arg,
 
1671
            uint32 packlength_arg,
 
1672
            TYPELIB *typelib_arg, CHARSET_INFO *charset_arg)
 
1673
    :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1674
                    unireg_check_arg, field_name_arg,
 
1675
                packlength_arg,
 
1676
                typelib_arg,charset_arg)
 
1677
    {
 
1678
      flags=(flags & ~ENUM_FLAG) | SET_FLAG;
 
1679
    }
 
1680
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1681
  int  store(double nr) { return Field_set::store((longlong) nr, false); }
 
1682
  int  store(longlong nr, bool unsigned_val);
 
1683
 
 
1684
  virtual bool zero_pack() const { return 1; }
 
1685
  String *val_str(String*,String *);
 
1686
  void sql_type(String &str) const;
 
1687
  enum_field_types real_type() const { return MYSQL_TYPE_SET; }
 
1688
  bool has_charset(void) const { return true; }
 
1689
};
 
1690
 
 
1691
 
 
1692
/*
 
1693
  Create field class for CREATE TABLE
 
1694
*/
 
1695
 
 
1696
class Create_field :public Sql_alloc
 
1697
{
 
1698
public:
 
1699
  const char *field_name;
 
1700
  const char *change;                   // If done with alter table
 
1701
  const char *after;                    // Put column after this one
 
1702
  LEX_STRING comment;                   // Comment for field
 
1703
  Item  *def;                           // Default value
 
1704
  enum  enum_field_types sql_type;
 
1705
  /*
 
1706
    At various stages in execution this can be length of field in bytes or
 
1707
    max number of characters. 
 
1708
  */
 
1709
  ulong length;
 
1710
  /*
 
1711
    The value of `length' as set by parser: is the number of characters
 
1712
    for most of the types, or of bytes for BLOBs or numeric types.
 
1713
  */
 
1714
  uint32 char_length;
 
1715
  uint  decimals, flags, pack_length, key_length;
 
1716
  Field::utype unireg_check;
 
1717
  TYPELIB *interval;                    // Which interval to use
 
1718
  TYPELIB *save_interval;               // Temporary copy for the above
 
1719
                                        // Used only for UCS2 intervals
 
1720
  List<String> interval_list;
 
1721
  CHARSET_INFO *charset;
 
1722
  Field *field;                         // For alter table
 
1723
 
 
1724
  uint8 row,col,sc_length,interval_id;  // For rea_create_table
 
1725
  uint  offset,pack_flag;
 
1726
  Create_field() :after(0) {}
 
1727
  Create_field(Field *field, Field *orig_field);
 
1728
  /* Used to make a clone of this object for ALTER/CREATE TABLE */
 
1729
  Create_field *clone(MEM_ROOT *mem_root) const
 
1730
    { return new (mem_root) Create_field(*this); }
 
1731
  void create_length_to_internal_length(void);
 
1732
 
 
1733
  inline enum column_format_type column_format() const
 
1734
  {
 
1735
    return (enum column_format_type)
 
1736
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
 
1737
  }
 
1738
 
 
1739
  /* Init for a tmp table field. To be extended if need be. */
 
1740
  void init_for_tmp_table(enum_field_types sql_type_arg,
 
1741
                          uint32 max_length, uint32 decimals,
 
1742
                          bool maybe_null, bool is_unsigned);
 
1743
 
 
1744
  bool init(THD *thd, char *field_name, enum_field_types type, char *length,
 
1745
            char *decimals, uint type_modifier, Item *default_value,
 
1746
            Item *on_update_value, LEX_STRING *comment, char *change,
 
1747
            List<String> *interval_list, CHARSET_INFO *cs,
 
1748
            uint uint_geom_type,
 
1749
            enum column_format_type column_format);
 
1750
};
 
1751
 
 
1752
 
 
1753
/*
 
1754
  A class for sending info to the client
 
1755
*/
 
1756
 
 
1757
class Send_field {
 
1758
 public:
728
1759
  const char *db_name;
729
 
  const char *table_name;
730
 
  const char *org_table_name;
731
 
  const char *col_name;
732
 
  const char *org_col_name;
733
 
  uint32_t length;
734
 
  uint32_t charsetnr;
735
 
  uint32_t flags;
736
 
  uint32_t decimals;
 
1760
  const char *table_name,*org_table_name;
 
1761
  const char *col_name,*org_col_name;
 
1762
  ulong length;
 
1763
  uint charsetnr, flags, decimals;
737
1764
  enum_field_types type;
738
 
  SendField() {}
 
1765
  Send_field() {}
739
1766
};
740
1767
 
741
 
/**
742
 
 * A class for quick copying data to fields
743
 
 */
744
 
class CopyField :public memory::SqlAlloc
745
 
{
 
1768
 
 
1769
/*
 
1770
  A class for quick copying data to fields
 
1771
*/
 
1772
 
 
1773
class Copy_field :public Sql_alloc {
746
1774
  /**
747
1775
    Convenience definition of a copy function returned by
748
1776
    get_copy_func.
749
1777
  */
750
 
  typedef void Copy_func(CopyField*);
 
1778
  typedef void Copy_func(Copy_field*);
751
1779
  Copy_func *get_copy_func(Field *to, Field *from);
752
1780
public:
753
 
  unsigned char *from_ptr;
754
 
  unsigned char *to_ptr;
755
 
  unsigned char *from_null_ptr;
756
 
  unsigned char *to_null_ptr;
757
 
  bool *null_row;
758
 
  uint32_t from_bit;
759
 
  uint32_t to_bit;
760
 
  uint32_t from_length;
761
 
  uint32_t to_length;
762
 
  Field *from_field;
763
 
  Field *to_field;
 
1781
  uchar *from_ptr,*to_ptr;
 
1782
  uchar *from_null_ptr,*to_null_ptr;
 
1783
  my_bool *null_row;
 
1784
  uint  from_bit,to_bit;
 
1785
  uint from_length,to_length;
 
1786
  Field *from_field,*to_field;
764
1787
  String tmp;                                   // For items
765
1788
 
766
 
  CopyField() {}
767
 
  ~CopyField() {}
768
 
  void set(Field *to,Field *from,bool save);    // Field to field
769
 
  void set(unsigned char *to,Field *from);              // Field to string
770
 
  void (*do_copy)(CopyField *);
771
 
  void (*do_copy2)(CopyField *);                // Used to handle null values
 
1789
  Copy_field() {}
 
1790
  ~Copy_field() {}
 
1791
  void set(Field *to,Field *from,bool save);    // Field to field 
 
1792
  void set(uchar *to,Field *from);              // Field to string
 
1793
  void (*do_copy)(Copy_field *);
 
1794
  void (*do_copy2)(Copy_field *);               // Used to handle null values
772
1795
};
773
1796
 
774
 
Field *make_field(TableShare *share,
775
 
                  memory::Root *root,
776
 
                  unsigned char *ptr,
777
 
                  uint32_t field_length,
778
 
                  bool is_nullable,
779
 
                  unsigned char *null_pos,
780
 
                  unsigned char null_bit,
781
 
                  uint8_t decimals,
782
 
                  enum_field_types field_type,
783
 
                  const CHARSET_INFO * cs,
784
 
                  Field::utype unireg_check,
785
 
                  TYPELIB *interval,
786
 
                  const char *field_name);
787
1797
 
788
 
uint32_t pack_length_to_packflag(uint32_t type);
789
 
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
 
1798
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length,
 
1799
                  uchar *null_pos, uchar null_bit,
 
1800
                  uint pack_flag, enum_field_types field_type,
 
1801
                  CHARSET_INFO *cs,
 
1802
                  Field::utype unireg_check,
 
1803
                  TYPELIB *interval, const char *field_name);
 
1804
uint pack_length_to_packflag(uint type);
 
1805
enum_field_types get_blob_type_from_length(ulong length);
 
1806
uint32 calc_pack_length(enum_field_types type,uint32 length);
790
1807
int set_field_to_null(Field *field);
791
1808
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
792
1809
 
793
 
/**
794
 
 * Tests if the given string contains important data:
795
 
 * not spaces for character string, or any data for binary string.
796
 
 *
797
 
 * @param pointer to the character set to use
798
 
 * @param String to test
799
 
 * @param String end
800
 
 *
801
 
 * @retval
802
 
 *  false - If string does not have important data
803
 
 * @retval
804
 
 *  true  - If string has some important data
805
 
 */
806
 
bool test_if_important_data(const CHARSET_INFO * const cs,
807
 
                            const char *str,
808
 
                            const char *strend);
809
 
 
810
 
} /* namespace drizzled */
811
 
 
812
 
#endif /* DRIZZLED_FIELD_H */
 
1810
/*
 
1811
  The following are for the interface with the .frm file
 
1812
*/
 
1813
 
 
1814
#define FIELDFLAG_DECIMAL               1
 
1815
#define FIELDFLAG_BINARY                1       // Shares same flag
 
1816
#define FIELDFLAG_NUMBER                2
 
1817
#define FIELDFLAG_ZEROFILL              4
 
1818
#define FIELDFLAG_PACK                  120     // Bits used for packing
 
1819
#define FIELDFLAG_INTERVAL              256     // mangled with decimals!
 
1820
#define FIELDFLAG_BITFIELD              512     // mangled with decimals!
 
1821
#define FIELDFLAG_BLOB                  1024    // mangled with decimals!
 
1822
#define FIELDFLAG_GEOM                  2048    // mangled with decimals!
 
1823
 
 
1824
#define FIELDFLAG_TREAT_BIT_AS_CHAR     4096    /* use Field_bit_as_char */
 
1825
 
 
1826
#define FIELDFLAG_LEFT_FULLSCREEN       8192
 
1827
#define FIELDFLAG_RIGHT_FULLSCREEN      16384
 
1828
#define FIELDFLAG_FORMAT_NUMBER         16384   // predit: ###,,## in output
 
1829
#define FIELDFLAG_NO_DEFAULT            16384   /* sql */
 
1830
#define FIELDFLAG_SUM                   ((uint) 32768)// predit: +#fieldflag
 
1831
#define FIELDFLAG_MAYBE_NULL            ((uint) 32768)// sql
 
1832
#define FIELDFLAG_HEX_ESCAPE            ((uint) 0x10000)
 
1833
#define FIELDFLAG_PACK_SHIFT            3
 
1834
#define FIELDFLAG_DEC_SHIFT             8
 
1835
#define FIELDFLAG_MAX_DEC               31
 
1836
#define FIELDFLAG_NUM_SCREEN_TYPE       0x7F01
 
1837
#define FIELDFLAG_ALFA_SCREEN_TYPE      0x7800
 
1838
 
 
1839
#define MTYP_TYPENR(type) (type & 127)  /* Remove bits from type */
 
1840
 
 
1841
#define f_is_dec(x)             ((x) & FIELDFLAG_DECIMAL)
 
1842
#define f_is_num(x)             ((x) & FIELDFLAG_NUMBER)
 
1843
#define f_is_zerofill(x)        ((x) & FIELDFLAG_ZEROFILL)
 
1844
#define f_is_packed(x)          ((x) & FIELDFLAG_PACK)
 
1845
#define f_packtype(x)           (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
 
1846
#define f_decimals(x)           ((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
 
1847
#define f_is_alpha(x)           (!f_is_num(x))
 
1848
#define f_is_binary(x)          ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
 
1849
#define f_is_enum(x)            (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
 
1850
#define f_is_bitfield(x)        (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
 
1851
#define f_is_blob(x)            (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
 
1852
#define f_is_equ(x)             ((x) & (1+2+FIELDFLAG_PACK+31*256))
 
1853
#define f_settype(x)            (((int) x) << FIELDFLAG_PACK_SHIFT)
 
1854
#define f_maybe_null(x)         (x & FIELDFLAG_MAYBE_NULL)
 
1855
#define f_no_default(x)         (x & FIELDFLAG_NO_DEFAULT)
 
1856
#define f_bit_as_char(x)        ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
 
1857
#define f_is_hex_escape(x)      ((x) & FIELDFLAG_HEX_ESCAPE)