~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Andrew Hutchings
  • Date: 2011-01-04 11:36:01 UTC
  • mto: This revision was merged to the branch mainline in revision 2057.
  • Revision ID: andrew@linuxjedi.co.uk-20110104113601-diiveyfl32dgaa6f
Refix using placement new for join code, vector for join cache buffer.
Also refix a bug in COND_CMP properly

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&);
98
93
   */
99
94
private:
100
95
  Table *table;
101
 
 
102
96
public:
103
97
  Table *getTable()
104
98
  {
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);
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
 
213
  virtual int store_time(type::Time *ltime, enum enum_drizzle_timestamp_type t_type);
 
214
  virtual double val_real()=0;
 
215
  virtual int64_t val_int()=0;
 
216
  virtual type::Decimal *val_decimal(type::Decimal *);
 
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
237
230
     an unnecessary free (and later, may be an alloc).
238
231
     This trickery is used to decrease a number of malloc calls.
239
232
  */
240
 
  virtual String *val_str(String*, String *) const =0;
241
 
 
 
233
  virtual String *val_str(String*, String *)=0;
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.
294
286
   */
295
287
  virtual bool eq_def(Field *field);
296
288
 
297
 
  virtual bool is_timestamp() const
298
 
  {
299
 
    return false;
300
 
  }
301
 
 
302
289
  /**
303
290
   * Returns size (in bytes) used to store field data in memory
304
291
   * (i.e. it returns the maximum size of the field in a row of the table,
363
350
  // For new field
364
351
  virtual uint32_t size_of() const =0;
365
352
 
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;
 
353
  bool is_null(ptrdiff_t row_offset= 0);
 
354
  bool is_real_null(ptrdiff_t row_offset= 0);
 
355
  bool is_null_in_record(const unsigned char *record);
 
356
  bool is_null_in_record_with_offset(ptrdiff_t offset);
370
357
  void set_null(ptrdiff_t row_offset= 0);
371
358
  void set_notnull(ptrdiff_t row_offset= 0);
372
 
  bool maybe_null(void) const;
373
 
  bool real_maybe_null(void) const;
 
359
  bool maybe_null(void);
 
360
  bool real_maybe_null(void);
374
361
 
375
362
  virtual void make_field(SendField *);
376
363
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
471
458
  int64_t val_int_internal(const unsigned char *new_ptr)
472
459
  {
473
460
    unsigned char *old_ptr= ptr;
 
461
    int64_t return_value;
474
462
    ptr= const_cast<unsigned char*>(new_ptr);
475
 
    int64_t return_value= val_int();
 
463
    return_value= val_int();
476
464
    ptr= old_ptr;
477
465
    return return_value;
478
466
  }
596
584
  }
597
585
  void copy_from_tmp(int offset);
598
586
  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;
 
587
  virtual bool get_date(type::Time *ltime,uint32_t fuzzydate);
 
588
  virtual bool get_time(type::Time *ltime);
601
589
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
602
590
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
603
591
  virtual bool has_charset(void) const { return false; }
629
617
      0 otherwise
630
618
  */
631
619
  bool set_warning(DRIZZLE_ERROR::enum_warning_level,
632
 
                   drizzled::error_t code,
 
620
                   unsigned int code,
633
621
                   int cuted_increment);
634
622
  /**
635
623
    Produce warning or note about datetime string data saved into field.
647
635
      thread.
648
636
  */
649
637
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
650
 
                            drizzled::error_t code,
 
638
                            uint32_t code,
651
639
                            const char *str,
652
640
                            uint32_t str_len,
653
 
                            type::timestamp_t ts_type,
 
641
                            enum enum_drizzle_timestamp_type ts_type,
654
642
                            int cuted_increment);
655
643
  /**
656
644
    Produce warning or note about integer datetime value saved into field.
667
655
      thread.
668
656
  */
669
657
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
670
 
                            drizzled::error_t code,
 
658
                            uint32_t code,
671
659
                            int64_t nr,
672
 
                            type::timestamp_t ts_type,
 
660
                            enum enum_drizzle_timestamp_type ts_type,
673
661
                            int cuted_increment);
674
662
  /**
675
663
    Produce warning or note about double datetime data saved into field.
685
673
      thread.
686
674
  */
687
675
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
688
 
                            const drizzled::error_t code,
 
676
                            const uint32_t code,
689
677
                            double nr,
690
 
                            type::timestamp_t ts_type);
 
678
                            enum enum_drizzle_timestamp_type ts_type);
691
679
  bool check_overflow(int op_result)
692
680
  {
693
681
    return (op_result == E_DEC_OVERFLOW);
738
726
  }
739
727
 
740
728
  /* Hash value */
741
 
  virtual void hash(uint32_t *nr, uint32_t *nr2) const;
 
729
  virtual void hash(uint32_t *nr, uint32_t *nr2);
742
730
  friend bool reopen_table(Session *,Table *,bool);
743
731
 
744
732
  friend class CopyField;
754
742
  friend class Item_sum_max;
755
743
  friend class Item_func_group_concat;
756
744
 
757
 
  bool isReadSet() const;
 
745
  bool isReadSet();
758
746
  bool isWriteSet();
759
747
  void setReadSet(bool arg= true);
760
748
  void setWriteSet(bool arg= true);
762
750
protected:
763
751
 
764
752
  void pack_num(uint64_t arg, unsigned char *destination= NULL);
765
 
  void pack_num(uint32_t arg, unsigned char *destination= NULL);
766
753
  uint64_t unpack_num(uint64_t &destination, const unsigned char *arg= NULL) const;
767
 
  uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
768
754
};
769
755
 
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
756
std::ostream& operator<<(std::ostream& output, const Field &field);
803
757
 
804
758
} /* namespace drizzled */
805
759
 
806
760
/** @TODO Why is this in the middle of the file???*/
807
 
#include <drizzled/create_field.h>
 
761
#include "drizzled/create_field.h"
808
762
 
809
763
namespace drizzled
810
764
{
833
787
  SendField() {}
834
788
};
835
789
 
 
790
/**
 
791
 * A class for quick copying data to fields
 
792
 */
 
793
class CopyField :public memory::SqlAlloc
 
794
{
 
795
  /**
 
796
    Convenience definition of a copy function returned by
 
797
    get_copy_func.
 
798
  */
 
799
  typedef void Copy_func(CopyField*);
 
800
  Copy_func *get_copy_func(Field *to, Field *from);
 
801
public:
 
802
  unsigned char *from_ptr;
 
803
  unsigned char *to_ptr;
 
804
  unsigned char *from_null_ptr;
 
805
  unsigned char *to_null_ptr;
 
806
  bool *null_row;
 
807
  uint32_t from_bit;
 
808
  uint32_t to_bit;
 
809
  uint32_t from_length;
 
810
  uint32_t to_length;
 
811
  Field *from_field;
 
812
  Field *to_field;
 
813
  String tmp;                                   // For items
 
814
 
 
815
  CopyField() {}
 
816
  ~CopyField() {}
 
817
  void set(Field *to,Field *from,bool save);    // Field to field
 
818
  void set(unsigned char *to,Field *from);              // Field to string
 
819
  void (*do_copy)(CopyField *);
 
820
  void (*do_copy2)(CopyField *);                // Used to handle null values
 
821
};
 
822
 
836
823
uint32_t pack_length_to_packflag(uint32_t type);
837
824
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
838
825
int set_field_to_null(Field *field);