~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.h

  • Committer: pcrews
  • Date: 2011-05-24 17:36:24 UTC
  • mfrom: (1099.4.232 drizzle)
  • Revision ID: pcrews@lucid32-20110524173624-mwr1bvq6fa1r01ao
Updated translations + 2011.05.18 tarball tag

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
 
26
26
 
27
 
#ifndef DRIZZLED_FIELD_H
28
 
#define DRIZZLED_FIELD_H
 
27
#pragma once
29
28
 
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"
 
29
#include <drizzled/common_fwd.h>
 
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.h>
 
36
#include <drizzled/item_result.h>
 
37
#include <drizzled/charset.h>
38
38
 
39
39
#include <string>
40
40
#include <vector>
41
41
 
42
 
#include "drizzled/visibility.h"
 
42
#include <drizzled/visibility.h>
43
43
 
44
 
namespace drizzled
45
 
{
 
44
namespace drizzled {
46
45
 
47
46
#define DATETIME_DEC                     6
48
47
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
49
48
 
50
 
#ifdef DEBUG
51
 
#define ASSERT_COLUMN_MARKED_FOR_READ assert(!getTable() || (getTable()->read_set == NULL || isReadSet()))
52
 
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(!getTable() || (getTable()->write_set == NULL || isWriteSet()))
53
 
#else
54
 
#define ASSERT_COLUMN_MARKED_FOR_READ assert(getTable())
55
 
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(getTable())
56
 
#endif
57
 
 
58
 
typedef struct st_typelib TYPELIB;
 
49
#define ASSERT_COLUMN_MARKED_FOR_READ assert(getTable() && (not getTable()->read_set || isReadSet()))
 
50
#define ASSERT_COLUMN_MARKED_FOR_WRITE assert(getTable() && (not getTable()->write_set || isWriteSet()))
59
51
 
60
52
const uint32_t max_field_size= (uint32_t) 4294967295U;
61
53
 
62
 
class SendField;
63
 
class CreateField;
64
 
class TableShare;
65
 
class Field;
66
 
struct CacheField;
67
 
 
68
54
int field_conv(Field *to,Field *from);
69
55
 
70
56
/**
202
188
  /* Store functions returns 1 on overflow and -1 on fatal error */
203
189
  virtual int store(const char *to,
204
190
                    uint32_t length,
205
 
                    const CHARSET_INFO * const cs)=0;
 
191
                    const charset_info_st * const cs)=0;
206
192
  virtual int store(double nr)=0;
207
193
  virtual int store(int64_t nr, bool unsigned_val)=0;
208
194
  virtual int store_decimal(const type::Decimal *d)=0;
209
195
  int store_and_check(enum_check_fields check_level,
210
196
                      const char *to,
211
197
                      uint32_t length,
212
 
                      const CHARSET_INFO * const cs);
 
198
                      const charset_info_st * const cs);
213
199
  /**
214
200
    This is called when storing a date in a string.
215
201
 
217
203
      Needs to be changed if/when we want to support different time formats.
218
204
  */
219
205
  virtual int store_time(type::Time &ltime, type::timestamp_t t_type);
220
 
  virtual double val_real()=0;
221
 
  virtual int64_t val_int()=0;
222
 
  virtual type::Decimal *val_decimal(type::Decimal *);
223
 
  String *val_str_internal(String *str)
 
206
  virtual double val_real() const=0;
 
207
  virtual int64_t val_int() const =0;
 
208
  virtual type::Decimal *val_decimal(type::Decimal *) const;
 
209
  String *val_str_internal(String *str) const
224
210
  {
225
211
    return val_str(str, str);
226
212
  }
237
223
     an unnecessary free (and later, may be an alloc).
238
224
     This trickery is used to decrease a number of malloc calls.
239
225
  */
240
 
  virtual String *val_str(String*, String *)=0;
 
226
  virtual String *val_str(String*, String *) const =0;
241
227
 
