~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Monty Taylor
  • Date: 2008-08-02 01:03:15 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080802010315-65h5938pymg9d99z
Moved m4 macros to top-level m4 dir, per GNU standards (and where gettext wanted it :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
  void operator=(Field &);
52
52
public:
53
53
  static void *operator new(size_t size) {return sql_alloc(size); }
54
 
  static void operator delete(void *ptr_arg __attribute__((__unused__)),
55
 
                              size_t size __attribute__((__unused__)))
 
54
  static void operator delete(void *ptr_arg __attribute__((unused)),
 
55
                              size_t size __attribute__((unused)))
56
56
  { TRASH(ptr_arg, size); }
57
57
 
58
58
  uchar         *ptr;                   // Position to field in record
107
107
  virtual int  store(double nr)=0;
108
108
  virtual int  store(int64_t nr, bool unsigned_val)=0;
109
109
  virtual int  store_decimal(const my_decimal *d)=0;
110
 
  virtual int store_time(MYSQL_TIME *ltime, timestamp_type t_type);
 
110
  virtual int store_time(DRIZZLE_TIME *ltime, timestamp_type t_type);
111
111
  int store(const char *to, uint length, CHARSET_INFO *cs,
112
112
            enum_check_fields check_level);
113
113
  virtual double val_real(void)=0;
119
119
     if it needs a temp buffer to convert result to string - use buf1
120
120
       example Field_tiny::val_str()
121
121
     if the value exists as a string already - use buf2
122
 
       example Field_string::val_str()
 
122
       example Field_varstring::val_str() (???)
123
123
     consequently, buf2 may be created as 'String buf;' - no memory
124
124
     will be allocated for it. buf1 will be allocated to hold a
125
125
     value if it's too small. Using allocated buffer for buf2 may result in
171
171
    metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
172
172
 
173
173
    Note: While most classes that override this method return pack_length(),
174
 
    the classes Field_string, Field_varstring, and Field_blob return 
 
174
    the classes Field_varstring, and Field_blob return 
175
175
    field_length + 1, field_length, and pack_length_no_ptr() respectfully.
176
176
  */
177
177
  virtual uint row_pack_length() { return 0; }
201
201
    return pack_length();
202
202
  };
203
203
 
204
 
  virtual int reset(void) { bzero(ptr,pack_length()); return 0; }
 
204
  virtual int reset(void) { memset(ptr, 0, pack_length()); return 0; }
205
205
  virtual void reset_fields() {}
206
206
  virtual void set_default()
207
207
  {
218
218
  virtual enum_field_types real_type() const { return type(); }
219
219
  inline  int cmp(const uchar *str) { return cmp(ptr,str); }
220
220
  virtual int cmp_max(const uchar *a, const uchar *b,
221
 
                      uint max_len __attribute__((__unused__)))
 
221
                      uint max_len __attribute__((unused)))
222
222
    { return cmp(a, b); }
223
223
  virtual int cmp(const uchar *,const uchar *)=0;
224
224
  virtual int cmp_binary(const uchar *a,const uchar *b,
225
 
                         uint32_t  __attribute__((__unused__)) max_length=~0)
 
225
                         uint32_t  __attribute__((unused)) max_length=~0)
226
226
  { return memcmp(a,b,pack_length()); }
227
227
  virtual int cmp_offset(uint row_offset)
228
228
  { return cmp(ptr,ptr+row_offset); }
230
230
  { return cmp_binary(ptr, ptr+row_offset); };
231
231
  virtual int key_cmp(const uchar *a,const uchar *b)
232
232
  { return cmp(a, b); }
233
 
  virtual int key_cmp(const uchar *str, uint length __attribute__((__unused__)))
 
233
  virtual int key_cmp(const uchar *str, uint length __attribute__((unused)))
234
234
  { return cmp(ptr,str); }
235
235
  virtual uint decimals() const { return 0; }
236
236
  /*
319
319
      null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,uchar*);
320
320
  }
321
321
  virtual void get_image(uchar *buff, uint length,
322
 
                         CHARSET_INFO *cs __attribute__((__unused__)))
 
322
                         CHARSET_INFO *cs __attribute__((unused)))
323
323
    { memcpy(buff,ptr,length); }
324
324
  virtual void set_image(const uchar *buff,uint length,
325
 
                         CHARSET_INFO *cs __attribute__((__unused__)))
 
325
                         CHARSET_INFO *cs __attribute__((unused)))
326
326
    { memcpy(ptr,buff,length); }
327
327
 
328
328
 
353
353
  */
354
354
 
355
355
  virtual uint get_key_image(uchar *buff, uint length,
356
 
                             imagetype type __attribute__((__unused__)))
 
356
                             imagetype type __attribute__((unused)))
