~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
28
#include "drizzled/sql_error.h"
2032 by Brian Aker
MErge in the include changes.
29
#include "drizzled/type/decimal.h"
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
30
#include "drizzled/key_map.h"
31
#include "drizzled/sql_list.h"
32
#include "drizzled/structs.h"
1241.9.61 by Monty Taylor
No more mystrings in drizzled/
33
#include "drizzled/charset_info.h"
1315.2.14 by Stewart Smith
move Item_result out to its own header file and out of common.h
34
#include "drizzled/item_result.h"
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
35
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
36
#include <string>
1052.2.5 by Nathan Williams
Changed container from list to vector for CreateField::interval_list. There is never inserts into the middle of the container, only push_back. Per jaypipes suggestion.
37
#include <vector>
1 by brian
clean slate
38
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
39
namespace drizzled
40
{
41
1 by brian
clean slate
42
#define DATETIME_DEC                     6
173.1.9 by Toru Maesaka
ripped out DOUBLE and moved to field/
43
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
1091 by Brian Aker
Collection of patches from new-cleanup (includes asserts for field in debug)
44
45
#ifdef DEBUG
1662.1.3 by Brian Aker
Fix for debug compile.
46
#define ASSERT_COLUMN_MARKED_FOR_READ assert(!getTable() || (getTable()->read_set == NULL || isReadSet()))
47
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(!getTable() || (getTable()->write_set == NULL || isWriteSet()))
1091 by Brian Aker
Collection of patches from new-cleanup (includes asserts for field in debug)
48
#else
1843.6.2 by Brian Aker
Add back in init(). Grr.... this should not be required.
49
#define ASSERT_COLUMN_MARKED_FOR_READ assert(getTable())
50
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(getTable())
1091 by Brian Aker
Collection of patches from new-cleanup (includes asserts for field in debug)
51
#endif
173.1.9 by Toru Maesaka
ripped out DOUBLE and moved to field/
52
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
53
typedef struct st_typelib TYPELIB;
54
205 by Brian Aker
uint32 -> uin32_t
55
const uint32_t max_field_size= (uint32_t) 4294967295U;
1 by brian
clean slate
56
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
57
class SendField;
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
58
class CreateField;
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
59
class TableShare;
798.2.29 by Brian Aker
Detangle more of the session object
60
class Field;
1539.1.6 by Brian Aker
Update for Join structure changes.
61
struct CacheField;
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
62
1 by brian
clean slate
63
int field_conv(Field *to,Field *from);
64
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
65
/**
66
 * Class representing a Field in a Table
67
 *
68
 * @details
69
 *
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
70
 * The value stored in the Field object is stored in the
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
71
 * unsigned char pointer member variable called ptr.  The
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
72
 * val_xxx() methods retrieve this raw byte value and
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
73
 * convert the byte into the appropriate output (int, decimal, etc).
74
 *
75
 * The store_xxx() methods take various input and convert
76
 * the input into the raw bytes stored in the ptr member variable.
77
 */
1 by brian
clean slate
78
class Field
79
{
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
80
  /* Prevent use of these */
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
81
  Field(const Field&);
1 by brian
clean slate
82
  void operator=(Field &);
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
83
1 by brian
clean slate
84
public:
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
85
  unsigned char *ptr; /**< Position to field in record. Stores raw field value */
86
  unsigned char *null_ptr; /**< Byte where null_bit is */
87
88
  /**
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
89
   * Pointer to the Table object containing this Field
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
90
   *
91
   * @note You can use table->in_use as replacement for current_session member
92
   * only inside of val_*() and store() members (e.g. you can't use it in cons)
93
   */
1660.1.3 by Brian Aker
Encapsulate Table in field
94
private:
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
95
  Table *table;
2068.6.11 by Brian Aker
Just initialize a class properly.
96
1660.1.3 by Brian Aker
Encapsulate Table in field
97
public:
1643.3.10 by Brian Aker
Column support, clean up of IS/DD for NULL type.
98
  Table *getTable()
99
  {
100
    assert(table);
101
    return table;
102
  }
103
1660.1.3 by Brian Aker
Encapsulate Table in field
104
  Table *getTable() const
105
  {
106
    assert(table);
107
    return table;
108
  }
109
110
  void setTable(Table *table_arg)
111
  {
112
    table= table_arg;
113
  }
114
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
115
  Table *orig_table; /**< Pointer to the original Table. @TODO What is "the original table"? */
116
  const char *field_name; /**< Name of the field */
117
  LEX_STRING comment; /**< A comment about the field */
118
119
  /** The field is part of the following keys */
120
  key_map	key_start;
121
  key_map part_of_key;
122
  key_map part_of_key_not_clustered;
123
  key_map part_of_sortkey;
124
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
125
  /*
1259.5.4 by Stewart Smith
better reflect reality in why we have TIMESTAMP types around.
126
    We use three additional unireg types for TIMESTAMP for hysterical
127
    raisins and limitations in the MySQL FRM file format.
128
129
    A good TODO is to clean this up as we can support just about
130
    anything in the table proto message now.
1 by brian
clean slate
131
  */
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
132
  enum utype
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
133
  {
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
134
    NONE,
135
    NEXT_NUMBER,
136
    TIMESTAMP_OLD_FIELD,
137
    TIMESTAMP_DN_FIELD,
138
    TIMESTAMP_UN_FIELD,
139
    TIMESTAMP_DNUN_FIELD
140
  };
1 by brian
clean slate
141
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
142
  utype	unireg_check;
143
  uint32_t field_length; /**< Length of this field in bytes */
144
  uint32_t flags;
2017.1.2 by Brian Aker
Fix for 693309.
145
146
  bool isUnsigned() const
147
  {
148
    return flags & UNSIGNED_FLAG;
149
  }
150
1999.4.2 by Brian Aker
Encapsulate the field's position.
151
private:
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
152
  uint16_t field_index; /**< Index of this Field in Table::fields array */
1999.4.1 by Brian Aker
First pass through, removing the need for us track the position in this
153
1999.4.2 by Brian Aker
Encapsulate the field's position.
154
public:
155
1999.4.1 by Brian Aker
First pass through, removing the need for us track the position in this
156
  uint16_t position() const
157
  {
158
    return field_index;
159
  }
160
161
  void setPosition(uint32_t arg)
162
  {
163
    field_index= arg;
164
  }
165
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
166
  unsigned char null_bit; /**< Bit used to test null bit */
1 by brian
clean slate
167
  /**
168
     If true, this field was created in create_tmp_field_from_item from a NULL
169
     value. This means that the type of the field is just a guess, and the type
170
     may be freely coerced to another type.
171
172
     @see create_tmp_field_from_item
173
     @see Item_type_holder::get_real_type
174
   */
175
  bool is_created_from_null_item;
176
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
177
  static void *operator new(size_t size);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
178
  static void *operator new(size_t size, memory::Root *mem_root);
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
179
  static void operator delete(void *, size_t)
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
180
  { }
1816.2.4 by Monty Taylor
Cleaned up a bunch more warnings.
181
  static void operator delete(void *, memory::Root *)
182
  { }
1055.2.4 by Jay Pipes
Style, indentation, and doxygen/documentation cleanup on Field class. Removal of dead methods in Field such as do_last_null_byte(), last_null_byte() and anonymous enum with LAST_NULL_BYTE_UNDEF...
183
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
184
  Field(unsigned char *ptr_arg,
185
        uint32_t length_arg,
186
        unsigned char *null_ptr_arg,
187
        unsigned char null_bit_arg,
188
        utype unireg_check_arg,
1 by brian
clean slate
189
        const char *field_name_arg);
190
  virtual ~Field() {}
1976.6.1 by Brian Aker
This is a fix for bug lp:686197
191
192
  bool hasDefault() const
193
  {
194
    return not (flags & NO_DEFAULT_VALUE_FLAG);
195
  }
196
1 by brian
clean slate
197
  /* Store functions returns 1 on overflow and -1 on fatal error */
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
198
  virtual int store(const char *to,
199
                    uint32_t length,
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
200
                    const CHARSET_INFO * const cs)=0;
201
  virtual int store(double nr)=0;
202
  virtual int store(int64_t nr, bool unsigned_val)=0;
2030.1.4 by Brian Aker
Change my_decimal to Decimal
203
  virtual int store_decimal(const type::Decimal *d)=0;
1996.2.1 by Brian Aker
uuid type code.
204
  int store_and_check(enum_check_fields check_level,
205
                      const char *to,
206
                      uint32_t length,
207
                      const CHARSET_INFO * const cs);
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
208
  /**
209
    This is called when storing a date in a string.
210
211
    @note
212
      Needs to be changed if/when we want to support different time formats.
213
  */
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
214
  virtual int store_time(type::Time *ltime, enum enum_drizzle_timestamp_type t_type);
1996.2.1 by Brian Aker
uuid type code.
215
  virtual double val_real()=0;
216
  virtual int64_t val_int()=0;
2030.1.4 by Brian Aker
Change my_decimal to Decimal
217
  virtual type::Decimal *val_decimal(type::Decimal *);
1996.2.1 by Brian Aker
uuid type code.
218
  String *val_str_internal(String *str)
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
219
  {
220
    return val_str(str, str);
221
  }
1 by brian
clean slate
222
  /*
223
     val_str(buf1, buf2) gets two buffers and should use them as follows:
224
     if it needs a temp buffer to convert result to string - use buf1
225
       example Field_tiny::val_str()
226
     if the value exists as a string already - use buf2
241 by Brian Aker
First pass of CHAR removal.
227
       example Field_varstring::val_str() (???)
1 by brian
clean slate
228
     consequently, buf2 may be created as 'String buf;' - no memory
229
     will be allocated for it. buf1 will be allocated to hold a
230
     value if it's too small. Using allocated buffer for buf2 may result in
231
     an unnecessary free (and later, may be an alloc).
232
     This trickery is used to decrease a number of malloc calls.
233
  */
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
234
  virtual String *val_str(String*, String *)=0;
1 by brian
clean slate
235
  /*
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
236
   str_needs_quotes() returns true if the value returned by val_str() needs
1 by brian
clean slate
237
   to be quoted when used in constructing an SQL query.
238
  */
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
239
  virtual bool str_needs_quotes() { return false; }
1 by brian
clean slate
240
  virtual Item_result result_type () const=0;
241
  virtual Item_result cmp_type () const { return result_type(); }
242
  virtual Item_result cast_to_int_type () const { return result_type(); }
2023.2.4 by Brian Aker
Merge in cast() for BOOLEAN.
243
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
244
  /**
245
     Check whether a field type can be partially indexed by a key.
246
247
     This is a static method, rather than a virtual function, because we need
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
248
     to check the type of a non-Field in alter_table().
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
249
250
     @param type  field type
251
252
     @retval
253
       true  Type can have a prefixed key
254
     @retval
255
       false Type can not have a prefixed key
256
  */
1 by brian
clean slate
257
  static bool type_can_have_key_part(enum_field_types);
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
258
  /**
259
    Return type of which can carry value of both given types in UNION result.
260
261
    @param a  type for merging
262
    @param b  type for merging
263
264
    @retval
265
      type of field
266
  */
1 by brian
clean slate
267
  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.
268
269
  /**
270
     Detect Item_result by given field type of UNION merge result.
271
272
     @param field_type  given field type
273
274
     @return
275
       Item_result (type of internal MySQL expression result)
276
  */
1 by brian
clean slate
277
  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.
278
279
  virtual bool eq(Field *field);
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
280
  /**
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
281
   * Returns true if the fields are equally defined
282
   *
283
   * @retval
284
   *  true  This Field is equally defined to supplied Field
285
   * @retval
286
   *  false This Field is NOT equally defined to supplied Field
287
   */
1 by brian
clean slate
288
  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.
289
2046.2.1 by Brian Aker
First pass on micro timestamp.
290
  virtual bool is_timestamp() const
291
  {
292
    return false;
293
  }
294
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
295
  /**
296
   * Returns size (in bytes) used to store field data in memory
297
   * (i.e. it returns the maximum size of the field in a row of the table,
298
   * which is located in RAM).
299
   */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
300
  virtual uint32_t pack_length() const;
1 by brian
clean slate
301
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
302
  /**
303
   * Returns size (in bytes) used to store field data on
304
   * storage (i.e. it returns the maximal size of the field in a row of the
305
   * table, which is located on disk).
306
   */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
307
  virtual uint32_t pack_length_in_rec() const;
1 by brian
clean slate
308
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
309
  /**
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
310
   * Return the "real size" of the data in memory.
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
311
   * For varstrings, this does _not_ include the length bytes.
312
   */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
313
  virtual uint32_t data_length();
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
314
  /**
315
   * Returns the number of bytes actually used to store the data
316
   * of the field. So for a varstring it includes both lenght byte(s) and
317
   * string data, and anything after data_length() bytes are unused.
318
   */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
319
  virtual uint32_t used_length();
320
  virtual uint32_t sort_length() const;
1 by brian
clean slate
321
322
  /**
323
     Get the maximum size of the data in packed format.
324
325
     @return Maximum data length of the field when packed using the
326
     Field::pack() function.
327
   */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
328
  virtual uint32_t max_data_length() const;
329
  virtual int reset(void);
330
  virtual void reset_fields();
331
  virtual void set_default();
332
  virtual bool binary() const;
333
  virtual bool zero_pack() const;
334
  virtual enum ha_base_keytype key_type() const;
335
  virtual uint32_t key_length() const;
1 by brian
clean slate
336
  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.
337
  virtual enum_field_types real_type() const;
1996.2.1 by Brian Aker
uuid type code.
338
  virtual int cmp_max(const unsigned char *a, const unsigned char *b, uint32_t max_len);
481 by Brian Aker
Remove all of uchar.
339
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
1996.2.1 by Brian Aker
uuid type code.
340
  int cmp_internal(const unsigned char *str) { return cmp(ptr,str); }
481 by Brian Aker
Remove all of uchar.
341
  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.
342
                         uint32_t max_length=UINT32_MAX);
343
  virtual int cmp_offset(uint32_t row_offset);
344
  virtual int cmp_binary_offset(uint32_t row_offset);
345
  virtual int key_cmp(const unsigned char *a,const unsigned char *b);
346
  virtual int key_cmp(const unsigned char *str, uint32_t length);
347
  virtual uint32_t decimals() const;
348
1 by brian
clean slate
349
  /*
350
    Caller beware: sql_type can change str.Ptr, so check
351
    ptr() to see if it changed if you are using your own buffer
352
    in str and restore it with set() if needed
353
  */
354
  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.
355
356
  // For new field
357
  virtual uint32_t size_of() const =0;
358
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
359
  bool is_null(ptrdiff_t row_offset= 0);
360
  bool is_real_null(ptrdiff_t row_offset= 0);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
361
  bool is_null_in_record(const unsigned char *record);
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
362
  bool is_null_in_record_with_offset(ptrdiff_t offset);
363
  void set_null(ptrdiff_t row_offset= 0);
364
  void set_notnull(ptrdiff_t row_offset= 0);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
365
  bool maybe_null(void);
366
  bool real_maybe_null(void);
1 by brian
clean slate
367
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
368
  virtual void make_field(SendField *);
481 by Brian Aker
Remove all of uchar.
369
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
438.1.13 by Brian Aker
uint cleanup.
370
  virtual bool optimize_range(uint32_t idx, uint32_t part);
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
371
  /**
372
   * Returns true for fields which, when compared with constant
373
   * items, can be casted to int64_t. In this case we will at 'fix_fields'
374
   * stage cast the constant items to int64_ts and at the execution stage
375
   * use field->val_int() for comparison.  Used to optimize clauses like
376
   * 'a_column BETWEEN date_const AND date_const'.
377
   */
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
378
  virtual bool can_be_compared_as_int64_t() const
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
379
  {
380
    return false;
381
  }
1 by brian
clean slate
382
  virtual void free() {}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
383
  virtual Field *new_field(memory::Root *root,
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
384
                           Table *new_table,
1 by brian
clean slate
385
                           bool keep_type);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
386
  virtual Field *new_key_field(memory::Root *root, Table *new_table,
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
387
                               unsigned char *new_ptr,
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
388
                               unsigned char *new_null_ptr,
438.1.13 by Brian Aker
uint cleanup.
389
                               uint32_t new_null_bit);
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
390
  /** This is used to generate a field in Table from TableShare */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
391
  Field *clone(memory::Root *mem_root, Table *new_table);
1996.2.1 by Brian Aker
uuid type code.
392
  void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
1 by brian
clean slate
393
  {
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
394
    ptr= ptr_arg;
395
    null_ptr= null_ptr_arg;
396
    null_bit= null_bit_arg;
1 by brian
clean slate
397
  }
1996.2.1 by Brian Aker
uuid type code.
398
  void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
399
  virtual void move_field_offset(ptrdiff_t ptr_diff)
1 by brian
clean slate
400
  {
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
401
    ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
1 by brian
clean slate
402
    if (null_ptr)
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
403
      null_ptr= ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
1 by brian
clean slate
404
  }
1055.2.5 by Jay Pipes
Removal of dead Field::image_type and st_key_part::image_type member variables. Legacy from geometry MyISAM types...
405
  virtual void get_image(unsigned char *buff, uint32_t length, const CHARSET_INFO * const)
406
  {
407
    memcpy(buff,ptr,length);
408
  }
409
  virtual void get_image(std::basic_string<unsigned char> &buff, uint32_t length, const CHARSET_INFO * const)
410
  {
411
    buff.append(ptr,length);
412
  }
413
  virtual void set_image(const unsigned char *buff,uint32_t length, const CHARSET_INFO * const)
414
  {
415
    memcpy(ptr,buff,length);
416
  }
1 by brian
clean slate
417
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
418
  /**
419
   * Copy a field part into an output buffer.
420
   *
421
   * @details
422
   *
423
   * This function makes a copy of field part of size equal to or
424
   * less than "length" parameter value.
425
   * For fields of string types (VARCHAR, TEXT) the rest of buffer
426
   * is padded by zero byte.
427
   *
428
   * @param output buffer
429
   * @param output buffer size
430
   *
431
   * @note
432
   *
433
   * For variable length character fields (i.e. UTF-8) the "length"
434
   * parameter means a number of output buffer bytes as if all field
435
   * characters have maximal possible size (mbmaxlen). In the other words,
436
   * "length" parameter is a number of characters multiplied by
437
   * field_charset->mbmaxlen.
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
438
   *
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
439
   * @retval
440
   *   Number of copied bytes (excluding padded zero bytes -- see above).
441
   */
1055.2.5 by Jay Pipes
Removal of dead Field::image_type and st_key_part::image_type member variables. Legacy from geometry MyISAM types...
442
  virtual uint32_t get_key_image(unsigned char *buff, uint32_t length)
1 by brian
clean slate
443
  {
444
    get_image(buff, length, &my_charset_bin);
445
    return length;
446
  }
1055.2.5 by Jay Pipes
Removal of dead Field::image_type and st_key_part::image_type member variables. Legacy from geometry MyISAM types...
447
  virtual uint32_t get_key_image(std::basic_string<unsigned char> &buff, uint32_t length)
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
448
  {
449
    get_image(buff, length, &my_charset_bin);
450
    return length;
451
  }
481 by Brian Aker
Remove all of uchar.
452
  virtual void set_key_image(const unsigned char *buff,uint32_t length)
1055.2.5 by Jay Pipes
Removal of dead Field::image_type and st_key_part::image_type member variables. Legacy from geometry MyISAM types...
453
  {
454
    set_image(buff,length, &my_charset_bin);
455
  }
1996.2.1 by Brian Aker
uuid type code.
456
  int64_t val_int_offset(uint32_t row_offset)
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
457
  {
458
    ptr+=row_offset;
459
    int64_t tmp=val_int();
460
    ptr-=row_offset;
461
    return tmp;
462
  }
463
1996.2.1 by Brian Aker
uuid type code.
464
  int64_t val_int_internal(const unsigned char *new_ptr)
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
465
  {
466
    unsigned char *old_ptr= ptr;
467
    int64_t return_value;
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
468
    ptr= const_cast<unsigned char*>(new_ptr);
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
469
    return_value= val_int();
470
    ptr= old_ptr;
471
    return return_value;
472
  }
1996.2.1 by Brian Aker
uuid type code.
473
474
  String *val_str_internal(String *str, const unsigned char *new_ptr)
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
475
  {
476
    unsigned char *old_ptr= ptr;
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
477
    ptr= const_cast<unsigned char*>(new_ptr);
1996.2.1 by Brian Aker
uuid type code.
478
    val_str_internal(str);
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
479
    ptr= old_ptr;
480
    return str;
481
  }
482
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
483
  /**
484
    Pack the field into a format suitable for storage and transfer.
485
486
    To implement packing functionality, only the virtual function
487
    should be overridden. The other functions are just convenience
488
    functions and hence should not be overridden.
489
490
    The value of <code>low_byte_first</code> is dependent on how the
491
    packed data is going to be used: for local use, e.g., temporary
492
    store on disk or in memory, use the native format since that is
493
    faster. For data that is going to be transfered to other machines
494
    (e.g., when writing data to the binary log), data should always be
495
    stored in little-endian format.
496
497
    @note The default method for packing fields just copy the raw bytes
498
    of the record into the destination, but never more than
499
    <code>max_length</code> characters.
500
501
    @param to
502
    Pointer to memory area where representation of field should be put.
503
504
    @param from
505
    Pointer to memory area where record representation of field is
506
    stored.
507
508
    @param max_length
509
    Maximum length of the field, as given in the column definition. For
510
    example, for <code>CHAR(1000)</code>, the <code>max_length</code>
511
    is 1000. This information is sometimes needed to decide how to pack
512
    the data.
513
514
    @param low_byte_first
515
    @c true if integers should be stored little-endian, @c false if
516
    native format should be used. Note that for little-endian machines,
517
    the value of this flag is a moot point since the native format is
518
    little-endian.
519
  */
779.3.16 by Monty Taylor
Some Sun warning fixes.
520
  virtual unsigned char *pack(unsigned char *to,
521
                              const unsigned char *from,
522
                              uint32_t max_length,
523
                              bool low_byte_first);
524
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
525
  unsigned char *pack(unsigned char *to, const unsigned char *from);
1 by brian
clean slate
526
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
527
  /**
528
    Unpack a field from row data.
529
530
    This method is used to unpack a field from a master whose size of
531
    the field is less than that of the slave.
532
533
    The <code>param_data</code> parameter is a two-byte integer (stored
534
    in the least significant 16 bits of the unsigned integer) usually
535
    consisting of two parts: the real type in the most significant byte
536
    and a original pack length in the least significant byte.
537
538
    The exact layout of the <code>param_data</code> field is given by
539
    the <code>Table_map_log_event::save_field_metadata()</code>.
540
541
    This is the default method for unpacking a field. It just copies
542
    the memory block in byte order (of original pack length bytes or
543
    length of field, whichever is smaller).
544
545
    @param   to         Destination of the data
546
    @param   from       Source of the data
547
    @param   param_data Real type and original pack length of the field
548
                        data
549
550
    @param low_byte_first
551
    If this flag is @c true, all composite entities (e.g., lengths)
552
    should be unpacked in little-endian format; otherwise, the entities
553
    are unpacked in native order.
554
555
    @return  New pointer into memory based on from + length of the data
556
  */
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
557
  virtual const unsigned char *unpack(unsigned char* to,
558
                                      const unsigned char *from,
559
                                      uint32_t param_data,
560
                                      bool low_byte_first);
1 by brian
clean slate
561
  /**
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
562
     @overload Field::unpack(unsigned char*, const unsigned char*,
563
                             uint32_t, bool)
1 by brian
clean slate
564
  */
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
565
  const unsigned char *unpack(unsigned char* to,
566
                              const unsigned char *from);
1 by brian
clean slate
567
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
568
  virtual unsigned char *pack_key(unsigned char* to,
569
                                  const unsigned char *from,
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
570
                                  uint32_t max_length,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
571
                                  bool low_byte_first)
1 by brian
clean slate
572
  {
573
    return pack(to, from, max_length, low_byte_first);
574
  }
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
575
  virtual const unsigned char *unpack_key(unsigned char* to,
576
                                          const unsigned char *from,
577
                                          uint32_t max_length,
578
                                          bool low_byte_first)
1 by brian
clean slate
579
  {
580
    return unpack(to, from, max_length, low_byte_first);
581
  }
438.1.13 by Brian Aker
uint cleanup.
582
  virtual uint32_t max_packed_col_length(uint32_t max_length)
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
583
  {
584
    return max_length;
585
  }
1 by brian
clean slate
586
1996.2.1 by Brian Aker
uuid type code.
587
  uint32_t offset(const unsigned char *record)
1 by brian
clean slate
588
  {
438.1.13 by Brian Aker
uint cleanup.
589
    return (uint32_t) (ptr - record);
1 by brian
clean slate
590
  }
591
  void copy_from_tmp(int offset);
1539.1.6 by Brian Aker
Update for Join structure changes.
592
  uint32_t fill_cache_field(CacheField *copy);
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
593
  virtual bool get_date(type::Time *ltime,uint32_t fuzzydate);
594
  virtual bool get_time(type::Time *ltime);
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
595
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
596
  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
597
  virtual bool has_charset(void) const { return false; }
644 by Brian Aker
Clean up warnings for Solaris.
598
  virtual void set_charset(const CHARSET_INFO * const)
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
599
  {}
1 by brian
clean slate
600
  virtual enum Derivation derivation(void) const
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
601
  {
602
    return DERIVATION_IMPLICIT;
603
  }
644 by Brian Aker
Clean up warnings for Solaris.
604
  virtual void set_derivation(enum Derivation)
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
605
  {}
606
  /**
607
    Produce warning or note about data saved into field.
608
609
    @param level            - level of message (Note/Warning/Error)
610
    @param code             - error code of message to be produced
611
    @param cuted_increment  - whenever we should increase cut fields count or not
612
613
    @note
614
      This function won't produce warning and increase cut fields counter
615
      if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
616
617
      if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
618
      This allows us to avoid notes in optimisation, like convert_constant_item().
619
620
    @retval
621
      1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
622
    @retval
623
      0 otherwise
624
  */
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
625
  bool set_warning(DRIZZLE_ERROR::enum_warning_level,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
626
                   unsigned int code,
1 by brian
clean slate
627
                   int cuted_increment);
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
628
  /**
629
    Produce warning or note about datetime string data saved into field.
630
631
    @param level            level of message (Note/Warning/Error)
632
    @param code             error code of message to be produced
633
    @param str              string value which we tried to save
634
    @param str_length       length of string which we tried to save
635
    @param ts_type          type of datetime value (datetime/date/time)
636
    @param cuted_increment  whenever we should increase cut fields count or not
637
638
    @note
639
      This function will always produce some warning but won't increase cut
640
      fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
641
      thread.
642
  */
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
643
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
644
                            uint32_t code,
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
645
                            const char *str,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
646
                            uint32_t str_len,
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
647
                            enum enum_drizzle_timestamp_type ts_type,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
648
                            int cuted_increment);
