~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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 by brian
clean slate
19
20
/*
21
  Because of the function new_field() all field classes that have static
22
  variables must declare the size_of() member function.
23
*/
24
520.8.2 by Monty Taylor
Moved sql_parse.h and sql_error.h out of common_includes.
25
#ifndef DRIZZLED_FIELD_H
26
#define DRIZZLED_FIELD_H
27
28
#include <drizzled/sql_error.h>
520.8.3 by Monty Taylor
Moved hash back to mysys.
29
#include <drizzled/my_decimal.h>
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
30
#include <drizzled/sql_bitmap.h>
31
#include <drizzled/sql_list.h>
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
32
#include <string>
1 by brian
clean slate
33
34
#define DATETIME_DEC                     6
173.1.9 by Toru Maesaka
ripped out DOUBLE and moved to field/
35
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
36
205 by Brian Aker
uint32 -> uin32_t
37
const uint32_t max_field_size= (uint32_t) 4294967295U;
1 by brian
clean slate
38
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
39
class Table;
1 by brian
clean slate
40
class Send_field;
41
class Protocol;
42
class Create_field;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
43
class virtual_column_info;
44
45
typedef struct st_table_share TABLE_SHARE;
46
1 by brian
clean slate
47
struct st_cache_field;
48
int field_conv(Field *to,Field *from);
49
438.1.13 by Brian Aker
uint cleanup.
50
inline uint32_t get_enum_pack_length(int elements)
1 by brian
clean slate
51
{
52
  return elements < 256 ? 1 : 2;
53
}
54
438.1.13 by Brian Aker
uint cleanup.
55
inline uint32_t get_set_pack_length(int elements)
1 by brian
clean slate
56
{
438.1.13 by Brian Aker
uint cleanup.
57
  uint32_t len= (elements + 7) / 8;
1 by brian
clean slate
58
  return len > 4 ? 8 : len;
59
}
60
61
class Field
62
{
63
  Field(const Item &);				/* Prevent use of these */
64
  void operator=(Field &);
65
public:
66
  static void *operator new(size_t size) {return sql_alloc(size); }
644 by Brian Aker
Clean up warnings for Solaris.
67
  static void operator delete(void *, size_t)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
68
  { TRASH(ptr_arg, size); }
1 by brian
clean slate
69
481 by Brian Aker
Remove all of uchar.
70
  unsigned char		*ptr;			// Position to field in record
71
  unsigned char		*null_ptr;		// Byte where null_bit is
1 by brian
clean slate
72
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
73
    Note that you can use table->in_use as replacement for current_session member
1 by brian
clean slate
74
    only inside of val_*() and store() members (e.g. you can't use it in cons)
75
  */
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
76
  Table *table;		// Pointer for table
77
  Table *orig_table;		// Pointer to original table
1 by brian
clean slate
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;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
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
1 by brian
clean slate
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,
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
92
                CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD,
1 by brian
clean slate
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;
205 by Brian Aker
uint32 -> uin32_t
98
  uint32_t	field_length;		// Length of field
99
  uint32_t	flags;
206 by Brian Aker
Removed final uint dead types.
100
  uint16_t        field_index;            // field number in fields array
481 by Brian Aker
Remove all of uchar.
101
  unsigned char		null_bit;		// Bit used to test null bit
1 by brian
clean slate
102
  /**
103
     If true, this field was created in create_tmp_field_from_item from a NULL
104
     value. This means that the type of the field is just a guess, and the type
105
     may be freely coerced to another type.
106
107
     @see create_tmp_field_from_item
108
     @see Item_type_holder::get_real_type
109
110
   */
111
  bool is_created_from_null_item;
112
383.7.1 by Andrey Zhakov
Initial submit of code and tests
113
  /* Virtual column data */
114
  virtual_column_info *vcol_info;
115
  /*
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
116
    Indication that the field is physically stored in tables
383.7.1 by Andrey Zhakov
Initial submit of code and tests
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
481 by Brian Aker
Remove all of uchar.
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,
1 by brian
clean slate
124
        const char *field_name_arg);
125
  virtual ~Field() {}
126
  /* Store functions returns 1 on overflow and -1 on fatal error */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
127
  virtual int  store(const char *to, uint32_t length,
128
                     const CHARSET_INFO * const cs)=0;
1 by brian
clean slate
129
  virtual int  store(double nr)=0;
152 by Brian Aker
longlong replacement
130
  virtual int  store(int64_t nr, bool unsigned_val)=0;
1 by brian
clean slate
131
  virtual int  store_decimal(const my_decimal *d)=0;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
132
  virtual int store_time(DRIZZLE_TIME *ltime,
133
                         enum enum_drizzle_timestamp_type t_type);
438.1.13 by Brian Aker
uint cleanup.
134
  int store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
1 by brian
clean slate
135
            enum_check_fields check_level);
136
  virtual double val_real(void)=0;
152 by Brian Aker
longlong replacement
137
  virtual int64_t val_int(void)=0;
1 by brian
clean slate
138
  virtual my_decimal *val_decimal(my_decimal *);
139
  inline String *val_str(String *str) { return val_str(str, str); }
140
  /*
141
     val_str(buf1, buf2) gets two buffers and should use them as follows:
142
     if it needs a temp buffer to convert result to string - use buf1
143
       example Field_tiny::val_str()
144
     if the value exists as a string already - use buf2
241 by Brian Aker
First pass of CHAR removal.
145
       example Field_varstring::val_str() (???)
1 by brian
clean slate
146
     consequently, buf2 may be created as 'String buf;' - no memory
147
     will be allocated for it. buf1 will be allocated to hold a
148
     value if it's too small. Using allocated buffer for buf2 may result in
149
     an unnecessary free (and later, may be an alloc).
150
     This trickery is used to decrease a number of malloc calls.
151
  */
152
  virtual String *val_str(String*,String *)=0;
275 by Brian Aker
Full removal of my_bool from central server.
153
  String *val_int_as_str(String *val_buffer, bool unsigned_flag);
1 by brian
clean slate
154
  /*
51.1.58 by Jay Pipes
Replace/remove DBUG and standardize TRUE/FALSE. Remove ASSERT_COLUMN_XXX macros, that work will be done on another
155
   str_needs_quotes() returns true if the value returned by val_str() needs
1 by brian
clean slate
156
   to be quoted when used in constructing an SQL query.
157
  */
51.1.58 by Jay Pipes
Replace/remove DBUG and standardize TRUE/FALSE. Remove ASSERT_COLUMN_XXX macros, that work will be done on another
158
  virtual bool str_needs_quotes() { return false; }
1 by brian
clean slate
159
  virtual Item_result result_type () const=0;
160
  virtual Item_result cmp_type () const { return result_type(); }
161
  virtual Item_result cast_to_int_type () const { return result_type(); }
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
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
  */
1 by brian
clean slate
175
  static bool type_can_have_key_part(enum_field_types);
176
  static enum_field_types field_type_merge(enum_field_types, enum_field_types);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
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
  */
1 by brian
clean slate
186
  static Item_result result_merge_type(enum_field_types);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
187
188
  virtual bool eq(Field *field);
1 by brian
clean slate
189
  virtual bool eq_def(Field *field);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
190
1 by brian
clean slate
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
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
196
  virtual uint32_t pack_length() const;
1 by brian
clean slate
197
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
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
203
  virtual uint32_t pack_length_in_rec() const;
438.1.13 by Brian Aker
uint cleanup.
204
  virtual int compatible_field_size(uint32_t field_metadata);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
205
  virtual uint32_t pack_length_from_metadata(uint32_t field_metadata);
206
1 by brian
clean slate
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
51.1.58 by Jay Pipes
Replace/remove DBUG and standardize TRUE/FALSE. Remove ASSERT_COLUMN_XXX macros, that work will be done on another
210
    designed to allow fields that do not use metadata to return true (1)
1 by brian
clean slate
211
    from compatible_field_size() which uses this function in the comparison.
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
212
    The default value for field metadata for fields that do not have
1 by brian
clean slate
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(),
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
216
    the classes Field_varstring, and Field_blob return
1 by brian
clean slate
217
    field_length + 1, field_length, and pack_length_no_ptr() respectfully.
218
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
219
  virtual uint32_t row_pack_length();
220
  virtual int save_field_metadata(unsigned char *first_byte);
1 by brian
clean slate
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
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
226
  virtual uint32_t data_length();
1 by brian
clean slate
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
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
232
  virtual uint32_t used_length();
233
  virtual uint32_t sort_length() const;
1 by brian
clean slate
234
235
  /**
236
     Get the maximum size of the data in packed format.
237
238
     @return Maximum data length of the field when packed using the
239
     Field::pack() function.
240
   */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
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;
1 by brian
clean slate
249
  virtual enum_field_types type() const =0;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
250
  virtual enum_field_types real_type() const;
481 by Brian Aker
Remove all of uchar.
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,
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
253
                      uint32_t max_len);
