~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Brian Aker
  • Date: 2009-10-16 10:27:33 UTC
  • mfrom: (1183.1.4 merge)
  • Revision ID: brian@gaz-20091016102733-b10po5oup0hjlilh
MergeĀ EngineĀ changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
 
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
 */
16
19
 
17
20
/*
18
21
  Because of the function new_field() all field classes that have static
19
22
  variables must declare the size_of() member function.
20
23
*/
21
24
 
22
 
#ifdef USE_PRAGMA_INTERFACE
23
 
#pragma interface                       /* gcc class implementation */
24
 
#endif
 
25
#ifndef DRIZZLED_FIELD_H
 
26
#define DRIZZLED_FIELD_H
 
27
 
 
28
#include "drizzled/sql_error.h"
 
29
#include "drizzled/my_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
 
 
35
#include <string>
 
36
#include <vector>
25
37
 
26
38
#define DATETIME_DEC                     6
27
39
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
28
40
 
 
41
#ifdef DEBUG
 
42
#define ASSERT_COLUMN_MARKED_FOR_READ assert(!table || (table->read_set == NULL || isReadSet()))
 
43
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(!table || (table->write_set == NULL || isWriteSet()))
 
44
#else
 
45
#define ASSERT_COLUMN_MARKED_FOR_READ
 
46
#define ASSERT_COLUMN_MARKED_FOR_WRITE
 
47
#endif
 
48
 
29
49
const uint32_t max_field_size= (uint32_t) 4294967295U;
30
50
 
31
 
class Send_field;
32
 
class Protocol;
33
 
class Create_field;
 
51
class SendField;
 
52
class CreateField;
 
53
class TableShare;
 
54
class Field;
34
55
struct st_cache_field;
 
56
 
35
57
int field_conv(Field *to,Field *from);
36
58
 
37
 
inline uint get_enum_pack_length(int elements)
 
59
inline uint32_t get_enum_pack_length(int elements)
38
60
{
39
61
  return elements < 256 ? 1 : 2;
40
62
}
41
63
 
42
 
inline uint get_set_pack_length(int elements)
43
 
{
44
 
  uint len= (elements + 7) / 8;
45
 
  return len > 4 ? 8 : len;
46
 
}
47
 
 
 
64
/**
 
65
 * Class representing a Field in a Table
 
66
 *
 
67
 * @details
 
68
 *
 
69
 * The value stored in the Field object is stored in the 
 
70
 * unsigned char pointer member variable called ptr.  The
 
71
 * val_xxx() methods retrieve this raw byte value and 
 
72
 * convert the byte into the appropriate output (int, decimal, etc).
 
73
 *
 
74
 * The store_xxx() methods take various input and convert
 
75
 * the input into the raw bytes stored in the ptr member variable.
 
76
 */