649
  /**
650
    Produce warning or note about integer datetime value saved into field.
651
652
    @param level            level of message (Note/Warning/Error)
653
    @param code             error code of message to be produced
654
    @param nr               numeric value which we tried to save
655
    @param ts_type          type of datetime value (datetime/date/time)
656
    @param cuted_increment  whenever we should increase cut fields count or not
657
658
    @note
659
      This function will always produce some warning but won't increase cut
660
      fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
661
      thread.
662
  */
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
663
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
664
                            uint32_t code,
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
665
                            int64_t nr,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
666
                            enum enum_drizzle_timestamp_type ts_type,
667
                            int cuted_increment);
668
  /**
669
    Produce warning or note about double datetime data saved into field.
670
671
    @param level            level of message (Note/Warning/Error)
672
    @param code             error code of message to be produced
673
    @param nr               double value which we tried to save
674
    @param ts_type          type of datetime value (datetime/date/time)
675
676
    @note
677
      This function will always produce some warning but won't increase cut
678
      fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
679
      thread.
680
  */
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
681
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
682
                            const uint32_t code,
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
683
                            double nr,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
684
                            enum enum_drizzle_timestamp_type ts_type);
1996.2.1 by Brian Aker
uuid type code.
685
  bool check_overflow(int op_result)
