~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:16:28 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: mordred@inaugust.com-20090304021628-rfq0b16uoi09g8tx
Fix to make VPATH builds work again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
  variables must declare the size_of() member function.
23
23
*/
24
24
 
25
 
#ifdef USE_PRAGMA_INTERFACE
26
 
#pragma interface                       /* gcc class implementation */
27
 
#endif
 
25
#ifndef DRIZZLED_FIELD_H
 
26
#define DRIZZLED_FIELD_H
 
27
 
 
28
#include <drizzled/sql_error.h>
 
29
#include <drizzled/my_decimal.h>
 
30
#include <drizzled/sql_bitmap.h>
 
31
#include <drizzled/sql_list.h>
 
32
/* System-wide common data structures */
 
33
#include <drizzled/structs.h>
 
34
#include <string>
28
35
 
29
36
#define DATETIME_DEC                     6
30
37
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
31
38
 
32
39
const uint32_t max_field_size= (uint32_t) 4294967295U;
33
40
 
 
41
class Table;
34
42
class Send_field;
35
43
class Protocol;
36
44
class Create_field;
 
45
class virtual_column_info;
 
46
 
 
47
class TABLE_SHARE;
 
48
 
 
49
class Field;
 
50
 
37
51
struct st_cache_field;
38
52
int field_conv(Field *to,Field *from);
39
53
 
42
56
  return elements < 256 ? 1 : 2;
43
57
}
44
58
 
45
 
inline uint32_t get_set_pack_length(int elements)
46
 