48
77
class Field
49
78
{
50
 
  Field(const Item &);                          /* Prevent use of these */
 
79
  /* Prevent use of these */
 
80
  Field(const Field&); 
51
81
  void operator=(Field &);
52
82
public:
53
 
  static void *operator new(size_t size) {return sql_alloc(size); }
54
 
  static void operator delete(void *ptr_arg __attribute__((unused)),
55
 
                              size_t size __attribute__((unused)))
56
 
  { TRASH(ptr_arg, size); }
57
 
 
58
 
  uchar         *ptr;                   // Position to field in record
59
 
  uchar         *null_ptr;              // Byte where null_bit is
 
83
  unsigned char *ptr; /**< Position to field in record. Stores raw field value */
 
84
  unsigned char *null_ptr; /**< Byte where null_bit is */
 
85
 
 
86
  /**
 
87
   * Pointer to the Table object containing this Field 
 
88
   *
 
89
   * @note You can use table->in_use as replacement for current_session member
 
90
   * only inside of val_*() and store() members (e.g. you can't use it in cons)
 
91
   */
 
92
  Table *table; 
 
93
  Table *orig_table; /**< Pointer to the original Table. @TODO What is "the original table"? */
 
94
  const char **table_name; /**< Pointer to the name of the table. @TODO This is redundant with Table::table_name. */
 
95
  const char *field_name; /**< Name of the field */
 
96
  LEX_STRING comment; /**< A comment about the field */
 
97
 
 
98
  /** The field is part of the following keys */
 
99
  key_map       key_start;
 
100
  key_map part_of_key;
 
101
  key_map part_of_key_not_clustered;
 
102
  key_map part_of_sortkey;
 
103
 
60
104
  /*
61
 
    Note that you can use table->in_use as replacement for current_thd member 
62
 
    only inside of val_*() and store() members (e.g. you can't use it in cons)
63
 
  */
64
 
  struct st_table *table;               // Pointer for table
65
 
  struct st_table *orig_table;          // Pointer to original table
66
 
  const char    **table_name, *field_name;
67
 
  LEX_STRING    comment;
68
 
  /* Field is part of the following keys */
69
 
  key_map       key_start, part_of_key, part_of_key_not_clustered;
70
 
  key_map       part_of_sortkey;
71
 
  /* 
72
 
    We use three additional unireg types for TIMESTAMP to overcome limitation 
73
 
    of current binary format of .frm file. We'd like to be able to support 
74
 
    NOW() as default and on update value for such fields but unable to hold 
 
105
    We use three additional unireg types for TIMESTAMP to overcome limitation
 
106
    of current binary format of .frm file. We'd like to be able to support
 
107
    NOW() as default and on update value for such fields but unable to hold
75
108
    this info anywhere except unireg_check field. This issue will be resolved
76
109
    in more clean way with transition to new text based .frm format.
77
110
    See also comment for Field_timestamp::Field_timestamp().
78
111
  */
79
 
  enum utype  { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
80
 
                CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
81
 
                BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
82
 
                TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
83
 
  enum imagetype { itRAW, itMBR};
 
112
  enum utype
 
113
  { 
 
114
    NONE,
 
115
    NEXT_NUMBER,
 
116
    TIMESTAMP_OLD_FIELD,
 
117
    TIMESTAMP_DN_FIELD,
 
118
    TIMESTAMP_UN_FIELD,
 
119
    TIMESTAMP_DNUN_FIELD
 
120
  };
84
121
 
85
 
  utype         unireg_check;
86
 
  uint32_t      field_length;           // Length of field
87
 
  uint32_t      flags;
88
 
  uint16_t        field_index;            // field number in fields array
89
 
  uchar         null_bit;               // Bit used to test null bit
 
122
  utype unireg_check;
 
123
  uint32_t field_length; /**< Length of this field in bytes */
 
124
  uint32_t flags;
 
125
  uint16_t field_index; /**< Index of this Field in Table::fields array */
 
126
  unsigned char null_bit; /**< Bit used to test null bit */
90
127
  /**
91
128
     If true, this field was created in create_tmp_field_from_item from a NULL
92
129
     value. This means that the type of the field is just a guess, and the type
94
131
 
95
132
     @see create_tmp_field_from_item
96
133
     @see Item_type_holder::get_real_type
97
 
 
98
134
   */
99
135
  bool is_created_from_null_item;
100
136
 
101
 
  Field(uchar *ptr_arg,uint32_t length_arg,uchar *null_ptr_arg,
102
 
        uchar null_bit_arg, utype unireg_check_arg,
 
137
  static void *operator new(size_t size) {return sql_alloc(size); }
 
138
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
139
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
 
140
  static void operator delete(void *, size_t)
 
141
  { TRASH(ptr_arg, size); }
 
142
 
 
143
  Field(unsigned char *ptr_arg,
 
144
        uint32_t length_arg,
 
145
        unsigned char *null_ptr_arg,
 
146
        unsigned char null_bit_arg,
 
147
        utype unireg_check_arg,
103
148
        const char *field_name_arg);
104
149
  virtual ~Field() {}
105
150
  /* Store functions returns 1 on overflow and -1 on fatal error */
106
 
  virtual int  store(const char *to, uint length, const CHARSET_INFO * const cs)=0;
107
 
  virtual int  store(double nr)=0;
108
 
  virtual int  store(int64_t nr, bool unsigned_val)=0;
109
 
  virtual int  store_decimal(const my_decimal *d)=0;
110
 
  virtual int store_time(DRIZZLE_TIME *ltime, timestamp_type t_type);
111
 
  int store(const char *to, uint length, const CHARSET_INFO * const cs,
 
151
  virtual int store(const char *to, 
 
152
                    uint32_t length, 
 
153
                    const CHARSET_INFO * const cs)=0;
 
154
  virtual int store(double nr)=0;
 
155
  virtual int store(int64_t nr, bool unsigned_val)=0;
 
156
  virtual int store_decimal(const my_decimal *d)=0;
 
157
  int store(const char *to, 
 
158
            uint32_t length,
 
159
            const CHARSET_INFO * const cs,
112
160
            enum_check_fields check_level);
 
161
  /**
 
162
    This is called when storing a date in a string.
 
163
 
 
164
    @note
 
165
      Needs to be changed if/when we want to support different time formats.
 
166
  */
 
167
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
113
168
  virtual double val_real(void)=0;
114
169
  virtual int64_t val_int(void)=0;
115
170
  virtual my_decimal *val_decimal(my_decimal *);
116
 
  inline String *val_str(String *str) { return val_str(str, str); }
 
171
  inline String *val_str(String *str) 
 
172
  {
 
173
    return val_str(str, str);
 
174
  }
117
175
  /*
118
176
     val_str(buf1, buf2) gets two buffers and should use them as follows:
119
177
     if it needs a temp buffer to convert result to string - use buf1
126
184
     an unnecessary free (and later, may be an alloc).
127
185
     This trickery is used to decrease a number of malloc calls.
128
186
  */
129
 
  virtual String *val_str(String*,String *)=0;
 
187
  virtual String *val_str(String*, String *)=0;
 
188
  /**
 
189
   * Interpret field value as an integer but return the result as a string.
 
190
   *
 
191
   * This is used for printing bit_fields as numbers while debugging.
 
192
   */
130
193
  String *val_int_as_str(String *val_buffer, bool unsigned_flag);
131
194
  /*
132
195
   str_needs_quotes() returns true if the value returned by val_str() needs
136
199
  virtual Item_result result_type () const=0;
137
200
  virtual Item_result cmp_type () const { return result_type(); }
138
201
  virtual Item_result cast_to_int_type () const { return result_type(); }
 
202
  /**
 
203
     Check whether a field type can be partially indexed by a key.
 
204
 
 
205
     This is a static method, rather than a virtual function, because we need
 
206
     to check the type of a non-Field in drizzled::alter_table().
 
207
 
 
208
     @param type  field type
 
209
 
 
210
     @retval
 
211
       true  Type can have a prefixed key
 
212
     @retval
 
213
       false Type can not have a prefixed key
 
214
  */
139
215
  static bool type_can_have_key_part(enum_field_types);
 
216
  /**
 
217
    Return type of which can carry value of both given types in UNION result.
 
218
 
 
219
    @param a  type for merging
 
220
    @param b  type for merging
 
221
 
 
222
    @retval
 
223
      type of field
 
224
  */
140
225
  static enum_field_types field_type_merge(enum_field_types, enum_field_types);
 
226
 
 
227
  /**
 
228
     Detect Item_result by given field type of UNION merge result.
 
229
 
 
230
     @param field_type  given field type
 
231
 
 
232
     @return
 
233
       Item_result (type of internal MySQL expression result)
 
234
  */
141
235
  static Item_result result_merge_type(enum_field_types);
142
 
  virtual bool eq(Field *field)
143
 
  {
144
 
    return (ptr == field->ptr && null_ptr == field->null_ptr &&
145
 
            null_bit == field->null_bit);
146
 
  }
 
236
 
 
237
  virtual bool eq(Field *field);
 
238
  /**
 
239
   * Returns true if the fields are equally defined
 
240
   *
 
241
   * @retval
 
242
   *  true  This Field is equally defined to supplied Field
 
243
   * @retval
 
244
   *  false This Field is NOT equally defined to supplied Field
 
245
   */
147
246
  virtual bool eq_def(Field *field);
148
 
  
149
 
  /*
150
 
    pack_length() returns size (in bytes) used to store field data in memory
151
 
    (i.e. it returns the maximum size of the field in a row of the table,
152
 
    which is located in RAM).
153
 
  */
154
 
  virtual uint32_t pack_length() const { return (uint32_t) field_length; }
155
 
 
156
 
  /*
157
 
    pack_length_in_rec() returns size (in bytes) used to store field data on
158
 
    storage (i.e. it returns the maximal size of the field in a row of the
159
 
    table, which is located on disk).
160
 
  */
161
 
  virtual uint32_t pack_length_in_rec() const { return pack_length(); }
162
 
  virtual int compatible_field_size(uint field_metadata);
163
 
  virtual uint pack_length_from_metadata(uint field_metadata)
164
 
  { return field_metadata; }
 
247
 
 
248
  /**
 
249
   * Returns size (in bytes) used to store field data in memory
 
250
   * (i.e. it returns the maximum size of the field in a row of the table,
 
251
   * which is located in RAM).
 
252
   */
 
253
  virtual uint32_t pack_length() const;
 
254
 
 
255
  /**
 
256
   * Returns size (in bytes) used to store field data on
 
257
   * storage (i.e. it returns the maximal size of the field in a row of the
 
258
   * table, which is located on disk).
 
259
   */
 
260
  virtual uint32_t pack_length_in_rec() const;
 
261
  /**
 
262
    Check to see if field size is compatible with destination.
 
263
 
 
264
    This method is used in row-based replication to verify that the slave's
 
265
    field size is less than or equal to the master's field size. The
 
266
    encoded field metadata (from the master or source) is decoded and compared
 
267
    to the size of this field (the slave or destination).
 
268
 
 
269
    @param   field_metadata   Encoded size in field metadata
 
270
 
 
271
    @retval 0 if this field's size is < the source field's size
 
272
    @retval 1 if this field's size is >= the source field's size
 
273
  */
 
274
  virtual int compatible_field_size(uint32_t field_metadata);
 
275
  virtual uint32_t pack_length_from_metadata(uint32_t field_metadata);
 
276
 
165
277
  /*
166
278
    This method is used to return the size of the data in a row-based
167
279
    replication row record. The default implementation of returning 0 is
168
280
    designed to allow fields that do not use metadata to return true (1)
169
281
    from compatible_field_size() which uses this function in the comparison.
170
 
    The default value for field metadata for fields that do not have 
 
282
    The default value for field metadata for fields that do not have
171
283
    metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
172
284
 
173
285
    Note: While most classes that override this method return pack_length(),
174
 
    the classes Field_varstring, and Field_blob return 
 
286
    the classes Field_varstring, and Field_blob return
175
287
    field_length + 1, field_length, and pack_length_no_ptr() respectfully.
176
288
  */
177
 
  virtual uint row_pack_length() { return 0; }
178
 
  virtual int save_field_metadata(uchar *first_byte)
179
 
  { return do_save_field_metadata(first_byte); }
 
289
  virtual uint32_t row_pack_length();
 
290
  virtual int save_field_metadata(unsigned char *first_byte);
180
291
 
181
 
  /*
182
 
    data_length() return the "real size" of the data in memory.
183
 
    For varstrings, this does _not_ include the length bytes.
184
 
  */
185
 
  virtual uint32_t data_length() { return pack_length(); }
186
 
  /*
187
 
    used_length() returns the number of bytes actually used to store the data
188
 
    of the field. So for a varstring it includes both lenght byte(s) and
189
 
    string data, and anything after data_length() bytes are unused.
190
 
  */
191
 
  virtual uint32_t used_length() { return pack_length(); }
192
 
  virtual uint32_t sort_length() const { return pack_length(); }
 
292
  /**
 
293
   * Return the "real size" of the data in memory. 
 
294
   * For varstrings, this does _not_ include the length bytes.
 
295
   */
 
296
  virtual uint32_t data_length();
 
297
  /**
 
298
   * Returns the number of bytes actually used to store the data
 
299
   * of the field. So for a varstring it includes both lenght byte(s) and
 
300
   * string data, and anything after data_length() bytes are unused.
 
301
   */
 
302
  virtual uint32_t used_length();
 
303
  virtual uint32_t sort_length() const;
193
304
 
194
305
  /**
195
306
     Get the maximum size of the data in packed format.
197
308
     @return Maximum data length of the field when packed using the
198
309
     Field::pack() function.
199
310
   */
200
 
  virtual uint32_t max_data_length() const {
201
 
    return pack_length();
202
 
  };
203
 
 
204
 
  virtual int reset(void) { memset(ptr, 0, pack_length()); return 0; }
205
 
  virtual void reset_fields() {}
206
 
  virtual void set_default()
207
 
  {
208
 
    my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values - table->record[0]);
209
 
    memcpy(ptr, ptr + l_offset, pack_length());
210
 
    if (null_ptr)
211
 
      *null_ptr= ((*null_ptr & (uchar) ~null_bit) | (null_ptr[l_offset] & null_bit));
212
 
  }
213
 
  virtual bool binary() const { return 1; }
214
 
  virtual bool zero_pack() const { return 1; }
215
 
  virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
216
 
  virtual uint32_t key_length() const { return pack_length(); }
 
311
  virtual uint32_t max_data_length() const;
 
312
  virtual int reset(void);
 
313
  virtual void reset_fields();
 
314
  virtual void set_default();
 
315
  virtual bool binary() const;
 
316
  virtual bool zero_pack() const;
 
317
  virtual enum ha_base_keytype key_type() const;
 
318
  virtual uint32_t key_length() const;
217
319
  virtual enum_field_types type() const =0;
218
 
  virtual enum_field_types real_type() const { return type(); }
219
 
  inline  int cmp(const uchar *str) { return cmp(ptr,str); }
220
 
  virtual int cmp_max(const uchar *a, const uchar *b,
221
 
                      uint max_len __attribute__((unused)))
222
 
    { return cmp(a, b); }
223
 
  virtual int cmp(const uchar *,const uchar *)=0;
224
 
  virtual int cmp_binary(const uchar *a,const uchar *b,
225
 
                         uint32_t  __attribute__((unused)) max_length=~0)
226
 
  { return memcmp(a,b,pack_length()); }
227
 
  virtual int cmp_offset(uint row_offset)
228
 
  { return cmp(ptr,ptr+row_offset); }
229
 
  virtual int cmp_binary_offset(uint row_offset)
230
 
  { return cmp_binary(ptr, ptr+row_offset); };
231
 
  virtual int key_cmp(const uchar *a,const uchar *b)
232
 
  { return cmp(a, b); }
233
 
  virtual int key_cmp(const uchar *str, uint length __attribute__((unused)))
234
 
  { return cmp(ptr,str); }
235
 
  virtual uint decimals() const { return 0; }
 
320
  virtual enum_field_types real_type() const;
 
321
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
 
322
  virtual int cmp_max(const unsigned char *a, const unsigned char *b,
 
323
                      uint32_t max_len);
 
324
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
 
325
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
 
326
                         uint32_t max_length=UINT32_MAX);
 
327
  virtual int cmp_offset(uint32_t row_offset);
 
328
  virtual int cmp_binary_offset(uint32_t row_offset);
 
329
  virtual int key_cmp(const unsigned char *a,const unsigned char *b);
 
330
  virtual int key_cmp(const unsigned char *str, uint32_t length);
 
331
  virtual uint32_t decimals() const;
 
332
 
236
333
  /*
237
334
    Caller beware: sql_type can change str.Ptr, so check
238
335
    ptr() to see if it changed if you are using your own buffer
239
336
    in str and restore it with set() if needed
240
337
  */
241
338
  virtual void sql_type(String &str) const =0;
242
 
  virtual uint size_of() const =0;              // For new field
243
 
  inline bool is_null(my_ptrdiff_t row_offset= 0)
244
 
  { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
245
 
  inline bool is_real_null(my_ptrdiff_t row_offset= 0)
246
 
    { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
247
 
  inline bool is_null_in_record(const uchar *record)
248
 
  {
249
 
    if (!null_ptr)
250
 
      return 0;
251
 
    return test(record[(uint) (null_ptr -table->record[0])] &
252
 
                null_bit);
253
 
  }
254
 
  inline bool is_null_in_record_with_offset(my_ptrdiff_t offset)
255
 
  {
256
 
    if (!null_ptr)
257
 
      return 0;
258
 
    return test(null_ptr[offset] & null_bit);
259
 
  }
260
 
  inline void set_null(my_ptrdiff_t row_offset= 0)
261
 
    { if (null_ptr) null_ptr[row_offset]|= null_bit; }
262
 
  inline void set_notnull(my_ptrdiff_t row_offset= 0)
263
 
    { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
264
 
  inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
265
 
  inline bool real_maybe_null(void) { return null_ptr != 0; }
266
 
 
267
 
  enum {
268
 
    LAST_NULL_BYTE_UNDEF= 0
269
 
  };
270
 
 
271
 
  /*
272
 
    Find the position of the last null byte for the field.
273
 
 
274
 
    SYNOPSIS
275
 
      last_null_byte()
276
 
 
277
 
    DESCRIPTION
278
 
      Return a pointer to the last byte of the null bytes where the
279
 
      field conceptually is placed.
280
 
 
281
 
    RETURN VALUE
282
 
      The position of the last null byte relative to the beginning of
283
 
      the record. If the field does not use any bits of the null
284
 
      bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
 
339
 
 
340
  // For new field
 
341
  virtual uint32_t size_of() const =0;
 
342
 
 
343
  bool is_null(ptrdiff_t row_offset= 0);
 
344
  bool is_real_null(ptrdiff_t row_offset= 0);
 
345
  bool is_null_in_record(const unsigned char *record);
 
346
  bool is_null_in_record_with_offset(ptrdiff_t offset);
 
347
  void set_null(ptrdiff_t row_offset= 0);
 
348
  void set_notnull(ptrdiff_t row_offset= 0);
 
349
  bool maybe_null(void);
 
350
  bool real_maybe_null(void);
 
351
 
 
352
  virtual void make_field(SendField *);
 
353
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
 
354
  virtual bool optimize_range(uint32_t idx, uint32_t part);
 
355
  /**
 
356
   * Returns true for fields which, when compared with constant
 
357
   * items, can be casted to int64_t. In this case we will at 'fix_fields'
 
358
   * stage cast the constant items to int64_ts and at the execution stage
 
359
   * use field->val_int() for comparison.  Used to optimize clauses like
 
360
   * 'a_column BETWEEN date_const AND date_const'.
285
361
   */
286
 
  size_t last_null_byte() const {
287
 
    size_t bytes= do_last_null_byte();
288
 
    assert(bytes <= table->s->null_bytes);
289
 
    return bytes;
 
362
  virtual bool can_be_compared_as_int64_t() const 
 
363
  {
 
364
    return false;
290
365
  }
291
 
 
292
 
  virtual void make_field(Send_field *);
293
 
  virtual void sort_string(uchar *buff,uint length)=0;
294
 
  virtual bool optimize_range(uint idx, uint part);
295
 
  /*
296
 
    This should be true for fields which, when compared with constant
297
 
    items, can be casted to int64_t. In this case we will at 'fix_fields'
298
 
    stage cast the constant items to int64_ts and at the execution stage
299
 
    use field->val_int() for comparison.  Used to optimize clauses like
300
 
    'a_column BETWEEN date_const, date_const'.
301
 
  */
302
 
  virtual bool can_be_compared_as_int64_t() const { return false; }
303
366
  virtual void free() {}
304
 
  virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table,
 
367
  virtual Field *new_field(MEM_ROOT *root, 
 
368
                           Table *new_table,
305
369
                           bool keep_type);
306
 
  virtual Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
307
 
                               uchar *new_ptr, uchar *new_null_ptr,
308
 
                               uint new_null_bit);
309
 
  Field *clone(MEM_ROOT *mem_root, struct st_table *new_table);
310
 
  inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
 
370
  virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
 
371
                               unsigned char *new_ptr, 
 
372
                               unsigned char *new_null_ptr,
 
373
                               uint32_t new_null_bit);
 
374
  /** This is used to generate a field in Table from TableShare */
 
375
  Field *clone(MEM_ROOT *mem_root, Table *new_table);
 
376
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
311
377
  {
312
 
    ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
 
378
    ptr= ptr_arg;
 
379
    null_ptr= null_ptr_arg;
 
380
    null_bit= null_bit_arg;
313
381
  }
314
 
  inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; }
315
 
  virtual void move_field_offset(my_ptrdiff_t ptr_diff)
 
382
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
 
383
  virtual void move_field_offset(ptrdiff_t ptr_diff)
316
384
  {
317
 
    ptr=ADD_TO_PTR(ptr,ptr_diff, uchar*);
 
385
    ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
318
386
    if (null_ptr)
319
 
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
320
 
  }
321
 
  virtual void get_image(uchar *buff, uint length,
322
 
                         const CHARSET_INFO * const cs __attribute__((unused)))
323
 
    { memcpy(buff,ptr,length); }
324
 
  virtual void set_image(const uchar *buff,uint length,
325
 
                         const CHARSET_INFO * const cs __attribute__((unused)))
326
 
    { memcpy(ptr,buff,length); }
327
 
 
328
 
 
329
 
  /*
330
 
    Copy a field part into an output buffer.
331
 
 
332
 
    SYNOPSIS
333
 
      Field::get_key_image()
334
 
      buff   [out] output buffer
335
 
      length       output buffer size
336
 
      type         itMBR for geometry blobs, otherwise itRAW
337
 
 
338
 
    DESCRIPTION
339
 
      This function makes a copy of field part of size equal to or
340
 
      less than "length" parameter value.
341
 
      For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
342
 
      is padded by zero byte.
343
 
 
344
 
    NOTES
345
 
      For variable length character fields (i.e. UTF-8) the "length"
346
 
      parameter means a number of output buffer bytes as if all field
347
 
      characters have maximal possible size (mbmaxlen). In the other words,
348
 
      "length" parameter is a number of characters multiplied by
349
 
      field_charset->mbmaxlen.
350
 
 
351
 
    RETURN
352
 
      Number of copied bytes (excluding padded zero bytes -- see above).
353
 
  */
354
 
 
355
 
  virtual uint get_key_image(uchar *buff, uint length,
356
 
                             imagetype type __attribute__((unused)))
357
 
  {
358
 
    get_image(buff, length, &my_charset_bin);
359
 
    return length;
360
 
  }
361
 
  virtual void set_key_image(const uchar *buff,uint length)
362
 
    { set_image(buff,length, &my_charset_bin); }
363
 
  inline int64_t val_int_offset(uint row_offset)
364
 
    {
365
 
      ptr+=row_offset;
366
 
      int64_t tmp=val_int();
367
 
      ptr-=row_offset;
368
 
      return tmp;
369
 
    }
370
 
  inline int64_t val_int(const uchar *new_ptr)
371
 
  {
372
 
    uchar *old_ptr= ptr;
 
387
      null_ptr= ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
 
388
  }
 
389
  virtual void get_image(unsigned char *buff, uint32_t length, const CHARSET_INFO * const)
 
390
  {
 
391
    memcpy(buff,ptr,length);
 
392
  }
 
393
  virtual void get_image(std::basic_string<unsigned char> &buff, uint32_t length, const CHARSET_INFO * const)
 
394
  {
 
395
    buff.append(ptr,length);
 
396
  }
 
397
  virtual void set_image(const unsigned char *buff,uint32_t length, const CHARSET_INFO * const)
 
398
  {
 
399
    memcpy(ptr,buff,length);
 
400
  }
 
401
 
 
402
  /**
 
403
   * Copy a field part into an output buffer.
 
404
   *
 
405
   * @details
 
406
   *
 
407
   * This function makes a copy of field part of size equal to or
 
408
   * less than "length" parameter value.
 
409
   * For fields of string types (VARCHAR, TEXT) the rest of buffer
 
410
   * is padded by zero byte.
 
411
   *
 
412
   * @param output buffer
 
413
   * @param output buffer size
 
414
   *
 
415
   * @note
 
416
   *
 
417
   * For variable length character fields (i.e. UTF-8) the "length"
 
418
   * parameter means a number of output buffer bytes as if all field
 
419
   * characters have maximal possible size (mbmaxlen). In the other words,
 
420
   * "length" parameter is a number of characters multiplied by
 
421
   * field_charset->mbmaxlen.
 
422
   * 
 
423
   * @retval
 
424
   *   Number of copied bytes (excluding padded zero bytes -- see above).
 
425
   */
 
426
  virtual uint32_t get_key_image(unsigned char *buff, uint32_t length)
 
427
  {
 
428
    get_image(buff, length, &my_charset_bin);
 
429
    return length;
 
430
  }
 
431
  virtual uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length)
 
432
  {
 
433
    get_image(buff, length, &my_charset_bin);
 
434
    return length;
 
435
  }
 
436
  virtual void set_key_image(const unsigned char *buff,uint32_t length)
 
437
  {
 
438
    set_image(buff,length, &my_charset_bin);
 
439
  }
 
440
  inline int64_t val_int_offset(uint32_t row_offset)
 
441
  {
 
442
    ptr+=row_offset;
 
443
    int64_t tmp=val_int();
 
444
    ptr-=row_offset;
 
445
    return tmp;
 
446
  }
 
447
 
 
448
  inline int64_t val_int(const unsigned char *new_ptr)
 
449
  {
 
450
    unsigned char *old_ptr= ptr;
373
451
    int64_t return_value;
374
 
    ptr= (uchar*) new_ptr;
 
452
    ptr= (unsigned char*) new_ptr;
375
453
    return_value= val_int();
376
454
    ptr= old_ptr;
377
455
    return return_value;
378
456
  }
379
 
  inline String *val_str(String *str, const uchar *new_ptr)
 
457
  inline String *val_str(String *str, const unsigned char *new_ptr)
380
458
  {
381
 
    uchar *old_ptr= ptr;
382
 
    ptr= (uchar*) new_ptr;
 
459
    unsigned char *old_ptr= ptr;
 
460
    ptr= (unsigned char*) new_ptr;
383
461
    val_str(str);
384
462
    ptr= old_ptr;
385
463
    return str;
386
464
  }
387
 
  virtual bool send_binary(Protocol *protocol);
388
 
 
389
 
  virtual uchar *pack(uchar *to, const uchar *from,
390
 
                      uint max_length, bool low_byte_first);
391
 
  /**
392
 
     @overload Field::pack(uchar*, const uchar*, uint, bool)
393
 
  */
394
 
  uchar *pack(uchar *to, const uchar *from)
395
 
  {
396
 
    uchar *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
397
 
    return(result);
398
 
  }
399
 
 
400
 
  virtual const uchar *unpack(uchar* to, const uchar *from,
401
 
                              uint param_data, bool low_byte_first);
402
 
  /**
403
 
     @overload Field::unpack(uchar*, const uchar*, uint, bool)
404
 
  */
405
 
  const uchar *unpack(uchar* to, const uchar *from)
406
 
  {
407
 
    const uchar *result= unpack(to, from, 0U, table->s->db_low_byte_first);
408
 
    return(result);
409
 
  }
410
 
 
411
 
  virtual uchar *pack_key(uchar* to, const uchar *from,
412
 
                          uint max_length, bool low_byte_first)
413
 
  {
414
 
    return pack(to, from, max_length, low_byte_first);
415
 
  }
416
 
  virtual uchar *pack_key_from_key_image(uchar* to, const uchar *from,
417
 
                                        uint max_length, bool low_byte_first)
418
 
  {
419
 
    return pack(to, from, max_length, low_byte_first);
420
 
  }
421
 
  virtual const uchar *unpack_key(uchar* to, const uchar *from,
422
 
                                  uint max_length, bool low_byte_first)
 
465
 
 
466
  /**
 
467
    Pack the field into a format suitable for storage and transfer.
 
468
 
 
469
    To implement packing functionality, only the virtual function
 
470
    should be overridden. The other functions are just convenience
 
471
    functions and hence should not be overridden.
 
472
 
 
473
    The value of <code>low_byte_first</code> is dependent on how the
 
474
    packed data is going to be used: for local use, e.g., temporary
 
475
    store on disk or in memory, use the native format since that is
 
476
    faster. For data that is going to be transfered to other machines
 
477
    (e.g., when writing data to the binary log), data should always be
 
478
    stored in little-endian format.
 
479
 
 
480
    @note The default method for packing fields just copy the raw bytes
 
481
    of the record into the destination, but never more than
 
482
    <code>max_length</code> characters.
 
483
 
 
484
    @param to
 
485
    Pointer to memory area where representation of field should be put.
 
486
 
 
487
    @param from
 
488
    Pointer to memory area where record representation of field is
 
489
    stored.
 
490
 
 
491
    @param max_length
 
492
    Maximum length of the field, as given in the column definition. For
 
493
    example, for <code>CHAR(1000)</code>, the <code>max_length</code>
 
494
    is 1000. This information is sometimes needed to decide how to pack
 
495
    the data.
 
496
 
 
497
    @param low_byte_first
 
498
    @c true if integers should be stored little-endian, @c false if
 
499
    native format should be used. Note that for little-endian machines,
 
500
    the value of this flag is a moot point since the native format is
 
501
    little-endian.
 
502
  */
 
503
  virtual unsigned char *pack(unsigned char *to,
 
504
                              const unsigned char *from,
 
505
                              uint32_t max_length,
 
506
                              bool low_byte_first);
 
507
 
 
508
  unsigned char *pack(unsigned char *to, const unsigned char *from);
 
509
 
 
510
  /**
 
511
    Unpack a field from row data.
 
512
 
 
513
    This method is used to unpack a field from a master whose size of
 
514
    the field is less than that of the slave.
 
515
 
 
516
    The <code>param_data</code> parameter is a two-byte integer (stored
 
517
    in the least significant 16 bits of the unsigned integer) usually
 
518
    consisting of two parts: the real type in the most significant byte
 
519
    and a original pack length in the least significant byte.
 
520
 
 
521
    The exact layout of the <code>param_data</code> field is given by
 
522
    the <code>Table_map_log_event::save_field_metadata()</code>.
 
523
 
 
524
    This is the default method for unpacking a field. It just copies
 
525
    the memory block in byte order (of original pack length bytes or
 
526
    length of field, whichever is smaller).
 
527
 
 
528
    @param   to         Destination of the data
 
529
    @param   from       Source of the data
 
530
    @param   param_data Real type and original pack length of the field
 
531
                        data
 
532
 
 
533
    @param low_byte_first
 
534
    If this flag is @c true, all composite entities (e.g., lengths)
 
535
    should be unpacked in little-endian format; otherwise, the entities
 
536
    are unpacked in native order.
 
537
 
 
538
    @return  New pointer into memory based on from + length of the data
 
539
  */
 
540
  virtual const unsigned char *unpack(unsigned char* to,
 
541
                                      const unsigned char *from,
 
542
                                      uint32_t param_data,
 
543
                                      bool low_byte_first);
 
544
  /**
 
545
     @overload Field::unpack(unsigned char*, const unsigned char*,
 
546
                             uint32_t, bool)
 
547
  */
 
548
  const unsigned char *unpack(unsigned char* to,
 
549
                              const unsigned char *from);
 
550
 
 
551
  virtual unsigned char *pack_key(unsigned char* to,
 
552
                                  const unsigned char *from,
 
553
                                  uint32_t max_length, 
 
554
                                  bool low_byte_first)
 
555
  {
 
556
    return pack(to, from, max_length, low_byte_first);
 
557
  }
 
558
  virtual unsigned char *pack_key_from_key_image(unsigned char* to,
 
559
                                                 const unsigned char *from,
 
560
                                                 uint32_t max_length,
 
561
                                                 bool low_byte_first)
 
562
  {
 
563
    return pack(to, from, max_length, low_byte_first);
 
564
  }
 
565
  virtual const unsigned char *unpack_key(unsigned char* to,
 
566
                                          const unsigned char *from,
 
567
                                          uint32_t max_length,
 
568
                                          bool low_byte_first)
423
569
  {
424
570
    return unpack(to, from, max_length, low_byte_first);
425
571
  }
426
 
  virtual uint packed_col_length(const uchar *to __attribute__((unused)),
427
 
                                 uint length)
428
 
  { return length;}
429
 
  virtual uint max_packed_col_length(uint max_length)
430
 
  { return max_length;}
431
 
 
432
 
  virtual int pack_cmp(const uchar *a,const uchar *b,
433
 
                       uint key_length_arg __attribute__((unused)),
434
 
                       bool insert_or_update __attribute__((unused)))
435
 
  { return cmp(a,b); }
436
 
  virtual int pack_cmp(const uchar *b,
437
 
                       uint key_length_arg __attribute__((unused)),
438
 
                       bool insert_or_update __attribute__((unused)))
439
 
  { return cmp(ptr,b); }
440
 
  uint offset(uchar *record)
441
 
  {
442
 
    return (uint) (ptr - record);
 
572
  virtual uint32_t packed_col_length(const unsigned char *to, uint32_t length);
 
573
  virtual uint32_t max_packed_col_length(uint32_t max_length)
 
574
  {
 
575
    return max_length;
 
576
  }
 
577
 
 
578
  virtual int pack_cmp(const unsigned char *a,
 
579
                       const unsigned char *b,
 
580
                       uint32_t key_length_arg,
 
581
                       bool insert_or_update);
 
582
  virtual int pack_cmp(const unsigned char *b,
 
583
                       uint32_t key_length_arg,
 
584
                       bool insert_or_update);
 
585
 
 
586
  inline uint32_t offset(unsigned char *record)
 
587
  {
 
588
    return (uint32_t) (ptr - record);
443
589
  }
444
590
  void copy_from_tmp(int offset);
445
 
  uint fill_cache_field(struct st_cache_field *copy);
446
 
  virtual bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
 
591
  uint32_t fill_cache_field(struct st_cache_field *copy);
 
592
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
447
593
  virtual bool get_time(DRIZZLE_TIME *ltime);
448
594
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
449
595
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
450
596
  virtual bool has_charset(void) const { return false; }
451
 
  virtual void set_charset(const CHARSET_INFO * const charset_arg __attribute__((unused)))
452
 
  { }
 
597
  virtual void set_charset(const CHARSET_INFO * const)
 
598
  {}
453
599
  virtual enum Derivation derivation(void) const
454
 
  { return DERIVATION_IMPLICIT; }
455
 
  virtual void set_derivation(enum Derivation derivation_arg __attribute__((unused)))
456
 
  { }
457
 
  bool set_warning(DRIZZLE_ERROR::enum_warning_level, unsigned int code,
 
600
  {
 
601
    return DERIVATION_IMPLICIT;
 
602
  }
 
603
  virtual void set_derivation(enum Derivation)
 
604
  {}
 
605
  /**
 
606
    Produce warning or note about data saved into field.
 
607
 
 
608
    @param level            - level of message (Note/Warning/Error)
 
609
    @param code             - error code of message to be produced
 
610
    @param cuted_increment  - whenever we should increase cut fields count or not
 
611
 
 
612
    @note
 
613
      This function won't produce warning and increase cut fields counter
 
614
      if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
 
615
 
 
616
      if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
 
617
      This allows us to avoid notes in optimisation, like convert_constant_item().
 
618
 
 
619
    @retval
 
620
      1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
 
621
    @retval
 
622
      0 otherwise
 
623
  */
 
624
  bool set_warning(DRIZZLE_ERROR::enum_warning_level, 
 
625
                   unsigned int code,
458
626
                   int cuted_increment);
459
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint code, 
460
 
                            const char *str, uint str_len,
461
 
                            timestamp_type ts_type, int cuted_increment);
462
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint code, 
463
 
                            int64_t nr, timestamp_type ts_type,
464
 
                            int cuted_increment);
465
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint code, 
466
 
                            double nr, timestamp_type ts_type);
 
627
  /**
 
628
    Produce warning or note about datetime string data saved into field.
 
629
 
 
630
    @param level            level of message (Note/Warning/Error)
 
631
    @param code             error code of message to be produced
 
632
    @param str              string value which we tried to save
 
633
    @param str_length       length of string which we tried to save
 
634
    @param ts_type          type of datetime value (datetime/date/time)
 
635
    @param cuted_increment  whenever we should increase cut fields count or not
 
636
 
 
637
    @note
 
638
      This function will always produce some warning but won't increase cut
 
639
      fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
 
640
      thread.
 
641
  */
 
642
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, 
 
643
                            uint32_t code,
 
644
                            const char *str, 
 
645
                            uint32_t str_len,
 
646
                            enum enum_drizzle_timestamp_type ts_type, 
 
647
                            int cuted_increment);
 