242
228
  /*
243
229
   str_needs_quotes() returns true if the value returned by val_str() needs
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);
367
 
  bool is_real_null(ptrdiff_t row_offset= 0);
368
 
  bool is_null_in_record(const unsigned char *record);
369
 
  bool is_null_in_record_with_offset(ptrdiff_t offset);
 
352
  bool is_null(ptrdiff_t row_offset= 0) const;
 
353
  bool is_real_null(ptrdiff_t row_offset= 0) const;
 
354
  bool is_null_in_record(const unsigned char *record) const;
 
355
  bool is_null_in_record_with_offset(ptrdiff_t offset) const;
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);
373
 
  bool real_maybe_null(void);
 
358
  bool maybe_null(void) const;
 
359
  bool real_maybe_null(void) const;
374
360
 
375
361
  virtual void make_field(SendField *);
376
362
  virtual void sort_string(unsigned char *buff,uint32_t length)=0;
409
395
    if (null_ptr)
410
396
      null_ptr= ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
411
397
  }
412
 
  virtual void get_image(unsigned char *buff, uint32_t length, const CHARSET_INFO * const)
 
398
  virtual void get_image(unsigned char *buff, uint32_t length, const charset_info_st * const)
413
399
  {
414
400
    memcpy(buff,ptr,length);
415
401
  }
416
 
  virtual void get_image(std::basic_string<unsigned char> &buff, uint32_t length, const CHARSET_INFO * const)
 
402
  virtual void get_image(std::basic_string<unsigned char> &buff, uint32_t length, const charset_info_st * const)
417
403
  {
418
404
    buff.append(ptr,length);
419
405
  }
420
 
  virtual void set_image(const unsigned char *buff,uint32_t length, const CHARSET_INFO * const)
 
406
  virtual void set_image(const unsigned char *buff,uint32_t length, const charset_info_st * const)
421
407
  {
422
408
    memcpy(ptr,buff,length);
423
409
  }
471
457
  int64_t val_int_internal(const unsigned char *new_ptr)
472
458
  {
473
459
    unsigned char *old_ptr= ptr;
474
 
    int64_t return_value;
475
460
    ptr= const_cast<unsigned char*>(new_ptr);
476
 
    return_value= val_int();
 
461
    int64_t return_value= val_int();
477
462
    ptr= old_ptr;
478
463
    return return_value;
479
464
  }
597
582
  }
598
583
  void copy_from_tmp(int offset);
599
584
  uint32_t fill_cache_field(CacheField *copy);
600
 
  virtual bool get_date(type::Time &ltime,uint32_t fuzzydate);
601
 
  virtual bool get_time(type::Time &ltime);
602
 
  virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
603
 
  virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
 
585
  virtual bool get_date(type::Time &ltime,uint32_t fuzzydate) const;
 
586
  virtual bool get_time(type::Time &ltime) const;
 
587
  virtual const charset_info_st *charset(void) const { return &my_charset_bin; }
 
588
  virtual const charset_info_st *sort_charset(void) const { return charset(); }
604
589
  virtual bool has_charset(void) const { return false; }
605
 
  virtual void set_charset(const CHARSET_INFO * const)
 
590
  virtual void set_charset(const charset_info_st * const)
606
591
  {}
607
592
  virtual enum Derivation derivation(void) const
608
593
  {
739
724
  }
740
725
 
741
726
  /* Hash value */
742
 
  virtual void hash(uint32_t *nr, uint32_t *nr2);
 
727
  virtual void hash(uint32_t *nr, uint32_t *nr2) const;
743
728
  friend bool reopen_table(Session *,Table *,bool);
744
729
 
745
730
  friend class CopyField;
755
740
  friend class Item_sum_max;
756
741
  friend class Item_func_group_concat;
757
742
 
758
 
  bool isReadSet();
 
743
  bool isReadSet() const;
759
744
  bool isWriteSet();
760
745
  void setReadSet(bool arg= true);
761
746
  void setWriteSet(bool arg= true);
768
753
  uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
769
754
};
770
755
 
 
756
namespace field {
 
757
 
 
758
inline bool isDateTime(const enum_field_types &arg)
 
759
{
 
760
  switch (arg)
 
761
  {
 
762
  case DRIZZLE_TYPE_DATE:
 
763
  case DRIZZLE_TYPE_DATETIME:
 
764
  case DRIZZLE_TYPE_MICROTIME:
 
765
  case DRIZZLE_TYPE_TIME:
 
766
  case DRIZZLE_TYPE_TIMESTAMP:
 
767
    return true;
 
768
 
 
769
  case DRIZZLE_TYPE_BLOB:
 
770
  case DRIZZLE_TYPE_BOOLEAN:
 
771
  case DRIZZLE_TYPE_DECIMAL:
 
772
  case DRIZZLE_TYPE_DOUBLE:
 
773
  case DRIZZLE_TYPE_ENUM:
 
774
  case DRIZZLE_TYPE_LONG:
 
775
  case DRIZZLE_TYPE_LONGLONG:
 
776
  case DRIZZLE_TYPE_NULL:
 
777
  case DRIZZLE_TYPE_UUID:
 
778
  case DRIZZLE_TYPE_VARCHAR:
 
779
    return false;
 
780
  }
 
781
 
 
782
  assert(0);
 
783
  abort();
 
784
}
 
785
 
 
786
} // namespace field
 
787
 
771
788
std::ostream& operator<<(std::ostream& output, const Field &field);
772
789
 
773
790
} /* namespace drizzled */
774
791
 
775
792
/** @TODO Why is this in the middle of the file???*/
776
 
#include "drizzled/create_field.h"
 
793
#include <drizzled/create_field.h>
777
794
 
778
795
namespace drizzled
779
796
{
820
837
 * @retval
821
838
 *  true  - If string has some important data
822
839
 */
823
 
bool test_if_important_data(const CHARSET_INFO * const cs,
 
840
bool test_if_important_data(const charset_info_st * const cs,
824
841
                            const char *str,
825
842
                            const char *strend);
826
843
 
827
844
} /* namespace drizzled */
828
845
 
829
 
#endif /* DRIZZLED_FIELD_H */