{
47
 
  uint32_t len= (elements + 7) / 8;
48
 
  return len > 4 ? 8 : len;
49
 
}
50
 
 
51
59
class Field
52
60
{
53
61
  Field(const Item &);                          /* Prevent use of these */
54
62
  void operator=(Field &);
55
63
public:
56
64
  static void *operator new(size_t size) {return sql_alloc(size); }
57
 
  static void operator delete(void *ptr_arg __attribute__((unused)),
58
 
                              size_t size __attribute__((unused)))
 
65
  static void *operator new(size_t size, MEM_ROOT *mem_root)
 
66
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
 
67
 
 
68
  static void operator delete(void *, size_t)
59
69
  { TRASH(ptr_arg, size); }
60
70
 
61
71
  unsigned char         *ptr;                   // Position to field in record
62
72
  unsigned char         *null_ptr;              // Byte where null_bit is
63
73
  /*
64
 
    Note that you can use table->in_use as replacement for current_thd member 
 
74
    Note that you can use table->in_use as replacement for current_session member
65
75
    only inside of val_*() and store() members (e.g. you can't use it in cons)
66
76
  */
67
77
  Table *table;         // Pointer for table
71
81
  /* Field is part of the following keys */
72
82
  key_map       key_start, part_of_key, part_of_key_not_clustered;
73
83
  key_map       part_of_sortkey;
74
 
  /* 
75
 
    We use three additional unireg types for TIMESTAMP to overcome limitation 
76
 
    of current binary format of .frm file. We'd like to be able to support 
77
 
    NOW() as default and on update value for such fields but unable to hold 
 
84
  /*
 
85
    We use three additional unireg types for TIMESTAMP to overcome limitation
 
86
    of current binary format of .frm file. We'd like to be able to support
 
87
    NOW() as default and on update value for such fields but unable to hold
78
88
    this info anywhere except unireg_check field. This issue will be resolved
79
89
    in more clean way with transition to new text based .frm format.
80
90
    See also comment for Field_timestamp::Field_timestamp().
81
91
  */
82
 
  enum utype  { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL,
83
 
                CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
84
 
                BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD,
 
92
  enum utype  { NONE,
 
93
                NEXT_NUMBER,
 
94
                TIMESTAMP_OLD_FIELD,
85
95
                TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD};
86
96
  enum imagetype { itRAW, itMBR};
87
97
 
101
111
   */
102
112
  bool is_created_from_null_item;
103
113
 
 
114
  /* Virtual column data */
 
115
  virtual_column_info *vcol_info;
 
116
  /*
 
117
    Indication that the field is physically stored in tables
 
118
    rather than just generated on SQL queries.
 
119
    As of now, false can only be set for generated-only virtual columns.
 
120
  */
 
121
  bool is_stored;
 
122
 
104
123
  Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
105
124
        unsigned char null_bit_arg, utype unireg_check_arg,
106
125
        const char *field_name_arg);
107
126
  virtual ~Field() {}
108
127
  /* Store functions returns 1 on overflow and -1 on fatal error */
109
 
  virtual int  store(const char *to, uint32_t length, const CHARSET_INFO * const cs)=0;
110
 
  virtual int  store(double nr)=0;
111
 
  virtual int  store(int64_t nr, bool unsigned_val)=0;
112
 
  virtual int  store_decimal(const my_decimal *d)=0;
113
 
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
114
 
  int store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
 
128
  virtual int store(const char *to, uint32_t length,
 
129
                    const CHARSET_INFO * const cs)=0;
 
130
  virtual int store(double nr)=0;
 
131
  virtual int store(int64_t nr, bool unsigned_val)=0;
 
132
  virtual int store_decimal(const my_decimal *d)=0;
 
133
  int store(const char *to, uint32_t length,
 
134
            const CHARSET_INFO * const cs,
115
135
            enum_check_fields check_level);
 
136
  virtual int store_time(DRIZZLE_TIME *ltime,
 
137
                         enum enum_drizzle_timestamp_type t_type);
116
138
  virtual double val_real(void)=0;
117
139
  virtual int64_t val_int(void)=0;
118
140
  virtual my_decimal *val_decimal(my_decimal *);
139
161
  virtual Item_result result_type () const=0;
140
162
  virtual Item_result cmp_type () const { return result_type(); }
141
163
  virtual Item_result cast_to_int_type () const { return result_type(); }
 
164
  /**
 
165
     Check whether a field type can be partially indexed by a key.
 
166
 
 
167
     This is a static method, rather than a virtual function, because we need
 
168
     to check the type of a non-Field in mysql_alter_table().
 
169
 
 
170
     @param type  field type
 
171
 
 
172
     @retval
 
173
       true  Type can have a prefixed key
 
174
     @retval
 
175
       false Type can not have a prefixed key
 
176
  */
142
177
  static bool type_can_have_key_part(enum_field_types);
143
178
  static enum_field_types field_type_merge(enum_field_types, enum_field_types);
 
179
 
 
180
  /**
 
181
     Detect Item_result by given field type of UNION merge result.
 
182
 
 
183
     @param field_type  given field type
 
184
 
 
185
     @return
 
186
       Item_result (type of internal MySQL expression result)
 
187
  */
144
188
  static Item_result result_merge_type(enum_field_types);
145
 
  virtual bool eq(Field *field)
146
 
  {
147
 
    return (ptr == field->ptr && null_ptr == field->null_ptr &&
148
 
            null_bit == field->null_bit);
149
 
  }
 
189
 
 
190
  virtual bool eq(Field *field);
150
191
  virtual bool eq_def(Field *field);
151
 
  
 
192
 
152
193
  /*
153
194
    pack_length() returns size (in bytes) used to store field data in memory
154
195
    (i.e. it returns the maximum size of the field in a row of the table,
155
196
    which is located in RAM).
156
197
  */
157
 
  virtual uint32_t pack_length() const { return (uint32_t) field_length; }
 
198
  virtual uint32_t pack_length() const;
158
199
 
159
200
  /*
160
201
    pack_length_in_rec() returns size (in bytes) used to store field data on
161
202
    storage (i.e. it returns the maximal size of the field in a row of the
162
203
    table, which is located on disk).
163
204
  */
164
 
  virtual uint32_t pack_length_in_rec() const { return pack_length(); }
 
205
  virtual uint32_t pack_length_in_rec() const;
165
206
  virtual int compatible_field_size(uint32_t field_metadata);
166
 
  virtual uint32_t pack_length_from_metadata(uint32_t field_metadata)
167
 
  { return field_metadata; }
 
207
  virtual uint32_t pack_length_from_metadata(uint32_t field_metadata);
 
208
 
168
209
  /*
169
210
    This method is used to return the size of the data in a row-based
170
211
    replication row record. The default implementation of returning 0 is
171
212
    designed to allow fields that do not use metadata to return true (1)
172
213
    from compatible_field_size() which uses this function in the comparison.
173
 
    The default value for field metadata for fields that do not have 
 
214
    The default value for field metadata for fields that do not have
174
215
    metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
175
216
 
176
217
    Note: While most classes that override this method return pack_length(),
177
 
    the classes Field_varstring, and Field_blob return 
 
218
    the classes Field_varstring, and Field_blob return
178
219
    field_length + 1, field_length, and pack_length_no_ptr() respectfully.
179
220
  */
180
 
  virtual uint32_t row_pack_length() { return 0; }
181
 
  virtual int save_field_metadata(unsigned char *first_byte)
182
 
  { return do_save_field_metadata(first_byte); }
 
221
  virtual uint32_t row_pack_length();
 
222
  virtual int save_field_metadata(unsigned char *first_byte);
183
223
 
184
224
  /*
185
225
    data_length() return the "real size" of the data in memory.
186
226
    For varstrings, this does _not_ include the length bytes.
187
227
  */
188
 
  virtual uint32_t data_length() { return pack_length(); }
 
228
  virtual uint32_t data_length();
189
229
  /*
190
230
    used_length() returns the number of bytes actually used to store the data
191
231
    of the field. So for a varstring it includes both lenght byte(s) and
192
232
    string data, and anything after data_length() bytes are unused.
193
233
  */
194
 
  virtual uint32_t used_length() { return pack_length(); }
195
 
  virtual uint32_t sort_length() const { return pack_length(); }
 
234
  virtual uint32_t used_length();
 
235
  virtual uint32_t sort_length() const;
196
236
 
197
237
  /**
198
238
     Get the maximum size of the data in packed format.
200
240
     @return Maximum data length of the field when packed using the
201
241
     Field::pack() function.
202
242
   */
203
 
  virtual uint32_t max_data_length() const {
204
 
    return pack_length();
205
 
  };
206
 
 
207
 
  virtual int reset(void) { memset(ptr, 0, pack_length()); return 0; }
208
 
  virtual void reset_fields() {}
209
 
  virtual void set_default()
210
 
  {
211
 
    my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
212
 
    memcpy(ptr, ptr + l_offset, pack_length());
213
 
    if (null_ptr)
214
 
      *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
215
 
  }
216
 
  virtual bool binary() const { return 1; }
217
 
  virtual bool zero_pack() const { return 1; }
218
 
  virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
219
 
  virtual uint32_t key_length() const { return pack_length(); }
 
243
  virtual uint32_t max_data_length() const;
 
244
  virtual int reset(void);
 
245
  virtual void reset_fields();
 
246
  virtual void set_default();
 
247
  virtual bool binary() const;
 
248
  virtual bool zero_pack() const;
 
249
  virtual enum ha_base_keytype key_type() const;
 
250
  virtual uint32_t key_length() const;
220
251
  virtual enum_field_types type() const =0;
221
 
  virtual enum_field_types real_type() const { return type(); }
 
252
  virtual enum_field_types real_type() const;
222
253
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
223
254
  virtual int cmp_max(const unsigned char *a, const unsigned char *b,
224
 
                      uint32_t max_len __attribute__((unused)))
225
 
    { return cmp(a, b); }
 
255
                      uint32_t max_len);