648
  /**
 
649
    Produce warning or note about integer datetime value saved into field.
 
650
 
 
651
    @param level            level of message (Note/Warning/Error)
 
652
    @param code             error code of message to be produced
 
653
    @param nr               numeric value which we tried to save
 
654
    @param ts_type          type of datetime value (datetime/date/time)
 
655
    @param cuted_increment  whenever we should increase cut fields count or not
 
656
 
 
657
    @note
 
658
      This function will always produce some warning but won't increase cut
 
659
      fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
 
660
      thread.
 
661
  */
 
662
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, 
 
663
                            uint32_t code,
 
664
                            int64_t nr, 
 
665
                            enum enum_drizzle_timestamp_type ts_type,
 
666
                            int cuted_increment);
 
667
  /**
 
668
    Produce warning or note about double datetime data saved into field.
 
669
 
 
670
    @param level            level of message (Note/Warning/Error)
 
671
    @param code             error code of message to be produced
 
672
    @param nr               double value which we tried to save
 
673
    @param ts_type          type of datetime value (datetime/date/time)
 
674
 
 
675
    @note
 
676
      This function will always produce some warning but won't increase cut
 
677
      fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
 
678
      thread.
 
679
  */
 
680
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, 
 
681
                            const uint32_t code,
 
682
                            double nr, 
 
