~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/field.h

  • Committer: Patrick Galbraith
  • Date: 2008-07-24 16:57:40 UTC
  • mto: (202.2.4 rename-mysql-to-drizzle)
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: patg@ishvara-20080724165740-x58yw6zs6d9o17lf
Most everything working with client rename
mysqlslap test still fails... can't connect to the server

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
19
16
 
20
17
/*
21
18
  Because of the function new_field() all field classes that have static
22
19
  variables must declare the size_of() member function.
23
20
*/
24
21
 
 
22
#ifdef USE_PRAGMA_INTERFACE
 
23
#pragma interface                       /* gcc class implementation */
 
24
#endif
25
25
 
26
26
#define DATETIME_DEC                     6
27
27
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
34
34
struct st_cache_field;
35
35
int field_conv(Field *to,Field *from);
36
36
 
37
 
inline uint32_t get_enum_pack_length(int elements)
 
37
inline uint get_enum_pack_length(int elements)
38
38
{
39
39
  return elements < 256 ? 1 : 2;
40
40
}
41
41
 
42
 
inline uint32_t get_set_pack_length(int elements)
 
42
inline uint get_set_pack_length(int elements)
43
43
{
44
 
  uint32_t len= (elements + 7) / 8;
 
44
  uint len= (elements + 7) / 8;
45
45
  return len > 4 ? 8 : len;
46
46
}
47
47
 
48
 
class virtual_column_info: public Sql_alloc
49
 
