~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

edit

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
 
#include <drizzled/sql_error.h>
31
 
#include <drizzled/type/decimal.h>
32
 
#include <drizzled/key_map.h>
33
 
#include <drizzled/sql_list.h>
34
 
#include <drizzled/structs.h>
35
 
#include <drizzled/charset_info.h>
36
 
#include <drizzled/item_result.h>
37
 
#include <drizzled/charset_info.h>
 
28
#include "drizzled/sql_error.h"
 
29
#include "drizzled/type/decimal.h"
 
30
#include "drizzled/key_map.h"
 
31
#include "drizzled/sql_list.h"
 
32
#include "drizzled/structs.h"
 
33
#include "drizzled/charset_info.h"
 
34
#include "drizzled/item_result.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&);
216
211
    @note
217
212
      Needs to be changed if/when we want to support different time formats.
218
213
  */
219
 
  virtual int store_time(type::Time &ltime, type::timestamp_t t_type);
220
 
  virtual double val_real() const=0;
221
 
  virtual int64_t val_int() const =0;
222
 
  virtual type::Decimal *val_decimal(type::Decimal *) const;
223
 
  String *val_str_internal(String *str) const
 
214
  virtual int store_time(type::Time *ltime, enum enum_drizzle_timestamp_type t_type);
 
215
  virtual double val_real()=0;
 
216
  virtual int64_t val_int()=0;
 
217
  virtual type::Decimal *val_decimal(type::Decimal *);
 
218
  String *val_str_internal(String *str)
224
219
  {
225
220
    return val_str(str, str);
226
221
  }
227
 
 
228
222
  /*
229
223
     val_str(buf1, buf2) gets two buffers and should use them as follows:
230
224
     if it needs a temp buffer to convert result to string - use buf1
237
231
     an unnecessary free (and later, may be an alloc).
238
232
     This trickery is used to decrease a number of malloc calls.
239
233
  */
240
 
  virtual String *val_str(String*, String *) const =0;
241
 
 
 
234
  virtual String *val_str(String*, String *)=0;
242
235
  /*
243
236
   str_needs_quotes() returns true if the value returned by val_str() needs
244
237
   to be quoted when used in constructing an SQL query.
363
356
  // For new field
364
357
  virtual uint32_t size_of() const =0;
365
358
 
366
 
  bool is_null(ptrdiff_t row_offset= 0) const;
367
 
  bool is_real_null(ptrdiff_t row_offset= 0) const;
368
 
  bool is_null_in_record(const unsigned char *record) const;
369
 
  bool is_null_in_record_with_offset(ptrdiff_t offset) const;
 
359
  bool is_null(ptrdiff_t row_offset= 0);
 
360
  bool is_real_null(ptrdiff_t row_offset= 0);
 
361
  bool is_null_in_record(const unsigned char *record);
 
362
  bool is_null_in_record_with_offset(ptrdiff_t offset);
370
363
  void set_null(ptrdiff_t row_offset= 0);
371
364
  void set_notnull(ptrdiff_t row_offset= 0);
372
 
  bool maybe_null(void) const;
373
 
  bool real_maybe_null(void) const;
 
365
  bool maybe_null(void);
 
366
  bool real_maybe_null(void);
374
367
 
375
368
  virtual void make_field(SendField *);
376
369
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
471
464
  int64_t val_int_internal(const unsigned char *new_ptr)
472
465
  {
473
466
    unsigned char *old_ptr= ptr;
 
467
    int64_t return_value;
474
468
    ptr= const_cast<unsigned char*>(new_ptr);
475
 
    int64_t return_value= val_int();
 
469
    return_value= val_int();
476
470
    ptr= old_ptr;
477
471
    return return_value;
478
472
  }
596
590
  }
597
591
  void copy_from_tmp(int offset);
598
592
  uint32_t fill_cache_field(CacheField *copy);
599
 
  virtual bool get_date(type::Time &ltime,uint32_t fuzzydate) const;
600
 
  virtual bool get_time(type::Time &ltime) const;
 
593
  virtual bool get_date(type::Time *ltime,uint32_t fuzzydate);
 
594
  virtual bool get_time(type::Time *ltime);
601
595
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
602
596
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
603
597
  virtual bool has_charset(void) const { return false; }
650
644
                            drizzled::error_t code,
651
645
                            const char *str,
652
646
                            uint32_t str_len,
653
 
                            type::timestamp_t ts_type,
 
647
                            enum enum_drizzle_timestamp_type ts_type,
654
648
                            int cuted_increment);
655
649
  /**
656
650
    Produce warning or note about integer datetime value saved into field.
669
663
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
670
664
                            drizzled::error_t code,
671
665
                            int64_t nr,
672
 
                            type::timestamp_t ts_type,
 
666
                            enum enum_drizzle_timestamp_type ts_type,
673
667
                            int cuted_increment);
674
668
  /**
675
669
    Produce warning or note about double datetime data saved into field.
687
681
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
688
682
                            const drizzled::error_t code,
689
683
                            double nr,
690
 
                            type::timestamp_t ts_type);
 
684
                            enum enum_drizzle_timestamp_type ts_type);
691
685
  bool check_overflow(int op_result)
692
686
  {
693
687
    return (op_result == E_DEC_OVERFLOW);
738
732
  }
739
733
 
740
734
  /* Hash value */