683
                            enum enum_drizzle_timestamp_type ts_type);
467
684
  inline bool check_overflow(int op_result)
468
685
  {
469
686
    return (op_result == E_DEC_OVERFLOW);
470
687
  }
 
688
  /**
 
689
    Process decimal library return codes and issue warnings for overflow and
 
690
    truncation.
 
691
 
 
692
    @param op_result  decimal library return code (E_DEC_* see include/decimal.h)
 
693
 
 
694
    @retval
 
695
      E_DEC_OVERFLOW   there was overflow
 
696
      E_DEC_TRUNCATED  there was truncation
 
697
    @retval
 
698
      0  no error or there was some other error except overflow or truncation
 
699
  */
471
700
  int warn_if_overflow(int op_result);
472
 
  void init(TABLE *table_arg)
473
 
  {
474
 
    orig_table= table= table_arg;
475
 
    table_name= &table_arg->alias;
476
 
  }
 
701
  void init(Table *table_arg);
477
702
 
478
703
  /* maximum possible display length */
479
704
  virtual uint32_t max_display_length()= 0;
480
705
 
481
 
  virtual uint is_equal(Create_field *new_field);
482
 
  /* convert decimal to int64_t with overflow check */
483
 
  int64_t convert_decimal2int64_t(const my_decimal *val, bool unsigned_flag,
484
 
                                    int *err);
 
