~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

Remove PLUGIN and MODULES.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "drizzled/sql_bitmap.h"
32
32
#include "drizzled/sql_list.h"
33
33
#include "drizzled/structs.h"
 
34
#include "drizzled/charset_info.h"
34
35
 
35
36
#include <string>
36
37
#include <vector>
46
47
#define ASSERT_COLUMN_MARKED_FOR_WRITE
47
48
#endif
48
49
 
 
50
typedef struct st_typelib TYPELIB;
 
51
 
49
52
const uint32_t max_field_size= (uint32_t) 4294967295U;
50
53
 
51
54
class SendField;
66
69
 *
67
70
 * @details
68
71
 *
69
 
 * The value stored in the Field object is stored in the 
 
72
 * The value stored in the Field object is stored in the
70
73
 * unsigned char pointer member variable called ptr.  The
71
 
 * val_xxx() methods retrieve this raw byte value and 
 
74
 * val_xxx() methods retrieve this raw byte value and
72
75
 * convert the byte into the appropriate output (int, decimal, etc).
73
76
 *
74
77
 * The store_xxx() methods take various input and convert
77
80
class Field
78
81
{
79
82
  /* Prevent use of these */
80
 
  Field(const Field&); 
 
83
  Field(const Field&);
81
84
  void operator=(Field &);
82
85
public:
83
86
  unsigned char *ptr; /**< Position to field in record. Stores raw field value */
84
87
  unsigned char *null_ptr; /**< Byte where null_bit is */
85
88
 
86
89
  /**
87
 
   * Pointer to the Table object containing this Field 
 
90
   * Pointer to the Table object containing this Field
88
91
   *
89
92
   * @note You can use table->in_use as replacement for current_session member
90
93
   * only inside of val_*() and store() members (e.g. you can't use it in cons)
91
94
   */
92
 
  Table *table; 
 
95
  Table *table;
93
96
  Table *orig_table; /**< Pointer to the original Table. @TODO What is "the original table"? */
94
97
  const char **table_name; /**< Pointer to the name of the table. @TODO This is redundant with Table::table_name. */
95
98
  const char *field_name; /**< Name of the field */
102
105
  key_map part_of_sortkey;
103
106
 
104
107
  /*
105
 
    We use three additional unireg types for TIMESTAMP to overcome limitation
106
 
    of current binary format of .frm file. We'd like to be able to support
107
 
    NOW() as default and on update value for such fields but unable to hold
108
 
    this info anywhere except unireg_check field. This issue will be resolved
109
 
    in more clean way with transition to new text based .frm format.
110
 
    See also comment for Field_timestamp::Field_timestamp().
 
108
    We use three additional unireg types for TIMESTAMP for hysterical
 
109
    raisins and limitations in the MySQL FRM file format.
 
110
 
 
111
    A good TODO is to clean this up as we can support just about
 
112
    anything in the table proto message now.
111
113
  */
112
114
  enum utype
113
 
  { 
 
115
  {
114
116
    NONE,
115
117
    NEXT_NUMBER,
116
118
    TIMESTAMP_OLD_FIELD,
134
136
   */
135
137
  bool is_created_from_null_item;
136
138
 
137
 
  static void *operator new(size_t size) {return sql_alloc(size); }
138
 
  static void *operator new(size_t size, MEM_ROOT *mem_root)
139
 
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
 
139
  static void *operator new(size_t size);
 
140
  static void *operator new(size_t size, drizzled::memory::Root *mem_root);
140
141
  static void operator delete(void *, size_t)
141
 
  { TRASH(ptr_arg, size); }
 
142
  { }
142
143
 
143
144
  Field(unsigned char *ptr_arg,
144
145
        uint32_t length_arg,
148
149
        const char *field_name_arg);
149
150
  virtual ~Field() {}
150
151
  /* Store functions returns 1 on overflow and -1 on fatal error */
151
 
  virtual int store(const char *to, 
152
 
                    uint32_t length, 
 
152
  virtual int store(const char *to,
 
153
                    uint32_t length,
153
154
                    const CHARSET_INFO * const cs)=0;
154
155
  virtual int store(double nr)=0;
155
156
  virtual int store(int64_t nr, bool unsigned_val)=0;
156
157
  virtual int store_decimal(const my_decimal *d)=0;
157
 
  int store(const char *to, 
 
158
  int store(const char *to,
158
159
            uint32_t length,
159
160
            const CHARSET_INFO * const cs,
160
161
            enum_check_fields check_level);
168
169
  virtual double val_real(void)=0;
169
170
  virtual int64_t val_int(void)=0;
170
171
  virtual my_decimal *val_decimal(my_decimal *);
171
 
  inline String *val_str(String *str) 
 
172
  inline String *val_str(String *str)
172
173
  {
173
174
    return val_str(str, str);
174
175
  }
287
288
    field_length + 1, field_length, and pack_length_no_ptr() respectfully.
288
289
  */
289
290
  virtual uint32_t row_pack_length();
290
 
  virtual int save_field_metadata(unsigned char *first_byte);
291
291
 
292
292
  /**
293
 
   * Return the "real size" of the data in memory. 
 
293
   * Return the "real size" of the data in memory.
294
294
   * For varstrings, this does _not_ include the length bytes.
295
295
   */
296
296
  virtual uint32_t data_length();
359
359
   * use field->val_int() for comparison.  Used to optimize clauses like
360
360
   * 'a_column BETWEEN date_const AND date_const'.
361
361
   */
362
 
  virtual bool can_be_compared_as_int64_t() const 
 
362
  virtual bool can_be_compared_as_int64_t() const
363
363
  {
364
364
    return false;
365
365
  }
366
366
  virtual void free() {}
367
 
  virtual Field *new_field(MEM_ROOT *root, 
 
367
  virtual Field *new_field(drizzled::memory::Root *root,
368
368
                           Table *new_table,
369
369
                           bool keep_type);
370
 
  virtual Field *new_key_field(MEM_ROOT *root, Table *new_table,
371
 
                               unsigned char *new_ptr, 
 
370
  virtual Field *new_key_field(drizzled::memory::Root *root, Table *new_table,
 
371
                               unsigned char *new_ptr,
372
372
                               unsigned char *new_null_ptr,
373
373
                               uint32_t new_null_bit);
374
374
  /** This is used to generate a field in Table from TableShare */
375
 
  Field *clone(MEM_ROOT *mem_root, Table *new_table);
 
375
  Field *clone(drizzled::memory::Root *mem_root, Table *new_table);
376
376
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
377
377
  {
378
378
    ptr= ptr_arg;
419
419
   * characters have maximal possible size (mbmaxlen). In the other words,
420
420
   * "length" parameter is a number of characters multiplied by
421
421
   * field_charset->mbmaxlen.
422
 
   * 
 
422
   *
423
423
   * @retval
424
424
   *   Number of copied bytes (excluding padded zero bytes -- see above).
425
425
   */
449
449
  {
450
450
    unsigned char *old_ptr= ptr;
451
451
    int64_t return_value;
452
 
    ptr= (unsigned char*) new_ptr;
 
452
    ptr= const_cast<unsigned char*>(new_ptr);
453
453
    return_value= val_int();
454
454
    ptr= old_ptr;
455
455
    return return_value;
457
457
  inline String *val_str(String *str, const unsigned char *new_ptr)
458
458
  {
459
459
    unsigned char *old_ptr= ptr;
460
 
    ptr= (unsigned char*) new_ptr;
 
460
    ptr= const_cast<unsigned char*>(new_ptr);
461
461
    val_str(str);
462
462
    ptr= old_ptr;
463
463
    return str;
550
550
 
551
551
  virtual unsigned char *pack_key(unsigned char* to,
552
552
                                  const unsigned char *from,
553
 
                                  uint32_t max_length, 
 
553
                                  uint32_t max_length,
554
554
                                  bool low_byte_first)
555
555
  {
556
556
    return pack(to, from, max_length, low_byte_first);
557
557
  }
558
 
  virtual unsigned char *pack_key_from_key_image(unsigned char* to,
559
 
                                                 const unsigned char *from,
560
 
                                                 uint32_t max_length,
561
 
                                                 bool low_byte_first)
562
 
  {
563
 
    return pack(to, from, max_length, low_byte_first);
564
 
  }
565
558
  virtual const unsigned char *unpack_key(unsigned char* to,
566
559
                                          const unsigned char *from,
567
560
                                          uint32_t max_length,
569
562
  {
570
563
    return unpack(to, from, max_length, low_byte_first);
571
564
  }
572
 
  virtual uint32_t packed_col_length(const unsigned char *to, uint32_t length);
573
565
  virtual uint32_t max_packed_col_length(uint32_t max_length)
574
566
  {
575
567
    return max_length;
576
568
  }
577
569
 
578
 
  virtual int pack_cmp(const unsigned char *a,
579
 
                       const unsigned char *b,
580
 
                       uint32_t key_length_arg,
581
 
                       bool insert_or_update);
582
 
  virtual int pack_cmp(const unsigned char *b,
583
 
                       uint32_t key_length_arg,
584
 
                       bool insert_or_update);
585
 
 
586
570
  inline uint32_t offset(unsigned char *record)
587
571
  {
588
572
    return (uint32_t) (ptr - record);
621
605
    @retval
622
606
      0 otherwise
623
607
  */
624
 
  bool set_warning(DRIZZLE_ERROR::enum_warning_level, 
 
608
  bool set_warning(DRIZZLE_ERROR::enum_warning_level,
625
609
                   unsigned int code,
626
610
                   int cuted_increment);
627
611
  /**
639
623
      fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
640
624
      thread.
641
625
  */
642
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, 
 
626
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
643
627
                            uint32_t code,
644
 
                            const char *str, 
 
628
                            const char *str,
645
629
                            uint32_t str_len,
646
 
                            enum enum_drizzle_timestamp_type ts_type, 
 
630
                            enum enum_drizzle_timestamp_type ts_type,
647
631
                            int cuted_increment);
648
632
  /**
649
633
    Produce warning or note about integer datetime value saved into field.
659
643
      fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
660
644
      thread.
661
645
  */
662
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, 
 
646
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
663
647
                            uint32_t code,
664
 
                            int64_t nr, 
 
648
                            int64_t nr,
665
649
                            enum enum_drizzle_timestamp_type ts_type,
666
650
                            int cuted_increment);
667
651
  /**
677
661
      fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
678
662
      thread.
679
663
  */
680
 
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, 
 
664
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
681
665
                            const uint32_t code,
682
 
                            double nr, 
 
666
                            double nr,
683
667
                            enum enum_drizzle_timestamp_type ts_type);
684
668
  inline bool check_overflow(int op_result)
685
669
  {
715
699
    @return
716
700
      value converted from val
717
701
  */
718
 
  int64_t convert_decimal2int64_t(const my_decimal *val, 
 
702
  int64_t convert_decimal2int64_t(const my_decimal *val,
719
703
                                  bool unsigned_flag,
720
704
                                  int *err);
721
705
  /* The max. number of characters */
751
735
  bool isWriteSet();
752
736
  void setReadSet(bool arg= true);
753
737
  void setWriteSet(bool arg= true);
754
 
 
755
 
private:
756
 
 
757
 
  /**
758
 
    Retrieve the field metadata for fields.
759
 
 
760
 
    This default implementation returns 0 and saves 0 in the metadata_ptr
761
 
    value.
762
 
 
763
 
    @param   metadata_ptr   First byte of field metadata
764
 
 
765
 
    @returns 0 no bytes written.
766
 
  */
767
 
  virtual int do_save_field_metadata(unsigned char *)
768
 
  {
769
 
    return 0;
770
 
  }
771
738
};
772
739
 
773
740
#include "drizzled/create_field.h"
780
747
 * Send_field is basically a stripped-down POD class for
781
748
 * representing basic information about a field...
782
749
 */
783
 
class SendField 
 
750
class SendField
784
751
{
785
752
public:
786
753
  const char *db_name;
799
766
/**
800
767
 * A class for quick copying data to fields
801
768
 */
802
 
class CopyField :public Sql_alloc
 
769
class CopyField :public drizzled::memory::SqlAlloc
803
770
{
804
771
  /**
805
772
    Convenience definition of a copy function returned by
830
797
};
831
798
 
832
799
Field *make_field(TableShare *share,
833
 
                  MEM_ROOT *root,
 
800
                  drizzled::memory::Root *root,
834
801
                  unsigned char *ptr,
835
802
                  uint32_t field_length,
836
803
                  bool is_nullable,