226
256
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
227
257
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
228
 
                         uint32_t  __attribute__((unused)) max_length=UINT32_MAX)
229
 
  { return memcmp(a,b,pack_length()); }
230
 
  virtual int cmp_offset(uint32_t row_offset)
231
 
  { return cmp(ptr,ptr+row_offset); }
232
 
  virtual int cmp_binary_offset(uint32_t row_offset)
233
 
  { return cmp_binary(ptr, ptr+row_offset); };
234
 
  virtual int key_cmp(const unsigned char *a,const unsigned char *b)
235
 
  { return cmp(a, b); }
236
 
  virtual int key_cmp(const unsigned char *str, uint32_t length __attribute__((unused)))
237
 
  { return cmp(ptr,str); }
238
 
  virtual uint32_t decimals() const { return 0; }
 
258
                         uint32_t max_length=UINT32_MAX);
 
259
  virtual int cmp_offset(uint32_t row_offset);
 
260
  virtual int cmp_binary_offset(uint32_t row_offset);
 
261
  virtual int key_cmp(const unsigned char *a,const unsigned char *b);
 
262
  virtual int key_cmp(const unsigned char *str, uint32_t length);
 
263
  virtual uint32_t decimals() const;
 
264
 
239
265
  /*
240
266
    Caller beware: sql_type can change str.Ptr, so check
241
267
    ptr() to see if it changed if you are using your own buffer
242
268
    in str and restore it with set() if needed
243
269
  */
244
270
  virtual void sql_type(String &str) const =0;
245
 
  virtual uint32_t size_of() const =0;          // For new field
246
 
  inline bool is_null(my_ptrdiff_t row_offset= 0)
247
 
  { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
248
 
  inline bool is_real_null(my_ptrdiff_t row_offset= 0)
249
 
    { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
250
 
  inline bool is_null_in_record(const unsigned char *record)
251
 
  {
252
 
    if (!null_ptr)
253
 
      return 0;
254
 
    return test(record[(uint32_t) (null_ptr -table->record[0])] &
255
 
                null_bit);
256
 
  }
257
 
  inline bool is_null_in_record_with_offset(my_ptrdiff_t offset)
258
 
  {
259
 
    if (!null_ptr)
260
 
      return 0;
261
 
    return test(null_ptr[offset] & null_bit);
262
 
  }
263
 
  inline void set_null(my_ptrdiff_t row_offset= 0)
264
 
    { if (null_ptr) null_ptr[row_offset]|= null_bit; }
265
 
  inline void set_notnull(my_ptrdiff_t row_offset= 0)
266
 
    { if (null_ptr) null_ptr[row_offset]&= (unsigned char) ~null_bit; }
267
 
  inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
268
 
  inline bool real_maybe_null(void) { return null_ptr != 0; }
 
271
 
 
272
  // For new field
 
273
  virtual uint32_t size_of() const =0;
 
274
 
 
275
  bool is_null(my_ptrdiff_t row_offset= 0);
 
276
  bool is_real_null(my_ptrdiff_t row_offset= 0);
 
277
  bool is_null_in_record(const unsigned char *record);
 
278
  bool is_null_in_record_with_offset(my_ptrdiff_t offset);
 
279
  void set_null(my_ptrdiff_t row_offset= 0);
 
280
  void set_notnull(my_ptrdiff_t row_offset= 0);
 
281
  bool maybe_null(void);
 
282
  bool real_maybe_null(void);
269
283
 
270
284
  enum {
271
285
    LAST_NULL_BYTE_UNDEF= 0
286
300
      the record. If the field does not use any bits of the null
287
301
      bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
288
302
   */
289
 
  size_t last_null_byte() const {
290
 
    size_t bytes= do_last_null_byte();
291
 
    assert(bytes <= table->getNullBytes());
292
 
    return bytes;
293
 
  }
 
303
  size_t last_null_byte() const;
294
304
 
295
305
  virtual void make_field(Send_field *);
296
306
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
322
332
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
323
333
  }
324
334
  virtual void get_image(unsigned char *buff, uint32_t length,
325
 
                         const CHARSET_INFO * const cs __attribute__((unused)))
 
335
                         const CHARSET_INFO * const)
326
336
    { memcpy(buff,ptr,length); }
 
337
  virtual void get_image(std::basic_string<unsigned char> &buff,
 
338
                         uint32_t length,
 
339
                         const CHARSET_INFO * const)
 
340
    { buff.append(ptr,length); }
327
341
  virtual void set_image(const unsigned char *buff,uint32_t length,
328
 
                         const CHARSET_INFO * const cs __attribute__((unused)))
 
342
                         const CHARSET_INFO * const)