1 by brian
clean slate
686
  {
687
    return (op_result == E_DEC_OVERFLOW);
688
  }
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
689
  /**
690
    Process decimal library return codes and issue warnings for overflow and
691
    truncation.
692
693
    @param op_result  decimal library return code (E_DEC_* see include/decimal.h)
694
695
    @retval
696
      E_DEC_OVERFLOW   there was overflow
697
      E_DEC_TRUNCATED  there was truncation
698
    @retval
699
      0  no error or there was some other error except overflow or truncation
700
  */
1 by brian
clean slate
701
  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.
702
  void init(Table *table_arg);
1 by brian
clean slate
703
704
  /* maximum possible display length */
205 by Brian Aker
uint32 -> uin32_t
705
  virtual uint32_t max_display_length()= 0;
1 by brian
clean slate
706
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
707
  virtual uint32_t is_equal(CreateField *new_field);
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
708
  /**
709
    Conversion from decimal to int64_t with checking overflow and
710
    setting correct value (min/max) in case of overflow.
711
712
    @param val             value which have to be converted
713
    @param unsigned_flag   type of integer in which we convert val
714
    @param err             variable to pass error code
715
716
    @return
717
      value converted from val
718
  */
2030.1.4 by Brian Aker
Change my_decimal to Decimal
719
  int64_t convert_decimal2int64_t(const type::Decimal *val,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
720
                                  bool unsigned_flag,
721
                                  int *err);