{
50
 
public:
51
 
  Item *expr_item;
52
 
  LEX_STRING expr_str;
53
 
  Item *item_free_list;
54
 
  virtual_column_info() 
55
 
  : expr_item(0), item_free_list(0),
56
 
    field_type(DRIZZLE_TYPE_VIRTUAL),
57
 
    is_stored(false), data_inited(false)
58
 
  {
59
 
    expr_str.str= NULL;
60
 
    expr_str.length= 0;
61
 
  };
62
 
  ~virtual_column_info() {}
63
 
  enum_field_types get_real_type()
64
 
  {
65
 
    assert(data_inited);
66
 
    return data_inited ? field_type : DRIZZLE_TYPE_VIRTUAL;
67
 
  }
68
 
  void set_field_type(enum_field_types fld_type)
69
 
  {
70
 
    /* Calling this function can only be done once. */
71
 
    assert(not data_inited);
72
 
    data_inited= true;
73
 
    field_type= fld_type;
74
 
  }
75
 
  bool get_field_stored()
76
 
  {
77
 
    assert(data_inited);
78
 
    return data_inited ? is_stored : true;
79
 
  }
80
 
  void set_field_stored(bool stored)
81
 
  {
82
 
    is_stored= stored;
83
 
  }
84
 
private:
85
 
  /*
86
 
    The following data is only updated by the parser and read
87
 
    when a Create_field object is created/initialized.
88
 
  */
89
 
  enum_field_types field_type;   /* Real field type*/
90
 
  bool is_stored;             /* Indication that the field is 
91
 
                                    phisically stored in the database*/
92
 
  /*
93
 
    This flag is used to prevent other applications from
94
 
    reading and using incorrect data.
95
 
  */
96
 
  bool data_inited; 
97
 
};
98
 
 
99
48
class Field
100
49
{
101
50
  Field(const Item &);                          /* Prevent use of these */
102
51
  void operator=(Field &);
103
52
public:
104
53
  static void *operator new(size_t size) {return sql_alloc(size); }
105
 
  static void operator delete(void *ptr_arg __attribute__((unused)),
106
 
                              size_t size __attribute__((unused)))
 
54
  static void operator delete(void *ptr_arg __attribute__((__unused__)),
 
55
                              size_t size __attribute__((__unused__)))
107
56
  { TRASH(ptr_arg, size); }
108
57
 
109
 
  unsigned char         *ptr;                   // Position to field in record
110
 
  unsigned char         *null_ptr;              // Byte where null_bit is
 
58
  uchar         *ptr;                   // Position to field in record
 
59
  uchar         *null_ptr;              // Byte where null_bit is
111
60
  /*
112
61
    Note that you can use table->in_use as replacement for current_thd member 
113
62
    only inside of val_*() and store() members (e.g. you can't use it in cons)
114
63
  */
115
 
  Table *table;         // Pointer for table
116
 
  Table *orig_table;            // Pointer to original table
 
64
  struct st_table *table;               // Pointer for table
 
65
  struct st_table *orig_table;          // Pointer to original table
117
66
  const char    **table_name, *field_name;
118
67
  LEX_STRING    comment;
119
68
  /* Field is part of the following keys */
137
86
  uint32_t      field_length;           // Length of field
138
87
  uint32_t      flags;
139
88
  uint16_t        field_index;            // field number in fields array
140
 
  unsigned char         null_bit;               // Bit used to test null bit
 
89
  uchar         null_bit;               // Bit used to test null bit
141
90
  /**
142
91
     If true, this field was created in create_tmp_field_from_item from a NULL
143
92
     value. This means that the type of the field is just a guess, and the type
149
98
   */
150
99
  bool is_created_from_null_item;
151
100
 
152
 
  /* Virtual column data */
153
 
  virtual_column_info *vcol_info;
154
 
  /*
155
 
    Indication that the field is phycically stored in tables 
156
 
    rather than just generated on SQL queries.
157
 
    As of now, false can only be set for generated-only virtual columns.
158
 
  */
159
 
  bool is_stored;
160
 
 
161
 
  Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
162
 
        unsigned char null_bit_arg, utype unireg_check_arg,
 
101
  Field(uchar *ptr_arg,uint32_t length_arg,uchar *null_ptr_arg,
 
102
        uchar null_bit_arg, utype unireg_check_arg,
163
103
        const char *field_name_arg);
164
104
  virtual ~Field() {}
165
105
  /* Store functions returns 1 on overflow and -1 on fatal error */
166
 
  virtual int  store(const char *to, uint32_t length, const CHARSET_INFO * const cs)=0;
 
106
  virtual int  store(const char *to, uint length,CHARSET_INFO *cs)=0;
167
107
  virtual int  store(double nr)=0;
168
108
  virtual int  store(int64_t nr, bool unsigned_val)=0;
169
109
  virtual int  store_decimal(const my_decimal *d)=0;
170
 
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
171
 
  int store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
 
110
  virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
 
111
  int store(const char *to, uint length, CHARSET_INFO *cs,
172
112
            enum_check_fields check_level);
173
113
  virtual double val_real(void)=0;
174
114
  virtual int64_t val_int(void)=0;
179
119
     if it needs a temp buffer to convert result to string - use buf1
180
120
       example Field_tiny::val_str()
181
121
     if the value exists as a string already - use buf2
182
 
       example Field_varstring::val_str() (???)
 
122
       example Field_string::val_str()
183
123
     consequently, buf2 may be created as 'String buf;' - no memory
184
124
     will be allocated for it. buf1 will be allocated to hold a
185
125
     value if it's too small. Using allocated buffer for buf2 may result in
187
127
     This trickery is used to decrease a number of malloc calls.
188
128
  */
189
129
  virtual String *val_str(String*,String *)=0;
190
 
  String *val_int_as_str(String *val_buffer, bool unsigned_flag);
 
130
  String *val_int_as_str(String *val_buffer, my_bool unsigned_flag);
191
131
  /*
192
132
   str_needs_quotes() returns true if the value returned by val_str() needs
193
133
   to be quoted when used in constructing an SQL query.
219
159
    table, which is located on disk).
220
160
  */
221
161
  virtual uint32_t pack_length_in_rec() const { return pack_length(); }
222
 
  virtual int compatible_field_size(uint32_t field_metadata);
223
 
  virtual uint32_t pack_length_from_metadata(uint32_t field_metadata)
 
162
  virtual int compatible_field_size(uint field_metadata);
 
163
  virtual uint pack_length_from_metadata(uint field_metadata)
224
164
  { return field_metadata; }
225
165
  /*
226
166
    This method is used to return the size of the data in a row-based
231
171
    metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
232
172
 
233
173
    Note: While most classes that override this method return pack_length(),
234
 
    the classes Field_varstring, and Field_blob return 
 
174
    the classes Field_string, Field_varstring, and Field_blob return 
235
175
    field_length + 1, field_length, and pack_length_no_ptr() respectfully.
236
176
  */
237
 
  virtual uint32_t row_pack_length() { return 0; }
238
 
  virtual int save_field_metadata(unsigned char *first_byte)
 
177
  virtual uint row_pack_length() { return 0; }
 
178
  virtual int save_field_metadata(uchar *first_byte)
239
179
  { return do_save_field_metadata(first_byte); }
240
180
 
241
181
  /*
261
201
    return pack_length();
262
202
  };
263
203
 
264
 
  virtual int reset(void) { memset(ptr, 0, pack_length()); return 0; }
 
204
  virtual int reset(void) { bzero(ptr,pack_length()); return 0; }
265
205
  virtual void reset_fields() {}
266
206
  virtual void set_default()
267
207
  {
268
 
    my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
 
208
    my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->s->default_values - table->record[0]);
269
209
    memcpy(ptr, ptr + l_offset, pack_length());
270
210
    if (null_ptr)
271
 
      *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
 
211
      *null_ptr= ((*null_ptr & (uchar) ~null_bit) | (null_ptr[l_offset] & null_bit));
272
212
  }
273
213
  virtual bool binary() const { return 1; }
274
214
  virtual bool zero_pack() const { return 1; }
276
216
  virtual uint32_t key_length() const { return pack_length(); }
277
217
  virtual enum_field_types type() const =0;
278
218
  virtual enum_field_types real_type() const { return type(); }
279
 
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
280
 
  virtual int cmp_max(const unsigned char *a, const unsigned char *b,
281
 
                      uint32_t max_len __attribute__((unused)))
 
219
  inline  int cmp(const uchar *str) { return cmp(ptr,str); }
 
220
  virtual int cmp_max(const uchar *a, const uchar *b,
 
221
                      uint max_len __attribute__((__unused__)))
282
222
    { return cmp(a, b); }
283
 
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
284
 
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
285
 
                         uint32_t  __attribute__((unused)) max_length=UINT32_MAX)
 
223
  virtual int cmp(const uchar *,const uchar *)=0;
 
224
  virtual int cmp_binary(const uchar *a,const uchar *b,
 
225
                         uint32_t  __attribute__((__unused__)) max_length=~0)
286
226
  { return memcmp(a,b,pack_length()); }
287
 
  virtual int cmp_offset(uint32_t row_offset)
 
227
  virtual int cmp_offset(uint row_offset)
288
228
  { return cmp(ptr,ptr+row_offset); }
289
 
  virtual int cmp_binary_offset(uint32_t row_offset)
 
229
  virtual int cmp_binary_offset(uint row_offset)
290
230
  { return cmp_binary(ptr, ptr+row_offset); };
291
 
  virtual int key_cmp(const unsigned char *a,const unsigned char *b)
 
231
  virtual int key_cmp(const uchar *a,const uchar *b)
292
232
  { return cmp(a, b); }
293
 
  virtual int key_cmp(const unsigned char *str, uint32_t length __attribute__((unused)))
 
233
  virtual int key_cmp(const uchar *str, uint length __attribute__((__unused__)))
294
234
  { return cmp(ptr,str); }
295
 
  virtual uint32_t decimals() const { return 0; }
 
235
  virtual uint decimals() const { return 0; }
296
236
  /*
297
237
    Caller beware: sql_type can change str.Ptr, so check
298
238
    ptr() to see if it changed if you are using your own buffer
299
239
    in str and restore it with set() if needed
300
240
  */
301
241
  virtual void sql_type(String &str) const =0;
302
 
  virtual uint32_t size_of() const =0;          // For new field
 
242
  virtual uint size_of() const =0;              // For new field
303
243
  inline bool is_null(my_ptrdiff_t row_offset= 0)
304
244
  { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
305
245
  inline bool is_real_null(my_ptrdiff_t row_offset= 0)
306
246
    { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : 0; }
307
 
  inline bool is_null_in_record(const unsigned char *record)
 
247
  inline bool is_null_in_record(const uchar *record)
308
248
  {
309
249
    if (!null_ptr)
310
250
      return 0;
311
 
    return test(record[(uint32_t) (null_ptr -table->record[0])] &
 
251
    return test(record[(uint) (null_ptr -table->record[0])] &
312
252
                null_bit);
313
253
  }
314
254
  inline bool is_null_in_record_with_offset(my_ptrdiff_t offset)
320
260
  inline void set_null(my_ptrdiff_t row_offset= 0)
321
261
    { if (null_ptr) null_ptr[row_offset]|= null_bit; }
322
262
  inline void set_notnull(my_ptrdiff_t row_offset= 0)
323
 
    { if (null_ptr) null_ptr[row_offset]&= (unsigned char) ~null_bit; }
 
263
    { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
324
264
  inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
325
265
  inline bool real_maybe_null(void) { return null_ptr != 0; }
326
266
 
345
285
   */
346
286
  size_t last_null_byte() const {
347
287
    size_t bytes= do_last_null_byte();
348
 
    assert(bytes <= table->getNullBytes());
 
288
    assert(bytes <= table->s->null_bytes);
349
289
    return bytes;
350
290
  }
351
291
 
352
292
  virtual void make_field(Send_field *);
353
 
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
354
 
  virtual bool optimize_range(uint32_t idx, uint32_t part);
 
293
  virtual void sort_string(uchar *buff,uint length)=0;
 
294
  virtual bool optimize_range(uint idx, uint part);
355
295
  /*
356
296
    This should be true for fields which, when compared with constant
357
297
    items, can be casted to int64_t. In this case we will at 'fix_fields'
361
301
  */
362
302
  virtual bool can_be_compared_as_int64_t() const { return false; }
363
303
  virtual void free() {}
364
 
  virtual Field *new_field(MEM_ROOT *root, Table *new_table,
 
304
  virtual Field *new_field(MEM_ROOT *root, struct st_table *new_table,
365
305
                           bool keep_type);
366
 
  virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
367
 
                               unsigned char *new_ptr, unsigned char *new_null_ptr,
368
 
                               uint32_t new_null_bit);
369
 
  Field *clone(MEM_ROOT *mem_root, Table *new_table);
370
 
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
 
306
  virtual Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
 
307
                               uchar *new_ptr, uchar *new_null_ptr,
 
308
                               uint new_null_bit);
 
309
  Field *clone(MEM_ROOT *mem_root, struct st_table *new_table);
 
310
  inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
371
311
  {
372
312
    ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
373
313
  }
374
 
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
 
314
  inline void move_field(uchar *ptr_arg) { ptr=ptr_arg; }
375
315
  virtual void move_field_offset(my_ptrdiff_t ptr_diff)
376
316
  {
377
 
    ptr=ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
 
317
    ptr=ADD_TO_PTR(ptr,ptr_diff, uchar*);
378
318
    if (null_ptr)
379
 
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
 
319
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
380
320
  }
381
 
  virtual void get_image(unsigned char *buff, uint32_t length,
382
 
                         const CHARSET_INFO * const cs __attribute__((unused)))
 
321
  virtual void get_image(uchar *buff, uint length,
 
322
                         CHARSET_INFO *cs __attribute__((__unused__)))
383
323
    { memcpy(buff,ptr,length); }
384
 
  virtual void set_image(const unsigned char *buff,uint32_t length,
385
 
                         const CHARSET_INFO * const cs __attribute__((unused)))
 
324
  virtual void set_image(const uchar *buff,uint length,
 
325
                         CHARSET_INFO *cs __attribute__((__unused__)))
386
326
    { memcpy(ptr,buff,length); }
387
327
 
388
328
 
412
352
      Number of copied bytes (excluding padded zero bytes -- see above).
413
353
  */
414
354
 
415
 
  virtual uint32_t get_key_image(unsigned char *buff, uint32_t length,
416
 
                             imagetype type __attribute__((unused)))
 
355
  virtual uint get_key_image(uchar *buff, uint length,
 
356
                             imagetype type __attribute__((__unused__)))
417
357
  {
418
358
    get_image(buff, length, &my_charset_bin);
419
359
    return length;
420
360
  }
421
 
  virtual void set_key_image(const unsigned char *buff,uint32_t length)
 
361
  virtual void set_key_image(const uchar *buff,uint length)
422
362
    { set_image(buff,length, &my_charset_bin); }
423
 
  inline int64_t val_int_offset(uint32_t row_offset)
 
363
  inline int64_t val_int_offset(uint row_offset)
424
364
    {
425
365
      ptr+=row_offset;
426
366
      int64_t tmp=val_int();
427
367
      ptr-=row_offset;
428
368
      return tmp;
429
369
    }
430
 
  inline int64_t val_int(const unsigned char *new_ptr)
 
370
  inline int64_t val_int(const uchar *new_ptr)
431
371
  {
432
 
    unsigned char *old_ptr= ptr;
 
372
    uchar *old_ptr= ptr;
433
373
    int64_t return_value;
434
 
    ptr= (unsigned char*) new_ptr;
 
374
    ptr= (uchar*) new_ptr;
435
375
    return_value= val_int();
436
376
    ptr= old_ptr;
437
377
    return return_value;
438
378
  }
439
 
  inline String *val_str(String *str, const unsigned char *new_ptr)
 
379
  inline String *val_str(String *str, const uchar *new_ptr)
440
380
  {
441
 
    unsigned char *old_ptr= ptr;
442
 
    ptr= (unsigned char*) new_ptr;
 
381
    uchar *old_ptr= ptr;
 
382
    ptr= (uchar*) new_ptr;
443
383
    val_str(str);
444
384
    ptr= old_ptr;
445
385
    return str;
446
386
  }
447
387
  virtual bool send_binary(Protocol *protocol);
448
388
 
449
 
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
450
 
                      uint32_t max_length, bool low_byte_first);
451
 
  /**
452
 
     @overload Field::pack(unsigned char*, const unsigned char*, uint32_t, bool)
453
 
  */
454
 
  unsigned char *pack(unsigned char *to, const unsigned char *from)
455
 
  {
456
 
    unsigned char *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
457
 
    return(result);
458
 
  }
459
 
 
460
 
  virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
461
 
                              uint32_t param_data, bool low_byte_first);
462
 
  /**
463
 
     @overload Field::unpack(unsigned char*, const unsigned char*, uint32_t, bool)
464
 
  */
465
 
  const unsigned char *unpack(unsigned char* to, const unsigned char *from)
466
 
  {
467
 
    const unsigned char *result= unpack(to, from, 0U, table->s->db_low_byte_first);
468
 
    return(result);
469
 
  }
470
 
 
471
 
  virtual unsigned char *pack_key(unsigned char* to, const unsigned char *from,
472
 
                          uint32_t max_length, bool low_byte_first)
473
 
  {
474
 
    return pack(to, from, max_length, low_byte_first);
475
 
  }
476
 
  virtual unsigned char *pack_key_from_key_image(unsigned char* to, const unsigned char *from,
477
 
                                        uint32_t max_length, bool low_byte_first)
478
 
  {
479
 
    return pack(to, from, max_length, low_byte_first);
480
 
  }
481
 
  virtual const unsigned char *unpack_key(unsigned char* to, const unsigned char *from,
482
 
                                  uint32_t max_length, bool low_byte_first)
 
389
  virtual uchar *pack(uchar *to, const uchar *from,
 
390
                      uint max_length, bool low_byte_first);
 
391
  /**
 
392
     @overload Field::pack(uchar*, const uchar*, uint, bool)
 
393
  */
 
394
  uchar *pack(uchar *to, const uchar *from)
 
395
  {
 
396
    uchar *result= this->pack(to, from, UINT_MAX, table->s->db_low_byte_first);
 
397
    return(result);
 
398
  }
 
399
 
 
400
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
401
                              uint param_data, bool low_byte_first);
 
