~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Brian Aker
  • Date: 2010-12-19 06:20:54 UTC
  • mfrom: (2005.1.1 bug673105)
  • Revision ID: brian@tangent.org-20101219062054-1kt0l3dxs4z2z8md
Merge Dave.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
  variables must declare the size_of() member function.
23
23
*/
24
24
 
25
 
 
26
 
 
27
25
#ifndef DRIZZLED_FIELD_H
28
26
#define DRIZZLED_FIELD_H
29
27
 
30
28
#include "drizzled/sql_error.h"
31
 
#include "drizzled/type/decimal.h"
 
29
#include "drizzled/decimal.h"
32
30
#include "drizzled/key_map.h"
33
31
#include "drizzled/sql_list.h"
34
32
#include "drizzled/structs.h"
35
33
#include "drizzled/charset_info.h"
36
34
#include "drizzled/item_result.h"
37
 
#include "drizzled/charset_info.h"
38
35
 
39
36
#include <string>
40
37
#include <vector>
41
38
 
42
 
#include "drizzled/visibility.h"
43
 
 
44
39
namespace drizzled
45
40
{
46
41
 
80
75
 * The store_xxx() methods take various input and convert
81
76
 * the input into the raw bytes stored in the ptr member variable.
82
77
 */
83
 
class DRIZZLED_API Field
 
78
class Field
84
79
{
85
80
  /* Prevent use of these */
86
81
  Field(const Field&);
98
93
   */
99
94
private:
100
95
  Table *table;
101
 
 
102
96
public:
103
97
  Table *getTable()
104
98
  {
147
141
  utype unireg_check;
148
142
  uint32_t field_length; /**< Length of this field in bytes */
149
143
  uint32_t flags;
150
 
 
151
 
  bool isUnsigned() const
152
 
  {
153
 
    return flags & UNSIGNED_FLAG;
154
 
  }
155
 
 
156
144
private:
157
145
  uint16_t field_index; /**< Index of this Field in Table::fields array */
158
146
 
205
193
                    const CHARSET_INFO * const cs)=0;
206
194
  virtual int store(double nr)=0;
207
195
  virtual int store(int64_t nr, bool unsigned_val)=0;
208
 
  virtual int store_decimal(const type::Decimal *d)=0;
 
196
  virtual int store_decimal(const my_decimal *d)=0;
209
197
  int store_and_check(enum_check_fields check_level,
210
198
                      const char *to,
211
199
                      uint32_t length,
216
204
    @note
217
205
      Needs to be changed if/when we want to support different time formats.
218
206
  */
219
 
  virtual int store_time(type::Time &ltime, type::timestamp_t t_type);
 
207
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
220
208
  virtual double val_real()=0;
221
209
  virtual int64_t val_int()=0;
222
 
  virtual type::Decimal *val_decimal(type::Decimal *);
 
210
  virtual my_decimal *val_decimal(my_decimal *);
223
211
  String *val_str_internal(String *str)
224
212
  {
225
213
    return val_str(str, str);
226
214
  }
227
 
 
228
215
  /*
229
216
     val_str(buf1, buf2) gets two buffers and should use them as follows:
230
217
     if it needs a temp buffer to convert result to string - use buf1
238
225
     This trickery is used to decrease a number of malloc calls.
239
226
  */
240
227
  virtual String *val_str(String*, String *)=0;
241
 
 
242
228
  /*
243
229
   str_needs_quotes() returns true if the value returned by val_str() needs
244
230
   to be quoted when used in constructing an SQL query.
247
233
  virtual Item_result result_type () const=0;
248
234
  virtual Item_result cmp_type () const { return result_type(); }
249
235
  virtual Item_result cast_to_int_type () const { return result_type(); }
250
 
 
251
236
  /**
252
237
     Check whether a field type can be partially indexed by a key.
253
238
 
294
279
   */
295
280
  virtual bool eq_def(Field *field);
296
281
 
297
 
  virtual bool is_timestamp() const
298
 
  {
299
 
    return false;
300
 
  }
301
 
 
302
282
  /**
303
283
   * Returns size (in bytes) used to store field data in memory
304
284
   * (i.e. it returns the maximum size of the field in a row of the table,
597
577
  }
598
578
  void copy_from_tmp(int offset);
599
579
  uint32_t fill_cache_field(CacheField *copy);
600
 
  virtual bool get_date(type::Time &ltime,uint32_t fuzzydate);
601
 
  virtual bool get_time(type::Time &ltime);
 
580
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
581
  virtual bool get_time(DRIZZLE_TIME *ltime);
602
582
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
603
583
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
604
584
  virtual bool has_charset(void) const { return false; }
630
610
      0 otherwise
631
611
  */
632
612
  bool set_warning(DRIZZLE_ERROR::enum_warning_level,
633
 
                   drizzled::error_t code,
 
613
                   unsigned int code,
634
614
                   int cuted_increment);
635
615
  /**
636
616
    Produce warning or note about datetime string data saved into field.
648
628
      thread.
649
629
  */
650
630
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
651
 
                            drizzled::error_t code,
 
631
                            uint32_t code,
652
632
                            const char *str,
653
633
                            uint32_t str_len,
654
 
                            type::timestamp_t ts_type,
 
634
                            enum enum_drizzle_timestamp_type ts_type,
655
635
                            int cuted_increment);
656
636
  /**
657
637
    Produce warning or note about integer datetime value saved into field.
668
648
      thread.
669
649
  */
670
650
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
671
 
                            drizzled::error_t code,
 
651
                            uint32_t code,
672
652
                            int64_t nr,
673
 
                            type::timestamp_t ts_type,
 
653
                            enum enum_drizzle_timestamp_type ts_type,
674
654
                            int cuted_increment);
675
655
  /**
676
656
    Produce warning or note about double datetime data saved into field.
686
666
      thread.
687
667
  */
688
668
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
689
 
                            const drizzled::error_t code,
 
669
                            const uint32_t code,
690
670
                            double nr,
691
 
                            type::timestamp_t ts_type);
 
