~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Lee
  • Date: 2009-01-01 03:07:33 UTC
  • mto: (758.1.3 devel)
  • mto: This revision was merged to the branch mainline in revision 759.
  • Revision ID: lbieber@lbieber-desktop-20090101030733-fb411b55f07vij8q
more header file cleanup

Show diffs side-by-side

added added

removed removed

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