706
  virtual uint32_t is_equal(CreateField *new_field);
 
707
  /**
 
708
    Conversion from decimal to int64_t with checking overflow and
 
709
    setting correct value (min/max) in case of overflow.
 
710
 
 
711
    @param val             value which have to be converted
 
712
    @param unsigned_flag   type of integer in which we convert val
 
713
    @param err             variable to pass error code
 
714
 
 
715
    @return
 
716
      value converted from val
 
717
  */
 
718
  int64_t convert_decimal2int64_t(const my_decimal *val, 
 
719
                                  bool unsigned_flag,
 
720
                                  int *err);
485
721
  /* The max. number of characters */
486
722
  inline uint32_t char_length() const
487
723
  {
496
732
 
497
733
  /* Hash value */
498
734
  virtual void hash(uint32_t *nr, uint32_t *nr2);
499
 
  friend bool reopen_table(THD *,struct st_table *,bool);
500
 
  friend int cre_myisam(char * name, register TABLE *form, uint options,
501
 
                        uint64_t auto_increment_value);
502
 
  friend class Copy_field;
 
735
  friend bool reopen_table(Session *,Table *,bool);
 
736
 
 
737
  friend class CopyField;
503
738
  friend class Item_avg_field;
504
739
  friend class Item_std_field;
505
740
  friend class Item_sum_num;
512
747
  friend class Item_sum_max;
513
748
  friend class Item_func_group_concat;
514
749
 
 
750
  bool isReadSet();
 
751
  bool isWriteSet();
 
752
  void setReadSet(bool arg= true);
 
753
  void setWriteSet(bool arg= true);
 
754
 
515
755
private:
516
 
  /*
517
 
    Primitive for implementing last_null_byte().
518
 
 
519
 
    SYNOPSIS
520
 
      do_last_null_byte()
521
 
 
522
 
    DESCRIPTION
523
 
      Primitive for the implementation of the last_null_byte()
524
 
      function. This represents the inheritance interface and can be
525
 
      overridden by subclasses.
526
 
   */
527
 
  virtual size_t do_last_null_byte() const;
 
756
 
 
757
  /**
 
758
    Retrieve the field metadata for fields.
 
759
 
 
760
    This default implementation returns 0 and saves 0 in the metadata_ptr
 
761
    value.
 
762
 
 
763
    @param   metadata_ptr   First byte of field metadata
 
764
 
 
765
    @returns 0 no bytes written.
 
766
  */
 
767
  virtual int do_save_field_metadata(unsigned char *)
 
768
  {
 
769
    return 0;
 
770
  }
 
771
};
 