481 by Brian Aker
Remove all of uchar.
254
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
255
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
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
1 by brian
clean slate
263
  /*
264
    Caller beware: sql_type can change str.Ptr, so check
265
    ptr() to see if it changed if you are using your own buffer
266
    in str and restore it with set() if needed
267
  */
268
  virtual void sql_type(String &str) const =0;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
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);
1 by brian
clean slate
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
   */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
301
  size_t last_null_byte() const;
1 by brian
clean slate
302
303
  virtual void make_field(Send_field *);
481 by Brian Aker
Remove all of uchar.
304
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
438.1.13 by Brian Aker
uint cleanup.
305
  virtual bool optimize_range(uint32_t idx, uint32_t part);
1 by brian
clean slate
306
  /*
307
    This should be true for fields which, when compared with constant
152 by Brian Aker
longlong replacement
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
1 by brian
clean slate
310
    use field->val_int() for comparison.  Used to optimize clauses like
311
    'a_column BETWEEN date_const, date_const'.
312
  */
152 by Brian Aker
longlong replacement
313
  virtual bool can_be_compared_as_int64_t() const { return false; }
1 by brian
clean slate
314
  virtual void free() {}
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
315
  virtual Field *new_field(MEM_ROOT *root, Table *new_table,
1 by brian
clean slate
316
                           bool keep_type);
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
317
  virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