402
  /**
 
403
     @overload Field::unpack(uchar*, const uchar*, uint, bool)
 
404
  */
 
405
  const uchar *unpack(uchar* to, const uchar *from)
 
406
  {
 
407
    const uchar *result= unpack(to, from, 0U, table->s->db_low_byte_first);
 
408
    return(result);
 
409
  }
 
410
 
 
411
  virtual uchar *pack_key(uchar* to, const uchar *from,
 
412
                          uint max_length, bool low_byte_first)
 
413
  {
 
414
    return pack(to, from, max_length, low_byte_first);
 
415
  }
 
416
  virtual uchar *pack_key_from_key_image(uchar* to, const uchar *from,
 
417
                                        uint max_length, bool low_byte_first)
 
418
  {
 
419
    return pack(to, from, max_length, low_byte_first);
 
420
  }
 
421
  virtual const uchar *unpack_key(uchar* to, const uchar *from,
 
422
                                  uint max_length, bool low_byte_first)
483
423
  {
484
424
    return unpack(to, from, max_length, low_byte_first);
485
425
  }
486
 
  virtual uint32_t packed_col_length(const unsigned char *to __attribute__((unused)),
487
 
                                 uint32_t length)
 
426
  virtual uint packed_col_length(const uchar *to __attribute__((__unused__)),
 
427
                                 uint length)
