~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/field.h

Removed dead variable, sorted authors file.

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/my_decimal.h>
30
 
#include <drizzled/sql_bitmap.h>
31
 
#include <drizzled/sql_list.h>
32
 
#include <string>
 
22
#ifdef USE_PRAGMA_INTERFACE
 
23
#pragma interface                       /* gcc class implementation */
 
24
#endif
33
25
 
34
26
#define DATETIME_DEC                     6
35
 
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
36
 
 
37
 
const uint32_t max_field_size= (uint32_t) 4294967295U;
38
 
 
39
 
class Table;
 
27
const uint32 max_field_size= (uint32) 4294967295U;
 
28
 
40
29
class Send_field;
41
30
class Protocol;
42
31
class Create_field;
43
 
class virtual_column_info;
44
 
 
45
 
typedef struct st_table_share TABLE_SHARE;
46
 
 
47
32
struct st_cache_field;
48
33
int field_conv(Field *to,Field *from);
49
34
 
50
 
inline uint32_t get_enum_pack_length(int elements)
 
35
inline uint get_enum_pack_length(int elements)
51
36
{
52
37
  return elements < 256 ? 1 : 2;
53
38
}
54
39
 
55
 
inline uint32_t get_set_pack_length(int elements)
 
40
inline uint get_set_pack_length(int elements)
56
41
{
57
 
  uint32_t len= (elements + 7) / 8;
 
42
  uint len= (elements + 7) / 8;
58
43
  return len > 4 ? 8 : len;
59
44
}
60
45
 
64
49
  void operator=(Field &);
65
50
public:
66
51
  static void *operator new(size_t size) {return sql_alloc(size); }
67
 
  static void operator delete(void *, size_t)
 
52
  static void operator delete(void *ptr_arg __attribute__((__unused__)),
 
53
                              size_t size __attribute__((__unused__)))
68
54
  { TRASH(ptr_arg, size); }
69
55
 
70
 
  unsigned char         *ptr;                   // Position to field in record
71
 
  unsigned char         *null_ptr;              // Byte where null_bit is
 
56
  uchar         *ptr;                   // Position to field in record
 
57
  uchar         *null_ptr;              // Byte where null_bit is
72
58
  /*
73
 
    Note that you can use table->in_use as replacement for current_session member
 
59
    Note that you can use table->in_use as replacement for current_thd member 
74
60
    only inside of val_*() and store() members (e.g. you can't use it in cons)
75
61
  */
76
 
  Table *table;         // Pointer for table
77
 
  Table *orig_table;            // Pointer to original table
 
62
  struct st_table *table;               // Pointer for table
 
63
  struct st_table *orig_table;          // Pointer to original table
78
64
  const char    **table_name, *field_name;
79
65
  LEX_STRING    comment;
80
66
  /* Field is part of the following keys */
81
67
  key_map       key_start, part_of_key, part_of_key_not_clustered;
82
68
  key_map       part_of_sortkey;
83
 
  /*
84
 
    We use three additional unireg types for TIMESTAMP to overcome limitation
85
 
    of current binary format of .frm file. We'd like to be able to support
86
 
    NOW() as default and on update value for such fields but unable to hold
 
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 
87
73
    this info anywhere except unireg_check field. This issue will be resolved
88
74
    in more clean way with transition to new text based .frm format.
89
75
    See also comment for Field_timestamp::Field_timestamp().
90
76
  */
91
77
  enum utype  { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
92
 
                CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
 
78
                CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
93
79
                BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
94
80
                TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
95
81
  enum imagetype { itRAW, itMBR};
96
82
 
97
83
  utype         unireg_check;
98
 
  uint32_t      field_length;           // Length of field
99
 
  uint32_t      flags;
100
 
  uint16_t        field_index;            // field number in fields array
101
 
  unsigned char         null_bit;               // Bit used to test null bit
 
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
102
88
  /**
103
89
     If true, this field was created in create_tmp_field_from_item from a NULL
104
90
     value. This means that the type of the field is just a guess, and the type
110
96
   */
111
97
  bool is_created_from_null_item;
112
98
 
113
 
  /* Virtual column data */
114
 
  virtual_column_info *vcol_info;
115
 
  /*
116
 
    Indication that the field is physically stored in tables
117
 
    rather than just generated on SQL queries.
118
 
    As of now, false can only be set for generated-only virtual columns.
119
 
  */
120
 
  bool is_stored;
121
 
 
122
 
  Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
123
 
        unsigned char null_bit_arg, 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,
124
101
        const char *field_name_arg);
125
102
  virtual ~Field() {}
126
103
  /* Store functions returns 1 on overflow and -1 on fatal error */
127
 
  virtual int  store(const char *to, uint32_t length,
128
 
                     const CHARSET_INFO * const cs)=0;
 
104
  virtual int  store(const char *to, uint length,CHARSET_INFO *cs)=0;
129
105
  virtual int  store(double nr)=0;
130
106
  virtual int  store(int64_t nr, bool unsigned_val)=0;
131
107
  virtual int  store_decimal(const my_decimal *d)=0;
132
 
  virtual int store_time(DRIZZLE_TIME *ltime,
133
 
                         enum enum_drizzle_timestamp_type t_type);
134
 
  int store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
 
108
  virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
 
109
  int store(const char *to, uint length, CHARSET_INFO *cs,
135
110
            enum_check_fields check_level);
136
111
  virtual double val_real(void)=0;
137
112
  virtual int64_t val_int(void)=0;
142
117
     if it needs a temp buffer to convert result to string - use buf1
143
118
       example Field_tiny::val_str()
144
119
     if the value exists as a string already - use buf2
145
 
       example Field_varstring::val_str() (???)
 
120
       example Field_string::val_str()
146
121
     consequently, buf2 may be created as 'String buf;' - no memory
147
122
     will be allocated for it. buf1 will be allocated to hold a
148
123
     value if it's too small. Using allocated buffer for buf2 may result in
150
125
     This trickery is used to decrease a number of malloc calls.
151
126
  */
152
127
  virtual String *val_str(String*,String *)=0;
153
 
  String *val_int_as_str(String *val_buffer, bool unsigned_flag);
 
128
  String *val_int_as_str(String *val_buffer, my_bool unsigned_flag);
154
129
  /*
155
130
   str_needs_quotes() returns true if the value returned by val_str() needs
156
131
   to be quoted when used in constructing an SQL query.
159
134
  virtual Item_result result_type () const=0;
160
135
  virtual Item_result cmp_type () const { return result_type(); }
161
136
  virtual Item_result cast_to_int_type () const { return result_type(); }
162
 
  /**
163
 
     Check whether a field type can be partially indexed by a key.
164
 
 
165
 
     This is a static method, rather than a virtual function, because we need
166
 
     to check the type of a non-Field in mysql_alter_table().
167
 
 
168
 
     @param type  field type
169
 
 
170
 
     @retval
171
 
       true  Type can have a prefixed key
172
 
     @retval
173
 
       false Type can not have a prefixed key
174
 
  */
175
137
  static bool type_can_have_key_part(enum_field_types);
176
138
  static enum_field_types field_type_merge(enum_field_types, enum_field_types);
177
 
 
178
 
  /**
179
 
     Detect Item_result by given field type of UNION merge result.
180
 
 
181
 
     @param field_type  given field type
182
 
 
183
 
     @return
184
 
       Item_result (type of internal MySQL expression result)
185
 
  */
186
139
  static Item_result result_merge_type(enum_field_types);
187
 
 
188
 
  virtual bool eq(Field *field);
 
140
  virtual bool eq(Field *field)
 
141
  {
 
142
    return (ptr == field->ptr && null_ptr == field->null_ptr &&
 
143
            null_bit == field->null_bit);
 
144
  }
189
145
  virtual bool eq_def(Field *field);
190
 
 
 
146
  
191
147
  /*
192
148
    pack_length() returns size (in bytes) used to store field data in memory
193
149
    (i.e. it returns the maximum size of the field in a row of the table,
194
150
    which is located in RAM).
195
151
  */
196
 
  virtual uint32_t pack_length() const;
 
152
  virtual uint32 pack_length() const { return (uint32) field_length; }
197
153
 