1 by brian
clean slate
722
  /* The max. number of characters */
1996.2.1 by Brian Aker
uuid type code.
723
  uint32_t char_length() const
1 by brian
clean slate
724
  {
725
    return field_length / charset()->mbmaxlen;
726
  }
727
1996.2.1 by Brian Aker
uuid type code.
728
  enum column_format_type column_format() const
1 by brian
clean slate
729
  {
730
    return (enum column_format_type)
731
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
732
  }
733
734
  /* Hash value */
290 by Brian Aker
Update for ulong change over.
735
  virtual void hash(uint32_t *nr, uint32_t *nr2);
520.1.21 by Brian Aker
THD -> Session rename
736
  friend bool reopen_table(Session *,Table *,bool);
1052.2.7 by Nathan Williams
Merged trunk and resolved conflicts.
737
1052.2.2 by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards.
738
  friend class CopyField;
1 by brian
clean slate
739
  friend class Item_avg_field;
740
  friend class Item_std_field;
741
  friend class Item_sum_num;
742
  friend class Item_sum_sum;
743
  friend class Item_sum_str;
744
  friend class Item_sum_count;
745
  friend class Item_sum_avg;
746
  friend class Item_sum_std;
747
  friend class Item_sum_min;
748
  friend class Item_sum_max;