488
428
  { return length;}
489
 
  virtual uint32_t max_packed_col_length(uint32_t max_length)
 
429
  virtual uint max_packed_col_length(uint max_length)
490
430
  { return max_length;}
491
431
 
492
 
  virtual int pack_cmp(const unsigned char *a,const unsigned char *b,
493
 
                       uint32_t key_length_arg __attribute__((unused)),
494
 
                       bool insert_or_update __attribute__((unused)))
 
432
  virtual int pack_cmp(const uchar *a,const uchar *b,
 
433
                       uint key_length_arg __attribute__((__unused__)),
 
434
                       my_bool insert_or_update __attribute__((__unused__)))
495
435
  { return cmp(a,b); }
496
 
  virtual int pack_cmp(const unsigned char *b,
497
 
                       uint32_t key_length_arg __attribute__((unused)),
498
 
                       bool insert_or_update __attribute__((unused)))
 
436
  virtual int pack_cmp(const uchar *b,
 
437
                       uint key_length_arg __attribute__((__unused__)),
 
438
                       my_bool insert_or_update __attribute__((__unused__)))
499
439
  { return cmp(ptr,b); }
500
 
  uint32_t offset(unsigned char *record)
 
440
  uint offset(uchar *record)
501
441
  {
502
 
    return (uint32_t) (ptr - record);
 
442
    return (uint) (ptr - record);
503
443
  }
504
444
  void copy_from_tmp(int offset);
505
 
  uint32_t fill_cache_field(struct st_cache_field *copy);
506
 
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
507
 
  virtual bool get_time(DRIZZLE_TIME *ltime);
508
 
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
509
 
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
 
445
  uint fill_cache_field(struct st_cache_field *copy);
 
446
  virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
 
447
  virtual bool get_time(MYSQL_TIME *ltime);
 
448
  virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
 
449
  virtual CHARSET_INFO *sort_charset(void) const { return charset(); }
510
450
  virtual bool has_charset(void) const { return false; }
511
 
  virtual void set_charset(const CHARSET_INFO * const charset_arg __attribute__((unused)))
 
451
  virtual void set_charset(CHARSET_INFO *charset_arg __attribute__((__unused__)))
512
452
  { }
513
453
  virtual enum Derivation derivation(void) const
514
454
  { return DERIVATION_IMPLICIT; }
515
 
  virtual void set_derivation(enum Derivation derivation_arg __attribute__((unused)))
 