357
357
  {
358
358
    get_image(buff, length, &my_charset_bin);
359
359
    return length;
423
423
  {
424
424
    return unpack(to, from, max_length, low_byte_first);
425
425
  }
426
 
  virtual uint packed_col_length(const uchar *to __attribute__((__unused__)),
 
426
  virtual uint packed_col_length(const uchar *to __attribute__((unused)),
427
427
                                 uint length)
428
428
  { return length;}
429
429
  virtual uint max_packed_col_length(uint max_length)
430
430
  { return max_length;}
431
431
 
432
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__)))
 
433
                       uint key_length_arg __attribute__((unused)),
 
434
                       my_bool insert_or_update __attribute__((unused)))
435
435
  { return cmp(a,b); }
436
436
  virtual int pack_cmp(const uchar *b,
437
 
                       uint key_length_arg __attribute__((__unused__)),
438
 
                       my_bool insert_or_update __attribute__((__unused__)))
 
437
                       uint key_length_arg __attribute__((unused)),
 
438
                       my_bool insert_or_update __attribute__((unused)))
439
439
  { return cmp(ptr,b); }
440
440
  uint offset(uchar *record)
441
441
  {
443
443
  }
444
444
  void copy_from_tmp(int offset);
445
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);
 
446
  virtual bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
 
447
  virtual bool get_time(DRIZZLE_TIME *ltime);
448
448
  virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
449
449
  virtual CHARSET_INFO *sort_charset(void) const { return charset(); }
450
450
  virtual bool has_charset(void) const { return false; }
451
 
  virtual void set_charset(CHARSET_INFO *charset_arg __attribute__((__unused__)))
 
451
  virtual void set_charset(CHARSET_INFO *charset_arg __attribute__((unused)))
452
452
  { }
453
453
  virtual enum Derivation derivation(void) const
454
454
  { return DERIVATION_IMPLICIT; }
455
 
  virtual void set_derivation(enum Derivation derivation_arg __attribute__((__unused__)))
 
455
  virtual void set_derivation(enum Derivation derivation_arg __attribute__((unused)))
456
456
  { }
457
457
  bool set_warning(MYSQL_ERROR::enum_warning_level, unsigned int code,
458
458
                   int cuted_increment);
536
536
 
537
537
   @returns 0 no bytes written.
538
538
*/
539
 
  virtual int do_save_field_metadata(uchar *metadata_ptr __attribute__((__unused__)))
 
539
  virtual int do_save_field_metadata(uchar *metadata_ptr __attribute__((unused)))
540
540
  { return 0; }
541
541
};
542
542
 
544
544
class Field_num :public Field {
545
545
public:
546
546
  const uint8_t dec;
547
 
  bool zerofill,unsigned_flag;  // Purify cannot handle bit fields
 
547
  bool decimal_precision;       // Purify cannot handle bit fields & only for decimal type
 
548
  bool unsigned_flag;   // Purify cannot handle bit fields
548
549
  Field_num(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
549
550
            uchar null_bit_arg, utype unireg_check_arg,
550
551
            const char *field_name_arg,
551
552
            uint8_t dec_arg, bool zero_arg, bool unsigned_arg);
552
553
  Item_result result_type () const { return REAL_RESULT; }
553
 
  void prepend_zeros(String *value);
554
 
  void add_zerofill_and_unsigned(String &res) const;
 
554
  void add_unsigned(String &res) const;
555
555
  friend class Create_field;
556
556
  void make_field(Send_field *);
557
557
  uint decimals() const { return (uint) dec; }
599
599
};
600
600
 
601
601
 
602
 
/* base class for Field_string, Field_varstring and Field_blob */
 
602
/* base class for Field_varstring and Field_blob */
603
603
 
604
604
class Field_longstr :public Field_str
605
605
{
653
653
               0, zero_arg,unsigned_arg)
654
654
    {}
655
655
  enum Item_result result_type () const { return INT_RESULT; }
656
 
  enum_field_types type() const { return MYSQL_TYPE_TINY;}
 
656
  enum_field_types type() const { return DRIZZLE_TYPE_TINY;}
657
657
  enum ha_base_keytype key_type() const
658
658
    { return unsigned_flag ? HA_KEYTYPE_BINARY : HA_KEYTYPE_INT8; }
659
659
  int store(const char *to,uint length,CHARSET_INFO *charset);
671
671
  uint32_t max_display_length() { return 4; }
672
672
 
673
673
  virtual uchar *pack(uchar* to, const uchar *from,
674
 
                      uint max_length __attribute__((__unused__)),
675
 
                      bool low_byte_first __attribute__((__unused__)))
 
674
                      uint max_length __attribute__((unused)),
 
675
                      bool low_byte_first __attribute__((unused)))
676
676
  {
677
677
    *to= *from;
678
678
    return to + 1;
679
679
  }
680
680
 
