~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Brian Aker
  • Date: 2010-09-12 01:42:27 UTC
  • mto: (1759.2.1 build)
  • mto: This revision was merged to the branch mainline in revision 1762.
  • Revision ID: brian@tangent.org-20100912014227-krt6d9z5ohqrokhb
Add two plugins to handle the string and math functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "drizzled/sql_error.h"
29
29
#include "drizzled/decimal.h"
30
30
#include "drizzled/key_map.h"
 
31
#include "drizzled/sql_bitmap.h"
31
32
#include "drizzled/sql_list.h"
32
33
#include "drizzled/structs.h"
33
34
#include "drizzled/charset_info.h"
46
47
#define ASSERT_COLUMN_MARKED_FOR_READ assert(!getTable() || (getTable()->read_set == NULL || isReadSet()))
47
48
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(!getTable() || (getTable()->write_set == NULL || isWriteSet()))
48
49
#else
49
 
#define ASSERT_COLUMN_MARKED_FOR_READ assert(getTable())
50
 
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(getTable())
 
50
#define ASSERT_COLUMN_MARKED_FOR_READ
 
51
#define ASSERT_COLUMN_MARKED_FOR_WRITE
51
52
#endif
52
53
 
53
54
typedef struct st_typelib TYPELIB;
62
63
 
63
64
int field_conv(Field *to,Field *from);
64
65
 
 
66
inline uint32_t get_enum_pack_length(int elements)
 
67
{
 
68
  return elements < 256 ? 1 : 2;
 
69
}
 
70
 
65
71
/**
66
72
 * Class representing a Field in a Table
67
73
 *
80
86
  /* Prevent use of these */
81
87
  Field(const Field&);
82
88
  void operator=(Field &);
83
 
 
84
89
public:
85
90
  unsigned char *ptr; /**< Position to field in record. Stores raw field value */
86
91
  unsigned char *null_ptr; /**< Byte where null_bit is */
141
146
  utype unireg_check;
142
147
  uint32_t field_length; /**< Length of this field in bytes */
143
148
  uint32_t flags;
144
 
private:
145
149
  uint16_t field_index; /**< Index of this Field in Table::fields array */
146
 
 
147
 
public:
148
 
 
149
 
  uint16_t position() const
150
 
  {
151
 
    return field_index;
152
 
  }
153
 
 
154
 
  void setPosition(uint32_t arg)
155
 
  {
156
 
    field_index= arg;
157
 
  }
158
 
 
159
150
  unsigned char null_bit; /**< Bit used to test null bit */
160
151
  /**
161
152
     If true, this field was created in create_tmp_field_from_item from a NULL
171
162
  static void *operator new(size_t size, memory::Root *mem_root);
172
163
  static void operator delete(void *, size_t)
173
164
  { }
174
 
  static void operator delete(void *, memory::Root *)
175
 
  { }
176
165
 
177
166
  Field(unsigned char *ptr_arg,
178
167
        uint32_t length_arg,
181
170
        utype unireg_check_arg,
182
171
        const char *field_name_arg);
183
172
  virtual ~Field() {}
184
 
 
185
 
  bool hasDefault() const
186
 
  {
187
 
    return not (flags & NO_DEFAULT_VALUE_FLAG);
188
 
  }
189
 
 
190
173
  /* Store functions returns 1 on overflow and -1 on fatal error */