455
  virtual void set_derivation(enum Derivation derivation_arg __attribute__((__unused__)))
516
456
  { }
517
 
  bool set_warning(DRIZZLE_ERROR::enum_warning_level, unsigned int code,
 
457
  bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
518
458
                   int cuted_increment);
519
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code, 
520
 
                            const char *str, uint32_t str_len,
521
 
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment);
522
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code, 
523
 
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
 
459
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, 
 
460
                            const char *str, uint str_len,
 
461
                            timestamp_type ts_type, int cuted_increment);
 
462
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, uint code, 
 
463
                            int64_t nr, timestamp_type ts_type,
524
464
                            int cuted_increment);
525
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint32_t code, 
526
 
                            double nr, enum enum_drizzle_timestamp_type ts_type);
 
465
  void set_datetime_warning(MYSQL_ERROR::enum_warning_level, const uint code, 
 
466
                            double nr, timestamp_type ts_type);
527
467
  inline bool check_overflow(int op_result)
528
468
  {
529
469
    return (op_result == E_DEC_OVERFLOW);
530
470
  }
531
471
  int warn_if_overflow(int op_result);
532
 
  void init(Table *table_arg)
 
472
  void init(TABLE *table_arg)
533
473
  {
534
474
    orig_table= table= table_arg;
535
475
    table_name= &table_arg->alias;
538
478
  /* maximum possible display length */
539
479
  virtual uint32_t max_display_length()= 0;
540
480
 
541
 
  virtual uint32_t is_equal(Create_field *new_field);
 
481
  virtual uint is_equal(Create_field *new_field);
542
482
  /* convert decimal to int64_t with overflow check */
543
483
  int64_t convert_decimal2int64_t(const my_decimal *val, bool unsigned_flag,
544
484
                                    int *err);
555
495
  }
556
496
 
557
497
  /* Hash value */
558
 
  virtual void hash(uint32_t *nr, uint32_t *nr2);
559
 
  friend bool reopen_table(THD *,Table *,bool);
560
 
  friend int cre_myisam(char * name, register Table *form, uint32_t options,
 
498
  virtual void hash(ulong *nr, ulong *nr2);
 
499
  friend bool reopen_table(THD *,struct st_table *,bool);
 
500
  friend int cre_myisam(char * name, register TABLE *form, uint options,
561
501
                        uint64_t auto_increment_value);
562
502
  friend class Copy_field;
563
503
  friend class Item_avg_field;
596
536
 
597
537
   @returns 0 no bytes written.
598
538
*/
599
 
  virtual int do_save_field_metadata(unsigned char *metadata_ptr __attribute__((unused)))
600
 
  { return 0; }
 
539
  virtual int do_save_field_metadata(uchar *metadata_ptr __attribute__((__unused__)))
 
540
  { return 0; }
 
541
};
 
542
 
 
543
 
 
544
class Field_num :public Field {
 
545
public:
 
546
  const uint8_t dec;
 
547
  bool zerofill,unsigned_flag;  // Purify cannot handle bit fields
 
548
  Field_num(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
 
549
            uchar null_bit_arg, utype unireg_check_arg,
 
550
            const char *field_name_arg,
 
551
            uint8_t dec_arg, bool zero_arg, bool unsigned_arg);
 
552
  Item_result result_type () const { return REAL_RESULT; }
 
553
  void prepend_zeros(String *value);
 
554
  void add_zerofill_and_unsigned(String &res) const;
 
555
  friend class Create_field;
 
556
  void make_field(Send_field *);
 
557
  uint decimals() const { return (uint) dec; }
 
558
  uint size_of() const { return sizeof(*this); }
 
559
  bool eq_def(Field *field);
 
560
  int store_decimal(const my_decimal *);
 
561
  my_decimal *val_decimal(my_decimal *);
 
562
  uint is_equal(Create_field *new_field);
 
563
  int check_int(CHARSET_INFO *cs, const char *str, int length,
 
564
                const char *int_end, int error);
 
565
  bool get_int(CHARSET_INFO *cs, const char *from, uint len, 
 
566
               int64_t *rnd, uint64_t unsigned_max, 
 
567
               int64_t signed_min, int64_t signed_max);
 
568
};
 
569
 
 
570
/* base class for all string related classes */
 
571
 
 
572
class Field_str :public Field {
 
573
protected:
 
574
  CHARSET_INFO *field_charset;
 
575
  enum Derivation field_derivation;
 
576
public:
 
577
  Field_str(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
 
578
            uchar null_bit_arg, utype unireg_check_arg,
 
579
            const char *field_name_arg, CHARSET_INFO *charset);
 
580
  Item_result result_type () const { return STRING_RESULT; }
 
581
  uint decimals() const { return NOT_FIXED_DEC; }
 
582
  int  store(double nr);
 
583
  int  store(int64_t nr, bool unsigned_val)=0;
 
584
  int  store_decimal(const my_decimal *);
 
585
  int  store(const char *to,uint length,CHARSET_INFO *cs)=0;
 
586
  uint size_of() const { return sizeof(*this); }
 
587
  CHARSET_INFO *charset(void) const { return field_charset; }
 
588
  void set_charset(CHARSET_INFO *charset_arg) { field_charset= charset_arg; }
 
589
  enum Derivation derivation(void) const { return field_derivation; }
 
590
  virtual void set_derivation(enum Derivation derivation_arg)
 
591
  { field_derivation= derivation_arg; }
 
592
  bool binary() const { return field_charset == &my_charset_bin; }
 
593
  uint32_t max_display_length() { return field_length; }
 
594
  friend class Create_field;
 
595
  my_decimal *val_decimal(my_decimal *);
 
596
  virtual bool str_needs_quotes() { return true; }
 
597
  bool compare_str_field_flags(Create_field *new_field, uint32_t flags);
 
598
  uint is_equal(Create_field *new_field);
 
599
};
 
600
 
 
601
 
 
602
/* base class for Field_string, Field_varstring and Field_blob */
 
603
 
 
604
class Field_longstr :public Field_str
 
