~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: Monty Taylor
  • Date: 2010-12-03 19:56:07 UTC
  • mto: (1975.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1976.
  • Revision ID: mordred@inaugust.com-20101203195607-yw50aynlw04dt5k6
All protocol stuff except for the buffer_length. WTF?

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
26
26
#define DRIZZLED_FIELD_H
27
27
 
28
28
#include "drizzled/sql_error.h"
29
 
#include "drizzled/type/decimal.h"
 
29
#include "drizzled/decimal.h"
30
30
#include "drizzled/key_map.h"
31
31
#include "drizzled/sql_list.h"
32
32
#include "drizzled/structs.h"
80
80
  /* Prevent use of these */
81
81
  Field(const Field&);
82
82
  void operator=(Field &);
83
 
 
84
83
public:
85
84
  unsigned char *ptr; /**< Position to field in record. Stores raw field value */
86
85
  unsigned char *null_ptr; /**< Byte where null_bit is */
93
92
   */
94
93
private:
95
94
  Table *table;
96
 
 
97
95
public:
98
96
  Table *getTable()
99
97
  {
142
140
  utype unireg_check;
143
141
  uint32_t field_length; /**< Length of this field in bytes */
144
142
  uint32_t flags;
145
 
 
146
 
  bool isUnsigned() const
147
 
  {
148
 
    return flags & UNSIGNED_FLAG;
149
 
  }
150
 
 
151
 
private:
152
143
  uint16_t field_index; /**< Index of this Field in Table::fields array */
153
 
 
154
 
public:
155
 
 
156
 
  uint16_t position() const
157
 
  {
158
 
    return field_index;
159
 
  }
160
 
 
161
 
  void setPosition(uint32_t arg)
162
 
  {
163
 
    field_index= arg;
164
 
  }
165
 
 
166
144
  unsigned char null_bit; /**< Bit used to test null bit */
167
145
  /**
168
146
     If true, this field was created in create_tmp_field_from_item from a NULL
188
166
        utype unireg_check_arg,
189
167
        const char *field_name_arg);
190
168
  virtual ~Field() {}
191
 
 
192
 
  bool hasDefault() const
193
 
  {
194
 
    return not (flags & NO_DEFAULT_VALUE_FLAG);
195
 
  }
196
 
 
197
169
  /* Store functions returns 1 on overflow and -1 on fatal error */
198
170
  virtual int store(const char *to,
199
171
                    uint32_t length,
200
172
                    const CHARSET_INFO * const cs)=0;
201
173
  virtual int store(double nr)=0;
202
174
  virtual int store(int64_t nr, bool unsigned_val)=0;
203
 
  virtual int store_decimal(const type::Decimal *d)=0;
204
 
  int store_and_check(enum_check_fields check_level,
205
 
                      const char *to,
206
 
                      uint32_t length,
207
 
                      const CHARSET_INFO * const cs);
 
175
  virtual int store_decimal(const my_decimal *d)=0;
 
176
  int store(const char *to,
 
177
            uint32_t length,
 
178
            const CHARSET_INFO * const cs,
 
179
            enum_check_fields check_level);
208
180
  /**
209
181
    This is called when storing a date in a string.
210
182
 
211
183
    @note
212
184
      Needs to be changed if/when we want to support different time formats.
213
185
  */
214
 
  virtual int store_time(type::Time *ltime, enum enum_drizzle_timestamp_type t_type);
215
 
  virtual double val_real()=0;
216
 
  virtual int64_t val_int()=0;
217
 
  virtual type::Decimal *val_decimal(type::Decimal *);
218
 
  String *val_str_internal(String *str)
 
186
  virtual int store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type t_type);
 
187
  virtual double val_real(void)=0;
 
188
  virtual int64_t val_int(void)=0;
 
189
  virtual my_decimal *val_decimal(my_decimal *);
 
190
  inline String *val_str(String *str)
219
191
  {
220
192
    return val_str(str, str);
221
193
  }
240
212
  virtual Item_result result_type () const=0;
241
213
  virtual Item_result cmp_type () const { return result_type(); }
242
214
  virtual Item_result cast_to_int_type () const { return result_type(); }
243
 
 
244
215
  /**
245
216
     Check whether a field type can be partially indexed by a key.
246
217
 
287
258
   */
288
259
  virtual bool eq_def(Field *field);
289
260
 
290
 
  virtual bool is_timestamp() const
291
 
  {
292
 
    return false;
293
 
  }
294
 
 
295
261
  /**
296
262
   * Returns size (in bytes) used to store field data in memory
297
263
   * (i.e. it returns the maximum size of the field in a row of the table,
335
301
  virtual uint32_t key_length() const;
336
302
  virtual enum_field_types type() const =0;
337
303
  virtual enum_field_types real_type() const;
338
 
  virtual int cmp_max(const unsigned char *a, const unsigned char *b, uint32_t max_len);
 
304
  inline  int cmp(const unsigned char *str) { return cmp(ptr,str); }
 
305
  virtual int cmp_max(const unsigned char *a, const unsigned char *b,
 
306
                      uint32_t max_len);
339
307
  virtual int cmp(const unsigned char *,const unsigned char *)=0;
340
 
  int cmp_internal(const unsigned char *str) { return cmp(ptr,str); }
341
308
  virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
342
309
                         uint32_t max_length=UINT32_MAX);
343
310
  virtual int cmp_offset(uint32_t row_offset);
389
356
                               uint32_t new_null_bit);
390
357
  /** This is used to generate a field in Table from TableShare */
391
358
  Field *clone(memory::Root *mem_root, Table *new_table);
392
 
  void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
 
359
  inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg)