772
 
 
773
#include "drizzled/create_field.h"
528
774
 
529
775
/**
530
 
   Retrieve the field metadata for fields.
531
 
 
532
 
   This default implementation returns 0 and saves 0 in the metadata_ptr
533
 
   value.
534
 
 
535
 
   @param   metadata_ptr   First byte of field metadata
536
 
 
537
 
   @returns 0 no bytes written.
538
 
*/
539
 
  virtual int do_save_field_metadata(uchar *metadata_ptr __attribute__((unused)))
540
 
  { return 0; }
541
 
};
542
 
 
543
 
 
544
 
class Field_num :public Field {
545
 
public:
546
 
  const uint8_t dec;
547
 
  bool decimal_precision;       // Purify cannot handle bit fields & only for decimal type
548
 
  bool unsigned_flag;   // Purify cannot handle bit fields
549
 
  Field_num(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
550
 
            uchar null_bit_arg, utype unireg_check_arg,
551
 
            const char *field_name_arg,
552
 
            uint8_t dec_arg, bool zero_arg, bool unsigned_arg);
553
 
  Item_result result_type () const { return REAL_RESULT; }
554
 
  void add_unsigned(String &res) const;
555
 
  friend class Create_field;
556
 
  void make_field(Send_field *);
557
 
  uint decimals() const { return (uint) dec; }
558
 
  uint size_of() const { return sizeof(*this); }
559
 
  bool eq_def(Field *field);
560
 
  int store_decimal(const my_decimal *);
561
 
  my_decimal *val_decimal(my_decimal *);
562
 
  uint is_equal(Create_field *new_field);
563
 
  int check_int(const CHARSET_INFO * const cs, const char *str, int length,
564
 
                const char *int_end, int error);
565
 
  bool get_int(const CHARSET_INFO * const cs, const char *from, uint len, 
566
 
               int64_t *rnd, uint64_t unsigned_max, 
567
 
               int64_t signed_min, int64_t signed_max);
568
 
};
569
 
 
570
 
/* base class for all string related classes */
571
 
 
572
 
class Field_str :public Field {
573
 
protected:
574
 
  const CHARSET_INFO *field_charset;
575
 
  enum Derivation field_derivation;
576
 
public:
577
 
  Field_str(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
578
 
            uchar null_bit_arg, utype unireg_check_arg,
579
 
            const char *field_name_arg, const CHARSET_INFO * const charset);
580
 
  Item_result result_type () const { return STRING_RESULT; }
581
 
  uint decimals() const { return NOT_FIXED_DEC; }
582
 
  int  store(double nr);
583
 
  int  store(int64_t nr, bool unsigned_val)=0;
584
 
  int  store_decimal(const my_decimal *);
585
 
  int  store(const char *to,uint length, const CHARSET_INFO * const cs)=0;
586
 
  uint size_of() const { return sizeof(*this); }
587
 
  const CHARSET_INFO *charset(void) const { return field_charset; }
588
 
  void set_charset(const CHARSET_INFO * const charset_arg) { field_charset= charset_arg; }
589
 
  enum Derivation derivation(void) const { return field_derivation; }
590
 
  virtual void set_derivation(enum Derivation derivation_arg)
591
 
  { field_derivation= derivation_arg; }
592
 
  bool binary() const { return field_charset == &my_charset_bin; }
593
 
  uint32_t max_display_length() { return field_length; }
594
 
  friend class Create_field;
595
 
  my_decimal *val_decimal(my_decimal *);
596
 
  virtual bool str_needs_quotes() { return true; }
597
 
  bool compare_str_field_flags(Create_field *new_field, uint32_t flags);
598
 
  uint is_equal(Create_field *new_field);
599
 
};
600
 
 
601
 
 
602
 
/* base class for Field_varstring and Field_blob */
603
 
 
604
 
class Field_longstr :public Field_str
605
 
{
606
 
protected:
607
 
  int report_if_important_data(const char *ptr, const char *end);
608
 
public:
609
 
  Field_longstr(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
610
 
                uchar null_bit_arg, utype unireg_check_arg,
611
 
                const char *field_name_arg, const CHARSET_INFO * const charset_arg)
612
 
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
613
 
               field_name_arg, charset_arg)
614
 
    {}
615
 
 
616
 
  int store_decimal(const my_decimal *d);
617
 
  uint32_t max_data_length() const;
618
 
};
619
 
 
620
 
/* base class for float and double and decimal (old one) */
621
 
class Field_real :public Field_num {
622
 
public:
623
 
  bool not_fixed;
624
 
 
625
 
  Field_real(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
626
 
             uchar null_bit_arg, utype unireg_check_arg,
627
 
             const char *field_name_arg,
628
 
             uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
629
 
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
630
 
               field_name_arg, dec_arg, zero_arg, unsigned_arg),
631
 
