~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Lee Bieber
  • Date: 2010-12-23 23:11:00 UTC
  • mfrom: (2024.1.1 clean)
  • Revision ID: kalebral@gmail.com-20101223231100-0rqirgz7ugkl10yp
Merge Brian - session list cleanup

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
  {
205
199
                    const CHARSET_INFO * const cs)=0;
206
200
  virtual int store(double nr)=0;
207
201
  virtual int store(int64_t nr, bool unsigned_val)=0;
208
 
  virtual int store_decimal(const type::Decimal *d)=0;
 
202
  virtual int store_decimal(const my_decimal *d)=0;
209
203
  int store_and_check(enum_check_fields check_level,
210
204
                      const char *to,
211
205
                      uint32_t length,
216
210
    @note
217
211
      Needs to be changed if/when we want to support different time formats.
218
212
  */
219
 
  virtual int store_time(type::Time &ltime, type::timestamp_t t_type);
 
213
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
220
214
  virtual double val_real()=0;
221
215
  virtual int64_t val_int()=0;
222
 
  virtual type::Decimal *val_decimal(type::Decimal *);
 
216
  virtual my_decimal *val_decimal(my_decimal *);
223
217
  String *val_str_internal(String *str)
224
218
  {
225
219
    return val_str(str, str);
226
220
  }
227
 
 
228
221
  /*
229
222
     val_str(buf1, buf2) gets two buffers and should use them as follows:
230
223
     if it needs a temp buffer to convert result to string - use buf1
238
231
     This trickery is used to decrease a number of malloc calls.
239
232
  */
240
233
  virtual String *val_str(String*, String *)=0;
241
 
 
242
234
  /*
243
235
   str_needs_quotes() returns true if the value returned by val_str() needs
244
236
   to be quoted when used in constructing an SQL query.
247
239
  virtual Item_result result_type () const=0;
248
240
  virtual Item_result cmp_type () const { return result_type(); }
249
241
  virtual Item_result cast_to_int_type () const { return result_type(); }
250
 
 
251
242
  /**
252
243
     Check whether a field type can be partially indexed by a key.
253
244
 
294
285
   */
295
286
  virtual bool eq_def(Field *field);
296
287
 
297
 
  virtual bool is_timestamp() const
298
 
  {
299
 
    return false;
300
 
  }
301
 
 
302
288
  /**
303
289
   * Returns size (in bytes) used to store field data in memory
304
290
   * (i.e. it returns the maximum size of the field in a row of the table,
597
583
  }
598
584
  void copy_from_tmp(int offset);
599
585
  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);
 
586
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
587
  virtual bool get_time(DRIZZLE_TIME *ltime);
602
588
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
603
589
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
604
590
  virtual bool has_charset(void) const { return false; }
630
616
      0 otherwise
631
617
  */
632
618
  bool set_warning(DRIZZLE_ERROR::enum_warning_level,
633
 
                   drizzled::error_t code,
 
619
                   unsigned int code,
634
620
                   int cuted_increment);
635
621
  /**
636
622
    Produce warning or note about datetime string data saved into field.
648
634
      thread.
649
635
  */
650
636
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
651
 
                            drizzled::error_t code,
 
637
                            uint32_t code,
652
638
                            const char *str,
653
639
                            uint32_t str_len,
654
 
                            type::timestamp_t ts_type,
 
640
                            enum enum_drizzle_timestamp_type ts_type,
655
641
                            int cuted_increment);
656
642
  /**
657
643
    Produce warning or note about integer datetime value saved into field.
668
654
      thread.
669
655
  */
670
656
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
671
 
                            drizzled::error_t code,
 
657
                            uint32_t code,
672
658
                            int64_t nr,
673
 
                            type::timestamp_t ts_type,
 
659
                            enum enum_drizzle_timestamp_type ts_type,
674
660
                            int cuted_increment);
675
661
  /**
676
662
    Produce warning or note about double datetime data saved into field.
686
672
      thread.
687
673
  */
688
674
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
689
 
                            const drizzled::error_t code,
 
675
                            const uint32_t code,
690
676
                            double nr,
691
 
                            type::timestamp_t ts_type);
 
677
                            enum enum_drizzle_timestamp_type ts_type);
692
678
  bool check_overflow(int op_result)
693
679
  {
694
680
    return (op_result == E_DEC_OVERFLOW);
723
709
    @return
724
710
      value converted from val
725
711
  */
726
 
  int64_t convert_decimal2int64_t(const type::Decimal *val,
 
712
  int64_t convert_decimal2int64_t(const my_decimal *val,
727
713
                                  bool unsigned_flag,
728
714
                                  int *err);
729
715
  /* The max. number of characters */
763
749
protected:
764
750
 
765
751
  void pack_num(uint64_t arg, unsigned char *destination= NULL);
766
 
  void pack_num(uint32_t arg, unsigned char *destination= NULL);
767
752
  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
753
};
770
754
 
771
755
std::ostream& operator<<(std::ostream& output, const Field &field);
802
786
  SendField() {}
803
787
};
804
788
 
 
789
/**
 
790
 * A class for quick copying data to fields
 
791
 */
 
792
class CopyField :public memory::SqlAlloc
 
793
{
 
794
  /**
 
795
    Convenience definition of a copy function returned by
 
796
    get_copy_func.
 
797
  */
 
798
  typedef void Copy_func(CopyField*);
 
799
  Copy_func *get_copy_func(Field *to, Field *from);
 
800
public:
 
801
  unsigned char *from_ptr;
 
802
  unsigned char *to_ptr;
 
803
  unsigned char *from_null_ptr;
 
804
  unsigned char *to_null_ptr;
 
805
  bool *null_row;
 
806
  uint32_t from_bit;
 
807
  uint32_t to_bit;
 
808
  uint32_t from_length;
 
809
  uint32_t to_length;
 
810
  Field *from_field;
 
811
  Field *to_field;
 
812
  String tmp;                                   // For items
 
813
 
 
814
  CopyField() {}
 
815
  ~CopyField() {}
 
816
  void set(Field *to,Field *from,bool save);    // Field to field
 
817
  void set(unsigned char *to,Field *from);              // Field to string
 
818
  void (*do_copy)(CopyField *);
 
819
  void (*do_copy2)(CopyField *);                // Used to handle null values
 
820
};
 
821
 
805
822
uint32_t pack_length_to_packflag(uint32_t type);
806
823
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
807
824
int set_field_to_null(Field *field);