605
{
 
606
protected:
 
607
  int report_if_important_data(const char *ptr, const char *end);
 
608
public:
 
609
  Field_longstr(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
 
610
                uchar null_bit_arg, utype unireg_check_arg,
 
611
                const char *field_name_arg, CHARSET_INFO *charset_arg)
 
612
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
 
613
               field_name_arg, charset_arg)
 
614
    {}
 
615
 
 
616
  int store_decimal(const my_decimal *d);
 
617
  uint32_t max_data_length() const;
 
618
};
 
619
 
 
620
/* base class for float and double and decimal (old one) */
 
621
class Field_real :public Field_num {
 
622
public:
 
623
  my_bool not_fixed;
 
624
 
 
625
  Field_real(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
 
626
             uchar null_bit_arg, utype unireg_check_arg,
 
627
             const char *field_name_arg,
 
628
             uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
 
629
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
 
630
               field_name_arg, dec_arg, zero_arg, unsigned_arg),
 
631
    not_fixed(dec_arg >= NOT_FIXED_DEC)
 
632
    {}
 
633
  int store_decimal(const my_decimal *);
 
634
  my_decimal *val_decimal(my_decimal *);
 
635
  int truncate(double *nr, double max_length);
 
636
  uint32_t max_display_length() { return field_length; }
 
637
  uint size_of() const { return sizeof(*this); }
 
638
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
639
                              uint param_data, bool low_byte_first);
 
640
  virtual uchar *pack(uchar* to, const uchar *from,
 
641
                      uint max_length, bool low_byte_first);
 
642
};
 
643
 
 
644
 
 
645
class Field_tiny :public Field_num {
 
646
public:
 
647
  Field_tiny(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
 
648
             uchar null_bit_arg,
 
649
             enum utype unireg_check_arg, const char *field_name_arg,
 
650
             bool zero_arg, bool unsigned_arg)
 
651
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
652
               unireg_check_arg, field_name_arg,
 
653
               0, zero_arg,unsigned_arg)
 
654
    {}
 
655
  enum Item_result result_type () const { return INT_RESULT; }
 
656
  enum_field_types type() const { return MYSQL_TYPE_TINY;}
 
657
  enum ha_base_keytype key_type() const
 
658
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
 
659
  int store(const char *to,uint length,CHARSET_INFO *charset);
 
660
  int store(double nr);
 
661
  int store(int64_t nr, bool unsigned_val);
 
662
  int reset(void) { ptr[0]=0; return 0; }
 
663
  double val_real(void);
 
664
  int64_t val_int(void);
 
665
  String *val_str(String*,String *);
 
666
  bool send_binary(Protocol *protocol);
 
667
  int cmp(const uchar *,const uchar *);
 
668
  void sort_string(uchar *buff,uint length);
 
669
  uint32_t pack_length() const { return 1; }
 
670
  void sql_type(String &str) const;
 
671
  uint32_t max_display_length() { return 4; }
 
672
 
 
673
  virtual uchar *pack(uchar* to, const uchar *from,
 
674
                      uint max_length __attribute__((__unused__)),
 
675
                      bool low_byte_first __attribute__((__unused__)))
 
676
  {
 
677
    *to= *from;
 
678
    return to + 1;
 
679
  }
 
680
 
 
681
  virtual const uchar *unpack(uchar* to, const uchar *from,
 
682
                              uint param_data __attribute__((__unused__)),
 
683
                              bool low_byte_first __attribute__((__unused__)))
 
684
  {
 
685
    *to= *from;
 
686
    return from + 1;
 
687
  }
 
688
};
 
689
 
 
690
 
 
691
class Field_enum :public Field_str {
 
692
protected:
 
693
  uint packlength;
 
694
public:
 
695
  TYPELIB *typelib;
 
696
  Field_enum(uchar *ptr_arg, uint32_t len_arg, uchar *null_ptr_arg,
 
697
             uchar null_bit_arg,
 
698
             enum utype unireg_check_arg, const char *field_name_arg,
 
699
             uint packlength_arg,
 
700
             TYPELIB *typelib_arg,
 
701
             CHARSET_INFO *charset_arg)
 
702
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
703
               unireg_check_arg, field_name_arg, charset_arg),
 
704
    packlength(packlength_arg),typelib(typelib_arg)
 
705
  {
 
706
      flags|=ENUM_FLAG;
 
707
  }
 
708
  Field *new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type);
 
709
  enum_field_types type() const { return MYSQL_TYPE_STRING; }
 
710
  enum Item_result cmp_type () const { return INT_RESULT; }
 
711
  enum Item_result cast_to_int_type () const { return INT_RESULT; }
 
712
  enum ha_base_keytype key_type() const;
 
713
  int  store(const char *to,uint length,CHARSET_INFO *charset);
 
714
  int  store(double nr);
 
715
  int  store(int64_t nr, bool unsigned_val);
 
716
  double val_real(void);
 
717
  int64_t val_int(void);
 
718
  String *val_str(String*,String *);
 
719
  int cmp(const uchar *,const uchar *);
 
720
  void sort_string(uchar *buff,uint length);
 
721
  uint32_t pack_length() const { return (uint32_t) packlength; }
 
722
  void store_type(uint64_t value);
 
723
  void sql_type(String &str) const;
 
724
  uint size_of() const { return sizeof(*this); }
 
725
  enum_field_types real_type() const { return MYSQL_TYPE_ENUM; }
 
726
  uint pack_length_from_metadata(uint field_metadata)
 
727
  { return (field_metadata & 0x00ff); }
 
728
  uint row_pack_length() { return pack_length(); }
 
729
  virtual bool zero_pack() const { return 0; }
 
730
  bool optimize_range(uint idx __attribute__((__unused__)),
 
731
                      uint part __attribute__((__unused__)))
 
732
  { return 0; }
 
733
  bool eq_def(Field *field);
 
734
  bool has_charset(void) const { return true; }
 
735
  /* enum and set are sorted as integers */
 
736
  CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
 
737
private:
 