749
  friend class Item_func_group_concat;
750
1003.1.9 by Brian Aker
Patches for Jay (aka name changes)
751
  bool isReadSet();
752
  bool isWriteSet();
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
753
  void setReadSet(bool arg= true);
754
  void setWriteSet(bool arg= true);
1999.4.5 by Brian Aker
Get all of the endian stuff out of the classes.
755
756
protected:
757
2016.1.2 by Brian Aker
Fix for Solaris
758
  void pack_num(uint64_t arg, unsigned char *destination= NULL);
2046.2.3 by Brian Aker
Add basic tests for microtime.
759
  void pack_num(uint32_t arg, unsigned char *destination= NULL);
2016.1.2 by Brian Aker
Fix for Solaris
760
  uint64_t unpack_num(uint64_t &destination, const unsigned char *arg= NULL) const;
2046.2.3 by Brian Aker
Add basic tests for microtime.
761
  uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
1 by brian
clean slate
762
};
763
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
764
std::ostream& operator<<(std::ostream& output, const Field &field);
765
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
766
} /* namespace drizzled */
767
768
/** @TODO Why is this in the middle of the file???*/
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
769
#include "drizzled/create_field.h"
770
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
771
namespace drizzled
772
{
773
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
774
/**
775
 * A class for sending field information to a client.
776
 *
777
 * @details
778
 *
779
 * Send_field is basically a stripped-down POD class for
780
 * representing basic information about a field...
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
781
 */
1241.3.2 by Trond Norbye
Cleanup: use c++ style casting
782
class SendField
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
783
{
784
public:
1 by brian
clean slate
785
  const char *db_name;
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
786
  const char *table_name;
787
  const char *org_table_name;
788
  const char *col_name;
789
  const char *org_col_name;
290 by Brian Aker
Update for ulong change over.
790
  uint32_t length;
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
791
  uint32_t charsetnr;
792
  uint32_t flags;
793
  uint32_t decimals;
1 by brian
clean slate
794
  enum_field_types type;
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
795
  SendField() {}
1 by brian
clean slate
796
};
797
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
798
/**
799
 * A class for quick copying data to fields
800
 */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
801
class CopyField :public memory::SqlAlloc
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
802
{
1 by brian
clean slate
803
  /**
804
    Convenience definition of a copy function returned by
805
    get_copy_func.
806
  */
1052.2.2 by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards.
807
  typedef void Copy_func(CopyField*);
1 by brian
clean slate
808
  Copy_func *get_copy_func(Field *to, Field *from);
2068.6.11 by Brian Aker
Just initialize a class properly.
809
1 by brian
clean slate
810
public:
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
811
  unsigned char *from_ptr;
812
  unsigned char *to_ptr;
813
  unsigned char *from_null_ptr;
814
  unsigned char *to_null_ptr;
274 by Brian Aker
my_bool conversion in Table
815
  bool *null_row;
1055.2.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
816
  uint32_t from_bit;
817
  uint32_t to_bit;
818
  uint32_t from_length;
819
  uint32_t to_length;
820
  Field *from_field;
821
  Field *to_field;
1 by brian
clean slate
822
  String tmp;					// For items
823
2068.6.11 by Brian Aker
Just initialize a class properly.
824
  CopyField() :
825
    from_ptr(0),
826
    to_ptr(0),
827
    from_null_ptr(0),
828
    to_null_ptr(0),
829
    null_row(0),
830
    from_bit(0),
831
    to_bit(0),
832
    from_length(0),
833
    to_length(0),
834
    from_field(0),
835
    to_field(0)
836
  {}
837
838
  ~CopyField()
839
  {}
840
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
841
  void set(Field *to,Field *from,bool save);	// Field to field
481 by Brian Aker
Remove all of uchar.
842
  void set(unsigned char *to,Field *from);		// Field to string
1052.2.2 by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards.
843
  void (*do_copy)(CopyField *);
844
  void (*do_copy2)(CopyField *);		// Used to handle null values
1 by brian
clean slate
845
};
846
438.1.13 by Brian Aker
uint cleanup.
847
uint32_t pack_length_to_packflag(uint32_t type);
205 by Brian Aker
uint32 -> uin32_t
848
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
1 by brian
clean slate
849
int set_field_to_null(Field *field);
850
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
851
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
852
/**
853
 * Tests if the given string contains important data:
854
 * not spaces for character string, or any data for binary string.
855
 *
856
 * @param pointer to the character set to use
857
 * @param String to test
858
 * @param String end
859
 *
860
 * @retval
861
 *  false - If string does not have important data
862
 * @retval
863
 *  true  - If string has some important data
864
 */
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
865
bool test_if_important_data(const CHARSET_INFO * const cs,
866
                            const char *str,
867
                            const char *strend);
520.8.2 by Monty Taylor
Moved sql_parse.h and sql_error.h out of common_includes.
868
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
869
} /* namespace drizzled */
870
520.8.2 by Monty Taylor
Moved sql_parse.h and sql_error.h out of common_includes.
871
#endif /* DRIZZLED_FIELD_H */