198
154
  /*
199
155
    pack_length_in_rec() returns size (in bytes) used to store field data on
200
156
    storage (i.e. it returns the maximal size of the field in a row of the
201
157
    table, which is located on disk).
202
158
  */
203
 
  virtual uint32_t pack_length_in_rec() const;
204
 
  virtual int compatible_field_size(uint32_t field_metadata);
205
 
  virtual uint32_t pack_length_from_metadata(uint32_t field_metadata);
206
 
 
 
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; }
207
163
  /*
208
164
    This method is used to return the size of the data in a row-based
209
165
    replication row record. The default implementation of returning 0 is
210
166
    designed to allow fields that do not use metadata to return true (1)
211
167
    from compatible_field_size() which uses this function in the comparison.
212
 
    The default value for field metadata for fields that do not have
 
168
    The default value for field metadata for fields that do not have 
213
169
    metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
214
170
 
215
171
    Note: While most classes that override this method return pack_length(),
216
 
    the classes Field_varstring, and Field_blob return
 
172
    the classes Field_string, Field_varstring, and Field_blob return 
217
173
    field_length + 1, field_length, and pack_length_no_ptr() respectfully.
218
174
  */
219
 
  virtual uint32_t row_pack_length();
220
 
  virtual int save_field_metadata(unsigned char *first_byte);
 
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); }
221
178
 
222
179
  /*
223
180
    data_length() return the "real size" of the data in memory.
224
181
    For varstrings, this does _not_ include the length bytes.
225
182
  */
226
 
  virtual uint32_t data_length();
 
183
  virtual uint32 data_length() { return pack_length(); }
227
184
  /*
228
185
    used_length() returns the number of bytes actually used to store the data
229
186
    of the field. So for a varstring it includes both lenght byte(s) and
230
187
    string data, and anything after data_length() bytes are unused.
231
188
  */
232
 
  virtual uint32_t used_length();
233
 
  virtual uint32_t sort_length() const;
 
189
  virtual uint32 used_length() { return pack_length(); }
 
190
  virtual uint32 sort_length() const { return pack_length(); }
234
191
 
235
192
  /**
236
193
     Get the maximum size of the data in packed format.
238
195
     @return Maximum data length of the field when packed using the
239
196
     Field::pack() function.
240
197
   */
241
 
  virtual uint32_t max_data_length() const;
242
 
  virtual int reset(void);
243
 
  virtual void reset_fields();
244
 
  virtual void set_default();
245
 
  virtual bool binary() const;
246
 
  virtual bool zero_pack() const;
247
 
  virtual enum ha_base_keytype key_type() const;
248
 
  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(); }
249
215
  virtual enum_field_types type() const =0;
250
 
  virtual enum_field_types real_type() const;
251
 
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
252
 
  virtual int cmp_max(const unsigned char *a, const unsigned char *b,
253
 
                      uint32_t max_len);
254
 
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
255
 
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
256
 
                         uint32_t max_length=UINT32_MAX);
257
 
  virtual int cmp_offset(uint32_t row_offset);
258
 
  virtual int cmp_binary_offset(uint32_t row_offset);
259
 
  virtual int key_cmp(const unsigned char *a,const unsigned char *b);
260
 
  virtual int key_cmp(const unsigned char *str, uint32_t length);
261
 
  virtual uint32_t decimals() const;
262
 
 
 
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; }
263
234
  /*
264
235
    Caller beware: sql_type can change str.Ptr, so check
265
236
    ptr() to see if it changed if you are using your own buffer
266
237
    in str and restore it with set() if needed
267
238
  */
268
239
  virtual void sql_type(String &str) const =0;
269
 
 
270
 
  // For new field
271
 
  virtual uint32_t size_of() const =0;
272
 
 
273
 
  bool is_null(my_ptrdiff_t row_offset= 0);
274
 
  bool is_real_null(my_ptrdiff_t row_offset= 0);
275
 
  bool is_null_in_record(const unsigned char *record);
276
 
  bool is_null_in_record_with_offset(my_ptrdiff_t offset);
277
 
  void set_null(my_ptrdiff_t row_offset= 0);
278
 
  void set_notnull(my_ptrdiff_t row_offset= 0);
279
 
  bool maybe_null(void);
280
 
  bool real_maybe_null(void);
 
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; }
281
264
 
282
265
  enum {
283
266
    LAST_NULL_BYTE_UNDEF= 0
298
281
      the record. If the field does not use any bits of the null
299
282
      bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
300
283
   */
301
 
  size_t last_null_byte() const;
 
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;
 
288
  }
302
289
 
303
290
  virtual void make_field(Send_field *);
304
 
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
305
 
  virtual bool optimize_range(uint32_t idx, uint32_t part);
 
291
  virtual void sort_string(uchar *buff,uint length)=0;
 
292
  virtual bool optimize_range(uint idx, uint part);
306
293
  /*
307
294
    This should be true for fields which, when compared with constant
308
295
    items, can be casted to int64_t. In this case we will at 'fix_fields'
312
299
  */
313
300
  virtual bool can_be_compared_as_int64_t() const { return false; }
314
301
  virtual void free() {}
315
 
  virtual Field *new_field(MEM_ROOT *root, Table *new_table,
 
302
  virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table,
316
303
                           bool keep_type);
317
 
  virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
318
 
                               unsigned char *new_ptr, unsigned char *new_null_ptr,
319
 
                               uint32_t new_null_bit);
320
 
  Field *clone(MEM_ROOT *mem_root, Table *new_table);
321
 
  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)
322
309
  {
323
310
    ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
324
311
  }
325
 
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
 
312
  inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; }
326
313
  virtual void move_field_offset(my_ptrdiff_t ptr_diff)
327
314
  {
328
 
    ptr=ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
 
315
    ptr=ADD_TO_PTR(ptr,ptr_diff, uchar*);
329
316
    if (null_ptr)
330
 
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
 
317
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
331
318
  }
332
 
  virtual void get_image(unsigned char *buff, uint32_t length,
333
 
                         const CHARSET_INFO * const)
 
319
  virtual void get_image(uchar *buff, uint length,
 
320
                         CHARSET_INFO *cs __attribute__((__unused__)))
334
321
    { memcpy(buff,ptr,length); }
335
 
  virtual void get_image(std::basic_string<unsigned char> &buff,
336
 
                         uint32_t length,
337
 
                         const CHARSET_INFO * const)
338
 
    { buff.append(ptr,length); }
339
 
  virtual void set_image(const unsigned char *buff,uint32_t length,
340
 
                         const CHARSET_INFO * const)
 
322
  virtual void set_image(const uchar *buff,uint length,
 
323
                         CHARSET_INFO *cs __attribute__((__unused__)))
341
324
    { memcpy(ptr,buff,length); }
342
325
 
343
326
 
367
350
      Number of copied bytes (excluding padded zero bytes -- see above).
368
351
  */
369
352
 
370
 
  virtual uint32_t get_key_image(unsigned char *buff, uint32_t length, imagetype)
371
 
  {
372
 
    get_image(buff, length, &my_charset_bin);
373
 
    return length;
374
 
  }
375
 
  virtual uint32_t get_key_image(std::basic_string<unsigned char> &buff,
376
 
                                 uint32_t length, imagetype)
377
 
  {
378
 
    get_image(buff, length, &my_charset_bin);
379
 
    return length;
380
 
  }
381
 
  virtual void set_key_image(const unsigned char *buff,uint32_t length)
 
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)
382
360
    { set_image(buff,length, &my_charset_bin); }
383
 
  inline int64_t val_int_offset(uint32_t row_offset)
 
361
  inline int64_t val_int_offset(uint row_offset)
384
362
    {
385
363
      ptr+=row_offset;
386
364
      int64_t tmp=val_int();
387
365
      ptr-=row_offset;
388
366
      return tmp;
389
367
    }
390
 
  inline int64_t val_int(const unsigned char *new_ptr)
 
368
  inline int64_t val_int(const uchar *new_ptr)
391
369
  {
392
 
    unsigned char *old_ptr= ptr;
 
370
    uchar *old_ptr= ptr;
393
371
    int64_t return_value;
394
 
    ptr= (unsigned char*) new_ptr;
 
372
    ptr= (uchar*) new_ptr;
395
373
    return_value= val_int();
396
374
    ptr= old_ptr;
397
375
    return return_value;
398
376
  }
