~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Brian Aker
  • Date: 2010-10-07 20:00:40 UTC
  • mto: (1822.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1823.
  • Revision ID: brian@tangent.org-20101007200040-st5l46s5i445vxoz
We no longer needed to look at the share when removing tables.

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;
80
81
  /* Prevent use of these */
81
82
  Field(const Field&);
82
83
  void operator=(Field &);
83
 
 
84
84
public:
85
85
  unsigned char *ptr; /**< Position to field in record. Stores raw field value */
86
86
  unsigned char *null_ptr; /**< Byte where null_bit is */
141
141
  utype unireg_check;
142
142
  uint32_t field_length; /**< Length of this field in bytes */
143
143
  uint32_t flags;
144
 
private:
145
144
  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
145
  unsigned char null_bit; /**< Bit used to test null bit */
160
146
  /**
161
147
     If true, this field was created in create_tmp_field_from_item from a NULL
171
157
  static void *operator new(size_t size, memory::Root *mem_root);
172
158
  static void operator delete(void *, size_t)
173
159
  { }
174
 
  static void operator delete(void *, memory::Root *)
175
 
  { }
176
160
 
177
161
  Field(unsigned char *ptr_arg,
178
162
        uint32_t length_arg,
181
165
        utype unireg_check_arg,
182
166
        const char *field_name_arg);
183
167
  virtual ~Field() {}
184
 
 
185
 
  bool hasDefault() const
186
 
  {
187
 
    return not (flags & NO_DEFAULT_VALUE_FLAG);
188
 
  }
189
 
 
190
168
  /* Store functions returns 1 on overflow and -1 on fatal error */
191
169
  virtual int store(const char *to,
192
170
                    uint32_t length,
194
172
  virtual int store(double nr)=0;
195
173
  virtual int store(int64_t nr, bool unsigned_val)=0;
196
174
  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);
 
175
  int store(const char *to,
 
176
            uint32_t length,
 
177
            const CHARSET_INFO * const cs,
 
178
            enum_check_fields check_level);
201
179
  /**
202
180
    This is called when storing a date in a string.
203
181
 
205
183
      Needs to be changed if/when we want to support different time formats.
206
184
  */
207
185
  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;
 
186
  virtual double val_real(void)=0;
 
187
  virtual int64_t val_int(void)=0;
210
188
  virtual my_decimal *val_decimal(my_decimal *);
211
 
  String *val_str_internal(String *str)
 
189
  inline String *val_str(String *str)
212
190
  {
213
191
    return val_str(str, str);
214
192
  }
322
300
  virtual uint32_t key_length() const;
323
301
  virtual enum_field_types type() const =0;
324
302
  virtual enum_field_types real_type() const;
325
 
  virtual int cmp_max(const unsigned char *a, const unsigned char *b, uint32_t max_len);
 
303
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
 
304
  virtual int cmp_max(const unsigned char *a, const unsigned char *b,
 
305
                      uint32_t max_len);
326
306
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
327
 
  int cmp_internal(const unsigned char *str) { return cmp(ptr,str); }
328
307
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
329
308
                         uint32_t max_length=UINT32_MAX);
330
309
  virtual int cmp_offset(uint32_t row_offset);
376
355
                               uint32_t new_null_bit);
377
356
  /** This is used to generate a field in Table from TableShare */
378
357
  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)
 
358
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
380
359
  {
381
360
    ptr= ptr_arg;
382
361
    null_ptr= null_ptr_arg;
383
362
    null_bit= null_bit_arg;
384
363
  }
385
 
  void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
 
364
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
386
365
  virtual void move_field_offset(ptrdiff_t ptr_diff)
387
366
  {
388
367
    ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
440
419
  {
441
420
    set_image(buff,length, &my_charset_bin);
442
421
  }
443
 
  int64_t val_int_offset(uint32_t row_offset)
 
422
  inline int64_t val_int_offset(uint32_t row_offset)
444
423
  {
445
424
    ptr+=row_offset;
446
425
    int64_t tmp=val_int();
448
427
    return tmp;
449
428
  }
450
429
 
451
 
  int64_t val_int_internal(const unsigned char *new_ptr)
 
430
  inline int64_t val_int(const unsigned char *new_ptr)
452
431
  {
453
432
    unsigned char *old_ptr= ptr;
454
433
    int64_t return_value;
457
436
    ptr= old_ptr;
458
437
    return return_value;
459
438
  }
460
 
 
461
 
  String *val_str_internal(String *str, const unsigned char *new_ptr)
 
439
  inline String *val_str(String *str, const unsigned char *new_ptr)
462
440
  {
463
441
    unsigned char *old_ptr= ptr;
464
442
    ptr= const_cast<unsigned char*>(new_ptr);
465
 
    val_str_internal(str);
 
443
    val_str(str);
466
444
    ptr= old_ptr;
467
445
    return str;
468
446
  }
571
549
    return max_length;
572
550
  }
573
551
 
574
 
  uint32_t offset(const unsigned char *record)
 
552
  inline uint32_t offset(const unsigned char *record)
575
553
  {
576
554
    return (uint32_t) (ptr - record);
577
555
  }
669
647
                            const uint32_t code,
670
648
                            double nr,
671
649
                            enum enum_drizzle_timestamp_type ts_type);
672
 
  bool check_overflow(int op_result)
 
650
  inline bool check_overflow(int op_result)
673
651
  {
674
652
    return (op_result == E_DEC_OVERFLOW);
675
653
  }
707
685
                                  bool unsigned_flag,
708
686
                                  int *err);
709
687
  /* The max. number of characters */
710
 
  uint32_t char_length() const
 
688
  inline uint32_t char_length() const
711
689
  {
712
690
    return field_length / charset()->mbmaxlen;
713
691
  }
714
692
 
715
 
  enum column_format_type column_format() const
 
693
  inline enum column_format_type column_format() const
716
694
  {
717
695
    return (enum column_format_type)
718
696
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
741
719
  void setWriteSet(bool arg= true);
742
720
};
743
721
 
744
 
std::ostream& operator<<(std::ostream& output, const Field &field);
745
 
 
746
722
} /* namespace drizzled */
747
723
 
748
724
/** @TODO Why is this in the middle of the file???*/