~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Monty Taylor
  • Date: 2010-12-26 00:22:34 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101226002234-2sb62sm2gs0iftuy
Fixing some of the innodb c++ casting issues.

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/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
  {
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);
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(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
 
214
  virtual double val_real()=0;
 
215
  virtual int64_t val_int()=0;
 
216
  virtual my_decimal *val_decimal(my_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.
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,
363
349
  // For new field
364
350
  virtual uint32_t size_of() const =0;
365
351
 
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;
 
352
  bool is_null(ptrdiff_t row_offset= 0);
 
353
  bool is_real_null(ptrdiff_t row_offset= 0);
 
354
  bool is_null_in_record(const unsigned char *record);
 
355
  bool is_null_in_record_with_offset(ptrdiff_t offset);
370
356
  void set_null(ptrdiff_t row_offset= 0);
371
357
  void set_notnull(ptrdiff_t row_offset= 0);
372
 
  bool maybe_null(void) const;
373
 
  bool real_maybe_null(void) const;
 
358
  bool maybe_null(void);
 
359
  bool real_maybe_null(void);
374
360
 
375
361
  virtual void make_field(SendField *);
376
362
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
471
457
  int64_t val_int_internal(const unsigned char *new_ptr)
472
458
  {
473
459
    unsigned char *old_ptr= ptr;
 
460
    int64_t return_value;
474
461
    ptr= const_cast<unsigned char*>(new_ptr);
475
 
    int64_t return_value= val_int();
 
462
    return_value= val_int();
476
463
    ptr= old_ptr;
477
464
    return return_value;
478
465
  }
596
583
  }
597
584
  void copy_from_tmp(int offset);
598
585
  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;
 
586
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
587
  virtual bool get_time(DRIZZLE_TIME *ltime);
601
588
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
602
589
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
603
590
  virtual bool has_charset(void) const { return false; }
629
616
      0 otherwise
630
617
  */
631
618
  bool set_warning(DRIZZLE_ERROR::enum_warning_level,
632
 
                   drizzled::error_t code,
 
619
                   unsigned int code,
633
620
                   int cuted_increment);
634
621
  /**
635
622
    Produce warning or note about datetime string data saved into field.
647
634
      thread.
648
635
  */
649
636
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
650
 
                            drizzled::error_t code,
 
637
                            uint32_t code,
651
638
                            const char *str,
652
639
                            uint32_t str_len,
653
 
                            type::timestamp_t ts_type,
 
640
                            enum enum_drizzle_timestamp_type ts_type,
654
641
                            int cuted_increment);
655
642
  /**
656
643
    Produce warning or note about integer datetime value saved into field.
667
654
      thread.
668
655
  */
669
656
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
670
 
                            drizzled::error_t code,
 
657
                            uint32_t code,
671
658
                            int64_t nr,
672
 
                            type::timestamp_t ts_type,
 
659
                            enum enum_drizzle_timestamp_type ts_type,
673
660
                            int cuted_increment);
674
661
  /**
675
662
    Produce warning or note about double datetime data saved into field.
685
672
      thread.
686
673
  */
687
674
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
688
 
                            const drizzled::error_t code,
 
675
                            const uint32_t code,
689
676
                            double nr,
690
 
                            type::timestamp_t ts_type);
 
677
                            enum enum_drizzle_timestamp_type ts_type);
691
678
  bool check_overflow(int op_result)
692
679
  {
693
680
    return (op_result == E_DEC_OVERFLOW);
722
709
    @return
723
710
      value converted from val
724
711
  */
725
 
  int64_t convert_decimal2int64_t(const type::Decimal *val,
 
712
  int64_t convert_decimal2int64_t(const my_decimal *val,
726
713
                                  bool unsigned_flag,
727
714
                                  int *err);
728
715
  /* The max. number of characters */
738
725
  }
739
726
 
740
727
  /* Hash value */
741
 
  virtual void hash(uint32_t *nr, uint32_t *nr2) const;
 
728
  virtual void hash(uint32_t *nr, uint32_t *nr2);
742
729
  friend bool reopen_table(Session *,Table *,bool);
743
730
 
744
731
  friend class CopyField;
754
741
  friend class Item_sum_max;
755
742
  friend class Item_func_group_concat;
756
743
 
757
 
  bool isReadSet() const;
 
744
  bool isReadSet();
758
745
  bool isWriteSet();
759
746
  void setReadSet(bool arg= true);
760
747
  void setWriteSet(bool arg= true);
762
749
protected:
763
750
 
764
751
  void pack_num(uint64_t arg, unsigned char *destination= NULL);
765
 
  void pack_num(uint32_t arg, unsigned char *destination= NULL);
766
752
  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
753
};
769
754
 
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
755
std::ostream& operator<<(std::ostream& output, const Field &field);
803
756
 
804
757
} /* namespace drizzled */
805
758
 
806
759
/** @TODO Why is this in the middle of the file???*/
807
 
#include <drizzled/create_field.h>
 
760
#include "drizzled/create_field.h"
808
761
 
809
762
namespace drizzled
810
763
{
833
786
  SendField() {}
834
787
};
835
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
 
836
822
uint32_t pack_length_to_packflag(uint32_t type);
837
823
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
838
824
int set_field_to_null(Field *field);