329
343
    { memcpy(ptr,buff,length); }
330
344
 
331
345
 
355
369
      Number of copied bytes (excluding padded zero bytes -- see above).
356
370
  */
357
371
 
358
 
  virtual uint32_t get_key_image(unsigned char *buff, uint32_t length,
359
 
                             imagetype type __attribute__((unused)))
 
372
  virtual uint32_t get_key_image(unsigned char *buff, uint32_t length, imagetype)
 
373
  {
 
374
    get_image(buff, length, &my_charset_bin);
 
375
    return length;
 
376
  }
 
377
  virtual uint32_t get_key_image(std::basic_string<unsigned char> &buff,
 
378
                                 uint32_t length, imagetype)
360
379
  {
361
380
    get_image(buff, length, &my_charset_bin);
362
381
    return length;
363
382
  }
364
383
  virtual void set_key_image(const unsigned char *buff,uint32_t length)
365
 
    { set_image(buff,length, &my_charset_bin); }
 
384
  { set_image(buff,length, &my_charset_bin); }
366
385
  inline int64_t val_int_offset(uint32_t row_offset)
367
 
    {
368
 
      ptr+=row_offset;
369
 
      int64_t tmp=val_int();
370
 
      ptr-=row_offset;
371
 
      return tmp;
372
 
    }
 
386
  {
 
387
    ptr+=row_offset;
 
388
    int64_t tmp=val_int();
 
389
    ptr-=row_offset;
 
390
    return tmp;
 
391
  }
 
392
 
373
393
  inline int64_t val_int(const unsigned char *new_ptr)
374
394
  {
375
395
    unsigned char *old_ptr= ptr;
387
407
    ptr= old_ptr;
388
408
    return str;
389
409
  }
390
 
  virtual bool send_binary(Protocol *protocol);
391
 
 
392
 
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
393
 
                      uint32_t max_length, bool low_byte_first);
394
 
  /**
395
 
     @overload Field::pack(unsigned char*, const unsigned char*, uint32_t, bool)
396
 
  */
397
 
  unsigned char *pack(unsigned char *to, const unsigned char *from)
398
 
  {
399
 
    unsigned char *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
400
 
    return(result);
401
 
  }
402
 
 
403
 
  virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
404
 
                              uint32_t param_data, bool low_byte_first);
405
 
  /**
406
 
     @overload Field::unpack(unsigned char*, const unsigned char*, uint32_t, bool)
407
 
  */
408
 
  const unsigned char *unpack(unsigned char* to, const unsigned char *from)
409
 
  {
410
 
    const unsigned char *result= unpack(to, from, 0U, table->s->db_low_byte_first);
411
 
    return(result);
412
 
  }
 
410
 
 
411
  virtual unsigned char *pack(unsigned char *to,
 
412
                              const unsigned char *from,
 
413
                              uint32_t max_length,
 
414
                              bool low_byte_first);
 
415
 
 
416
  unsigned char *pack(unsigned char *to, const unsigned char *from);
 
417
 
 
418
  virtual const unsigned char *unpack(unsigned char* to,
 
419
                                      const unsigned char *from,
 
420
                                      uint32_t param_data,
 
421
                                      bool low_byte_first);
 
422
  /**
 
423
     @overload Field::unpack(unsigned char*, const unsigned char*,
 
424
                             uint32_t, bool)
 
425
  */
 
426
  const unsigned char *unpack(unsigned char* to,
 
427
                              const unsigned char *from);
413
428
 
414
429
  virtual unsigned char *pack_key(unsigned char* to, const unsigned char *from,
415
430
                          uint32_t max_length, bool low_byte_first)
416
431
  {
417
432
    return pack(to, from, max_length, low_byte_first);
418
433
  }
419
 
  virtual unsigned char *pack_key_from_key_image(unsigned char* to, const unsigned char *from,
420
 
                                        uint32_t max_length, bool low_byte_first)
 