191
174
  virtual int store(const char *to,
192
175
                    uint32_t length,
194
177
  virtual int store(double nr)=0;
195
178
  virtual int store(int64_t nr, bool unsigned_val)=0;
196
179
  virtual int store_decimal(const my_decimal *d)=0;
197
 
  int store_and_check(enum_check_fields check_level,
198
 
                      const char *to,
199
 
                      uint32_t length,
200
 
                      const CHARSET_INFO * const cs);
 
180
  int store(const char *to,
 
181
            uint32_t length,
 
182
            const CHARSET_INFO * const cs,
 
183
            enum_check_fields check_level);
201
184
  /**
202
185
    This is called when storing a date in a string.
203
186
 
205
188
      Needs to be changed if/when we want to support different time formats.
206
189
  */
207
190
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
208
 
  virtual double val_real()=0;
209
 
  virtual int64_t val_int()=0;
 
191
  virtual double val_real(void)=0;
 
192
  virtual int64_t val_int(void)=0;
210
193
  virtual my_decimal *val_decimal(my_decimal *);
211
 
  String *val_str_internal(String *str)
 
194
  inline String *val_str(String *str)
212
195
  {
213
196
    return val_str(str, str);
214
197
  }
322
305
  virtual uint32_t key_length() const;
323
306
  virtual enum_field_types type() const =0;
324
307
  virtual enum_field_types real_type() const;
325
 
  virtual int cmp_max(const unsigned char *a, const unsigned char *b, uint32_t max_len);
 
308
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
 
309
  virtual int cmp_max(const unsigned char *a, const unsigned char *b,
 
310
                      uint32_t max_len);
326
311
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
327
 
  int cmp_internal(const unsigned char *str) { return cmp(ptr,str); }
328
312
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
329
313
                         uint32_t max_length=UINT32_MAX);
330
314
  virtual int cmp_offset(uint32_t row_offset);
376
360
                               uint32_t new_null_bit);
377
361
  /** This is used to generate a field in Table from TableShare */
378
362
  Field *clone(memory::Root *mem_root, Table *new_table);
379
 
  void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
 
363
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
380
364
  {
381
365
    ptr= ptr_arg;
382
366
    null_ptr= null_ptr_arg;
383
367
    null_bit= null_bit_arg;
384
368
  }
385
 
  void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
 
369
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
386
370
  virtual void move_field_offset(ptrdiff_t ptr_diff)
387
371
  {
388
372
    ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
440
424
  {
441
425
    set_image(buff,length, &my_charset_bin);
442
426
  }
443
 
  int64_t val_int_offset(uint32_t row_offset)
 
427
  inline int64_t val_int_offset(uint32_t row_offset)
444
428
  {
445
429
    ptr+=row_offset;
446
430
    int64_t tmp=val_int();
448
432
    return tmp;
449
433
  }
450
434
 
451
 
  int64_t val_int_internal(const unsigned char *new_ptr)
 
435
  inline int64_t val_int(const unsigned char *new_ptr)
452
436
  {
453
437
    unsigned char *old_ptr= ptr;
454
438
    int64_t return_value;
457
441
    ptr= old_ptr;
458
442
    return return_value;
459
443
  }
460
 
 
461
 
  String *val_str_internal(String *str, const unsigned char *new_ptr)
 
444
  inline String *val_str(String *str, const unsigned char *new_ptr)
462
445
  {
463
446
    unsigned char *old_ptr= ptr;
464
447
    ptr= const_cast<unsigned char*>(new_ptr);
465
 
    val_str_internal(str);
 
448
    val_str(str);
466
449
    ptr= old_ptr;
467
450
    return str;
468
451
  }
571
554
    return max_length;
572
555
  }
573
556
 
574
 
  uint32_t offset(const unsigned char *record)
 
557
  inline uint32_t offset(const unsigned char *record)
575
558
  {
576
559
    return (uint32_t) (ptr - record);
577
560
  }
669
652
                            const uint32_t code,
670
653
                            double nr,
671
654
                            enum enum_drizzle_timestamp_type ts_type);
672
 
  bool check_overflow(int op_result)
 
655
  inline bool check_overflow(int op_result)
673
656
  {
674
657
    return (op_result == E_DEC_OVERFLOW);
675
658
  }
707
690
                                  bool unsigned_flag,
708
691
                                  int *err);
709
692
  /* The max. number of characters */
710
 
  uint32_t char_length() const
 
693
  inline uint32_t char_length() const
711
694
  {
712
695
    return field_length / charset()->mbmaxlen;
713
696
  }
714
697
 
715
 
  enum column_format_type column_format() const
 
698
  inline enum column_format_type column_format() const
716
699
  {
717
700
    return (enum column_format_type)
718
701
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
741
724
  void setWriteSet(bool arg= true);
742
725
};
743
726
 
744
 
std::ostream& operator<<(std::ostream& output, const Field &field);
745
 
 
746
727
} /* namespace drizzled */
747
728
 
748
729
/** @TODO Why is this in the middle of the file???*/