481 by Brian Aker
Remove all of uchar.
318
                               unsigned char *new_ptr, unsigned char *new_null_ptr,
438.1.13 by Brian Aker
uint cleanup.
319
                               uint32_t new_null_bit);
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
320
  Field *clone(MEM_ROOT *mem_root, Table *new_table);
481 by Brian Aker
Remove all of uchar.
321
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
1 by brian
clean slate
322
  {
323
    ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
324
  }
481 by Brian Aker
Remove all of uchar.
325
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
1 by brian
clean slate
326
  virtual void move_field_offset(my_ptrdiff_t ptr_diff)
327
  {
481 by Brian Aker
Remove all of uchar.
328
    ptr=ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
1 by brian
clean slate
329
    if (null_ptr)
481 by Brian Aker
Remove all of uchar.
330
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
1 by brian
clean slate
331
  }
481 by Brian Aker
Remove all of uchar.
332
  virtual void get_image(unsigned char *buff, uint32_t length,
644 by Brian Aker
Clean up warnings for Solaris.
333
                         const CHARSET_INFO * const)
1 by brian
clean slate
334
    { memcpy(buff,ptr,length); }
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
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); }
481 by Brian Aker
Remove all of uchar.
339
  virtual void set_image(const unsigned char *buff,uint32_t length,
644 by Brian Aker
Clean up warnings for Solaris.
340
                         const CHARSET_INFO * const)
1 by brian
clean slate
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
644 by Brian Aker
Clean up warnings for Solaris.
370
  virtual uint32_t get_key_image(unsigned char *buff, uint32_t length, imagetype)
1 by brian
clean slate
371
  {
372
    get_image(buff, length, &my_charset_bin);
373
    return length;
374
  }
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
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
  }
481 by Brian Aker
Remove all of uchar.
381
  virtual void set_key_image(const unsigned char *buff,uint32_t length)
1 by brian
clean slate
382
    { set_image(buff,length, &my_charset_bin); }
438.1.13 by Brian Aker
uint cleanup.
383
  inline int64_t val_int_offset(uint32_t row_offset)