393
360
  {
394
361
    ptr= ptr_arg;
395
362
    null_ptr= null_ptr_arg;
396
363
    null_bit= null_bit_arg;
397
364
  }
398
 
  void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
 
365
  inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
399
366
  virtual void move_field_offset(ptrdiff_t ptr_diff)
400
367
  {
401
368
    ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
453
420
  {
454
421
    set_image(buff,length, &my_charset_bin);
455
422
  }
456
 
  int64_t val_int_offset(uint32_t row_offset)
 
423
  inline int64_t val_int_offset(uint32_t row_offset)
457
424
  {
458
425
    ptr+=row_offset;
459
426
    int64_t tmp=val_int();
461
428
    return tmp;
462
429
  }
463
430
 
464
 
  int64_t val_int_internal(const unsigned char *new_ptr)
 
431
  inline int64_t val_int(const unsigned char *new_ptr)
465
432
  {
466
433
    unsigned char *old_ptr= ptr;
467
434
    int64_t return_value;
470
437
    ptr= old_ptr;
471
438
    return return_value;
472
439
  }
473
 
 
474
 
  String *val_str_internal(String *str, const unsigned char *new_ptr)
 
440
  inline String *val_str(String *str, const unsigned char *new_ptr)
475
441
  {
476
442
    unsigned char *old_ptr= ptr;
477
443
    ptr= const_cast<unsigned char*>(new_ptr);
478
 
    val_str_internal(str);
 
444
    val_str(str);
479
445
    ptr= old_ptr;
480
446
    return str;
481
447
  }
584
550
    return max_length;
585
551
  }
586
552
 
587
 
  uint32_t offset(const unsigned char *record)
 
553
  inline uint32_t offset(const unsigned char *record)
588
554
  {
589
555
    return (uint32_t) (ptr - record);
590
556
  }
591
557
  void copy_from_tmp(int offset);
592
558
  uint32_t fill_cache_field(CacheField *copy);
593
 
  virtual bool get_date(type::Time *ltime,uint32_t fuzzydate);
594
 
  virtual bool get_time(type::Time *ltime);
 
559
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
560
  virtual bool get_time(DRIZZLE_TIME *ltime);