399
 
  inline String *val_str(String *str, const unsigned char *new_ptr)
 
377
  inline String *val_str(String *str, const uchar *new_ptr)
400
378
  {
401
 
    unsigned char *old_ptr= ptr;
402
 
    ptr= (unsigned char*) new_ptr;
 
379
    uchar *old_ptr= ptr;
 
380
    ptr= (uchar*) new_ptr;
403
381
    val_str(str);
404
382
    ptr= old_ptr;
405
383
    return str;
406
384
  }
407
385
  virtual bool send_binary(Protocol *protocol);
408
386
 
409
 
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
410
 
                              uint32_t max_length, bool low_byte_first);
411
 
  /**
412
 
     @overload Field::pack(unsigned char*, const unsigned char*,
413
 
                           uint32_t, bool)
414
 
  */
415
 
  unsigned char *pack(unsigned char *to, const unsigned char *from);
416
 
 
417
 
  virtual const unsigned char *unpack(unsigned char* to,
418
 
                                      const unsigned char *from,
419
 
                                      uint32_t param_data,
420
 
                                      bool low_byte_first);
421
 
  /**
422
 
     @overload Field::unpack(unsigned char*, const unsigned char*,
423
 
                             uint32_t, bool)
424
 
  */
425
 
  const unsigned char *unpack(unsigned char* to, const unsigned char *from);
426
 
 
427
 
  virtual unsigned char *pack_key(unsigned char* to, const unsigned char *from,
428
 
                          uint32_t max_length, bool low_byte_first)
429
 
  {
430
 
    return pack(to, from, max_length, low_byte_first);
431
 
  }
432
 
  virtual unsigned char *pack_key_from_key_image(unsigned char* to,
433
 
                                                 const unsigned char *from,
434
 
                                                 uint32_t max_length,
435
 
                                                 bool low_byte_first)
436
 
  {
437
 
    return pack(to, from, max_length, low_byte_first);
438
 
  }
439
 
  virtual const unsigned char *unpack_key(unsigned char* to,
440
 
                                          const unsigned char *from,
441
 
                                          uint32_t max_length,
442
 
                                          bool low_byte_first)
 
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)
443
421
  {
444
422
    return unpack(to, from, max_length, low_byte_first);
445
423
  }
446
 
  virtual uint32_t packed_col_length(const unsigned char *to, uint32_t length);
447
 
  virtual uint32_t max_packed_col_length(uint32_t max_length)
 
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)
448
428
  { return max_length;}
449
429
 
450
 
  virtual int pack_cmp(const unsigned char *a,const unsigned char *b,
451
 
                       uint32_t key_length_arg,
452
 
                       bool insert_or_update);
453
 
  virtual int pack_cmp(const unsigned char *b,
454
 
                       uint32_t key_length_arg,
455
 
                       bool insert_or_update);
456
 
 
457
 
  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)
458
439
  {
459
 
    return (uint32_t) (ptr - record);
 
440
    return (uint) (ptr - record);
460
441
  }
461
442
  void copy_from_tmp(int offset);
462
 
  uint32_t fill_cache_field(struct st_cache_field *copy);
463
 
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
464
 
  virtual bool get_time(DRIZZLE_TIME *ltime);
465
 
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
466
 
  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(); }
467
448
  virtual bool has_charset(void) const { return false; }
468
 
  virtual void set_charset(const CHARSET_INFO * const)
 
449
  virtual void set_charset(CHARSET_INFO *charset_arg __attribute__((__unused__)))
469
450
  { }
470
451
  virtual enum Derivation derivation(void) const
471
452
  { return DERIVATION_IMPLICIT; }
472
 
  virtual void set_derivation(enum Derivation)
 
453
  virtual void set_derivation(enum Derivation derivation_arg __attribute__((__unused__)))
473
454
  { }
474
 
  bool set_warning(DRIZZLE_ERROR::enum_warning_level, unsigned int code,
 
455
  bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
475
456
                   int cuted_increment);
476
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code,
477
 
                            const char *str, uint32_t str_len,
478
 
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment);
479
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code,
480
 
                            int64_t nr, 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
                            int64_t nr, timestamp_type ts_type,
481
462
                            int cuted_increment);
482
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint32_t code,
483
 
                            double nr, enum enum_drizzle_timestamp_type ts_type);
 
463
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code, 
 
464
                            double nr, timestamp_type ts_type);
484
465
  inline bool check_overflow(int op_result)
485
466
  {
486
467
    return (op_result == E_DEC_OVERFLOW);
487
468
  }
488
469
  int warn_if_overflow(int op_result);
489
 
  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
  }
490
475
 
491
476
  /* maximum possible display length */
492
 
  virtual uint32_t max_display_length()= 0;
 
477
  virtual uint32 max_display_length()= 0;
493
478
 
494
 
  virtual uint32_t is_equal(Create_field *new_field);
 
479
  virtual uint is_equal(Create_field *new_field);
495
480
  /* convert decimal to int64_t with overflow check */
496
481
  int64_t convert_decimal2int64_t(const my_decimal *val, bool unsigned_flag,
497
482
                                    int *err);
498
483
  /* The max. number of characters */
499
 
  inline uint32_t char_length() const
 
484
  inline uint32 char_length() const
500
485
  {
501
486
    return field_length / charset()->mbmaxlen;
502
487
  }
508
493
  }
509
494
 
510
495
  /* Hash value */
511
 
  virtual void hash(uint32_t *nr, uint32_t *nr2);
512
 
  friend bool reopen_table(Session *,Table *,bool);
513
 
  friend int cre_myisam(char * name, register Table *form, uint32_t options,
 
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,
514
499
                        uint64_t auto_increment_value);
515
500
  friend class Copy_field;
516
501
  friend class Item_avg_field;
549
534
 
550
535
   @returns 0 no bytes written.
551
536
*/
552
 
  virtual int do_save_field_metadata(unsigned char *)
553
 
  { return 0; }
554
 
};
 
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
               int64_t *rnd, uint64_t unsigned_max, 
 