1 by brian
clean slate
384
    {
385
      ptr+=row_offset;
152 by Brian Aker
longlong replacement
386
      int64_t tmp=val_int();
1 by brian
clean slate
387
      ptr-=row_offset;
388
      return tmp;
389
    }
481 by Brian Aker
Remove all of uchar.
390
  inline int64_t val_int(const unsigned char *new_ptr)
1 by brian
clean slate
391
  {
481 by Brian Aker
Remove all of uchar.
392
    unsigned char *old_ptr= ptr;
152 by Brian Aker
longlong replacement
393
    int64_t return_value;
481 by Brian Aker
Remove all of uchar.
394
    ptr= (unsigned char*) new_ptr;
1 by brian
clean slate
395
    return_value= val_int();
396
    ptr= old_ptr;
397
    return return_value;
398
  }
481 by Brian Aker
Remove all of uchar.
399
  inline String *val_str(String *str, const unsigned char *new_ptr)
1 by brian
clean slate
400
  {
481 by Brian Aker
Remove all of uchar.
401
    unsigned char *old_ptr= ptr;
402
    ptr= (unsigned char*) new_ptr;
1 by brian
clean slate
403
    val_str(str);
404
    ptr= old_ptr;
405
    return str;
406
  }
407
  virtual bool send_binary(Protocol *protocol);
408
481 by Brian Aker
Remove all of uchar.
409
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
410
                              uint32_t max_length, bool low_byte_first);
1 by brian
clean slate
411
  /**
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
412
     @overload Field::pack(unsigned char*, const unsigned char*,
413
                           uint32_t, bool)
1 by brian
clean slate
414
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
415
  unsigned char *pack(unsigned char *to, const unsigned char *from);
1 by brian
clean slate
416
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
417
  virtual const unsigned char *unpack(unsigned char* to,
418
                                      const unsigned char *from,
419
                                      uint32_t param_data,
420
                                      bool low_byte_first);
1 by brian
clean slate
421
  /**
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
422
     @overload Field::unpack(unsigned char*, const unsigned char*,
423
                             uint32_t, bool)
1 by brian
clean slate
424
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
425
  const unsigned char *unpack(unsigned char* to, const unsigned char *from);
1 by brian
clean slate
426
481 by Brian Aker
Remove all of uchar.
427
  virtual unsigned char *pack_key(unsigned char* to, const unsigned char *from,
438.1.13 by Brian Aker
uint cleanup.
428
                          uint32_t max_length, bool low_byte_first)
1 by brian
clean slate
429
  {
430
    return pack(to, from, max_length, low_byte_first);
431
  }
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
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)
1 by brian
clean slate
436
  {
437
    return pack(to, from, max_length, low_byte_first);
438
  }
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
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)
1 by brian
clean slate
443
  {
444
    return unpack(to, from, max_length, low_byte_first);
445
  }
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
446
  virtual uint32_t packed_col_length(const unsigned char *to, uint32_t length);
438.1.13 by Brian Aker
uint cleanup.
447
  virtual uint32_t max_packed_col_length(uint32_t max_length)
1 by brian
clean slate
448
  { return max_length;}
449
481 by Brian Aker
Remove all of uchar.
450
  virtual int pack_cmp(const unsigned char *a,const unsigned char *b,
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
451
                       uint32_t key_length_arg,
452
                       bool insert_or_update);
481 by Brian Aker
Remove all of uchar.
453
  virtual int pack_cmp(const unsigned char *b,
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
454
                       uint32_t key_length_arg,
455
                       bool insert_or_update);
456
481 by Brian Aker
Remove all of uchar.
457
  uint32_t offset(unsigned char *record)
1 by brian
clean slate
458
  {
438.1.13 by Brian Aker
uint cleanup.
459
    return (uint32_t) (ptr - record);
1 by brian
clean slate
460
  }
461
  void copy_from_tmp(int offset);
438.1.13 by Brian Aker
uint cleanup.
462
  uint32_t fill_cache_field(struct st_cache_field *copy);
463
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
464
  virtual bool get_time(DRIZZLE_TIME *ltime);
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
465
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
466
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
51.1.58 by Jay Pipes
Replace/remove DBUG and standardize TRUE/FALSE. Remove ASSERT_COLUMN_XXX macros, that work will be done on another
467
  virtual bool has_charset(void) const { return false; }
644 by Brian Aker
Clean up warnings for Solaris.
468
  virtual void set_charset(const CHARSET_INFO * const)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
469
  { }
1 by brian
clean slate
470
  virtual enum Derivation derivation(void) const
471
  { return DERIVATION_IMPLICIT; }
644 by Brian Aker
Clean up warnings for Solaris.
472
  virtual void set_derivation(enum Derivation)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
473
  { }
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
474
  bool set_warning(DRIZZLE_ERROR::enum_warning_level, unsigned int code,
1 by brian
clean slate
475
                   int cuted_increment);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
476
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code,
438.1.13 by Brian Aker
uint cleanup.
477
                            const char *str, uint32_t str_len,
398.1.1 by Monty Taylor
Remove typedef enum enum_drizzle_timestamp_type timestamp_type;
478
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
479
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code,
398.1.1 by Monty Taylor
Remove typedef enum enum_drizzle_timestamp_type timestamp_type;
480
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
1 by brian
clean slate
481
                            int cuted_increment);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
482
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint32_t code,
398.1.1 by Monty Taylor
Remove typedef enum enum_drizzle_timestamp_type timestamp_type;
483
                            double nr, enum enum_drizzle_timestamp_type ts_type);
1 by brian
clean slate
484
  inline bool check_overflow(int op_result)
485
  {
486
    return (op_result == E_DEC_OVERFLOW);
487
  }
488
  int warn_if_overflow(int op_result);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
489
  void init(Table *table_arg);
1 by brian
clean slate
490
491
  /* maximum possible display length */