738
  int do_save_field_metadata(uchar *first_byte);
601
739
};
602
740
 
603
741
/*
617
755
    At various stages in execution this can be length of field in bytes or
618
756
    max number of characters. 
619
757
  */
620
 
  uint32_t length;
 
758
  ulong length;
621
759
  /*
622
760
    The value of `length' as set by parser: is the number of characters
623
761
    for most of the types, or of bytes for BLOBs or numeric types.
624
762
  */
625
763
  uint32_t char_length;
626
 
  uint32_t  decimals, flags, pack_length, key_length;
 
764
  uint  decimals, flags, pack_length, key_length;
627
765
  Field::utype unireg_check;
628
766
  TYPELIB *interval;                    // Which interval to use
629
767
  TYPELIB *save_interval;               // Temporary copy for the above
630
768
                                        // Used only for UCS2 intervals
631
769
  List<String> interval_list;
632
 
  const CHARSET_INFO *charset;
 
770
  CHARSET_INFO *charset;
633
771
  Field *field;                         // For alter table
634
772
 
635
773
  uint8_t row,col,sc_length,interval_id;        // For rea_create_table
636
 
  uint32_t      offset,pack_flag;
637
 
 
638
 
  /* Virtual column expression statement */
639
 
  virtual_column_info *vcol_info;
640
 
  /*
641
 
    Indication that the field is phycically stored in tables 
642
 
    rather than just generated on SQL queries.
643
 
    As of now, FALSE can only be set for generated-only virtual columns.
644
 
  */
645
 
  bool is_stored;
646
 
 
 
774
  uint  offset,pack_flag;
647
775
  Create_field() :after(0) {}
648
776
  Create_field(Field *field, Field *orig_field);
649
777
  /* Used to make a clone of this object for ALTER/CREATE TABLE */
663
791
                          bool maybe_null, bool is_unsigned);
664
792
 
665
793
  bool init(THD *thd, char *field_name, enum_field_types type, char *length,
666
 
            char *decimals, uint32_t type_modifier, Item *default_value,
 
794
            char *decimals, uint type_modifier, Item *default_value,
667
795
            Item *on_update_value, LEX_STRING *comment, char *change,
668
 
            List<String> *interval_list, const CHARSET_INFO * const cs,
669
 
            uint32_t uint_geom_type,
670
 
            enum column_format_type column_format,
671
 
            virtual_column_info *vcol_info);
 
796
            List<String> *interval_list, CHARSET_INFO *cs,
 
797
            uint uint_geom_type,
 
798
            enum column_format_type column_format);
672
799
};
673
800
 
674
801
 
681
808
  const char *db_name;
682
809
  const char *table_name,*org_table_name;
683
810
  const char *col_name,*org_col_name;
684
 
  uint32_t length;
685
 
  uint32_t charsetnr, flags, decimals;
 
811
  ulong length;
 
812
  uint charsetnr, flags, decimals;
686
813
  enum_field_types type;
687
814
  Send_field() {}
688
815
};
700
827
  typedef void Copy_func(Copy_field*);
701
828
  Copy_func *get_copy_func(Field *to, Field *from);
702
829
public:
703
 
  unsigned char *from_ptr,*to_ptr;
704
 
  unsigned char *from_null_ptr,*to_null_ptr;
705
 
  bool *null_row;
706
 
  uint32_t      from_bit,to_bit;
707
 
  uint32_t from_length,to_length;
 
830
  uchar *from_ptr,*to_ptr;
 
831
  uchar *from_null_ptr,*to_null_ptr;
 
832
  my_bool *null_row;
 
833
  uint  from_bit,to_bit;
 
834
  uint from_length,to_length;
708
835
  Field *from_field,*to_field;
709
836
  String tmp;                                   // For items
710
837
 
711
838
  Copy_field() {}
712
839
  ~Copy_field() {}
713
840
  void set(Field *to,Field *from,bool save);    // Field to field 
714
 
  void set(unsigned char *to,Field *from);              // Field to string
 
841
  void set(uchar *to,Field *from);              // Field to string
715
842
  void (*do_copy)(Copy_field *);
716
843
  void (*do_copy2)(Copy_field *);               // Used to handle null values
717
844
};
718
845
 
719
846
 
720
 
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
721
 
                  unsigned char *null_pos, unsigned char null_bit,
722
 
                  uint32_t pack_flag, enum_field_types field_type,
723
 
                  const CHARSET_INFO * cs,
 
847
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32_t field_length,
 
848
                  uchar *null_pos, uchar null_bit,
 
849
                  uint pack_flag, enum_field_types field_type,
 
850
                  CHARSET_INFO *cs,
724
851
                  Field::utype unireg_check,
725
852
                  TYPELIB *interval, const char *field_name);
726
 
uint32_t pack_length_to_packflag(uint32_t type);
727
 
enum_field_types get_blob_type_from_length(uint32_t length);
 
853
uint pack_length_to_packflag(uint type);
 
854
enum_field_types get_blob_type_from_length(ulong length);
728
855
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
729
856
int set_field_to_null(Field *field);
730
857
int set_field_to_null_with_conversions(Field *field, bool no_conversions);
731
858
 
732
 
 
733
859
bool
734
 
test_if_important_data(const CHARSET_INFO * const cs, 
735
 
                       const char *str,
736
 
                       const char *strend);
 
860
check_string_copy_error(Field_str *field,
 
861
                        const char *well_formed_error_pos,
 
862
                        const char *cannot_convert_error_pos,
 
863
                        const char *end,
 
864
                        CHARSET_INFO *cs);
737
865
 
738
866
/*
739
867
  Field subclasses
740
868
 */
741
 
#include <drizzled/field/str.h>
742
 
#include <drizzled/field/longstr.h>
743
 
#include <drizzled/field/num.h>
744
 
#include <drizzled/field/blob.h>
745
 
#include <drizzled/field/enum.h>
746
 
#include <drizzled/field/null.h>
747
 
#include <drizzled/field/date.h>
748
 
