~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Brian Aker
  • Date: 2011-02-08 02:06:04 UTC
  • mto: (2152.2.1 alter-table)
  • mto: This revision was merged to the branch mainline in revision 2154.
  • Revision ID: brian@tangent.org-20110208020604-p23mwd9yvamuwbwu
Merge in column varchar build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#ifndef DRIZZLED_FIELD_H
28
28
#define DRIZZLED_FIELD_H
29
29
 
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>
 
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/visibility.h"
38
38
 
39
39
#include <string>
40
40
#include <vector>
41
41
 
42
 
#include <drizzled/visibility.h>
 
42
#include "drizzled/visibility.h"
43
43
 
44
44
namespace drizzled
45
45
{
217
217
      Needs to be changed if/when we want to support different time formats.
218
218
  */
219
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
 
220
  virtual double val_real()=0;
 
221
  virtual int64_t val_int()=0;
 
222
  virtual type::Decimal *val_decimal(type::Decimal *);
 
223
  String *val_str_internal(String *str)
224
224
  {
225
225
    return val_str(str, str);
226
226
  }
237
237
     an unnecessary free (and later, may be an alloc).
238
238
     This trickery is used to decrease a number of malloc calls.
239
239
  */
240
 
  virtual String *val_str(String*, String *) const =0;
 
240
  virtual String *val_str(String*, String *)=0;
241
241
 
242
242
  /*
243
243
   str_needs_quotes() returns true if the value returned by val_str() needs
363
363
  // For new field
364
364
  virtual uint32_t size_of() const =0;
365
365
 
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;
 
366
  bool is_null(ptrdiff_t row_offset= 0);
 
367
  bool is_real_null(ptrdiff_t row_offset= 0);
 
368
  bool is_null_in_record(const unsigned char *record);
 
369
  bool is_null_in_record_with_offset(ptrdiff_t offset);
370
370
  void set_null(ptrdiff_t row_offset= 0);
371
371
  void set_notnull(ptrdiff_t row_offset= 0);
372
 
  bool maybe_null(void) const;
373
 
  bool real_maybe_null(void) const;
 
372
  bool maybe_null(void);
 
373
  bool real_maybe_null(void);
374
374
 
375
375
  virtual void make_field(SendField *);
376
376
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
471
471
  int64_t val_int_internal(const unsigned char *new_ptr)
472
472
  {
473
473
    unsigned char *old_ptr= ptr;
 
474
    int64_t return_value;
474
475
    ptr= const_cast<unsigned char*>(new_ptr);
475
 
    int64_t return_value= val_int();
 
476
    return_value= val_int();
476
477
    ptr= old_ptr;
477
478
    return return_value;
478
479
  }
596
597
  }
597
598
  void copy_from_tmp(int offset);
598
599
  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;
 
600
  virtual bool get_date(type::Time &ltime,uint32_t fuzzydate);
 
601
  virtual bool get_time(type::Time &ltime);
601
602
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
602
603
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
603
604
  virtual bool has_charset(void) const { return false; }
738
739
  }
739
740
 
740
741
  /* Hash value */
741
 
  virtual void hash(uint32_t *nr, uint32_t *nr2) const;
 
742
  virtual void hash(uint32_t *nr, uint32_t *nr2);
742
743
  friend bool reopen_table(Session *,Table *,bool);
743
744
 
744
745
  friend class CopyField;
754
755
  friend class Item_sum_max;
755
756
  friend class Item_func_group_concat;
756
757
 
757
 
  bool isReadSet() const;
 
758
  bool isReadSet();
758
759
  bool isWriteSet();
759
760
  void setReadSet(bool arg= true);
760
761
  void setWriteSet(bool arg= true);
767
768
  uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
768
769
};
769
770
 
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
771
std::ostream& operator<<(std::ostream& output, const Field &field);
803
772
 
804
773
} /* namespace drizzled */
805
774
 
806
775
/** @TODO Why is this in the middle of the file???*/
807
 
#include <drizzled/create_field.h>
 
776
#include "drizzled/create_field.h"
808
777
 
809
778
namespace drizzled
810
779
{
833
802
  SendField() {}
834
803
};
835
804
 
 
805
/**
 
806
 * A class for quick copying data to fields
 
807
 */
 
808
class CopyField :public memory::SqlAlloc
 
809
{
 
810
  /**
 
811
    Convenience definition of a copy function returned by
 
812
    get_copy_func.
 
813
  */
 
814
  typedef void Copy_func(CopyField*);
 
815
  Copy_func *get_copy_func(Field *to, Field *from);
 
816
 
 
817
public:
 
818
  unsigned char *from_ptr;
 
819
  unsigned char *to_ptr;
 
820
  unsigned char *from_null_ptr;
 
821
  unsigned char *to_null_ptr;
 
822
  bool *null_row;
 
823
  uint32_t from_bit;
 
824
  uint32_t to_bit;
 
825
  uint32_t from_length;
 
826
  uint32_t to_length;
 
827
  Field *from_field;
 
828
  Field *to_field;
 
829
  String tmp;                                   // For items
 
830
 
 
831
  CopyField() :
 
832
    from_ptr(0),
 
833
    to_ptr(0),
 
834
    from_null_ptr(0),
 
835
    to_null_ptr(0),
 
836
    null_row(0),
 
837
    from_bit(0),
 
838
    to_bit(0),
 
839
    from_length(0),
 
840
    to_length(0),
 
841
    from_field(0),
 
842
    to_field(0)
 
843
  {}
 
844
 
 
845
  ~CopyField()
 
846
  {}
 
847
 
 
848
  void set(Field *to,Field *from,bool save);    // Field to field
 
849
  void set(unsigned char *to,Field *from);              // Field to string
 
850
  void (*do_copy)(CopyField *);
 
851
  void (*do_copy2)(CopyField *);                // Used to handle null values
 
852
};
 
853
 
836
854
uint32_t pack_length_to_packflag(uint32_t type);
837
855
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
838
856
int set_field_to_null(Field *field);