22
22
variables must declare the size_of() member function.
25
#ifndef DRIZZLED_FIELD_H
26
#define DRIZZLED_FIELD_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"
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_info.h>
36
#include <drizzled/item_result.h>
37
#include <drizzled/charset_info.h>
42
#include <drizzled/visibility.h>
190
200
/* Store functions returns 1 on overflow and -1 on fatal error */
191
201
virtual int store(const char *to,
193
const CHARSET_INFO * const cs)=0;
203
const charset_info_st * const cs)=0;
194
204
virtual int store(double nr)=0;
195
205
virtual int store(int64_t nr, bool unsigned_val)=0;
196
virtual int store_decimal(const my_decimal *d)=0;
206
virtual int store_decimal(const type::Decimal *d)=0;
197
207
int store_and_check(enum_check_fields check_level,
200
const CHARSET_INFO * const cs);
210
const charset_info_st * const cs);
202
212
This is called when storing a date in a string.
205
215
Needs to be changed if/when we want to support different time formats.
207
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;
210
virtual my_decimal *val_decimal(my_decimal *);
211
String *val_str_internal(String *str)
217
virtual int store_time(type::Time <ime, type::timestamp_t t_type);
218
virtual double val_real() const=0;
219
virtual int64_t val_int() const =0;
220
virtual type::Decimal *val_decimal(type::Decimal *) const;
221
String *val_str_internal(String *str) const
213
223
return val_str(str, str);
216
227
val_str(buf1, buf2) gets two buffers and should use them as follows:
217
228
if it needs a temp buffer to convert result to string - use buf1
224
235
an unnecessary free (and later, may be an alloc).
225
236
This trickery is used to decrease a number of malloc calls.
227
virtual String *val_str(String*, String *)=0;
238
virtual String *val_str(String*, String *) const =0;
229
241
str_needs_quotes() returns true if the value returned by val_str() needs
230
242
to be quoted when used in constructing an SQL query.
233
245
virtual Item_result result_type () const=0;
234
246
virtual Item_result cmp_type () const { return result_type(); }
235
247
virtual Item_result cast_to_int_type () const { return result_type(); }
237
250
Check whether a field type can be partially indexed by a key.
280
293
virtual bool eq_def(Field *field);
295
virtual bool is_timestamp() const
283
301
* Returns size (in bytes) used to store field data in memory
284
302
* (i.e. it returns the maximum size of the field in a row of the table,
344
362
virtual uint32_t size_of() const =0;
346
bool is_null(ptrdiff_t row_offset= 0);
347
bool is_real_null(ptrdiff_t row_offset= 0);
348
bool is_null_in_record(const unsigned char *record);
349
bool is_null_in_record_with_offset(ptrdiff_t offset);
364
bool is_null(ptrdiff_t row_offset= 0) const;
365
bool is_real_null(ptrdiff_t row_offset= 0) const;
366
bool is_null_in_record(const unsigned char *record) const;
367
bool is_null_in_record_with_offset(ptrdiff_t offset) const;
350
368
void set_null(ptrdiff_t row_offset= 0);
351
369
void set_notnull(ptrdiff_t row_offset= 0);
352
bool maybe_null(void);
353
bool real_maybe_null(void);
370
bool maybe_null(void) const;
371
bool real_maybe_null(void) const;
355
373
virtual void make_field(SendField *);
356
374
virtual void sort_string(unsigned char *buff,uint32_t length)=0;
390
408
null_ptr= ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*);
392
virtual void get_image(unsigned char *buff, uint32_t length, const CHARSET_INFO * const)
410
virtual void get_image(unsigned char *buff, uint32_t length, const charset_info_st * const)
394
412
memcpy(buff,ptr,length);
396
virtual void get_image(std::basic_string<unsigned char> &buff, uint32_t length, const CHARSET_INFO * const)
414
virtual void get_image(std::basic_string<unsigned char> &buff, uint32_t length, const charset_info_st * const)
398
416
buff.append(ptr,length);
400
virtual void set_image(const unsigned char *buff,uint32_t length, const CHARSET_INFO * const)
418
virtual void set_image(const unsigned char *buff,uint32_t length, const charset_info_st * const)
402
420
memcpy(ptr,buff,length);
578
595
void copy_from_tmp(int offset);
579
596
uint32_t fill_cache_field(CacheField *copy);
580
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
581
virtual bool get_time(DRIZZLE_TIME *ltime);
582
virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
583
virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
597
virtual bool get_date(type::Time <ime,uint32_t fuzzydate) const;
598
virtual bool get_time(type::Time <ime) const;
599
virtual const charset_info_st *charset(void) const { return &my_charset_bin; }
600
virtual const charset_info_st *sort_charset(void) const { return charset(); }
584
601
virtual bool has_charset(void) const { return false; }
585
virtual void set_charset(const CHARSET_INFO * const)
602
virtual void set_charset(const charset_info_st * const)
587
604
virtual enum Derivation derivation(void) const
630
647
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
648
drizzled::error_t code,
633
650
uint32_t str_len,
634
enum enum_drizzle_timestamp_type ts_type,
651
type::timestamp_t ts_type,
635
652
int cuted_increment);
637
654
Produce warning or note about integer datetime value saved into field.
650
667
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
668
drizzled::error_t code,
653
enum enum_drizzle_timestamp_type ts_type,
670
type::timestamp_t ts_type,
654
671
int cuted_increment);
656
673
Produce warning or note about double datetime data saved into field.
668
685
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
686
const drizzled::error_t code,
671
enum enum_drizzle_timestamp_type ts_type);
688
type::timestamp_t ts_type);
672
689
bool check_overflow(int op_result)
674
691
return (op_result == E_DEC_OVERFLOW);
722
virtual void hash(uint32_t *nr, uint32_t *nr2);
739
virtual void hash(uint32_t *nr, uint32_t *nr2) const;
723
740
friend bool reopen_table(Session *,Table *,bool);
725
742
friend class CopyField;
735
752
friend class Item_sum_max;
736
753
friend class Item_func_group_concat;
755
bool isReadSet() const;
739
756
bool isWriteSet();
740
757
void setReadSet(bool arg= true);
741
758
void setWriteSet(bool arg= true);
762
void pack_num(uint64_t arg, unsigned char *destination= NULL);
763
void pack_num(uint32_t arg, unsigned char *destination= NULL);
764
uint64_t unpack_num(uint64_t &destination, const unsigned char *arg= NULL) const;
765
uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
770
inline bool isDateTime(const enum_field_types &arg)
774
case DRIZZLE_TYPE_DATE:
775
case DRIZZLE_TYPE_DATETIME:
776
case DRIZZLE_TYPE_MICROTIME:
777
case DRIZZLE_TYPE_TIME:
778
case DRIZZLE_TYPE_TIMESTAMP:
781
case DRIZZLE_TYPE_BLOB:
782
case DRIZZLE_TYPE_BOOLEAN:
783
case DRIZZLE_TYPE_DECIMAL:
784
case DRIZZLE_TYPE_DOUBLE:
785
case DRIZZLE_TYPE_ENUM:
786
case DRIZZLE_TYPE_LONG:
787
case DRIZZLE_TYPE_LONGLONG:
788
case DRIZZLE_TYPE_NULL:
789
case DRIZZLE_TYPE_UUID:
790
case DRIZZLE_TYPE_VARCHAR:
744
800
std::ostream& operator<<(std::ostream& output, const Field &field);
746
802
} /* namespace drizzled */
748
804
/** @TODO Why is this in the middle of the file???*/
749
#include "drizzled/create_field.h"
805
#include <drizzled/create_field.h>
751
807
namespace drizzled
779
* A class for quick copying data to fields
781
class CopyField :public memory::SqlAlloc
784
Convenience definition of a copy function returned by
787
typedef void Copy_func(CopyField*);
788
Copy_func *get_copy_func(Field *to, Field *from);
790
unsigned char *from_ptr;
791
unsigned char *to_ptr;
792
unsigned char *from_null_ptr;
793
unsigned char *to_null_ptr;
797
uint32_t from_length;
801
String tmp; // For items
805
void set(Field *to,Field *from,bool save); // Field to field
806
void set(unsigned char *to,Field *from); // Field to string
807
void (*do_copy)(CopyField *);
808
void (*do_copy2)(CopyField *); // Used to handle null values
811
834
uint32_t pack_length_to_packflag(uint32_t type);
812
835
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
813
836
int set_field_to_null(Field *field);
827
850
* true - If string has some important data
829
bool test_if_important_data(const CHARSET_INFO * const cs,
852
bool test_if_important_data(const charset_info_st * const cs,
831
854
const char *strend);
833
856
} /* namespace drizzled */
835
#endif /* DRIZZLED_FIELD_H */