    not_fixed(dec_arg >= NOT_FIXED_DEC)
632
 
    {}
633
 
  int store_decimal(const my_decimal *);
634
 
  my_decimal *val_decimal(my_decimal *);
635
 
  int truncate(double *nr, double max_length);
636
 
  uint32_t max_display_length() { return field_length; }
637
 
  uint size_of() const { return sizeof(*this); }
638
 
  virtual const uchar *unpack(uchar* to, const uchar *from,
639
 
                              uint param_data, bool low_byte_first);
640
 
  virtual uchar *pack(uchar* to, const uchar *from,
641
 
                      uint max_length, bool low_byte_first);
642
 
};
643
 
 
644
 
 
645
 
class Field_tiny :public Field_num {
646
 
public:
647
 
  Field_tiny(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
648
 
             uchar null_bit_arg,
649
 
             enum utype unireg_check_arg, const char *field_name_arg,
650
 
             bool zero_arg, bool unsigned_arg)
651
 
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
652
 
               unireg_check_arg, field_name_arg,
653
 
               0, zero_arg,unsigned_arg)
654
 
    {}
655
 
  enum Item_result result_type () const { return INT_RESULT; }
656
 
  enum_field_types type() const { return DRIZZLE_TYPE_TINY;}
657
 
  enum ha_base_keytype key_type() const
658
 
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
659
 
  int store(const char *to,uint length, const CHARSET_INFO * const charset);
660
 
  int store(double nr);
661
 
  int store(int64_t nr, bool unsigned_val);
662
 
  int reset(void) { ptr[0]=0; return 0; }
663
 
  double val_real(void);
664
 
  int64_t val_int(void);
665
 
  String *val_str(String*,String *);
666
 
  bool send_binary(Protocol *protocol);
667
 
  int cmp(const uchar *,const uchar *);
668
 
  void sort_string(uchar *buff,uint length);
669
 
  uint32_t pack_length() const { return 1; }
670
 
  void sql_type(String &str) const;
671
 
  uint32_t max_display_length() { return 4; }
672
 
 
673
 
  virtual uchar *pack(uchar* to, const uchar *from,
674
 
                      uint max_length __attribute__((unused)),
675
 
                      bool low_byte_first __attribute__((unused)))
676
 
  {
677
 
    *to= *from;
678
 
    return to + 1;
679
 
  }
680
 
 
681
 
  virtual const uchar *unpack(uchar* to, const uchar *from,
682
 
                              uint param_data __attribute__((unused)),
683
 
                              bool low_byte_first __attribute__((unused)))
684
 
  {
685
 
    *to= *from;
686
 
    return from + 1;
687
 
  }
688
 
};
689
 
 
690
 
 
691
 
class Field_enum :public Field_str {
692
 
protected:
693
 
  uint packlength;
694
 
public:
695
 
  TYPELIB *typelib;
696
 
  Field_enum(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
697
 
             uchar null_bit_arg,
698
 
             enum utype unireg_check_arg, const char *field_name_arg,
699
 
             uint packlength_arg,
700
 
             TYPELIB *typelib_arg,
701
 
             const CHARSET_INFO * const charset_arg)
702
 
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
703
 
               unireg_check_arg, field_name_arg, charset_arg),
704
 
    packlength(packlength_arg),typelib(typelib_arg)
705
 
  {
706
 
      flags|=ENUM_FLAG;
707
 
  }
708
 
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
709
 
  enum_field_types type() const { return DRIZZLE_TYPE_ENUM; }
710
 
  enum Item_result cmp_type () const { return INT_RESULT; }
711
 
  enum Item_result cast_to_int_type () const { return INT_RESULT; }
712
 
  enum ha_base_keytype key_type() const;
713
 
  int  store(const char *to,uint length, const CHARSET_INFO * const charset);
714
 
  int  store(double nr);
715
 
  int  store(int64_t nr, bool unsigned_val);
716
 
  double val_real(void);
717
 
  int64_t val_int(void);
718
 
  String *val_str(String*,String *);
719
 
  int cmp(const uchar *,const uchar *);
720
 
  void sort_string(uchar *buff,uint length);
721
 
  uint32_t pack_length() const { return (uint32_t) packlength; }
722
 
  void store_type(uint64_t value);
723
 
  void sql_type(String &str) const;
724
 
  uint size_of() const { return sizeof(*this); }
725
 
  enum_field_types real_type() const { return DRIZZLE_TYPE_ENUM; }
726
 
  uint pack_length_from_metadata(uint field_metadata)
727
 
  { return (field_metadata & 0x00ff); }
728
 
  uint row_pack_length() { return pack_length(); }
729
 
  virtual bool zero_pack() const { return 0; }
730
 
  bool optimize_range(uint idx __attribute__((unused)),
731
 
                      uint part __attribute__((unused)))
732
 
  { return 0; }
733
 
  bool eq_def(Field *field);
734
 
  bool has_charset(void) const { return true; }
735
 
  /* enum and set are sorted as integers */
736
 
  const CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
737
 
private:
738
 
  int do_save_field_metadata(uchar *first_byte);
739
 
};
740
 
 
741
 
/*
742
 
  Create field class for CREATE TABLE
743
 
*/
744
 
 
745
 
class Create_field :public Sql_alloc
746
 
{
747
 
public:
748
 
  const char *field_name;
749
 
  const char *change;                   // If done with alter table
750
 
  const char *after;                    // Put column after this one
751
 
  LEX_STRING comment;                   // Comment for field
752
 
  Item  *def;                           // Default value
753
 
  enum  enum_field_types sql_type;
754
 
  /*
755
 
    At various stages in execution this can be length of field in bytes or
756
 
    max number of characters. 
757
 
  */
758
 
  uint32_t length;
759
 
  /*
760
 
    The value of `length' as set by parser: is the number of characters
761
 
    for most of the types, or of bytes for BLOBs or numeric types.
762
 
  */
763
 
  uint32_t char_length;
764
 
  uint  decimals, flags, pack_length, key_length;
765
 
  Field::utype unireg_check;
766
 
  TYPELIB *interval;                    // Which interval to use
767
 
  TYPELIB *save_interval;               // Temporary copy for the above
768
 
                                        // Used only for UCS2 intervals
769
 
  List<String> interval_list;
770
 
  const CHARSET_INFO *charset;
771
 
  Field *field;                         // For alter table
772
 
 
773
 
  uint8_t row,col,sc_length,interval_id;        // For rea_create_table
774
 
  uint  offset,pack_flag;
775
 
  Create_field() :after(0) {}
776
 
  Create_field(Field *field, Field *orig_field);
777
 
  /* Used to make a clone of this object for ALTER/CREATE TABLE */
778
 
  Create_field *clone(MEM_ROOT *mem_root) const
779
 
    { return new (mem_root) Create_field(*this); }
780
 
  void create_length_to_internal_length(void);
781
 
 
782
 
  inline enum column_format_type column_format() const
783
 
  {
784
 
    return (enum column_format_type)
785
 
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
786
 
  }
787
 
 
788
 
  /* Init for a tmp table field. To be extended if need be. */
789
 
  void init_for_tmp_table(enum_field_types sql_type_arg,
790
 
                          uint32_t max_length, uint32_t decimals,
791
 
                          bool maybe_null, bool is_unsigned);
792
 
 
793
 
  bool init(THD *thd, char *field_name, enum_field_types type, char *length,
794
 
            char *decimals, uint type_modifier, Item *default_value,
795
 
            Item *on_update_value, LEX_STRING *comment, char *change,
796
 
            List<String> *interval_list, const CHARSET_INFO * const cs,
797
 
            uint uint_geom_type,
798
 
            enum column_format_type column_format);
799
 
};
800
 
 
801
 
 
802
 
/*
803
 
  A class for sending info to the client
804
 
*/
805
 
 
806
 
class Send_field {
807
 
