~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Monty Taylor
  • Date: 2008-10-06 04:45:56 UTC
  • mfrom: (438.1.13 drizzle)
  • Revision ID: monty@inaugust.com-20081006044556-5urk8k3yhnnl3o1p
Merged in from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
struct st_cache_field;
38
38
int field_conv(Field *to,Field *from);
39
39
 
40
 
inline uint get_enum_pack_length(int elements)
 
40
inline uint32_t get_enum_pack_length(int elements)
41
41
{
42
42
  return elements < 256 ? 1 : 2;
43
43
}
44
44
 
45
 
inline uint get_set_pack_length(int elements)
 
45
inline uint32_t get_set_pack_length(int elements)
46
46
{
47
 
  uint len= (elements + 7) / 8;
 
47
  uint32_t len= (elements + 7) / 8;
48
48
  return len > 4 ? 8 : len;
49
49
}
50
50
 
106
106
        const char *field_name_arg);
107
107
  virtual ~Field() {}
108
108
  /* Store functions returns 1 on overflow and -1 on fatal error */
109
 
  virtual int  store(const char *to, uint length, const CHARSET_INFO * const cs)=0;
 
109
  virtual int  store(const char *to, uint32_t length, const CHARSET_INFO * const cs)=0;
110
110
  virtual int  store(double nr)=0;
111
111
  virtual int  store(int64_t nr, bool unsigned_val)=0;
112
112
  virtual int  store_decimal(const my_decimal *d)=0;
113
113
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
114
 
  int store(const char *to, uint length, const CHARSET_INFO * const cs,
 
114
  int store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
115
115
            enum_check_fields check_level);
116
116
  virtual double val_real(void)=0;
117
117
  virtual int64_t val_int(void)=0;
162
162
    table, which is located on disk).
163
163
  */
164
164
  virtual uint32_t pack_length_in_rec() const { return pack_length(); }
165
 
  virtual int compatible_field_size(uint field_metadata);
166
 
  virtual uint pack_length_from_metadata(uint field_metadata)
 
165
  virtual int compatible_field_size(uint32_t field_metadata);
 
166
  virtual uint32_t pack_length_from_metadata(uint32_t field_metadata)
167
167
  { return field_metadata; }
168
168
  /*
169
169
    This method is used to return the size of the data in a row-based
177
177
    the classes Field_varstring, and Field_blob return 
178
178
    field_length + 1, field_length, and pack_length_no_ptr() respectfully.
179
179
  */
180
 
  virtual uint row_pack_length() { return 0; }
 
180
  virtual uint32_t row_pack_length() { return 0; }
181
181
  virtual int save_field_metadata(uchar *first_byte)
182
182
  { return do_save_field_metadata(first_byte); }
183
183
 
221
221
  virtual enum_field_types real_type() const { return type(); }
222
222
  inline  int cmp(const uchar *str) { return cmp(ptr,str); }
223
223
  virtual int cmp_max(const uchar *a, const uchar *b,
224
 
                      uint max_len __attribute__((unused)))
 
224
                      uint32_t max_len __attribute__((unused)))
225
225
    { return cmp(a, b); }
226
226
  virtual int cmp(const uchar *,const uchar *)=0;
227
227
  virtual int cmp_binary(const uchar *a,const uchar *b,
228
228
                         uint32_t  __attribute__((unused)) max_length=UINT32_MAX)
229
229
  { return memcmp(a,b,pack_length()); }
230
 
  virtual int cmp_offset(uint row_offset)
 
230
  virtual int cmp_offset(uint32_t row_offset)
231
231
  { return cmp(ptr,ptr+row_offset); }
232
 
  virtual int cmp_binary_offset(uint row_offset)
 
232
  virtual int cmp_binary_offset(uint32_t row_offset)
233
233
  { return cmp_binary(ptr, ptr+row_offset); };
234
234
  virtual int key_cmp(const uchar *a,const uchar *b)
235
235
  { return cmp(a, b); }
236
 
  virtual int key_cmp(const uchar *str, uint length __attribute__((unused)))
 
236
  virtual int key_cmp(const uchar *str, uint32_t length __attribute__((unused)))
237
237
  { return cmp(ptr,str); }
238
 
  virtual uint decimals() const { return 0; }
 
238
  virtual uint32_t decimals() const { return 0; }