681
681
  virtual const uchar *unpack(uchar* to, const uchar *from,
682
 
                              uint param_data __attribute__((__unused__)),
683
 
                              bool low_byte_first __attribute__((__unused__)))
 
682
                              uint param_data __attribute__((unused)),
 
683
                              bool low_byte_first __attribute__((unused)))
684
684
  {
685
685
    *to= *from;
686
686
    return from + 1;
706
706
      flags|=ENUM_FLAG;
707
707
  }
708
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; }
 
709
  enum_field_types type() const { return DRIZZLE_TYPE_ENUM; }
710
710
  enum Item_result cmp_type () const { return INT_RESULT; }
711
711
  enum Item_result cast_to_int_type () const { return INT_RESULT; }
712
712
  enum ha_base_keytype key_type() const;
722
722
  void store_type(uint64_t value);
723
723
  void sql_type(String &str) const;
724
724
  uint size_of() const { return sizeof(*this); }
725
 
  enum_field_types real_type() const { return MYSQL_TYPE_ENUM; }
 
725
  enum_field_types real_type() const { return DRIZZLE_TYPE_ENUM; }
726
726
  uint pack_length_from_metadata(uint field_metadata)
727
727
  { return (field_metadata & 0x00ff); }
728
728
  uint row_pack_length() { return pack_length(); }
729
729
  virtual bool zero_pack() const { return 0; }
730
 
  bool optimize_range(uint idx __attribute__((__unused__)),
731
 
                      uint part __attribute__((__unused__)))
 
730
  bool optimize_range(uint idx __attribute__((unused)),
 
731
                      uint part __attribute__((unused)))
732
732
  { return 0; }
733
733
  bool eq_def(Field *field);
734
734
  bool has_charset(void) const { return true; }
866
866
/*
867
867
  Field subclasses
868
868
 */
869
 
#include "drizzle/server/field/blob.h"
870
 
#include "drizzle/server/field/null.h"
871
 
#include "drizzle/server/field/year.h"
872
 
#include "drizzle/server/field/date.h"
873
 
#include "drizzle/server/field/decimal.h"
874
 
#include "drizzle/server/field/double.h"
875
 
#include "drizzle/server/field/short.h"
876
 
#include "drizzle/server/field/long.h"
877
 
#include "drizzle/server/field/int64_t.h"
878
 
#include "drizzle/server/field/timetype.h"
879
 
#include "drizzle/server/field/timestamp.h"
880
 
#include "drizzle/server/field/datetime.h"
881
 
#include "drizzle/server/field/string.h"
882
 
#include "drizzle/server/field/varstring.h"
883
 
#include "drizzle/server/field/set.h"
 
869
#include <drizzled/field/blob.h>
 
870
#include <drizzled/field/null.h>
 
871
#include <drizzled/field/date.h>
 
872
#include <drizzled/field/fdecimal.h>
 
873
#include <drizzled/field/double.h>
 
874
#include <drizzled/field/short.h>
 
875
#include <drizzled/field/long.h>
 
876
#include <drizzled/field/int64_t.h>
 
877
#include <drizzled/field/timetype.h>
 
878
#include <drizzled/field/timestamp.h>
 
879
#include <drizzled/field/datetime.h>
 
880
#include <drizzled/field/fstring.h>
 
881
#include <drizzled/field/varstring.h>
 
882
#include <drizzled/field/set.h>
884
883
 
885
884
/*
886
885
  The following are for the interface with the .frm file
889
888
#define FIELDFLAG_DECIMAL               1
890
889
#define FIELDFLAG_BINARY                1       // Shares same flag
891
890
#define FIELDFLAG_NUMBER                2
892
 
#define FIELDFLAG_ZEROFILL              4
 
891
#define FIELDFLAG_DECIMAL_POSITION      4
893
892
#define FIELDFLAG_PACK                  120     // Bits used for packing
894
893
#define FIELDFLAG_INTERVAL              256     // mangled with decimals!
895
894
#define FIELDFLAG_BITFIELD              512     // mangled with decimals!
915
914
 
916
915
#define f_is_dec(x)             ((x) & FIELDFLAG_DECIMAL)
917
916
#define f_is_num(x)             ((x) & FIELDFLAG_NUMBER)
918
 
#define f_is_zerofill(x)        ((x) & FIELDFLAG_ZEROFILL)
 
917
#define f_is_decimal_precision(x)       ((x) & FIELDFLAG_DECIMAL_POSITION)
919
918
#define f_is_packed(x)          ((x) & FIELDFLAG_PACK)
920
919
#define f_packtype(x)           (((x) >> FIELDFLAG_PACK_SHIFT) & 15)
921
920
#define f_decimals(x)           ((uint8_t) (((x) >> FIELDFLAG_DEC_SHIFT) & FIELDFLAG_MAX_DEC))