565
               int64_t signed_min, int64_t 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(int64_t 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(int64_t 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
  int64_t 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(int64_t nr, bool unsigned_val);
 
711
  int reset(void) { ptr[0]=0; return 0; }
 
712
  double val_real(void);
 
713
  int64_t 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(int64_t nr, bool unsigned_val);
 
762
  int reset(void) { ptr[0]=ptr[1]=0; return 0; }
 
763
  double val_real(void);
 
764
  int64_t 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(int64_t 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
  int64_t 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_int64_t :public Field_num {
 
893
public:
 
894
  Field_int64_t(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_int64_t(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(int64_t 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
  int64_t 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_int64_t() 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_t val;
 
935
#ifdef WORDS_BIGENDIAN
 
936
    if (table->s->db_low_byte_first)
 
937
      val = sint8korr(from);
 
938
    else
 
939
#endif
 
940
      int64_tget(val, from);
 
941
 
 
942
#ifdef WORDS_BIGENDIAN
 
943
    if (low_byte_first)
 
944
      int8store(to, val);
 
945
    else
 
946
#endif
 
947
      int64_tstore(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_t val;
 
956
#ifdef WORDS_BIGENDIAN
 
957
    if (low_byte_first)
 
958
      val = sint8korr(from);
 
959
    else
 
960
#endif
 
961
      int64_tget(val, from);
 
962
 
 
963
#ifdef WORDS_BIGENDIAN
 
964
    if (table->s->db_low_byte_first)
 
965
      int8store(to, val);
 
966
    else
 
967
#endif
 
968
      int64_tstore(to, val);
 
969
    return from + sizeof(val);
 
970
  }
 
971
};
 
972
 
 
973
class Field_double :public Field_real {
 
974
public:
 
975
  Field_double(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_double(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
  Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
 
989
               uint8 dec_arg, my_bool not_fixed_arg)
 
990
    :Field_real((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
 
991
                NONE, field_name_arg, dec_arg, 0, 0)
 
992
    {not_fixed= not_fixed_arg; }
 
993
  enum_field_types type() const { return MYSQL_TYPE_DOUBLE;}
 
994
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
 
995
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
996
  int  store(double nr);
 
997
  int  store(int64_t nr, bool unsigned_val);
 
998
  int reset(void) { bzero(ptr,sizeof(double)); return 0; }
 
999
  double val_real(void);
 
1000
  int64_t val_int(void);
 
1001
  String *val_str(String*,String *);
 
1002
  bool send_binary(Protocol *protocol);
 
1003
  int cmp(const uchar *,const uchar *);
 
1004
  void sort_string(uchar *buff,uint length);
 
1005
  uint32 pack_length() const { return sizeof(double); }
 
1006
  uint row_pack_length() { return pack_length(); }
 
1007
  void sql_type(String &str) const;
 
1008
private:
 
1009
  int do_save_field_metadata(uchar *first_byte);
 
1010
};
 
1011
 
 
1012
 
 
1013
/* Everything saved in this will disappear. It will always return NULL */
 
1014
 
 
1015
class Field_null :public Field_str {
 
1016
  static uchar null[1];
 
1017
public:
 
1018
  Field_null(uchar *ptr_arg, uint32 len_arg,
 
1019
             enum utype unireg_check_arg, const char *field_name_arg,
 
1020
             CHARSET_INFO *cs)
 
1021
    :Field_str(ptr_arg, len_arg, null, 1,
 
1022
               unireg_check_arg, field_name_arg, cs)
 
1023
    {}
 
1024
  enum_field_types type() const { return MYSQL_TYPE_NULL;}
 
1025
  int  store(const char *to __attribute__((__unused__)),
 
1026
             uint length __attribute__((__unused__)),
 
1027
             CHARSET_INFO *cs __attribute__((__unused__)))
 
1028
  { null[0]=1; return 0; }
 
1029
  int store(double nr __attribute__((__unused__)))
 
1030
  { null[0]=1; return 0; }
 
1031
  int store(int64_t nr __attribute__((__unused__)),
 
1032
            bool unsigned_val __attribute__((__unused__)))
 
1033
  { null[0]=1; return 0; }
 
1034
  int store_decimal(const my_decimal *d __attribute__((__unused__)))
 
1035
  { null[0]=1; return 0; }
 
1036
  int reset(void)
 
1037
  { return 0; }
 
1038
  double val_real(void)
 
1039
  { return 0.0;}
 
1040
  int64_t val_int(void)
 
1041
  { return 0;}
 
1042
  my_decimal *val_decimal(my_decimal *) { return 0; }
 
1043
  String *val_str(String *value __attribute__((__unused__)),
 
1044
                  String *value2)
 
1045
  { value2->length(0); return value2;}
 
1046
  int cmp(const uchar *a __attribute__((__unused__)),
 
1047
          const uchar *b __attribute__((__unused__))) { return 0;}
 
1048
  void sort_string(uchar *buff __attribute__((__unused__)),
 
1049
                   uint length __attribute__((__unused__)))  {}
 
1050
  uint32 pack_length() const { return 0; }
 
1051
  void sql_type(String &str) const;
 
1052
  uint size_of() const { return sizeof(*this); }
 
1053
  uint32 max_display_length() { return 4; }
 
1054
};
 
1055
 
 
1056
 
 
1057
class Field_timestamp :public Field_str {
 
1058
public:
 
1059
  Field_timestamp(uchar *ptr_arg, uint32 len_arg,
 
1060
                  uchar *null_ptr_arg, uchar null_bit_arg,
 
1061
                  enum utype unireg_check_arg, const char *field_name_arg,
 
1062
                  TABLE_SHARE *share, CHARSET_INFO *cs);
 
1063
  Field_timestamp(bool maybe_null_arg, const char *field_name_arg,
 
1064
                  CHARSET_INFO *cs);
 
1065
  enum_field_types type() const { return MYSQL_TYPE_TIMESTAMP;}
 
1066
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
 
1067
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1068
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1069
  int  store(double nr);
 
1070
  int  store(int64_t nr, bool unsigned_val);
 
1071
  int  reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
 
1072
  double val_real(void);
 
1073
  int64_t val_int(void);
 
1074
  String *val_str(String*,String *);
 
1075
  bool send_binary(Protocol *protocol);
 
1076
  int cmp(const uchar *,const uchar *);
 
1077
  void sort_string(uchar *buff,uint length);
 
1078
  uint32 pack_length() const { return 4; }
 
1079
  void sql_type(String &str) const;
 
1080
  bool can_be_compared_as_int64_t() const { return true; }
 
1081
  bool zero_pack() const { return 0; }
 
1082
  void set_time();
 
1083
  virtual void set_default()
 
1084
  {
 
1085
    if (table->timestamp_field == this &&
 
1086
        unireg_check != TIMESTAMP_UN_FIELD)
 
1087
      set_time();
 
1088
    else
 
1089
      Field::set_default();
 
1090
  }
 
1091
  /* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
 
1092
  inline long get_timestamp(my_bool *null_value)
 
1093
  {
 
1094
    if ((*null_value= is_null()))
 
1095
      return 0;
 
1096
#ifdef WORDS_BIGENDIAN
 
1097
    if (table && table->s->db_low_byte_first)
 
1098
      return sint4korr(ptr);
 
1099
#endif
 
1100
    long tmp;
 
1101
    longget(tmp,ptr);
 
1102
    return tmp;
 
1103
  }
 
1104
  inline void store_timestamp(my_time_t timestamp)
 
1105
  {
 
1106
#ifdef WORDS_BIGENDIAN
 
1107
    if (table && table->s->db_low_byte_first)
 
1108
    {
 
1109
      int4store(ptr,timestamp);
 
1110
    }
 
1111
    else
 
1112
#endif
 
1113
      longstore(ptr,(uint32) timestamp);
 
1114
  }
 
1115
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
1116
  bool get_time(MYSQL_TIME *ltime);
 
1117
  timestamp_auto_set_type get_auto_set_type() const;
 
1118
};
 
1119
 
 
1120
 
 
1121
class Field_year :public Field_tiny {
 
1122
public:
 
1123
  Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
1124
             uchar null_bit_arg,
 
1125
             enum utype unireg_check_arg, const char *field_name_arg)
 
1126
    :Field_tiny(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1127
                unireg_check_arg, field_name_arg, 1, 1)
 
1128
    {}
 
1129
  enum_field_types type() const { return MYSQL_TYPE_YEAR;}
 
1130
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1131
  int  store(double nr);
 
1132
  int  store(int64_t nr, bool unsigned_val);
 
1133
  double val_real(void);
 
1134
  int64_t val_int(void);
 
1135
  String *val_str(String*,String *);
 
1136
  bool send_binary(Protocol *protocol);
 
1137
  void sql_type(String &str) const;
 
1138
  bool can_be_compared_as_int64_t() const { return true; }
 
1139
};
 
1140
 
 
1141
 
 
1142
class Field_newdate :public Field_str {
 
1143
public:
 
1144
  Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
 
1145
                enum utype unireg_check_arg, const char *field_name_arg,
 
1146
                CHARSET_INFO *cs)
 
1147
    :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
 
1148
               unireg_check_arg, field_name_arg, cs)
 
1149
    {}
 
1150
  Field_newdate(bool maybe_null_arg, const char *field_name_arg,
 
1151
                CHARSET_INFO *cs)
 
1152
    :Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
 
1153
               NONE, field_name_arg, cs) {}
 
1154
  enum_field_types type() const { return MYSQL_TYPE_NEWDATE;}
 
1155
  enum_field_types real_type() const { return MYSQL_TYPE_NEWDATE; }
 
1156
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; }
 
1157
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1158
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1159
  int  store(double nr);
 
1160
  int  store(int64_t nr, bool unsigned_val);
 
1161
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
 
1162
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
 
1163
  double val_real(void);
 
1164
  int64_t val_int(void);
 
1165
  String *val_str(String*,String *);
 
1166
  bool send_binary(Protocol *protocol);
 
1167
  int cmp(const uchar *,const uchar *);
 
1168
  void sort_string(uchar *buff,uint length);
 
1169
  uint32 pack_length() const { return 3; }
 
1170
  void sql_type(String &str) const;
 
1171
  bool can_be_compared_as_int64_t() const { return true; }
 
1172
  bool zero_pack() const { return 1; }
 
1173
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
1174
  bool get_time(MYSQL_TIME *ltime);
 
1175
};
 
1176
 
 
1177
 
 
1178
class Field_time :public Field_str {
 
1179
public:
 
1180
  Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
 
1181
             enum utype unireg_check_arg, const char *field_name_arg,
 
1182
             CHARSET_INFO *cs)
 
1183
    :Field_str(ptr_arg, 8, null_ptr_arg, null_bit_arg,
 
1184
               unireg_check_arg, field_name_arg, cs)
 
1185
    {}
 
1186
  Field_time(bool maybe_null_arg, const char *field_name_arg,
 
1187
             CHARSET_INFO *cs)
 
1188
    :Field_str((uchar*) 0,8, maybe_null_arg ? (uchar*) "": 0,0,
 
1189
               NONE, field_name_arg, cs) {}
 
1190
  enum_field_types type() const { return MYSQL_TYPE_TIME;}
 
1191
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; }
 
1192
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1193
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
 
1194
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
1195
  int store(double nr);
 
1196
  int store(int64_t nr, bool unsigned_val);
 
1197
  int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; }
 
1198
  double val_real(void);
 
1199
  int64_t val_int(void);
 
1200
  String *val_str(String*,String *);
 
1201
  bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
 
1202
  bool send_binary(Protocol *protocol);
 
1203
  bool get_time(MYSQL_TIME *ltime);
 
1204
  int cmp(const uchar *,const uchar *);
 
1205
  void sort_string(uchar *buff,uint length);
 
1206
  uint32 pack_length() const { return 3; }
 
1207
  void sql_type(String &str) const;
 
1208
  bool can_be_compared_as_int64_t() const { return true; }
 
1209
  bool zero_pack() const { return 1; }
 
1210
};
 
1211
 
 
1212
 
 
1213
class Field_datetime :public Field_str {
 
1214
public:
 
1215
  Field_datetime(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, 19, null_ptr_arg, null_bit_arg,
 
1219
               unireg_check_arg, field_name_arg, cs)
 
1220
    {}
 
1221
  Field_datetime(bool maybe_null_arg, const char *field_name_arg,
 
1222
                 CHARSET_INFO *cs)
 
1223
    :Field_str((uchar*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
 
1224
               NONE, field_name_arg, cs) {}
 
1225
  enum_field_types type() const { return MYSQL_TYPE_DATETIME;}
 
1226
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
 
1227
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1228
  uint decimals() const { return DATETIME_DEC; }
 
1229
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1230
  int  store(double nr);
 
1231
  int  store(int64_t nr, bool unsigned_val);
 
1232
  int store_time(MYSQL_TIME *ltime, timestamp_type type);
 
1233
  int reset(void)
 
1234
  {
 
1235
    ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0;
 
1236
    return 0;
 
1237
  }
 
1238
  double val_real(void);
 
1239
  int64_t val_int(void);
 
1240
  String *val_str(String*,String *);
 
1241
  bool send_binary(Protocol *protocol);
 
1242
  int cmp(const uchar *,const uchar *);
 
1243
  void sort_string(uchar *buff,uint length);
 
1244
  uint32 pack_length() const { return 8; }
 
1245
  void sql_type(String &str) const;
 
1246
  bool can_be_compared_as_int64_t() const { return true; }
 
1247
  bool zero_pack() const { return 1; }
 
1248
  bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
1249
  bool get_time(MYSQL_TIME *ltime);
 
1250
};
 
1251
 
 
1252
 
 
1253
class Field_string :public Field_longstr {
 
1254
public:
 
1255
  bool can_alter_field_type;
 
1256
  Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
 
1257
               uchar null_bit_arg,
 
1258
               enum utype unireg_check_arg, const char *field_name_arg,
 
1259
               CHARSET_INFO *cs)
 
1260
    :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1261
                   unireg_check_arg, field_name_arg, cs),
 
1262
     can_alter_field_type(1) {};
 
1263
  Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
 
1264
               CHARSET_INFO *cs)
 
1265
    :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
1266
                   NONE, field_name_arg, cs),
 
1267
     can_alter_field_type(1) {};
 
1268
 
 
1269
  enum_field_types type() const
 
1270
  {
 
1271
    return  MYSQL_TYPE_STRING;
 
1272
  }
 
1273
  enum ha_base_keytype key_type() const
 
1274
    { return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; }
 
1275
  bool zero_pack() const { return 0; }
 
1276
  int reset(void)
 
1277
  {
 
1278
    charset()->cset->fill(charset(),(char*) ptr, field_length,
 
1279
                          (has_charset() ? ' ' : 0));
 
1280
    return 0;
 
1281
  }
 
1282
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
1283
  int store(int64_t nr, bool unsigned_val);
 
1284
  int store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
 
1285
  double val_real(void);
 
1286
  int64_t val_int(void);
 
1287
  String *val_str(String*,String *);
 
1288
  my_decimal *val_decimal(my_decimal *);
 
1289
  int cmp(const uchar *,const uchar *);
 
1290
  void sort_string(uchar *buff,uint length);
 
1291
  void sql_type(String &str) const;
 
1292
  virtual uchar *pack(uchar *to, const uchar *from,
 
1293
                      uint max_length, bool low_byte_first);
 
1294
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
1295
                              uint param_data, bool low_byte_first);
 
1296
  uint pack_length_from_metadata(uint field_metadata)
 
1297
  { return (field_metadata & 0x00ff); }
 
1298
  uint row_pack_length() { return (field_length + 1); }
 
1299
  int pack_cmp(const uchar *a,const uchar *b,uint key_length,
 
1300
               my_bool insert_or_update);
 
1301
  int pack_cmp(const uchar *b,uint key_length,my_bool insert_or_update);
 
1302
  uint packed_col_length(const uchar *to, uint length);
 
1303
  uint max_packed_col_length(uint max_length);
 
1304
  uint size_of() const { return sizeof(*this); }
 
1305
  enum_field_types real_type() const { return MYSQL_TYPE_STRING; }
 
1306
  bool has_charset(void) const
 
1307
  { return charset() == &my_charset_bin ? false : true; }
 
1308
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
 
1309
  virtual uint get_key_image(uchar *buff,uint length, imagetype type);
 
1310
private:
 
1311
  int do_save_field_metadata(uchar *first_byte);
 
1312
};
 
1313
 
 
1314
 
 
1315
class Field_varstring :public Field_longstr {
 
1316
public:
 
1317
  /*
 
1318
    The maximum space available in a Field_varstring, in bytes. See
 
1319
    length_bytes.
 
1320
  */
 
1321
  static const uint MAX_SIZE;
 
1322
  /* Store number of bytes used to store length (1 or 2) */
 
1323
  uint32 length_bytes;
 
1324
  Field_varstring(uchar *ptr_arg,
 
1325
                  uint32 len_arg, uint length_bytes_arg,
 
1326
                  uchar *null_ptr_arg, uchar null_bit_arg,
 
1327
                  enum utype unireg_check_arg, const char *field_name_arg,
 
1328
                  TABLE_SHARE *share, CHARSET_INFO *cs)
 
1329
    :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1330
                   unireg_check_arg, field_name_arg, cs),
 
1331
     length_bytes(length_bytes_arg)
 
1332
  {
 
1333
    share->varchar_fields++;
 
1334
  }
 
1335
  Field_varstring(uint32 len_arg,bool maybe_null_arg,
 
1336
                  const char *field_name_arg,
 
1337
                  TABLE_SHARE *share, CHARSET_INFO *cs)
 
1338
    :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
1339
                   NONE, field_name_arg, cs),
 
1340
     length_bytes(len_arg < 256 ? 1 :2)
 
1341
  {
 
1342
    share->varchar_fields++;
 
1343
  }
 
1344
 
 
1345
  enum_field_types type() const { return MYSQL_TYPE_VARCHAR; }
 
1346
  enum ha_base_keytype key_type() const;
 
1347
  uint row_pack_length() { return field_length; }
 
1348
  bool zero_pack() const { return 0; }
 
1349
  int  reset(void) { bzero(ptr,field_length+length_bytes); return 0; }
 
1350
  uint32 pack_length() const { return (uint32) field_length+length_bytes; }
 
1351
  uint32 key_length() const { return (uint32) field_length; }
 
1352
  uint32 sort_length() const
 
1353
  {
 
1354
    return (uint32) field_length + (field_charset == &my_charset_bin ?
 
1355
                                    length_bytes : 0);
 
1356
  }
 
1357
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1358
  int  store(int64_t nr, bool unsigned_val);
 
1359
  int  store(double nr) { return Field_str::store(nr); } /* QQ: To be deleted */
 
1360
  double val_real(void);
 
1361
  int64_t val_int(void);
 
1362
  String *val_str(String*,String *);
 
1363
  my_decimal *val_decimal(my_decimal *);
 
1364
  int cmp_max(const uchar *, const uchar *, uint max_length);
 
1365
  int cmp(const uchar *a,const uchar *b)
 
1366
  {
 
1367
    return cmp_max(a, b, ~0L);
 
1368
  }
 
1369
  void sort_string(uchar *buff,uint length);
 
1370
  uint get_key_image(uchar *buff,uint length, imagetype type);
 
1371
  void set_key_image(const uchar *buff,uint length);
 
1372
  void sql_type(String &str) const;
 
1373
  virtual uchar *pack(uchar *to, const uchar *from,
 
1374
                      uint max_length, bool low_byte_first);
 
1375
  uchar *pack_key(uchar *to, const uchar *from, uint max_length, bool low_byte_first);
 
1376
  uchar *pack_key_from_key_image(uchar* to, const uchar *from,
 
1377
                                 uint max_length, bool low_byte_first);
 
1378
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
1379
                              uint param_data, bool low_byte_first);
 
1380
  const uchar *unpack_key(uchar* to, const uchar *from,
 
1381
                          uint max_length, bool low_byte_first);
 
1382
  int pack_cmp(const uchar *a, const uchar *b, uint key_length,
 
1383
               my_bool insert_or_update);
 
1384
  int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
 
1385
  int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
 
1386
  int key_cmp(const uchar *,const uchar*);
 
1387
  int key_cmp(const uchar *str, uint length);
 
1388
  uint packed_col_length(const uchar *to, uint length);
 
1389
  uint max_packed_col_length(uint max_length);
 
1390
  uint32 data_length();
 
1391
  uint32 used_length();
 
1392
  uint size_of() const { return sizeof(*this); }
 
1393
  enum_field_types real_type() const { return MYSQL_TYPE_VARCHAR; }
 
1394
  bool has_charset(void) const
 
1395
  { return charset() == &my_charset_bin ? false : true; }
 
1396
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
 
1397
  Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
 
1398
                       uchar *new_ptr, uchar *new_null_ptr,
 
1399
                       uint new_null_bit);
 
1400
  uint is_equal(Create_field *new_field);
 
1401
  void hash(ulong *nr, ulong *nr2);
 
1402
private:
 
1403
  int do_save_field_metadata(uchar *first_byte);
 
1404
};
 
1405
 
 
1406
 
 
1407
class Field_blob :public Field_longstr {
 
1408
protected:
 
1409
  uint packlength;
 
1410
  String value;                         // For temporaries
 
1411
public:
 
1412
  Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
 
1413
             enum utype unireg_check_arg, const char *field_name_arg,
 
1414
             TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs);
 
1415
  Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
 
1416
             CHARSET_INFO *cs)
 
1417
    :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
1418
                   NONE, field_name_arg, cs),
 
1419
    packlength(4)
 
1420
  {
 
1421
    flags|= BLOB_FLAG;
 
1422
  }
 
1423
  Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
 
1424
             CHARSET_INFO *cs, bool set_packlength)
 
1425
    :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
 
1426
                   NONE, field_name_arg, cs)
 