 public:
 
776
 * A class for sending field information to a client.
 
777
 *
 
778
 * @details
 
779
 *
 
780
 * Send_field is basically a stripped-down POD class for
 
781
 * representing basic information about a field...
 
782
 */
 
783
class SendField 
 
784
{
 
785
public:
808
786
  const char *db_name;
809
 
  const char *table_name,*org_table_name;
810
 
  const char *col_name,*org_col_name;
 
787
  const char *table_name;
 
788
  const char *org_table_name;
 
789
  const char *col_name;
 
790
  const char *org_col_name;
811
791
  uint32_t length;
812
 
  uint charsetnr, flags, decimals;
 
792
  uint32_t charsetnr;
 
793
  uint32_t flags;
 
794
  uint32_t decimals;
813
795
  enum_field_types type;
814
 
  Send_field() {}
 
796
  SendField() {}
815
797
};
816
798
 
817
 
 
818
 
/*
819
 
  A class for quick copying data to fields
820
 
*/
821
 
 
822
 
class Copy_field :public Sql_alloc {
 
799
/**
 
800
 * A class for quick copying data to fields
 
801
 */
 
802
class CopyField :public Sql_alloc
 
803
{
823
804
  /**
824
805
    Convenience definition of a copy function returned by
825
806
    get_copy_func.
826
807
  */
827
 
  typedef void Copy_func(Copy_field*);
 
808
  typedef void Copy_func(CopyField*);
828
809
  Copy_func *get_copy_func(Field *to, Field *from);
829
810
public:
830
 
  uchar *from_ptr,*to_ptr;
831
 
  uchar *from_null_ptr,*to_null_ptr;
 
811
  unsigned char *from_ptr;
 
812
  unsigned char *to_ptr;
 
813
  unsigned char *from_null_ptr;
 
814
  unsigned char *to_null_ptr;
832
815
  bool *null_row;
833
 
  uint  from_bit,to_bit;
834
 
  uint from_length,to_length;
835
 
  Field *from_field,*to_field;
 
816
  uint32_t from_bit;
 
817
  uint32_t to_bit;
 
818
  uint32_t from_length;
 
819
  uint32_t to_length;
 
820
  Field *from_field;
 
821
  Field *to_field;
836
822
  String tmp;                                   // For items
837
823
 
838
 
  Copy_field() {}
839
 
  ~Copy_field() {}
840
 
  void set(Field *to,Field *from,bool save);    // Field to field 
841
 
  void set(uchar *to,Field *from);              // Field to string
842
 
  void (*do_copy)(Copy_field *);
843
 
  void (*do_copy2)(Copy_field *);               // Used to handle null values
 
824
  CopyField() {}
 
825
  ~CopyField() {}
 
826
  void set(Field *to,Field *from,bool save);    // Field to field
 
827
  void set(unsigned char *to,Field *from);              // Field to string
 
828
  void (*do_copy)(CopyField *);
 
829
  void (*do_copy2)(CopyField *);                // Used to handle null values
844
830
};
845
831
 
 
832
Field *make_field(TableShare *share,
 
833
                  MEM_ROOT *root,
 
834
                  unsigned char *ptr,
 
835
                  uint32_t field_length,
 
836
                  bool is_nullable,
 
837
                  unsigned char *null_pos,
 
838
                  unsigned char null_bit,
 
839
                  uint8_t decimals,
 
840
                  enum_field_types field_type,
 
841
                  const CHARSET_INFO * cs,
 
842
                  Field::utype unireg_check,
 
843
                  TYPELIB *interval,
 
844
                  const char *field_name);
846
845
 
847
 
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32_t field_length,
848
 
                  uchar *null_pos, uchar null_bit,
849
 
                  uint pack_flag, enum_field_types field_type,
850
 
                  const CHARSET_INFO * cs,
851
 
                  Field::utype unireg_check,
852
 
                  TYPELIB *interval, const char *field_name);
853
 
uint pack_length_to_packflag(uint type);
854
 
enum_field_types get_blob_type_from_length(uint32_t length);
 
846
uint32_t pack_length_to_packflag(uint32_t type);
855
847
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
856
848
int set_field_to_null(Field *field);
857
849
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
858
850
 
859
 
bool
860
 
check_string_copy_error(Field_str *field,
861
 
                        const char *well_formed_error_pos,
862
 
                        const char *cannot_convert_error_pos,
863
 
                        const char *end,
864
 
                        const CHARSET_INFO * const cs);
865
 
 
866
 
/*
867
 
  Field subclasses
 
851
/**
 
852
 * Tests if the given string contains important data:
 
853
 * not spaces for character string, or any data for binary string.
 
854
 *
 
855
 * @param pointer to the character set to use
 
856
 * @param String to test
 
857
 * @param String end
 
858
 *
 
859
 * @retval
 
860
 *  false - If string does not have important data
 
861
 * @retval
 
862
 *  true  - If string has some important data
868
863
 */
869
 
#include <drizzled/field/blob.h>
870
 
#include <drizzled/field/null.h>
871
 
#include <drizzled/field/date.h>
872
 
#include <drizzled/field/fdecimal.h>
873
 
#include <drizzled/field/double.h>
874
 
#include <drizzled/field/short.h>
875
 
#include <drizzled/field/long.h>
876
 
#include <drizzled/field/int64_t.h>
877
 
#include <drizzled/field/timetype.h>
878
 
#include <drizzled/field/timestamp.h>
879
 
#include <drizzled/field/datetime.h>
880
 
#include <drizzled/field/fstring.h>
881
 
#include <drizzled/field/varstring.h>
882
 
 
883
 
/*
884
 
  The following are for the interface with the .frm file
885
 
*/
886
 
 
887
 
#define FIELDFLAG_DECIMAL               1
888
 
#define FIELDFLAG_BINARY                1       // Shares same flag
889
 
#define FIELDFLAG_NUMBER                2
890
 
#define FIELDFLAG_DECIMAL_POSITION      4
891
 
#define FIELDFLAG_PACK                  120     // Bits used for packing
892
 
#define FIELDFLAG_INTERVAL              256     // mangled with decimals!
893
 
#define FIELDFLAG_BITFIELD              512     // mangled with decimals!
894
 
#define FIELDFLAG_BLOB                  1024    // mangled with decimals!
895
 
#define FIELDFLAG_GEOM                  2048    // mangled with decimals!
896
 
 
897
 
#define FIELDFLAG_TREAT_BIT_AS_CHAR     4096    /* use Field_bit_as_char */
898
 
 
899
 
#define FIELDFLAG_LEFT_FULLSCREEN       8192
900
 
#define FIELDFLAG_RIGHT_FULLSCREEN      16384
901
 
#define FIELDFLAG_FORMAT_NUMBER         16384   // predit: ###,,## in output
902
 
#define FIELDFLAG_NO_DEFAULT            16384   /* sql */
903
 
#define FIELDFLAG_SUM                   ((uint) 32768)// predit: +#fieldflag
904
 
#define FIELDFLAG_MAYBE_NULL            ((uint) 32768)// sql
905
 
#define FIELDFLAG_HEX_ESCAPE            ((uint) 0x10000)
906
 
#define FIELDFLAG_PACK_SHIFT            3
907
 
#define FIELDFLAG_DEC_SHIFT             8
908
 
#define FIELDFLAG_MAX_DEC               31
909
 
#define FIELDFLAG_NUM_SCREEN_TYPE       0x7F01
910
 
#define FIELDFLAG_ALFA_SCREEN_TYPE      0x7800
911
 
 
912
 
#define MTYP_TYPENR(type) (type & 127)  /* Remove bits from type */
913
 
 
914
 
#define f_is_dec(x)             ((x) & FIELDFLAG_DECIMAL)
915
 
#define f_is_num(x)             ((x) & FIELDFLAG_NUMBER)
916
 
#define f_is_decimal_precision(x)       ((x) & FIELDFLAG_DECIMAL_POSITION)
917
 
#define f_is_packed(x)          ((x) & FIELDFLAG_PACK)
918
 
#define f_packtype(x)           (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
919
 
#define f_decimals(x)           ((uint8_t) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
920
 
#define f_is_alpha(x)           (!f_is_num(x))
921
 
#define f_is_binary(x)          ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
922
 
#define f_is_enum(x)            (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
923
 
#define f_is_bitfield(x)        (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
924
 
#define f_is_blob(x)            (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
925
 
#define f_is_equ(x)             ((x) & (1+2+FIELDFLAG_PACK+31*256))
926
 
#define f_settype(x)            (((int) x) << FIELDFLAG_PACK_SHIFT)
927
 
#define f_maybe_null(x)         (x & FIELDFLAG_MAYBE_NULL)
928
 
#define f_no_default(x)         (x & FIELDFLAG_NO_DEFAULT)
929
 
#define f_bit_as_char(x)        ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
930
 
#define f_is_hex_escape(x)      ((x) & FIELDFLAG_HEX_ESCAPE)
931
 
 
 
864
bool test_if_important_data(const CHARSET_INFO * const cs,
 
865
                            const char *str,
 
866
                            const char *strend);
 
867
 
 
868
#endif /* DRIZZLED_FIELD_H */