741
 
  virtual void hash(uint32_t *nr, uint32_t *nr2) const;
 
735
  virtual void hash(uint32_t *nr, uint32_t *nr2);
742
736
  friend bool reopen_table(Session *,Table *,bool);
743
737
 
744
738
  friend class CopyField;
754
748
  friend class Item_sum_max;
755
749
  friend class Item_func_group_concat;
756
750
 
757
 
  bool isReadSet() const;
 
751
  bool isReadSet();
758
752
  bool isWriteSet();
759
753
  void setReadSet(bool arg= true);
760
754
  void setWriteSet(bool arg= true);
767
761
  uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
768
762
};
769
763
 
770
 
namespace field {
771
 
 
772
 
inline bool isDateTime(const enum_field_types &arg)
773
 
{
774
 
  switch (arg)
775
 
  {
776
 
  case DRIZZLE_TYPE_DATE:
777
 
  case DRIZZLE_TYPE_DATETIME:
778
 
  case DRIZZLE_TYPE_MICROTIME:
779
 
  case DRIZZLE_TYPE_TIME:
780
 
  case DRIZZLE_TYPE_TIMESTAMP:
781
 
    return true;
782
 
 
783
 
  case DRIZZLE_TYPE_BLOB:
784
 
  case DRIZZLE_TYPE_BOOLEAN:
785
 
  case DRIZZLE_TYPE_DECIMAL:
786
 
  case DRIZZLE_TYPE_DOUBLE:
787
 
  case DRIZZLE_TYPE_ENUM:
788
 
  case DRIZZLE_TYPE_LONG:
789
 
  case DRIZZLE_TYPE_LONGLONG:
790
 
  case DRIZZLE_TYPE_NULL:
791
 
  case DRIZZLE_TYPE_UUID:
792
 
  case DRIZZLE_TYPE_VARCHAR:
793
 
    return false;
794
 
  }
795
 
 
796
 
  assert(0);
797
 
  abort();
798
 
}
799
 
 
800
 
} // namespace field
801
 
 
802
764
std::ostream& operator<<(std::ostream& output, const Field &field);
803
765
 
804
766
} /* namespace drizzled */
805
767
 
806
768
/** @TODO Why is this in the middle of the file???*/
807
 
#include <drizzled/create_field.h>
 
769
#include "drizzled/create_field.h"
808
770
 
809
771
namespace drizzled
810
772
{
833
795
  SendField() {}
834
796
};
835
797
 
 
798
/**
 
799
 * A class for quick copying data to fields
 
800
 */
 
801
class CopyField :public memory::SqlAlloc
 
802
{
 
803
  /**
 
804
    Convenience definition of a copy function returned by
 
805
    get_copy_func.
 
806
  */
 
807
  typedef void Copy_func(CopyField*);
 
808
  Copy_func *get_copy_func(Field *to, Field *from);
 
809
 
 
810
public:
 
811
  unsigned char *from_ptr;
 
812
  unsigned char *to_ptr;
 
813
  unsigned char *from_null_ptr;
 
814
  unsigned char *to_null_ptr;
 
815
  bool *null_row;
 
816
  uint32_t from_bit;
 
817
  uint32_t to_bit;
 
818
  uint32_t from_length;
 
819
  uint32_t to_length;
 
820
  Field *from_field;
 
821
  Field *to_field;
 
822
  String tmp;                                   // For items
 
823
 
 
824
  CopyField() :
 
825
    from_ptr(0),
 
826
    to_ptr(0),
 
827
    from_null_ptr(0),
 
828
    to_null_ptr(0),
 
829
    null_row(0),
 
830
    from_bit(0),
 
831
    to_bit(0),
 
832
    from_length(0),
 
833
    to_length(0),
 
834
    from_field(0),
 
835
    to_field(0)
 
836
  {}
 
837
 
 
838
  ~CopyField()
 
839
  {}
 
840
 
 
841
  void set(Field *to,Field *from,bool save);    // Field to field
 
842
  void set(unsigned char *to,Field *from);              // Field to string
 
843
  void (*do_copy)(CopyField *);
 
844
  void (*do_copy2)(CopyField *);                // Used to handle null values
 
845
};
 
846
 
836
847
uint32_t pack_length_to_packflag(uint32_t type);
837
848
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
838
849
int set_field_to_null(Field *field);