434
  virtual unsigned char *pack_key_from_key_image(unsigned char* to,
 
435
                                                 const unsigned char *from,
 
436
                                                 uint32_t max_length,
 
437
                                                 bool low_byte_first)
421
438
  {
422
439
    return pack(to, from, max_length, low_byte_first);
423
440
  }
424
 
  virtual const unsigned char *unpack_key(unsigned char* to, const unsigned char *from,
425
 
                                  uint32_t max_length, bool low_byte_first)
 
441
  virtual const unsigned char *unpack_key(unsigned char* to,
 
442
                                          const unsigned char *from,
 
443
                                          uint32_t max_length,
 
444
                                          bool low_byte_first)
426
445
  {
427
446
    return unpack(to, from, max_length, low_byte_first);
428
447
  }
429
 
  virtual uint32_t packed_col_length(const unsigned char *to __attribute__((unused)),
430
 
                                 uint32_t length)
431
 
  { return length;}
 
448
  virtual uint32_t packed_col_length(const unsigned char *to, uint32_t length);
432
449
  virtual uint32_t max_packed_col_length(uint32_t max_length)
433
450
  { return max_length;}
434
451
 
435
452
  virtual int pack_cmp(const unsigned char *a,const unsigned char *b,
436
 
                       uint32_t key_length_arg __attribute__((unused)),
437
 
                       bool insert_or_update __attribute__((unused)))
438
 
  { return cmp(a,b); }
 
453
                       uint32_t key_length_arg,
 
454
                       bool insert_or_update);
439
455
  virtual int pack_cmp(const unsigned char *b,
440
 
                       uint32_t key_length_arg __attribute__((unused)),
441
 
                       bool insert_or_update __attribute__((unused)))
442
 
  { return cmp(ptr,b); }
 
456
                       uint32_t key_length_arg,
 
457
                       bool insert_or_update);
 
458
 
443
459
  uint32_t offset(unsigned char *record)
444
460
  {
445
461
    return (uint32_t) (ptr - record);
451
467
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
452
468
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
453
469
  virtual bool has_charset(void) const { return false; }
454
 
  virtual void set_charset(const CHARSET_INFO * const charset_arg __attribute__((unused)))
 
470
  virtual void set_charset(const CHARSET_INFO * const)
455
471
  { }
456
472
  virtual enum Derivation derivation(void) const
457
473
  { return DERIVATION_IMPLICIT; }
458
 
  virtual void set_derivation(enum Derivation derivation_arg __attribute__((unused)))
 
474
  virtual void set_derivation(enum Derivation)
459
475
  { }
460
476
  bool set_warning(DRIZZLE_ERROR::enum_warning_level, unsigned int code,
461
477
                   int cuted_increment);
462
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code, 
 
478
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code,
463
479
                            const char *str, uint32_t str_len,
464
480
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment);
465
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code, 
 
481
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code,
466
482
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
467
483
                            int cuted_increment);
468
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint32_t code, 
 
484
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint32_t code,
469
485
                            double nr, enum enum_drizzle_timestamp_type ts_type);
470
486
  inline bool check_overflow(int op_result)
471
487
  {
472
488
    return (op_result == E_DEC_OVERFLOW);
473
489
  }
474
490
  int warn_if_overflow(int op_result);
475
 
  void init(Table *table_arg)
476
 
  {
477
 
    orig_table= table= table_arg;
478
 
    table_name= &table_arg->alias;
479
 
  }
 
491
  void init(Table *table_arg);
480
492
 
481
493
  /* maximum possible display length */
482
494
  virtual uint32_t max_display_length()= 0;
499
511
 
500
512
  /* Hash value */
501
513
  virtual void hash(uint32_t *nr, uint32_t *nr2);
502
 
  friend bool reopen_table(THD *,Table *,bool);
 
514
  friend bool reopen_table(Session *,Table *,bool);
503
515
  friend int cre_myisam(char * name, register Table *form, uint32_t options,
504
516
                        uint64_t auto_increment_value);
505
517
  friend class Copy_field;
539
551
 
540
552
   @returns 0 no bytes written.
541
553
*/
542
 
  virtual int do_save_field_metadata(unsigned char *metadata_ptr __attribute__((unused)))
 
554
  virtual int do_save_field_metadata(unsigned char *)
543
555
  { return 0; }
544
556
};
545
557
 
546
 
 
547
 
class Field_num :public Field {
548
 
public:
549
 
  const uint8_t dec;
550
 
  bool decimal_precision;       // Purify cannot handle bit fields & only for decimal type
551
 
  bool unsigned_flag;   // Purify cannot handle bit fields
552
 
  Field_num(unsigned char *ptr_arg,uint32_t len_arg, unsigned char *null_ptr_arg,
553
 
            unsigned char null_bit_arg, utype unireg_check_arg,
554
 
            const char *field_name_arg,
555
 
            uint8_t dec_arg, bool zero_arg, bool unsigned_arg);
556
 
  Item_result result_type () const { return REAL_RESULT; }
557
 
  void add_unsigned(String &res) const;
558
 
  friend class Create_field;
559
 
  void make_field(Send_field *);
560
 