1427
  {
 
1428
    flags|= BLOB_FLAG;
 
1429
    packlength= 4;
 
1430
    if (set_packlength)
 
1431
    {
 
1432
      uint32 l_char_length= len_arg/cs->mbmaxlen;
 
1433
      packlength= l_char_length <= 255 ? 1 :
 
1434
                  l_char_length <= 65535 ? 2 :
 
1435
                  l_char_length <= 16777215 ? 3 : 4;
 
1436
    }
 
1437
  }
 
1438
  Field_blob(uint32 packlength_arg)
 
1439
    :Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
 
1440
    packlength(packlength_arg) {}
 
1441
  enum_field_types type() const { return MYSQL_TYPE_BLOB;}
 
1442
  enum ha_base_keytype key_type() const
 
1443
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
 
1444
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1445
  int  store(double nr);
 
1446
  int  store(int64_t nr, bool unsigned_val);
 
1447
  double val_real(void);
 
1448
  int64_t val_int(void);
 
1449
  String *val_str(String*,String *);
 
1450
  my_decimal *val_decimal(my_decimal *);
 
1451
  int cmp_max(const uchar *, const uchar *, uint max_length);
 
1452
  int cmp(const uchar *a,const uchar *b)
 
1453
    { return cmp_max(a, b, ~0L); }
 