239
239
  /*
240
240
    Caller beware: sql_type can change str.Ptr, so check
241
241
    ptr() to see if it changed if you are using your own buffer
242
242
    in str and restore it with set() if needed
243
243
  */
244
244
  virtual void sql_type(String &str) const =0;
245
 
  virtual uint size_of() const =0;              // For new field
 
245
  virtual uint32_t size_of() const =0;          // For new field
246
246
  inline bool is_null(my_ptrdiff_t row_offset= 0)
247
247
  { return null_ptr ? (null_ptr[row_offset] & null_bit ? 1 : 0) : table->null_row; }
248
248
  inline bool is_real_null(my_ptrdiff_t row_offset= 0)
251
251
  {
252
252
    if (!null_ptr)
253
253
      return 0;
254
 
    return test(record[(uint) (null_ptr -table->record[0])] &
 
254
    return test(record[(uint32_t) (null_ptr -table->record[0])] &
255
255
                null_bit);
256
256
  }
257
257
  inline bool is_null_in_record_with_offset(my_ptrdiff_t offset)
293
293
  }
294
294
 
295
295
  virtual void make_field(Send_field *);
296
 
  virtual void sort_string(uchar *buff,uint length)=0;
297
 
  virtual bool optimize_range(uint idx, uint part);
 
296
  virtual void sort_string(uchar *buff,uint32_t length)=0;
 
297
  virtual bool optimize_range(uint32_t idx, uint32_t part);
298
298
  /*
299
299
    This should be true for fields which, when compared with constant
300
300
    items, can be casted to int64_t. In this case we will at 'fix_fields'
308
308
                           bool keep_type);
309
309
  virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
310
310
                               uchar *new_ptr, uchar *new_null_ptr,
311
 
                               uint new_null_bit);
 
311
                               uint32_t new_null_bit);
312
312
  Field *clone(MEM_ROOT *mem_root, Table *new_table);
313
313
  inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
314
314
  {
321
321
    if (null_ptr)
322
322
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
323
323
  }
324
 
  virtual void get_image(uchar *buff, uint length,
 
324
  virtual void get_image(uchar *buff, uint32_t length,
325
325
                         const CHARSET_INFO * const cs __attribute__((unused)))
326
326
    { memcpy(buff,ptr,length); }
327
 
  virtual void set_image(const uchar *buff,uint length,
 
327
  virtual void set_image(const uchar *buff,uint32_t length,
328
328
                         const CHARSET_INFO * const cs __attribute__((unused)))
329
329
    { memcpy(ptr,buff,length); }
330
330
 
355
355
      Number of copied bytes (excluding padded zero bytes -- see above).
356
356
  */
357
357
 
358
 
  virtual uint get_key_image(uchar *buff, uint length,
 
358
  virtual uint32_t get_key_image(uchar *buff, uint32_t length,
359
359
                             imagetype type __attribute__((unused)))
360
360
  {
361
361
    get_image(buff, length, &my_charset_bin);
362
362
    return length;
363
363
  }
364
 
  virtual void set_key_image(const uchar *buff,uint length)
 
364
  virtual void set_key_image(const uchar *buff,uint32_t length)
365
365
    { set_image(buff,length, &my_charset_bin); }
366
 
  inline int64_t val_int_offset(uint row_offset)
 
366
  inline int64_t val_int_offset(uint32_t row_offset)
367
367
    {
368
368
      ptr+=row_offset;
369
369
      int64_t tmp=val_int();
390
390
  virtual bool send_binary(Protocol *protocol);
391
391
 
392
392
  virtual uchar *pack(uchar *to, const uchar *from,
393
 
                      uint max_length, bool low_byte_first);
 
393
                      uint32_t max_length, bool low_byte_first);
394
394
  /**
395
 
     @overload Field::pack(uchar*, const uchar*, uint, bool)
 
395
     @overload Field::pack(uchar*, const uchar*, uint32_t, bool)
396
396
  */
397
397
  uchar *pack(uchar *to, const uchar *from)
398
398
  {
401
401
  }
402
402
 
403
403
  virtual const uchar *unpack(uchar* to, const uchar *from,
404
 
                              uint param_data, bool low_byte_first);
 
404
                              uint32_t param_data, bool low_byte_first);
405
405
  /**
406
 
     @overload Field::unpack(uchar*, const uchar*, uint, bool)
 
406
     @overload Field::unpack(uchar*, const uchar*, uint32_t, bool)
407
407
  */