  uint32_t decimals() const { return (uint32_t) dec; }
561
 
  uint32_t size_of() const { return sizeof(*this); }
562
 
  bool eq_def(Field *field);
563
 
  int store_decimal(const my_decimal *);
564
 
  my_decimal *val_decimal(my_decimal *);
565
 
  uint32_t is_equal(Create_field *new_field);
566
 
  int check_int(const CHARSET_INFO * const cs, const char *str, int length,
567
 
                const char *int_end, int error);
568
 
  bool get_int(const CHARSET_INFO * const cs, const char *from, uint32_t len, 
569
 
               int64_t *rnd, uint64_t unsigned_max, 
570
 
               int64_t signed_min, int64_t signed_max);
571
 
};
572
 
 
573
 
/* base class for all string related classes */
574
 
 
575
 
class Field_str :public Field {
576
 
protected:
577
 
  const CHARSET_INFO *field_charset;
578
 
  enum Derivation field_derivation;
579
 
public:
580
 
  Field_str(unsigned char *ptr_arg,uint32_t len_arg, unsigned char *null_ptr_arg,
581
 
            unsigned char null_bit_arg, utype unireg_check_arg,
582
 
            const char *field_name_arg, const CHARSET_INFO * const charset);
583
 
  Item_result result_type () const { return STRING_RESULT; }
584
 
  uint32_t decimals() const { return NOT_FIXED_DEC; }
585
 
  int  store(double nr);
586
 
  int  store(int64_t nr, bool unsigned_val)=0;
587
 
  int  store_decimal(const my_decimal *);
588
 
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const cs)=0;
589
 
  uint32_t size_of() const { return sizeof(*this); }
590
 
  const CHARSET_INFO *charset(void) const { return field_charset; }
591
 
  void set_charset(const CHARSET_INFO * const charset_arg) { field_charset= charset_arg; }
592
 
  enum Derivation derivation(void) const { return field_derivation; }
593
 
  virtual void set_derivation(enum Derivation derivation_arg)
594
 
  { field_derivation= derivation_arg; }
595
 
  bool binary() const { return field_charset == &my_charset_bin; }
596
 
  uint32_t max_display_length() { return field_length; }
597
 
  friend class Create_field;
598
 
  my_decimal *val_decimal(my_decimal *);
599
 
  virtual bool str_needs_quotes() { return true; }
600
 
  bool compare_str_field_flags(Create_field *new_field, uint32_t flags);
601
 
  uint32_t is_equal(Create_field *new_field);
602
 
};
603
 
 
604
 
 
605
 
/* base class for Field_varstring and Field_blob */
606
 
 
607
 
class Field_longstr :public Field_str
608
 
{
609
 
protected:
610
 
  int report_if_important_data(const char *ptr, const char *end);
611
 
public:
612
 
  Field_longstr(unsigned char *ptr_arg, uint32_t len_arg, unsigned char *null_ptr_arg,
613
 
                unsigned char null_bit_arg, utype unireg_check_arg,
614
 
                const char *field_name_arg, const CHARSET_INFO * const charset_arg)
615
 
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
616
 
               field_name_arg, charset_arg)
617
 
    {}
618
 
 
619
 
  int store_decimal(const my_decimal *d);
620
 
  uint32_t max_data_length() const;
621
 
};
622
 
 
623
 
/* base class for float and double and decimal (old one) */
624
 
class Field_real :public Field_num {
625
 
public:
626
 
  bool not_fixed;
627
 
 
628
 
  Field_real(unsigned char *ptr_arg, uint32_t len_arg, unsigned char *null_ptr_arg,
629
 
             unsigned char null_bit_arg, utype unireg_check_arg,
630
 
             const char *field_name_arg,
631
 
             uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
632
 
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
633
 
               field_name_arg, dec_arg, zero_arg, unsigned_arg),
634
 
    not_fixed(dec_arg >= NOT_FIXED_DEC)
635
 
    {}
636
 
  int store_decimal(const my_decimal *);
637
 
  my_decimal *val_decimal(my_decimal *);
638
 
  int truncate(double *nr, double max_length);
639
 
  uint32_t max_display_length() { return field_length; }
640
 
  uint32_t size_of() const { return sizeof(*this); }
641
 
  virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
642
 
                              uint32_t param_data, bool low_byte_first);
643
 
  virtual unsigned char *pack(unsigned char* to, const unsigned char *from,
644
 
                      uint32_t max_length, bool low_byte_first);
645
 
};
646
 
 
647
 
 
648
 
class Field_tiny :public Field_num {
649
 
public:
650
 
  Field_tiny(unsigned char *ptr_arg, uint32_t len_arg, unsigned char *null_ptr_arg,
651
 
             unsigned char null_bit_arg,
652
 
             enum utype unireg_check_arg, const char *field_name_arg,
653
 
             bool zero_arg, bool unsigned_arg)
654
 
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
655
 
               unireg_check_arg, field_name_arg,
656
 
               0, zero_arg,unsigned_arg)
657
 
    {}
658
 
  enum Item_result result_type () const { return INT_RESULT; }