1454
  int cmp(const uchar *a, uint32 a_length, const uchar *b, uint32 b_length);
 
1455
  int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
 
1456
  int key_cmp(const uchar *,const uchar*);
 
1457
  int key_cmp(const uchar *str, uint length);
 
1458
  uint32 key_length() const { return 0; }
 
1459
  void sort_string(uchar *buff,uint length);
 
1460
  uint32 pack_length() const
 
1461
  { return (uint32) (packlength+table->s->blob_ptr_size); }
 
1462
 
 
1463
  /**
 
1464
     Return the packed length without the pointer size added. 
 
1465
 
 
1466
     This is used to determine the size of the actual data in the row
 
1467
     buffer.
 
1468
 
 
1469
     @returns The length of the raw data itself without the pointer.
 
1470
  */
 
1471
  uint32 pack_length_no_ptr() const
 
1472
  { return (uint32) (packlength); }
 
1473
  uint row_pack_length() { return pack_length_no_ptr(); }
 
1474
  uint32 sort_length() const;
 
1475
  virtual uint32 max_data_length() const
 
1476
  {
 
1477
    return (uint32) (((uint64_t) 1 << (packlength*8)) -1);
 
1478
  }
 
1479
  int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; }
 
1480
  void reset_fields() { bzero((uchar*) &value,sizeof(value)); }
 
1481
#ifndef WORDS_BIGENDIAN
 
1482
  static
 
1483
#endif
 
1484
  void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number, bool low_byte_first);
 
1485
  void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number)
 
1486
  {
 
1487
    store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
 
1488
  }
 
1489
  inline void store_length(uint32 number)
 
1490
  {
 
1491
    store_length(ptr, packlength, number);
 
1492
  }
 
1493
 
 
1494
  /**
 
1495
     Return the packed length plus the length of the data. 
 
1496
 
 
1497
     This is used to determine the size of the data plus the 
 
1498
     packed length portion in the row data.
 
1499
 
 
1500
     @returns The length in the row plus the size of the data.
 
1501
  */
 
1502
  uint32 get_packed_size(const uchar *ptr_arg, bool low_byte_first)
 
1503
    {return packlength + get_length(ptr_arg, packlength, low_byte_first);}
 
1504
 
 
1505
  inline uint32 get_length(uint row_offset= 0)
 
1506
  { return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); }
 
1507
  uint32 get_length(const uchar *ptr, uint packlength, bool low_byte_first);
 
1508
  uint32 get_length(const uchar *ptr_arg)
 
1509
  { return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); }
 
1510
  void put_length(uchar *pos, uint32 length);
 
1511
  inline void get_ptr(uchar **str)
 
1512
    {
 
1513
      memcpy_fixed((uchar*) str,ptr+packlength,sizeof(uchar*));
 
1514
    }
 
1515
  inline void get_ptr(uchar **str, uint row_offset)
 
1516
    {
 
1517
      memcpy_fixed((uchar*) str,ptr+packlength+row_offset,sizeof(char*));
 
1518
    }
 
1519
  inline void set_ptr(uchar *length, uchar *data)
 