205 by Brian Aker
uint32 -> uin32_t
492
  virtual uint32_t max_display_length()= 0;
1 by brian
clean slate
493
438.1.13 by Brian Aker
uint cleanup.
494
  virtual uint32_t is_equal(Create_field *new_field);
152 by Brian Aker
longlong replacement
495
  /* convert decimal to int64_t with overflow check */
496
  int64_t convert_decimal2int64_t(const my_decimal *val, bool unsigned_flag,
1 by brian
clean slate
497
                                    int *err);
498
  /* The max. number of characters */
205 by Brian Aker
uint32 -> uin32_t
499
  inline uint32_t char_length() const
1 by brian
clean slate
500
  {
501
    return field_length / charset()->mbmaxlen;
502
  }
503
504
  inline enum column_format_type column_format() const
505
  {
506
    return (enum column_format_type)
507
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
508
  }
509
510
  /* Hash value */
290 by Brian Aker
Update for ulong change over.
511
  virtual void hash(uint32_t *nr, uint32_t *nr2);
520.1.21 by Brian Aker
THD -> Session rename
512
  friend bool reopen_table(Session *,Table *,bool);
438.1.13 by Brian Aker
uint cleanup.
513
  friend int cre_myisam(char * name, register Table *form, uint32_t options,
1 by brian
clean slate
514
			uint64_t auto_increment_value);
515
  friend class Copy_field;
516
  friend class Item_avg_field;
517
  friend class Item_std_field;
518
  friend class Item_sum_num;
519
  friend class Item_sum_sum;
520
  friend class Item_sum_str;
521
  friend class Item_sum_count;
522
  friend class Item_sum_avg;
523
  friend class Item_sum_std;
524
  friend class Item_sum_min;
525
  friend class Item_sum_max;
526
  friend class Item_func_group_concat;
527
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
*/
644 by Brian Aker
Clean up warnings for Solaris.
552
  virtual int do_save_field_metadata(unsigned char *)
1 by brian
clean slate
553
  { return 0; }