595
561
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
596
562
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
597
563
  virtual bool has_charset(void) const { return false; }
623
589
      0 otherwise
624
590
  */
625
591
  bool set_warning(DRIZZLE_ERROR::enum_warning_level,
626
 
                   drizzled::error_t code,
 
592
                   unsigned int code,
627
593
                   int cuted_increment);
628
594
  /**
629
595
    Produce warning or note about datetime string data saved into field.
641
607
      thread.
642
608
  */
643
609
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
644
 
                            drizzled::error_t code,
 
610
                            uint32_t code,
645
611
                            const char *str,
646
612
                            uint32_t str_len,
647
613
                            enum enum_drizzle_timestamp_type ts_type,
661
627
      thread.
662
628
  */
663
629
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
664
 
                            drizzled::error_t code,
 
630
                            uint32_t code,
665
631
                            int64_t nr,
666
632
                            enum enum_drizzle_timestamp_type ts_type,
667
633
                            int cuted_increment);
679
645
      thread.
680
646
  */
681
647
  void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
682
 
                            const drizzled::error_t code,
 
648
                            const uint32_t code,
683
649
                            double nr,
684
650
                            enum enum_drizzle_timestamp_type ts_type);
685
 
  bool check_overflow(int op_result)
 
651
  inline bool check_overflow(int op_result)
686
652
  {
687
653
    return (op_result == E_DEC_OVERFLOW);
688
654
  }
716
682
    @return
717
683
      value converted from val
718
684
  */
719
 
  int64_t convert_decimal2int64_t(const type::Decimal *val,
 
685
  int64_t convert_decimal2int64_t(const my_decimal *val,
720
686
                                  bool unsigned_flag,
721
687
                                  int *err);
722
688
  /* The max. number of characters */
723
 
  uint32_t char_length() const
 
689
  inline uint32_t char_length() const
724
690
  {
725
691
    return field_length / charset()->mbmaxlen;
726
692
  }
727
693
 
728
 
  enum column_format_type column_format() const
 
694
  inline enum column_format_type column_format() const
729
695
  {
730
696
    return (enum column_format_type)
731
697
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
752
718
  bool isWriteSet();
753
719
  void setReadSet(bool arg= true);
754
720
  void setWriteSet(bool arg= true);
755
 
 
756
 
protected:
757
 
 
758
 
  void pack_num(uint64_t arg, unsigned char *destination= NULL);
759
 
  void pack_num(uint32_t arg, unsigned char *destination= NULL);
760
 
  uint64_t unpack_num(uint64_t &destination, const unsigned char *arg= NULL) const;
761
 
  uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
762
721
};
763
722
 
764
 
std::ostream& operator<<(std::ostream& output, const Field &field);
765
 
 
766
723
} /* namespace drizzled */
767
724
 
768
725
/** @TODO Why is this in the middle of the file???*/
806
763
  */
807
764
  typedef void Copy_func(CopyField*);
808
765
  Copy_func *get_copy_func(Field *to, Field *from);
809
 
 
810
766
public:
811
767
  unsigned char *from_ptr;
812
768
  unsigned char *to_ptr;
821
777
  Field *to_field;
822
778
  String tmp;                                   // For items
823
779
 
824
 
  CopyField() :
825
 
    from_ptr(0),
826
 
    to_ptr(0),
827
 
    from_null_ptr(0),
828
 
    to_null_ptr(0),
829
 
    null_row(0),
830
 
    from_bit(0),
831
 
    to_bit(0),
832
 
    from_length(0),
833
 
    to_length(0),
834
 
    from_field(0),
835
 
    to_field(0)
836
 
  {}
837
 
 
838
 
  ~CopyField()
839
 
  {}
840
 
 
 
780
  CopyField() {}
 
781
  ~CopyField() {}
841
782
  void set(Field *to,Field *from,bool save);    // Field to field
842
783
  void set(unsigned char *to,Field *from);              // Field to string
843
784
  void (*do_copy)(CopyField *);