1520
    {
 
1521
      memcpy(ptr,length,packlength);
 
1522
      memcpy_fixed(ptr+packlength,&data,sizeof(char*));
 
1523
    }
 
1524
  void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length, uchar *data)
 
1525
    {
 
1526
      uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
 
1527
      store_length(ptr_ofs, packlength, length);
 
1528
      memcpy_fixed(ptr_ofs+packlength,&data,sizeof(char*));
 
1529
    }
 
1530
  inline void set_ptr(uint32 length, uchar *data)
 
1531
    {
 
1532
      set_ptr_offset(0, length, data);
 
1533
    }
 
1534
  uint get_key_image(uchar *buff,uint length, imagetype type);
 
1535
  void set_key_image(const uchar *buff,uint length);
 
1536
  void sql_type(String &str) const;
 
1537
  inline bool copy()
 
1538
  {
 
1539
    uchar *tmp;
 
1540
    get_ptr(&tmp);
 
1541
    if (value.copy((char*) tmp, get_length(), charset()))
 
1542
    {
 
1543
      Field_blob::reset();
 
1544
      return 1;
 
1545
    }
 
1546
    tmp=(uchar*) value.ptr();
 
1547
    memcpy_fixed(ptr+packlength,&tmp,sizeof(char*));
 
1548
    return 0;
 
1549
  }
 
1550
  virtual uchar *pack(uchar *to, const uchar *from,
 
1551
                      uint max_length, bool low_byte_first);
 
1552
  uchar *pack_key(uchar *to, const uchar *from,
 
1553
                  uint max_length, bool low_byte_first);
 
1554
  uchar *pack_key_from_key_image(uchar* to, const uchar *from,
 
1555
                                 uint max_length, bool low_byte_first);
 
1556
  virtual const uchar *unpack(uchar *to, const uchar *from,
 
1557
                              uint param_data, bool low_byte_first);
 
1558
  const uchar *unpack_key(uchar* to, const uchar *from,
 
1559
                          uint max_length, bool low_byte_first);
 
1560
  int pack_cmp(const uchar *a, const uchar *b, uint key_length,
 
1561
               my_bool insert_or_update);
 
1562
  int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
 
1563
  uint packed_col_length(const uchar *col_ptr, uint length);
 
1564
  uint max_packed_col_length(uint max_length);
 
1565
  void free() { value.free(); }
 
1566
  inline void clear_temporary() { bzero((uchar*) &value,sizeof(value)); }
 
1567
  friend int field_conv(Field *to,Field *from);
 
1568
  uint size_of() const { return sizeof(*this); }
 
1569
  bool has_charset(void) const
 
1570
  { return charset() == &my_charset_bin ? false : true; }
 
1571
  uint32 max_display_length();
 
1572
  uint is_equal(Create_field *new_field);
 
1573
  inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
 
1574
  inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
 
1575
private:
 
1576
  int do_save_field_metadata(uchar *first_byte);
 
1577
};
 
1578
 
 
1579
 
 
1580
class Field_enum :public Field_str {
 
1581
protected:
 
1582
  uint packlength;
 
1583
public:
 
1584
  TYPELIB *typelib;
 
1585
  Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
1586
             uchar null_bit_arg,
 
1587
             enum utype unireg_check_arg, const char *field_name_arg,
 
1588
             uint packlength_arg,
 
1589
             TYPELIB *typelib_arg,
 
1590
             CHARSET_INFO *charset_arg)
 
1591
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1592
               unireg_check_arg, field_name_arg, charset_arg),
 
1593
    packlength(packlength_arg),typelib(typelib_arg)
 
1594
  {
 
1595
      flags|=ENUM_FLAG;
 
1596
  }
 
1597
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
 
1598
  enum_field_types type() const { return MYSQL_TYPE_STRING; }
 
1599
  enum Item_result cmp_type () const { return INT_RESULT; }
 
1600
  enum Item_result cast_to_int_type () const { return INT_RESULT; }
 
1601
  enum ha_base_keytype key_type() const;
 
1602
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1603
  int  store(double nr);
 
1604
  int  store(int64_t nr, bool unsigned_val);
 
1605
  double val_real(void);
 
1606
  int64_t val_int(void);
 
1607
  String *val_str(String*,String *);
 
1608
  int cmp(const uchar *,const uchar *);
 
1609
  void sort_string(uchar *buff,uint length);
 
1610
  uint32 pack_length() const { return (uint32) packlength; }
 
1611
  void store_type(uint64_t value);
 
1612
  void sql_type(String &str) const;
 
1613
  uint size_of() const { return sizeof(*this); }
 
1614
  enum_field_types real_type() const { return MYSQL_TYPE_ENUM; }
 
1615
  uint pack_length_from_metadata(uint field_metadata)
 
1616
  { return (field_metadata & 0x00ff); }
 
1617
  uint row_pack_length() { return pack_length(); }
 
1618
  virtual bool zero_pack() const { return 0; }
 
1619
  bool optimize_range(uint idx __attribute__((__unused__)),
 
1620
                      uint part __attribute__((__unused__)))
 
1621
  { return 0; }
 
1622
  bool eq_def(Field *field);
 
1623
  bool has_charset(void) const { return true; }
 
1624
  /* enum and set are sorted as integers */
 
1625
  CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
 
1626
private:
 
1627
  int do_save_field_metadata(uchar *first_byte);
 
1628
};
 
1629
 
 
1630
 
 
1631
class Field_set :public Field_enum {
 
1632
public:
 
1633
  Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 
1634
            uchar null_bit_arg,
 
1635
            enum utype unireg_check_arg, const char *field_name_arg,
 
1636
            uint32 packlength_arg,
 
1637
            TYPELIB *typelib_arg, CHARSET_INFO *charset_arg)
 
1638
    :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1639
                    unireg_check_arg, field_name_arg,
 
1640
                packlength_arg,
 
1641
                typelib_arg,charset_arg)
 
1642
    {
 
1643
      flags=(flags & ~ENUM_FLAG) | SET_FLAG;
 
1644
    }
 
1645
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
1646
  int  store(double nr) { return Field_set::store((int64_t) nr, false); }
 
1647
  int  store(int64_t nr, bool unsigned_val);
 
1648
 
 
1649
  virtual bool zero_pack() const { return 1; }
 
1650
  String *val_str(String*,String *);
 
1651
  void sql_type(String &str) const;
 
1652
  enum_field_types real_type() const { return MYSQL_TYPE_SET; }
 
1653
  bool has_charset(void) const { return true; }
 
1654
};
 
1655
 
555
1656
 
556
1657
/*
557
1658
  Create field class for CREATE TABLE
568
1669
  enum  enum_field_types sql_type;
569
1670
  /*
570
1671
    At various stages in execution this can be length of field in bytes or
571
 
    max number of characters.
 
1672
    max number of characters. 
572
1673
  */
573
 
  uint32_t length;
 
1674
  ulong length;
574
1675
  /*
575
1676
    The value of `length' as set by parser: is the number of characters
576
1677
    for most of the types, or of bytes for BLOBs or numeric types.
577
1678
  */
578
 
  uint32_t char_length;
579
 
  uint32_t  decimals, flags, pack_length, key_length;
 
1679
  uint32 char_length;
 
1680
  uint  decimals, flags, pack_length, key_length;
580
1681
  Field::utype unireg_check;
581
1682
  TYPELIB *interval;                    // Which interval to use
582
1683
  TYPELIB *save_interval;               // Temporary copy for the above
583
1684
                                        // Used only for UCS2 intervals
584
1685
  List<String> interval_list;
585
 
  const CHARSET_INFO *charset;
 
1686
  CHARSET_INFO *charset;
586
1687
  Field *field;                         // For alter table
587
1688
 
588
 
  uint8_t row,col,sc_length,interval_id;        // For rea_create_table
589
 
  uint32_t      offset,pack_flag;
590
 
 
591
 
  /* Virtual column expression statement */
592
 
  virtual_column_info *vcol_info;
593
 
  /*
594
 
    Indication that the field is phycically stored in tables
595
 
    rather than just generated on SQL queries.
596
 
    As of now, FALSE can only be set for generated-only virtual columns.
597
 
  */
