1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
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
22
22
variables must declare the size_of() member function.
27
25
#ifndef DRIZZLED_FIELD_H
28
26
#define DRIZZLED_FIELD_H
30
28
#include "drizzled/sql_error.h"
31
#include "drizzled/type/decimal.h"
29
#include "drizzled/decimal.h"
32
30
#include "drizzled/key_map.h"
33
31
#include "drizzled/sql_list.h"
34
32
#include "drizzled/structs.h"
35
33
#include "drizzled/charset_info.h"
36
34
#include "drizzled/item_result.h"
37
#include "drizzled/charset_info.h"
42
#include "drizzled/visibility.h"
80
75
* The store_xxx() methods take various input and convert
81
76
* the input into the raw bytes stored in the ptr member variable.
83
class DRIZZLED_API Field
85
80
/* Prevent use of these */
86
81
Field(const Field&);
87
82
void operator=(Field &);
90
84
unsigned char *ptr; /**< Position to field in record. Stores raw field value */
91
85
unsigned char *null_ptr; /**< Byte where null_bit is */
147
140
utype unireg_check;
148
141
uint32_t field_length; /**< Length of this field in bytes */
151
bool isUnsigned() const
153
return flags & UNSIGNED_FLAG;
157
143
uint16_t field_index; /**< Index of this Field in Table::fields array */
161
uint16_t position() const
166
void setPosition(uint32_t arg)
171
144
unsigned char null_bit; /**< Bit used to test null bit */
173
146
If true, this field was created in create_tmp_field_from_item from a NULL
193
166
utype unireg_check_arg,
194
167
const char *field_name_arg);
195
168
virtual ~Field() {}
197
bool hasDefault() const
199
return not (flags & NO_DEFAULT_VALUE_FLAG);
202
169
/* Store functions returns 1 on overflow and -1 on fatal error */
203
170
virtual int store(const char *to,
205
172
const CHARSET_INFO * const cs)=0;
206
173
virtual int store(double nr)=0;
207
174
virtual int store(int64_t nr, bool unsigned_val)=0;
208
virtual int store_decimal(const type::Decimal *d)=0;
209
int store_and_check(enum_check_fields check_level,
212
const CHARSET_INFO * const cs);
175
virtual int store_decimal(const my_decimal *d)=0;
176
int store(const char *to,
178
const CHARSET_INFO * const cs,
179
enum_check_fields check_level);
214
181
This is called when storing a date in a string.
217
184
Needs to be changed if/when we want to support different time formats.
219
virtual int store_time(type::Time <ime, 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)
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)
225
192
return val_str(str, str);
229
195
val_str(buf1, buf2) gets two buffers and should use them as follows:
230
196
if it needs a temp buffer to convert result to string - use buf1
238
204
This trickery is used to decrease a number of malloc calls.
240
206
virtual String *val_str(String*, String *)=0;
243
208
str_needs_quotes() returns true if the value returned by val_str() needs
244
209
to be quoted when used in constructing an SQL query.
247
212
virtual Item_result result_type () const=0;
248
213
virtual Item_result cmp_type () const { return result_type(); }
249
214
virtual Item_result cast_to_int_type () const { return result_type(); }
252
216
Check whether a field type can be partially indexed by a key.
295
259
virtual bool eq_def(Field *field);
297
virtual bool is_timestamp() const
303
262
* Returns size (in bytes) used to store field data in memory
304
263
* (i.e. it returns the maximum size of the field in a row of the table,
342
301
virtual uint32_t key_length() const;
343
302
virtual enum_field_types type() const =0;
344
303
virtual enum_field_types real_type() const;
345
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,
346
307
virtual int cmp(const unsigned char *,const unsigned char *)=0;
347
int cmp_internal(const unsigned char *str) { return cmp(ptr,str); }
348
308
virtual int cmp_binary(const unsigned char *a,const unsigned char *b,
349
309
uint32_t max_length=UINT32_MAX);
350
310
virtual int cmp_offset(uint32_t row_offset);
396
356
uint32_t new_null_bit);
397
357
/** This is used to generate a field in Table from TableShare */
398
358
Field *clone(memory::Root *mem_root, Table *new_table);
399
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)
402
362
null_ptr= null_ptr_arg;
403
363
null_bit= null_bit_arg;
405
void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
365
inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; }
406
366
virtual void move_field_offset(ptrdiff_t ptr_diff)
408
368
ptr= ADD_TO_PTR(ptr,ptr_diff, unsigned char*);
478
438
return return_value;
481
String *val_str_internal(String *str, const unsigned char *new_ptr)
440
inline String *val_str(String *str, const unsigned char *new_ptr)
483
442
unsigned char *old_ptr= ptr;
484
443
ptr= const_cast<unsigned char*>(new_ptr);
485
val_str_internal(str);
591
550
return max_length;
594
uint32_t offset(const unsigned char *record)
553
inline uint32_t offset(const unsigned char *record)
596
555
return (uint32_t) (ptr - record);
598
557
void copy_from_tmp(int offset);
599
558
uint32_t fill_cache_field(CacheField *copy);
600
virtual bool get_date(type::Time <ime,uint32_t fuzzydate);
601
virtual bool get_time(type::Time <ime);
559
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
560
virtual bool get_time(DRIZZLE_TIME *ltime);
602
561
virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; }
603
562
virtual const CHARSET_INFO *sort_charset(void) const { return charset(); }
604
563
virtual bool has_charset(void) const { return false; }
650
609
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
651
drizzled::error_t code,
653
612
uint32_t str_len,
654
type::timestamp_t ts_type,
613
enum enum_drizzle_timestamp_type ts_type,
655
614
int cuted_increment);
657
616
Produce warning or note about integer datetime value saved into field.
670
629
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
671
drizzled::error_t code,
673
type::timestamp_t ts_type,
632
enum enum_drizzle_timestamp_type ts_type,
674
633
int cuted_increment);
676
635
Produce warning or note about double datetime data saved into field.
688
647
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level,
689
const drizzled::error_t code,
691
type::timestamp_t ts_type);
692
bool check_overflow(int op_result)
650
enum enum_drizzle_timestamp_type ts_type);
651
inline bool check_overflow(int op_result)
694
653
return (op_result == E_DEC_OVERFLOW);
724
683
value converted from val
726
int64_t convert_decimal2int64_t(const type::Decimal *val,
685
int64_t convert_decimal2int64_t(const my_decimal *val,
727
686
bool unsigned_flag,
729
688
/* The max. number of characters */
730
uint32_t char_length() const
689
inline uint32_t char_length() const
732
691
return field_length / charset()->mbmaxlen;
735
enum column_format_type column_format() const
694
inline enum column_format_type column_format() const
737
696
return (enum column_format_type)
738
697
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
759
718
bool isWriteSet();
760
719
void setReadSet(bool arg= true);
761
720
void setWriteSet(bool arg= true);
765
void pack_num(uint64_t arg, unsigned char *destination= NULL);
766
void pack_num(uint32_t arg, unsigned char *destination= NULL);
767
uint64_t unpack_num(uint64_t &destination, const unsigned char *arg= NULL) const;
768
uint32_t unpack_num(uint32_t &destination, const unsigned char *arg= NULL) const;
771
std::ostream& operator<<(std::ostream& output, const Field &field);
773
723
} /* namespace drizzled */
775
725
/** @TODO Why is this in the middle of the file???*/
756
* A class for quick copying data to fields
758
class CopyField :public memory::SqlAlloc
761
Convenience definition of a copy function returned by
764
typedef void Copy_func(CopyField*);
765
Copy_func *get_copy_func(Field *to, Field *from);
767
unsigned char *from_ptr;
768
unsigned char *to_ptr;
769
unsigned char *from_null_ptr;
770
unsigned char *to_null_ptr;
774
uint32_t from_length;
778
String tmp; // For items
782
void set(Field *to,Field *from,bool save); // Field to field
783
void set(unsigned char *to,Field *from); // Field to string
784
void (*do_copy)(CopyField *);
785
void (*do_copy2)(CopyField *); // Used to handle null values
805
788
uint32_t pack_length_to_packflag(uint32_t type);
806
789
uint32_t calc_pack_length(enum_field_types type,uint32_t length);
807
790
int set_field_to_null(Field *field);