659
 
  enum_field_types type() const { return DRIZZLE_TYPE_TINY;}
660
 
  enum ha_base_keytype key_type() const
661
 
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
662
 
  int store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
663
 
  int store(double nr);
664
 
  int store(int64_t nr, bool unsigned_val);
665
 
  int reset(void) { ptr[0]=0; return 0; }
666
 
  double val_real(void);
667
 
  int64_t val_int(void);
668
 
  String *val_str(String*,String *);
669
 
  bool send_binary(Protocol *protocol);
670
 
  int cmp(const unsigned char *,const unsigned char *);
671
 
  void sort_string(unsigned char *buff,uint32_t length);
672
 
  uint32_t pack_length() const { return 1; }
673
 
  void sql_type(String &str) const;
674
 
  uint32_t max_display_length() { return 4; }
675
 
 
676
 
  virtual unsigned char *pack(unsigned char* to, const unsigned char *from,
677
 
                      uint32_t max_length __attribute__((unused)),
678
 
                      bool low_byte_first __attribute__((unused)))
679
 
  {
680
 
    *to= *from;
681
 
    return to + 1;
682
 
  }
683
 
 
684
 
  virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
685
 
                              uint32_t param_data __attribute__((unused)),
686
 
                              bool low_byte_first __attribute__((unused)))
687
 
  {
688
 
    *to= *from;
689
 
    return from + 1;
690
 
  }
691
 
};
692
 
 
693
558
/*
694
559
  Create field class for CREATE TABLE
695
560
*/
705
570
  enum  enum_field_types sql_type;
706
571
  /*
707
572
    At various stages in execution this can be length of field in bytes or
708
 
    max number of characters. 
 
573
    max number of characters.
709
574
  */
710
575
  uint32_t length;
711
576
  /*
722
587
  const CHARSET_INFO *charset;
723
588
  Field *field;                         // For alter table
724
589
 
725
 
  uint8_t row,col,sc_length,interval_id;        // For rea_create_table
 
590
  uint8_t       interval_id;    // For rea_create_table
726
591
  uint32_t      offset,pack_flag;
 
592
 
 
593
  /* Virtual column expression statement */
 
594
  virtual_column_info *vcol_info;
 
595
  /*
 
596
    Indication that the field is phycically stored in tables
 
597
    rather than just generated on SQL queries.
 
598
    As of now, FALSE can only be set for generated-only virtual columns.
 
599
  */
 
600
  bool is_stored;
 
601
 
727
602
  Create_field() :after(0) {}
728
603
  Create_field(Field *field, Field *orig_field);
729
604
  /* Used to make a clone of this object for ALTER/CREATE TABLE */
742
617
                          uint32_t max_length, uint32_t decimals,
743
618
                          bool maybe_null, bool is_unsigned);
744
619
 
745
 
  bool init(THD *thd, char *field_name, enum_field_types type, char *length,
 
620
  bool init(Session *session, char *field_name, enum_field_types type, char *length,
746
621
            char *decimals, uint32_t type_modifier, Item *default_value,
747
622
            Item *on_update_value, LEX_STRING *comment, char *change,
748
623
            List<String> *interval_list, const CHARSET_INFO * const cs,
749
624
            uint32_t uint_geom_type,
750
 
            enum column_format_type column_format);
 
625
            enum column_format_type column_format,
 
626
            virtual_column_info *vcol_info);
751
627
};
752
628
 
753
629
 
789
665
 
790
666
  Copy_field() {}
791
667
  ~Copy_field() {}
792
 
  void set(Field *to,Field *from,bool save);    // Field to field 
 
668
  void set(Field *to,Field *from,bool save);    // Field to field
793
669
  void set(unsigned char *to,Field *from);              // Field to string
794
670
  void (*do_copy)(Copy_field *);
795
671
  void (*do_copy2)(Copy_field *);               // Used to handle null values
796
672
};
797
673
 
798
674
 
799
 
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
800
 
                  unsigned char *null_pos, unsigned char null_bit,
801
 
                  uint32_t pack_flag, enum_field_types field_type,
802
 
                  const CHARSET_INFO * cs,
803
 
                  Field::utype unireg_check,
804
 
                  TYPELIB *interval, const char *field_name);
 
675
Field *make_field(TABLE_SHARE *share, MEM_ROOT *root, unsigned char *ptr, uint32_t field_length,
 
676
                  unsigned char *null_pos, unsigned char null_bit,
 
677
                  uint32_t pack_flag, enum_field_types field_type,
 
678
                  const CHARSET_INFO * cs,
 
679
                  Field::utype unireg_check,
 
680
                  TYPELIB *interval, const char *field_name);
 
681
 
805
682
uint32_t pack_length_to_packflag(uint32_t type);
806
683
enum_field_types get_blob_type_from_length(uint32_t length);
807
684
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
808
685
int set_field_to_null(Field *field);
809
686
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
810
687
 
 
688
 
811
689
bool
812
 