#include <drizzled/field/fdecimal.h>
749
 
#include <drizzled/field/real.h>
750
 
#include <drizzled/field/double.h>
751
 
#include <drizzled/field/long.h>
752
 
#include <drizzled/field/int64_t.h>
753
 
#include <drizzled/field/num.h>
754
 
#include <drizzled/field/timetype.h>
755
 
#include <drizzled/field/timestamp.h>
756
 
#include <drizzled/field/datetime.h>
757
 
#include <drizzled/field/fstring.h>
758
 
#include <drizzled/field/varstring.h>
 
869
#include "field/blob.h"
 
870
#include "field/null.h"
 
871
#include "field/year.h"
 
872
#include "field/date.h"
 
873
#include "field/decimal.h"
 
874
#include "field/double.h"
 
875
#include "field/short.h"
 
876
#include "field/long.h"
 
877
#include "field/int64_t.h"
 
878
#include "field/timetype.h"
 
879
#include "field/timestamp.h"
 
880
#include "field/datetime.h"
 
881
#include "field/string.h"
 
882
#include "field/varstring.h"
 
883
#include "field/set.h"
759
884
 
760
885
/*
761
886
  The following are for the interface with the .frm file
764
889
#define FIELDFLAG_DECIMAL               1
765
890
#define FIELDFLAG_BINARY                1       // Shares same flag
766
891
#define FIELDFLAG_NUMBER                2
767
 
#define FIELDFLAG_DECIMAL_POSITION      4
 
892
#define FIELDFLAG_ZEROFILL              4
768
893
#define FIELDFLAG_PACK                  120     // Bits used for packing
769
894
#define FIELDFLAG_INTERVAL              256     // mangled with decimals!
770
895
#define FIELDFLAG_BITFIELD              512     // mangled with decimals!
777
902
#define FIELDFLAG_RIGHT_FULLSCREEN      16384
778
903
#define FIELDFLAG_FORMAT_NUMBER         16384   // predit: ###,,## in output
779
904
#define FIELDFLAG_NO_DEFAULT            16384   /* sql */
780
 
#define FIELDFLAG_SUM                   ((uint32_t) 32768)// predit: +#fieldflag
781
 
#define FIELDFLAG_MAYBE_NULL            ((uint32_t) 32768)// sql
782
 
#define FIELDFLAG_HEX_ESCAPE            ((uint32_t) 0x10000)
 
905
#define FIELDFLAG_SUM                   ((uint) 32768)// predit: +#fieldflag
 
906
#define FIELDFLAG_MAYBE_NULL            ((uint) 32768)// sql
 
907
#define FIELDFLAG_HEX_ESCAPE            ((uint) 0x10000)
783
908
#define FIELDFLAG_PACK_SHIFT            3
784
909
#define FIELDFLAG_DEC_SHIFT             8
785
910
#define FIELDFLAG_MAX_DEC               31
790
915
 
791
916
#define f_is_dec(x)             ((x) & FIELDFLAG_DECIMAL)
792
917
#define f_is_num(x)             ((x) & FIELDFLAG_NUMBER)
793
 
#define f_is_decimal_precision(x)       ((x) & FIELDFLAG_DECIMAL_POSITION)
 
918
#define f_is_zerofill(x)        ((x) & FIELDFLAG_ZEROFILL)
794
919
#define f_is_packed(x)          ((x) & FIELDFLAG_PACK)
795
920
#define f_packtype(x)           (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
796
921
#define f_decimals(x)           ((uint8_t) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))
806
931
#define f_bit_as_char(x)        ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
807
932
#define f_is_hex_escape(x)      ((x) & FIELDFLAG_HEX_ESCAPE)
808
933
 
809
 
bool
810
 
check_string_copy_error(Field_str *field,
811
 
                        const char *well_formed_error_pos,
812
 
                        const char *cannot_convert_error_pos,
813
 
                        const char *end,
814
 
                        const CHARSET_INFO * const cs);
815
 
 
816
 
 
817
 
class Field_tiny :public Field_num {
818
 
public:
819
 
  Field_tiny(unsigned char *ptr_arg, uint32_t len_arg, unsigned char *null_ptr_arg,
820
 
             unsigned char null_bit_arg,
821
 
             enum utype unireg_check_arg, const char *field_name_arg,
822
 
             bool zero_arg, bool unsigned_arg)
823
 
    :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
824
 
               unireg_check_arg, field_name_arg,
825
 
               0, zero_arg,unsigned_arg)
826
 
    {}
827
 
  enum Item_result result_type () const { return INT_RESULT; }
828
 
  enum_field_types type() const { return DRIZZLE_TYPE_TINY;}
829
 
  enum ha_base_keytype key_type() const
830
 
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
831
 
  int store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
832
 
  int store(double nr);
833
 
  int store(int64_t nr, bool unsigned_val);
834
 
  int reset(void) { ptr[0]=0; return 0; }
835
 
  double val_real(void);
836
 
  int64_t val_int(void);
837
 
  String *val_str(String*,String *);
838
 
  bool send_binary(Protocol *protocol);
839
 
  int cmp(const unsigned char *,const unsigned char *);
840
 
  void sort_string(unsigned char *buff,uint32_t length);
841
 
  uint32_t pack_length() const { return 1; }
842
 
  void sql_type(String &str) const;
843
 
  uint32_t max_display_length() { return 4; }
844
 
 
845
 
  virtual unsigned char *pack(unsigned char* to, const unsigned char *from,
846
 
                      uint32_t max_length __attribute__((unused)),
847
 
                      bool low_byte_first __attribute__((unused)))
848
 
  {
849
 
    *to= *from;
850
 
    return to + 1;
851
 
  }
852
 
 
853
 
  virtual const unsigned char *unpack(unsigned char* to, const unsigned char *from,
854
 
                              uint32_t param_data __attribute__((unused)),
855
 
                              bool low_byte_first __attribute__((unused)))
856
 
  {
857
 
    *to= *from;
858
 
    return from + 1;
859
 
  }
860
 
};