408
408
  const uchar *unpack(uchar* to, const uchar *from)
409
409
  {
412
412
  }
413
413
 
414
414
  virtual uchar *pack_key(uchar* to, const uchar *from,
415
 
                          uint max_length, bool low_byte_first)
 
415
                          uint32_t max_length, bool low_byte_first)
416
416
  {
417
417
    return pack(to, from, max_length, low_byte_first);
418
418
  }
419
419
  virtual uchar *pack_key_from_key_image(uchar* to, const uchar *from,
420
 
                                        uint max_length, bool low_byte_first)
 
420
                                        uint32_t max_length, bool low_byte_first)
421
421
  {
422
422
    return pack(to, from, max_length, low_byte_first);
423
423
  }
424
424
  virtual const uchar *unpack_key(uchar* to, const uchar *from,
425
 
                                  uint max_length, bool low_byte_first)
 
425
                                  uint32_t max_length, bool low_byte_first)
426
426
  {
427
427
    return unpack(to, from, max_length, low_byte_first);
428
428
  }
429
 
  virtual uint packed_col_length(const uchar *to __attribute__((unused)),
430
 
                                 uint length)
 
429
  virtual uint32_t packed_col_length(const uchar *to __attribute__((unused)),
 
430
                                 uint32_t length)
431
431
  { return length;}
432
 
  virtual uint max_packed_col_length(uint max_length)
 
432
  virtual uint32_t max_packed_col_length(uint32_t max_length)
433
433
  { return max_length;}
434
434
 
435
435
  virtual int pack_cmp(const uchar *a,const uchar *b,
436
 
                       uint key_length_arg __attribute__((unused)),
 
436
                       uint32_t key_length_arg __attribute__((unused)),
437
437
                       bool insert_or_update __attribute__((unused)))
438
438
  { return cmp(a,b); }
439
439
  virtual int pack_cmp(const uchar *b,
440
 
                       uint key_length_arg __attribute__((unused)),
 
440
                       uint32_t key_length_arg __attribute__((unused)),
441
441
                       bool insert_or_update __attribute__((unused)))
442
442
  { return cmp(ptr,b); }
443
 
  uint offset(uchar *record)
 
443
  uint32_t offset(uchar *record)
444
444
  {
445
 
    return (uint) (ptr - record);
 
445
    return (uint32_t) (ptr - record);
446
446
  }
447
447
  void copy_from_tmp(int offset);
448
 
  uint fill_cache_field(struct st_cache_field *copy);
449
 
  virtual bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
 
448
  uint32_t fill_cache_field(struct st_cache_field *copy);
 
449
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
450
450
  virtual bool get_time(DRIZZLE_TIME *ltime);
451
451
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
452
452
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
459
459
  { }
460
460
  bool set_warning(DRIZZLE_ERROR::enum_warning_level, unsigned int code,
461
461
                   int cuted_increment);
462
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint code, 
463
 
                            const char *str, uint str_len,
 
462
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code, 
 
463
                            const char *str, uint32_t str_len,
464
464
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment);
465
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint code, 
 
465
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code, 
466
466
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
467
467
                            int cuted_increment);
468
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint code, 
 
468
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint32_t code, 
469
469
                            double nr, enum enum_drizzle_timestamp_type ts_type);
470
470
  inline bool check_overflow(int op_result)