671
                            enum enum_drizzle_timestamp_type ts_type);
692
672
  bool check_overflow(int op_result)
693
673
  {
694
674
    return (op_result == E_DEC_OVERFLOW);
723
703
    @return
724
704
      value converted from val
725
705
  */
726
 
  int64_t convert_decimal2int64_t(const type::Decimal *val,
 
706
  int64_t convert_decimal2int64_t(const my_decimal *val,
727
707
                                  bool unsigned_flag,
728
708
                                  int *err);
729
709
  /* The max. number of characters */
759
739
  bool isWriteSet();
760
740
  void setReadSet(bool arg= true);
761
741
  void setWriteSet(bool arg= true);
762
 
 
763
 
protected:
764
 
 
765
 
  void pack_num(uint64_t arg, unsigned char *destination= NULL);
766
 
  void pack_num(uint32_t arg, unsigned char *destination= NULL);
767
 
  uint64_t unpack_num(uint64_t &destination, const unsigned char *arg= NULL) const;
768
 
  uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
769
742
};
770
743
 
771
744
std::ostream& operator<<(std::ostream& output, const Field &field);
802
775
  SendField() {}
803
776
};
804
777
 
 
778
/**
 
779
 * A class for quick copying data to fields
 
780
 */
 
781
class CopyField :public memory::SqlAlloc
 
782
{
 
783
  /**
 
784
    Convenience definition of a copy function returned by
 
785
    get_copy_func.
 
786
  */
 
787
  typedef void Copy_func(CopyField*);
 
788
  Copy_func *get_copy_func(Field *to, Field *from);
 
789
public:
 
790
  unsigned char *from_ptr;
 
791
  unsigned char *to_ptr;
 
792
  unsigned char *from_null_ptr;
 
793
  unsigned char *to_null_ptr;
 
794
  bool *null_row;
 
795
  uint32_t from_bit;
 
796
  uint32_t to_bit;
 
797
  uint32_t from_length;
 
798
  uint32_t to_length;
 
799
  Field *from_field;
 
800
  Field *to_field;
 
801
  String tmp;                                   // For items
 
802
 
 
803
  CopyField() {}
 
804
  ~CopyField() {}
 
805
  void set(Field *to,Field *from,bool save);    // Field to field
 
806
  void set(unsigned char *to,Field *from);              // Field to string
 
807
  void (*do_copy)(CopyField *);
 
808
  void (*do_copy2)(CopyField *);                // Used to handle null values
 
809
};
 
810
 
805
811
uint32_t pack_length_to_packflag(uint32_t type);
806
812
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
807
813
int set_field_to_null(Field *field);