554
};
555
556
/*
557
  Create field class for CREATE TABLE
558
*/
559
560
class Create_field :public Sql_alloc
561
{
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
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
571
    max number of characters.
1 by brian
clean slate
572
  */
290 by Brian Aker
Update for ulong change over.
573
  uint32_t length;
1 by brian
clean slate
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
  */
205 by Brian Aker
uint32 -> uin32_t
578
  uint32_t char_length;
438.1.13 by Brian Aker
uint cleanup.
579
  uint32_t  decimals, flags, pack_length, key_length;
1 by brian
clean slate
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;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
585
  const CHARSET_INFO *charset;
1 by brian
clean slate
586
  Field *field;				// For alter table
587
206 by Brian Aker
Removed final uint dead types.
588
  uint8_t row,col,sc_length,interval_id;	// For rea_create_table
438.1.13 by Brian Aker
uint cleanup.
589
  uint32_t	offset,pack_flag;
383.7.1 by Andrey Zhakov
Initial submit of code and tests
590
591
  /* Virtual column expression statement */
592
  virtual_column_info *vcol_info;
593
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
594
    Indication that the field is phycically stored in tables
383.7.1 by Andrey Zhakov
Initial submit of code and tests
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
1 by brian
clean slate
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
608
  {
609
    return (enum column_format_type)
610
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
611
  }
612
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,
205 by Brian Aker
uint32 -> uin32_t
615
                          uint32_t max_length, uint32_t decimals,
1 by brian
clean slate
616
                          bool maybe_null, bool is_unsigned);
617
520.1.22 by Brian Aker
Second pass of thd cleanup
618
  bool init(Session *session, char *field_name, enum_field_types type, char *length,
438.1.13 by Brian Aker
uint cleanup.
619
            char *decimals, uint32_t type_modifier, Item *default_value,
1 by brian
clean slate
620
            Item *on_update_value, LEX_STRING *comment, char *change,
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
621
            List<String> *interval_list, const CHARSET_INFO * const cs,
438.1.13 by Brian Aker
uint cleanup.
622
            uint32_t uint_geom_type,
383.7.1 by Andrey Zhakov
Initial submit of code and tests
623
            enum column_format_type column_format,
624
            virtual_column_info *vcol_info);
1 by brian
clean slate
625
};
626
627
628
/*
629
  A class for sending info to the client
630
*/
631
632
class Send_field {
633
 public:
634
  const char *db_name;
635
  const char *table_name,*org_table_name;
636
  const char *col_name,*org_col_name;
290 by Brian Aker
Update for ulong change over.
637
  uint32_t length;
438.1.13 by Brian Aker
uint cleanup.
638
  uint32_t charsetnr, flags, decimals;
1 by brian
clean slate
639
  enum_field_types type;
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:
481 by Brian Aker
Remove all of uchar.
656
  unsigned char *from_ptr,*to_ptr;
657
  unsigned char *from_null_ptr,*to_null_ptr;
274 by Brian Aker
my_bool conversion in Table
658
  bool *null_row;
438.1.13 by Brian Aker
uint cleanup.
659
  uint32_t	from_bit,to_bit;
660
  uint32_t from_length,to_length;
1 by brian
clean slate
661
  Field *from_field,*to_field;
662
  String tmp;					// For items
663
664
  Copy_field() {}
665
  ~Copy_field() {}
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
666
  void set(Field *to,Field *from,bool save);	// Field to field
481 by Brian Aker
Remove all of uchar.
667
  void set(unsigned char *to,Field *from);		// Field to string
1 by brian
clean slate
668
  void (*do_copy)(Copy_field *);
669
  void (*do_copy2)(Copy_field *);		// Used to handle null values
670
};
671
672
481 by Brian Aker
Remove all of uchar.
673
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
575.4.7 by Monty Taylor
More header cleanup.
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
438.1.13 by Brian Aker
uint cleanup.
680
uint32_t pack_length_to_packflag(uint32_t type);
290 by Brian Aker
Update for ulong change over.
681
enum_field_types get_blob_type_from_length(uint32_t length);
205 by Brian Aker
uint32 -> uin32_t
682
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
1 by brian
clean slate
683
int set_field_to_null(Field *field);
684
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
685
173.1.3 by Toru Maesaka
ripped out datetime and moved to field/
686
483.1.4 by Lee
break out Field_longstr
687
bool
584.5.1 by Monty Taylor
Removed field includes from field.h.
688
test_if_important_data(const CHARSET_INFO * const cs,
689
                       const char *str,
483.1.4 by Lee
break out Field_longstr
690
                       const char *strend);
691
520.8.2 by Monty Taylor
Moved sql_parse.h and sql_error.h out of common_includes.
692
693
#endif /* DRIZZLED_FIELD_H */