471
471
  {
481
481
  /* maximum possible display length */
482
482
  virtual uint32_t max_display_length()= 0;
483
483
 
484
 
  virtual uint is_equal(Create_field *new_field);
 
484
  virtual uint32_t is_equal(Create_field *new_field);
485
485
  /* convert decimal to int64_t with overflow check */
486
486
  int64_t convert_decimal2int64_t(const my_decimal *val, bool unsigned_flag,
487
487
                                    int *err);
500
500
  /* Hash value */
501
501
  virtual void hash(uint32_t *nr, uint32_t *nr2);
502
502
  friend bool reopen_table(THD *,Table *,bool);
503
 
  friend int cre_myisam(char * name, register Table *form, uint options,
 
503
  friend int cre_myisam(char * name, register Table *form, uint32_t options,
504
504
                        uint64_t auto_increment_value);
505
505
  friend class Copy_field;
506
506
  friend class Item_avg_field;
557
557
  void add_unsigned(String &res) const;
558
558
  friend class Create_field;
559
559
  void make_field(Send_field *);
560
 
  uint decimals() const { return (uint) dec; }
561
 
  uint size_of() const { return sizeof(*this); }
 
560
  uint32_t decimals() const { return (uint32_t) dec; }
 
561
  uint32_t size_of() const { return sizeof(*this); }
562
562
  bool eq_def(Field *field);
563
563
  int store_decimal(const my_decimal *);
564
564
  my_decimal *val_decimal(my_decimal *);
565
 
  uint is_equal(Create_field *new_field);
 
565
  uint32_t is_equal(Create_field *new_field);
566
566
  int check_int(const CHARSET_INFO * const cs, const char *str, int length,
567
567
                const char *int_end, int error);
568
 
  bool get_int(const CHARSET_INFO * const cs, const char *from, uint len, 
 
568
  bool get_int(const CHARSET_INFO * const cs, const char *from, uint32_t len, 
569
569
               int64_t *rnd, uint64_t unsigned_max, 
570
570
               int64_t signed_min, int64_t signed_max);
571
571
};
581
581
            uchar null_bit_arg, utype unireg_check_arg,
582
582
            const char *field_name_arg, const CHARSET_INFO * const charset);
583
583
  Item_result result_type () const { return STRING_RESULT; }
584
 
  uint decimals() const { return NOT_FIXED_DEC; }
 
584
  uint32_t decimals() const { return NOT_FIXED_DEC; }
585
585
  int  store(double nr);
586
586
  int  store(int64_t nr, bool unsigned_val)=0;
587
587
  int  store_decimal(const my_decimal *);
588
 
  int  store(const char *to,uint length, const CHARSET_INFO * const cs)=0;
589
 
  uint size_of() const { return sizeof(*this); }
 
588
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const cs)=0;
 
589
  uint32_t size_of() const { return sizeof(*this); }
590
590
  const CHARSET_INFO *charset(void) const { return field_charset; }
591
591
  void set_charset(const CHARSET_INFO * const charset_arg) { field_charset= charset_arg; }
592
592
  enum Derivation derivation(void) const { return field_derivation; }
598
598
  my_decimal *val_decimal(my_decimal *);
599
599
  virtual bool str_needs_quotes() { return true; }
600
600
  bool compare_str_field_flags(Create_field *new_field, uint32_t flags);
601
 
  uint is_equal(Create_field *new_field);
 
601
  uint32_t is_equal(Create_field *new_field);
602
602
};
603
603
 
604
604
 
637
637
  my_decimal *val_decimal(my_decimal *);
638
638
  int truncate(double *nr, double max_length);
639
639
  uint32_t max_display_length() { return field_length; }
640
 
  uint size_of() const { return sizeof(*this); }
 
640
  uint32_t size_of() const { return sizeof(*this); }
641
641
  virtual const uchar *unpack(uchar* to, const uchar *from,
642
 
                              uint param_data, bool low_byte_first);
 
642
                              uint32_t param_data, bool low_byte_first);
643
643
  virtual uchar *pack(uchar* to, const uchar *from,
644
 
                      uint max_length, bool low_byte_first);
 
644
                      uint32_t max_length, bool low_byte_first);
645
645
};
646
646
 
647
647
 
659
659
  enum_field_types type() const { return DRIZZLE_TYPE_TINY;}
660
660
  enum ha_base_keytype key_type() const
661
661
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
662
 
  int store(const char *to,uint length, const CHARSET_INFO * const charset);
 
662
  int store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
663
663
  int store(double nr);
664
664
  int store(int64_t nr, bool unsigned_val);
665
665
  int reset(void) { ptr[0]=0; return 0; }
668
668
  String *val_str(String*,String *);
669
669
  bool send_binary(Protocol *protocol);
670
670
  int cmp(const uchar *,const uchar *);
671
 
  void sort_string(uchar *buff,uint length);
 
671
  void sort_string(uchar *buff,uint32_t length);
672
672
  uint32_t pack_length() const { return 1; }
673
673
  void sql_type(String &str) const;
674
674
  uint32_t max_display_length() { return 4; }
675
675
 
676
676
  virtual uchar *pack(uchar* to, const uchar *from,
677
 
                      uint max_length __attribute__((unused)),
 
677
                      uint32_t max_length __attribute__((unused)),
678
678
                      bool low_byte_first __attribute__((unused)))
679
679
  {
680
680
    *to= *from;
682
682
  }