check_string_copy_error(Field_str *field,
813
 
                        const char *well_formed_error_pos,
814
 
                        const char *cannot_convert_error_pos,
815
 
                        const char *end,
816
 
                        const CHARSET_INFO * const cs);
817
 
 
818
 
/*
819
 
  Field subclasses
820
 
 */
821
 
#include <drizzled/field/blob.h>
822
 
#include <drizzled/field/enum.h>
823
 
#include <drizzled/field/null.h>
824
 
#include <drizzled/field/date.h>
825
 
#include <drizzled/field/fdecimal.h>
826
 
#include <drizzled/field/double.h>
827
 
#include <drizzled/field/long.h>
828
 
#include <drizzled/field/int64_t.h>
829
 
#include <drizzled/field/timetype.h>
830
 
#include <drizzled/field/timestamp.h>
831
 
#include <drizzled/field/datetime.h>
832
 
#include <drizzled/field/fstring.h>
833
 
#include <drizzled/field/varstring.h>
834
 
 
835
 
/*
836
 
  The following are for the interface with the .frm file
837
 
*/
838
 
 
839
 
#define FIELDFLAG_DECIMAL               1
840
 
#define FIELDFLAG_BINARY                1       // Shares same flag
841
 
#define FIELDFLAG_NUMBER                2
842
 
#define FIELDFLAG_DECIMAL_POSITION      4
843
 
#define FIELDFLAG_PACK                  120     // Bits used for packing
844
 
#define FIELDFLAG_INTERVAL              256     // mangled with decimals!
845
 
#define FIELDFLAG_BITFIELD              512     // mangled with decimals!
846
 
#define FIELDFLAG_BLOB                  1024    // mangled with decimals!
847
 
#define FIELDFLAG_GEOM                  2048    // mangled with decimals!
848
 
 
849
 
#define FIELDFLAG_TREAT_BIT_AS_CHAR     4096    /* use Field_bit_as_char */
850
 
 
851
 
#define FIELDFLAG_LEFT_FULLSCREEN       8192
852
 
#define FIELDFLAG_RIGHT_FULLSCREEN      16384
853
 
#define FIELDFLAG_FORMAT_NUMBER         16384   // predit: ###,,## in output
854
 
#define FIELDFLAG_NO_DEFAULT            16384   /* sql */
855
 
#define FIELDFLAG_SUM                   ((uint32_t) 32768)// predit: +#fieldflag
856
 
#define FIELDFLAG_MAYBE_NULL            ((uint32_t) 32768)// sql
857
 
#define FIELDFLAG_HEX_ESCAPE            ((uint32_t) 0x10000)
858
 
#define FIELDFLAG_PACK_SHIFT            3
859
 
#define FIELDFLAG_DEC_SHIFT             8
860
 
#define FIELDFLAG_MAX_DEC               31
861
 
#define FIELDFLAG_NUM_SCREEN_TYPE       0x7F01
862
 
#define FIELDFLAG_ALFA_SCREEN_TYPE      0x7800
863
 
 
864
 
#define MTYP_TYPENR(type) (type & 127)  /* Remove bits from type */
865
 
 
866
 
#define f_is_dec(x)             ((x) & FIELDFLAG_DECIMAL)
867
 
#define f_is_num(x)             ((x) & FIELDFLAG_NUMBER)
868
 
#define f_is_decimal_precision(x)       ((x) & FIELDFLAG_DECIMAL_POSITION)
869
 
#define f_is_packed(x)          ((x) & FIELDFLAG_PACK)
870
 
#define f_packtype(x)           (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
871
 
#define f_decimals(x)           ((uint8_t) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
872
 
#define f_is_alpha(x)           (!f_is_num(x))
873
 
#define f_is_binary(x)          ((x) & FIELDFLAG_BINARY) // 4.0- compatibility
874
 
#define f_is_enum(x)            (((x) & (FIELDFLAG_INTERVAL | FIELDFLAG_NUMBER)) == FIELDFLAG_INTERVAL)
875
 
#define f_is_bitfield(x)        (((x) & (FIELDFLAG_BITFIELD | FIELDFLAG_NUMBER)) == FIELDFLAG_BITFIELD)
876
 
#define f_is_blob(x)            (((x) & (FIELDFLAG_BLOB | FIELDFLAG_NUMBER)) == FIELDFLAG_BLOB)
877
 
#define f_is_equ(x)             ((x) & (1+2+FIELDFLAG_PACK+31*256))
878
 
#define f_settype(x)            (((int) x) << FIELDFLAG_PACK_SHIFT)
879
 
#define f_maybe_null(x)         (x & FIELDFLAG_MAYBE_NULL)
880
 
#define f_no_default(x)         (x & FIELDFLAG_NO_DEFAULT)
881
 
#define f_bit_as_char(x)        ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
882
 
#define f_is_hex_escape(x)      ((x) & FIELDFLAG_HEX_ESCAPE)
883
 
 
 
690
test_if_important_data(const CHARSET_INFO * const cs,
 
691
                       const char *str,
 
692
                       const char *strend);
 
693
 
 
694
 
 
695
#endif /* DRIZZLED_FIELD_H */