598
 
  bool is_stored;
599
 
 
 
1689
  uint8 row,col,sc_length,interval_id;  // For rea_create_table
 
1690
  uint  offset,pack_flag;
600
1691
  Create_field() :after(0) {}
601
1692
  Create_field(Field *field, Field *orig_field);
602
1693
  /* Used to make a clone of this object for ALTER/CREATE TABLE */
612
1703
 
613
1704
  /* Init for a tmp table field. To be extended if need be. */
614
1705
  void init_for_tmp_table(enum_field_types sql_type_arg,
615
 
                          uint32_t max_length, uint32_t decimals,
 
1706
                          uint32 max_length, uint32 decimals,
616
1707
                          bool maybe_null, bool is_unsigned);
617
1708
 
618
 
  bool init(Session *session, char *field_name, enum_field_types type, char *length,
619
 
            char *decimals, uint32_t type_modifier, Item *default_value,
 
1709
  bool init(THD *thd, char *field_name, enum_field_types type, char *length,
 
1710
            char *decimals, uint type_modifier, Item *default_value,
620
1711
            Item *on_update_value, LEX_STRING *comment, char *change,
621
 
            List<String> *interval_list, const CHARSET_INFO * const cs,
622
 
            uint32_t uint_geom_type,
623
 
            enum column_format_type column_format,
624
 
            virtual_column_info *vcol_info);
 
1712
            List<String> *interval_list, CHARSET_INFO *cs,
 
1713
            uint uint_geom_type,
 
1714
            enum column_format_type column_format);
625
1715
};
626
1716
 
627
1717
 
634
1724
  const char *db_name;
635
1725
  const char *table_name,*org_table_name;
636
1726
  const char *col_name,*org_col_name;
637
 
  uint32_t length;
638
 
  uint32_t charsetnr, flags, decimals;
 
1727
  ulong length;
 
1728
  uint charsetnr, flags, decimals;
639
1729
  enum_field_types type;
640
1730
  Send_field() {}
641
1731
};
653
1743
  typedef void Copy_func(Copy_field*);
654
1744
  Copy_func *get_copy_func(Field *to, Field *from);
655
1745
public:
656
 
  unsigned char *from_ptr,*to_ptr;
657
 
  unsigned char *from_null_ptr,*to_null_ptr;
658
 
  bool *null_row;
659
 
  uint32_t      from_bit,to_bit;
660
 
  uint32_t from_length,to_length;
 
1746
  uchar *from_ptr,*to_ptr;
 
1747
  uchar *from_null_ptr,*to_null_ptr;
 
1748
  my_bool *null_row;
 
1749
  uint  from_bit,to_bit;
 
1750
  uint from_length,to_length;
661
1751
  Field *from_field,*to_field;
662
1752
  String tmp;                                   // For items
663
1753
 
664
1754
  Copy_field() {}
665
1755
  ~Copy_field() {}
666
 
  void set(Field *to,Field *from,bool save);    // Field to field
667
 
  void set(unsigned char *to,Field *from);              // Field to string
 
1756
  void set(Field *to,Field *from,bool save);    // Field to field 
 
1757
  void set(uchar *to,Field *from);              // Field to string
668
1758
  void (*do_copy)(Copy_field *);
669
1759
  void (*do_copy2)(Copy_field *);               // Used to handle null values
670
1760
};
671
1761
 
672
1762
 
673
 
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
674
 
                  unsigned char *null_pos, unsigned char null_bit,
675
 
                  uint32_t pack_flag, enum_field_types field_type,
676
 
                  const CHARSET_INFO * cs,
677
 
                  Field::utype unireg_check,
678
 
                  TYPELIB *interval, const char *field_name);
679
 
 
680
 
uint32_t pack_length_to_packflag(uint32_t type);
681
 
enum_field_types get_blob_type_from_length(uint32_t length);
682
 
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
 
1763
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length,
 
1764
                  uchar *null_pos, uchar null_bit,
 
1765
                  uint pack_flag, enum_field_types field_type,
 
1766
                  CHARSET_INFO *cs,
 
1767
                  Field::utype unireg_check,
 
1768
                  TYPELIB *interval, const char *field_name);
 
1769
uint pack_length_to_packflag(uint type);
 
1770
enum_field_types get_blob_type_from_length(ulong length);
 
1771
uint32 calc_pack_length(enum_field_types type,uint32 length);
683
1772
int set_field_to_null(Field *field);
684
1773
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
685
1774
 
686
 
 
687
 
bool
688
 
test_if_important_data(const CHARSET_INFO * const cs,
689
 
                       const char *str,
690
 
                       const char *strend);
691
 
 
692
 
 
693
 
#endif /* DRIZZLED_FIELD_H */
 
1775
/*
 
1776
  The following are for the interface with the .frm file
 
1777
*/
 
1778
 
 
1779
#define FIELDFLAG_DECIMAL               1
 
1780
#define FIELDFLAG_BINARY                1       // Shares same flag
 
1781
#define FIELDFLAG_NUMBER                2
 
1782
#define FIELDFLAG_ZEROFILL              4
 
1783
#define FIELDFLAG_PACK                  120     // Bits used for packing
 
1784
#define FIELDFLAG_INTERVAL              256     // mangled with decimals!
 
1785
#define FIELDFLAG_BITFIELD              512     // mangled with decimals!
 
1786
#define FIELDFLAG_BLOB                  1024    // mangled with decimals!
 
1787
#define FIELDFLAG_GEOM                  2048    // mangled with decimals!
 
1788
 
 
1789
#define FIELDFLAG_TREAT_BIT_AS_CHAR     4096    /* use Field_bit_as_char */
 
1790
 
 
1791
#define FIELDFLAG_LEFT_FULLSCREEN       8192
 
1792
#define FIELDFLAG_RIGHT_FULLSCREEN      16384
 
1793
#define FIELDFLAG_FORMAT_NUMBER         16384   // predit: ###,,## in output
 
1794
#define FIELDFLAG_NO_DEFAULT            16384   /* sql */
 
1795
#define FIELDFLAG_SUM                   ((uint) 32768)// predit: +#fieldflag
 
1796
#define FIELDFLAG_MAYBE_NULL            ((uint) 32768)// sql
 
1797
#define FIELDFLAG_HEX_ESCAPE            ((uint) 0x10000)
 
1798
#define FIELDFLAG_PACK_SHIFT            3
 
1799
#define FIELDFLAG_DEC_SHIFT             8
 
1800
#define FIELDFLAG_MAX_DEC               31
 
1801
#define FIELDFLAG_NUM_SCREEN_TYPE       0x7F01
 
1802
#define FIELDFLAG_ALFA_SCREEN_TYPE      0x7800
 
1803
 
 
1804
#define MTYP_TYPENR(type) (type & 127)  /* Remove bits from type */
 
1805
 
 
1806
#define f_is_dec(x)             ((x) & FIELDFLAG_DECIMAL)
 
1807
#define f_is_num(x)             ((x) & FIELDFLAG_NUMBER)
 
1808
#define f_is_zerofill(x)        ((x) & FIELDFLAG_ZEROFILL)
 
1809
#define f_is_packed(x)          ((x) & FIELDFLAG_PACK)
 
1810
#define f_packtype(x)           (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
 
1811
#define f_decimals(x)           ((uint8) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
 
1812
#define f_is_alpha(x)           (!f_is_num(x))
 
1813
#define f_is_binary(x)          ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
 
1814
#define f_is_enum(x)            (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
 
1815
#define f_is_bitfield(x)        (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
 
1816
#define f_is_blob(x)            (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
 
1817
#define f_is_equ(x)             ((x) & (1+2+FIELDFLAG_PACK+31*256))
 
1818
#define f_settype(x)            (((int) x) << FIELDFLAG_PACK_SHIFT)
 
1819
#define f_maybe_null(x)         (x & FIELDFLAG_MAYBE_NULL)
 
1820
#define f_no_default(x)         (x & FIELDFLAG_NO_DEFAULT)
 
1821
#define f_bit_as_char(x)        ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
 
1822
#define f_is_hex_escape(x)      ((x) & FIELDFLAG_HEX_ESCAPE)