683
683
 
684
684
  virtual const uchar *unpack(uchar* to, const uchar *from,
685
 
                              uint param_data __attribute__((unused)),
 
685
                              uint32_t param_data __attribute__((unused)),
686
686
                              bool low_byte_first __attribute__((unused)))
687
687
  {
688
688
    *to= *from;
713
713
    for most of the types, or of bytes for BLOBs or numeric types.
714
714
  */
715
715
  uint32_t char_length;
716
 
  uint  decimals, flags, pack_length, key_length;
 
716
  uint32_t  decimals, flags, pack_length, key_length;
717
717
  Field::utype unireg_check;
718
718
  TYPELIB *interval;                    // Which interval to use
719
719
  TYPELIB *save_interval;               // Temporary copy for the above
723
723
  Field *field;                         // For alter table
724
724
 
725
725
  uint8_t row,col,sc_length,interval_id;        // For rea_create_table
726
 
  uint  offset,pack_flag;
 
726
  uint32_t      offset,pack_flag;
727
727
  Create_field() :after(0) {}
728
728
  Create_field(Field *field, Field *orig_field);
729
729
  /* Used to make a clone of this object for ALTER/CREATE TABLE */
743
743
                          bool maybe_null, bool is_unsigned);
744
744
 
745
745
  bool init(THD *thd, char *field_name, enum_field_types type, char *length,
746
 
            char *decimals, uint type_modifier, Item *default_value,
 
746
            char *decimals, uint32_t type_modifier, Item *default_value,
747
747
            Item *on_update_value, LEX_STRING *comment, char *change,
748
748
            List<String> *interval_list, const CHARSET_INFO * const cs,
749
 
            uint uint_geom_type,
 
749
            uint32_t uint_geom_type,
750
750
            enum column_format_type column_format);
751
751
};
752
752
 
761
761
  const char *table_name,*org_table_name;
762
762
  const char *col_name,*org_col_name;
763
763
  uint32_t length;
764
 
  uint charsetnr, flags, decimals;
 
764
  uint32_t charsetnr, flags, decimals;
765
765
  enum_field_types type;
766
766
  Send_field() {}
767
767
};
782
782
  uchar *from_ptr,*to_ptr;
783
783
  uchar *from_null_ptr,*to_null_ptr;
784
784
  bool *null_row;
785
 
  uint  from_bit,to_bit;
786
 
  uint from_length,to_length;
 
785
  uint32_t      from_bit,to_bit;
 
786
  uint32_t from_length,to_length;
787
787
  Field *from_field,*to_field;
788
788
  String tmp;                                   // For items
789
789
 
798
798
 
799
799
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32_t field_length,
800
800
                  uchar *null_pos, uchar null_bit,
801
 
                  uint pack_flag, enum_field_types field_type,
 
801
                  uint32_t pack_flag, enum_field_types field_type,
802
802
                  const CHARSET_INFO * cs,
803
803
                  Field::utype unireg_check,
804
804
                  TYPELIB *interval, const char *field_name);
805
 
uint pack_length_to_packflag(uint type);
 
805
uint32_t pack_length_to_packflag(uint32_t type);
806
806
enum_field_types get_blob_type_from_length(uint32_t length);
807
807
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
808
808
int set_field_to_null(Field *field);
852
852
#define FIELDFLAG_RIGHT_FULLSCREEN      16384
853
853
#define FIELDFLAG_FORMAT_NUMBER         16384   // predit: ###,,## in output
854
854
#define FIELDFLAG_NO_DEFAULT            16384   /* sql */
855
 
#define FIELDFLAG_SUM                   ((uint) 32768)// predit: +#fieldflag
856
 
#define FIELDFLAG_MAYBE_NULL            ((uint) 32768)// sql
857
 
#define FIELDFLAG_HEX_ESCAPE            ((uint) 0x10000)
 
855
#define FIELDFLAG_SUM                   ((uint32_t) 32768)// predit: +#fieldflag
 
856
#define FIELDFLAG_MAYBE_NULL            ((uint32_t) 32768)// sql
 
857
#define FIELDFLAG_HEX_ESCAPE            ((uint32_t) 0x10000)
858
858
#define FIELDFLAG_PACK_SHIFT            3
859
859
#define FIELDFLAG_DEC_SHIFT             8
860
860
#define FIELDFLAG_MAX_DEC               31