390.1.2
by Monty Taylor
Fixed copyright headers in drizzled/ |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
1
by brian
clean slate |
19 |
|
20 |
/*
|
|
21 |
Because of the function new_field() all field classes that have static
|
|
22 |
variables must declare the size_of() member function.
|
|
23 |
*/
|
|
24 |
||
520.8.2
by Monty Taylor
Moved sql_parse.h and sql_error.h out of common_includes. |
25 |
#ifndef DRIZZLED_FIELD_H
|
26 |
#define DRIZZLED_FIELD_H
|
|
27 |
||
28 |
#include <drizzled/sql_error.h> |
|
520.8.3
by Monty Taylor
Moved hash back to mysys. |
29 |
#include <drizzled/my_decimal.h> |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
30 |
#include <drizzled/sql_bitmap.h> |
31 |
#include <drizzled/sql_list.h> |
|
801.1.2
by Brian Aker
Short global cleanup for includes. |
32 |
/* System-wide common data structures */
|
33 |
#include <drizzled/structs.h> |
|
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
34 |
#include <string> |
1
by brian
clean slate |
35 |
|
36 |
#define DATETIME_DEC 6
|
|
173.1.9
by Toru Maesaka
ripped out DOUBLE and moved to field/ |
37 |
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
|
38 |
||
205
by Brian Aker
uint32 -> uin32_t |
39 |
const uint32_t max_field_size= (uint32_t) 4294967295U; |
1
by brian
clean slate |
40 |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
41 |
class Table; |
1
by brian
clean slate |
42 |
class Send_field; |
43 |
class Protocol; |
|
44 |
class Create_field; |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
45 |
class virtual_column_info; |
46 |
||
796
by Brian Aker
Test case fixes + TABLE_CACHE to class (will rename in manner which is NOT |
47 |
class TABLE_SHARE; |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
48 |
|
798.2.29
by Brian Aker
Detangle more of the session object |
49 |
class Field; |
50 |
||
1
by brian
clean slate |
51 |
struct st_cache_field; |
52 |
int field_conv(Field *to,Field *from); |
|
53 |
||
438.1.13
by Brian Aker
uint cleanup. |
54 |
inline uint32_t get_enum_pack_length(int elements) |
1
by brian
clean slate |
55 |
{
|
56 |
return elements < 256 ? 1 : 2; |
|
57 |
}
|
|
58 |
||
438.1.13
by Brian Aker
uint cleanup. |
59 |
inline uint32_t get_set_pack_length(int elements) |
1
by brian
clean slate |
60 |
{
|
438.1.13
by Brian Aker
uint cleanup. |
61 |
uint32_t len= (elements + 7) / 8; |
1
by brian
clean slate |
62 |
return len > 4 ? 8 : len; |
63 |
}
|
|
64 |
||
65 |
class Field |
|
66 |
{
|
|
67 |
Field(const Item &); /* Prevent use of these */ |
|
68 |
void operator=(Field &); |
|
69 |
public: |
|
70 |
static void *operator new(size_t size) {return sql_alloc(size); } |
|
644
by Brian Aker
Clean up warnings for Solaris. |
71 |
static void operator delete(void *, size_t) |
53.2.32
by Monty Taylor
First large swath at getting handler stuff clean. |
72 |
{ TRASH(ptr_arg, size); } |
1
by brian
clean slate |
73 |
|
481
by Brian Aker
Remove all of uchar. |
74 |
unsigned char *ptr; // Position to field in record |
75 |
unsigned char *null_ptr; // Byte where null_bit is |
|
1
by brian
clean slate |
76 |
/*
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
77 |
Note that you can use table->in_use as replacement for current_session member
|
1
by brian
clean slate |
78 |
only inside of val_*() and store() members (e.g. you can't use it in cons)
|
79 |
*/
|
|
327.1.1
by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure). |
80 |
Table *table; // Pointer for table |
81 |
Table *orig_table; // Pointer to original table |
|
1
by brian
clean slate |
82 |
const char **table_name, *field_name; |
83 |
LEX_STRING comment; |
|
84 |
/* Field is part of the following keys */
|
|
85 |
key_map key_start, part_of_key, part_of_key_not_clustered; |
|
86 |
key_map part_of_sortkey; |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
87 |
/*
|
88 |
We use three additional unireg types for TIMESTAMP to overcome limitation
|
|
89 |
of current binary format of .frm file. We'd like to be able to support
|
|
90 |
NOW() as default and on update value for such fields but unable to hold
|
|
1
by brian
clean slate |
91 |
this info anywhere except unireg_check field. This issue will be resolved
|
92 |
in more clean way with transition to new text based .frm format.
|
|
93 |
See also comment for Field_timestamp::Field_timestamp().
|
|
94 |
*/
|
|
95 |
enum utype { NONE,DATE,SHIELD,NOEMPTY,CASEUP,PNR,BGNR,PGNR,YES,NO,REL, |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
96 |
CHECK,EMPTY,UNKNOWN_FIELD,CASEDN,NEXT_NUMBER,INTERVAL_FIELD, |
1
by brian
clean slate |
97 |
BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE, BLOB_FIELD, |
98 |
TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD}; |
|
99 |
enum imagetype { itRAW, itMBR}; |
|
100 |
||
101 |
utype unireg_check; |
|
205
by Brian Aker
uint32 -> uin32_t |
102 |
uint32_t field_length; // Length of field |
103 |
uint32_t flags; |
|
206
by Brian Aker
Removed final uint dead types. |
104 |
uint16_t field_index; // field number in fields array |
481
by Brian Aker
Remove all of uchar. |
105 |
unsigned char null_bit; // Bit used to test null bit |
1
by brian
clean slate |
106 |
/**
|
107 |
If true, this field was created in create_tmp_field_from_item from a NULL
|
|
108 |
value. This means that the type of the field is just a guess, and the type
|
|
109 |
may be freely coerced to another type.
|
|
110 |
||
111 |
@see create_tmp_field_from_item
|
|
112 |
@see Item_type_holder::get_real_type
|
|
113 |
||
114 |
*/
|
|
115 |
bool is_created_from_null_item; |
|
116 |
||
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
117 |
/* Virtual column data */
|
118 |
virtual_column_info *vcol_info; |
|
119 |
/*
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
120 |
Indication that the field is physically stored in tables
|
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
121 |
rather than just generated on SQL queries.
|
122 |
As of now, false can only be set for generated-only virtual columns.
|
|
123 |
*/
|
|
124 |
bool is_stored; |
|
125 |
||
481
by Brian Aker
Remove all of uchar. |
126 |
Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg, |
127 |
unsigned char null_bit_arg, utype unireg_check_arg, |
|
1
by brian
clean slate |
128 |
const char *field_name_arg); |
129 |
virtual ~Field() {} |
|
130 |
/* Store functions returns 1 on overflow and -1 on fatal error */
|
|
779.3.18
by Monty Taylor
Cleaned up warnings up through innodb. |
131 |
virtual int store(const char *to, uint32_t length, |
132 |
const CHARSET_INFO * const cs)=0; |
|
133 |
virtual int store(double nr)=0; |
|
134 |
virtual int store(int64_t nr, bool unsigned_val)=0; |
|
135 |
virtual int store_decimal(const my_decimal *d)=0; |
|
136 |
int store(const char *to, uint32_t length, |
|
137 |
const CHARSET_INFO * const cs, |
|
138 |
enum_check_fields check_level); |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
139 |
virtual int store_time(DRIZZLE_TIME *ltime, |
140 |
enum enum_drizzle_timestamp_type t_type); |
|
1
by brian
clean slate |
141 |
virtual double val_real(void)=0; |
152
by Brian Aker
longlong replacement |
142 |
virtual int64_t val_int(void)=0; |
1
by brian
clean slate |
143 |
virtual my_decimal *val_decimal(my_decimal *); |
144 |
inline String *val_str(String *str) { return val_str(str, str); } |
|
145 |
/*
|
|
146 |
val_str(buf1, buf2) gets two buffers and should use them as follows:
|
|
147 |
if it needs a temp buffer to convert result to string - use buf1
|
|
148 |
example Field_tiny::val_str()
|
|
149 |
if the value exists as a string already - use buf2
|
|
241
by Brian Aker
First pass of CHAR removal. |
150 |
example Field_varstring::val_str() (???)
|
1
by brian
clean slate |
151 |
consequently, buf2 may be created as 'String buf;' - no memory
|
152 |
will be allocated for it. buf1 will be allocated to hold a
|
|
153 |
value if it's too small. Using allocated buffer for buf2 may result in
|
|
154 |
an unnecessary free (and later, may be an alloc).
|
|
155 |
This trickery is used to decrease a number of malloc calls.
|
|
156 |
*/
|
|
157 |
virtual String *val_str(String*,String *)=0; |
|
275
by Brian Aker
Full removal of my_bool from central server. |
158 |
String *val_int_as_str(String *val_buffer, bool unsigned_flag); |
1
by brian
clean slate |
159 |
/*
|
51.1.58
by Jay Pipes
Replace/remove DBUG and standardize TRUE/FALSE. Remove ASSERT_COLUMN_XXX macros, that work will be done on another |
160 |
str_needs_quotes() returns true if the value returned by val_str() needs
|
1
by brian
clean slate |
161 |
to be quoted when used in constructing an SQL query.
|
162 |
*/
|
|
51.1.58
by Jay Pipes
Replace/remove DBUG and standardize TRUE/FALSE. Remove ASSERT_COLUMN_XXX macros, that work will be done on another |
163 |
virtual bool str_needs_quotes() { return false; } |
1
by brian
clean slate |
164 |
virtual Item_result result_type () const=0; |
165 |
virtual Item_result cmp_type () const { return result_type(); } |
|
166 |
virtual Item_result cast_to_int_type () const { return result_type(); } |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
167 |
/**
|
168 |
Check whether a field type can be partially indexed by a key.
|
|
169 |
||
170 |
This is a static method, rather than a virtual function, because we need
|
|
171 |
to check the type of a non-Field in mysql_alter_table().
|
|
172 |
||
173 |
@param type field type
|
|
174 |
||
175 |
@retval
|
|
176 |
true Type can have a prefixed key
|
|
177 |
@retval
|
|
178 |
false Type can not have a prefixed key
|
|
179 |
*/
|
|
1
by brian
clean slate |
180 |
static bool type_can_have_key_part(enum_field_types); |
181 |
static enum_field_types field_type_merge(enum_field_types, enum_field_types); |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
182 |
|
183 |
/**
|
|
184 |
Detect Item_result by given field type of UNION merge result.
|
|
185 |
||
186 |
@param field_type given field type
|
|
187 |
||
188 |
@return
|
|
189 |
Item_result (type of internal MySQL expression result)
|
|
190 |
*/
|
|
1
by brian
clean slate |
191 |
static Item_result result_merge_type(enum_field_types); |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
192 |
|
193 |
virtual bool eq(Field *field); |
|
1
by brian
clean slate |
194 |
virtual bool eq_def(Field *field); |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
195 |
|
1
by brian
clean slate |
196 |
/*
|
197 |
pack_length() returns size (in bytes) used to store field data in memory
|
|
198 |
(i.e. it returns the maximum size of the field in a row of the table,
|
|
199 |
which is located in RAM).
|
|
200 |
*/
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
201 |
virtual uint32_t pack_length() const; |
1
by brian
clean slate |
202 |
|
203 |
/*
|
|
204 |
pack_length_in_rec() returns size (in bytes) used to store field data on
|
|
205 |
storage (i.e. it returns the maximal size of the field in a row of the
|
|
206 |
table, which is located on disk).
|
|
207 |
*/
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
208 |
virtual uint32_t pack_length_in_rec() const; |
438.1.13
by Brian Aker
uint cleanup. |
209 |
virtual int compatible_field_size(uint32_t field_metadata); |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
210 |
virtual uint32_t pack_length_from_metadata(uint32_t field_metadata); |
211 |
||
1
by brian
clean slate |
212 |
/*
|
213 |
This method is used to return the size of the data in a row-based
|
|
214 |
replication row record. The default implementation of returning 0 is
|
|
51.1.58
by Jay Pipes
Replace/remove DBUG and standardize TRUE/FALSE. Remove ASSERT_COLUMN_XXX macros, that work will be done on another |
215 |
designed to allow fields that do not use metadata to return true (1)
|
1
by brian
clean slate |
216 |
from compatible_field_size() which uses this function in the comparison.
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
217 |
The default value for field metadata for fields that do not have
|
1
by brian
clean slate |
218 |
metadata is 0. Thus, 0 == 0 means the fields are compatible in size.
|
219 |
||
220 |
Note: While most classes that override this method return pack_length(),
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
221 |
the classes Field_varstring, and Field_blob return
|
1
by brian
clean slate |
222 |
field_length + 1, field_length, and pack_length_no_ptr() respectfully.
|
223 |
*/
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
224 |
virtual uint32_t row_pack_length(); |
225 |
virtual int save_field_metadata(unsigned char *first_byte); |
|
1
by brian
clean slate |
226 |
|
227 |
/*
|
|
228 |
data_length() return the "real size" of the data in memory.
|
|
229 |
For varstrings, this does _not_ include the length bytes.
|
|
230 |
*/
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
231 |
virtual uint32_t data_length(); |
1
by brian
clean slate |
232 |
/*
|
233 |
used_length() returns the number of bytes actually used to store the data
|
|
234 |
of the field. So for a varstring it includes both lenght byte(s) and
|
|
235 |
string data, and anything after data_length() bytes are unused.
|
|
236 |
*/
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
237 |
virtual uint32_t used_length(); |
238 |
virtual uint32_t sort_length() const; |
|
1
by brian
clean slate |
239 |
|
240 |
/**
|
|
241 |
Get the maximum size of the data in packed format.
|
|
242 |
||
243 |
@return Maximum data length of the field when packed using the
|
|
244 |
Field::pack() function.
|
|
245 |
*/
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
246 |
virtual uint32_t max_data_length() const; |
247 |
virtual int reset(void); |
|
248 |
virtual void reset_fields(); |
|
249 |
virtual void set_default(); |
|
250 |
virtual bool binary() const; |
|
251 |
virtual bool zero_pack() const; |
|
252 |
virtual enum ha_base_keytype key_type() const; |
|
253 |
virtual uint32_t key_length() const; |
|
1
by brian
clean slate |
254 |
virtual enum_field_types type() const =0; |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
255 |
virtual enum_field_types real_type() const; |
481
by Brian Aker
Remove all of uchar. |
256 |
inline int cmp(const unsigned char *str) { return cmp(ptr,str); } |
257 |
virtual int cmp_max(const unsigned char *a, const unsigned char *b, |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
258 |
uint32_t max_len); |
481
by Brian Aker
Remove all of uchar. |
259 |
virtual int cmp(const unsigned char *,const unsigned char *)=0; |
260 |
virtual int cmp_binary(const unsigned char *a,const unsigned char *b, |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
261 |
uint32_t max_length=UINT32_MAX); |
262 |
virtual int cmp_offset(uint32_t row_offset); |
|
263 |
virtual int cmp_binary_offset(uint32_t row_offset); |
|
264 |
virtual int key_cmp(const unsigned char *a,const unsigned char *b); |
|
265 |
virtual int key_cmp(const unsigned char *str, uint32_t length); |
|
266 |
virtual uint32_t decimals() const; |
|
267 |
||
1
by brian
clean slate |
268 |
/*
|
269 |
Caller beware: sql_type can change str.Ptr, so check
|
|
270 |
ptr() to see if it changed if you are using your own buffer
|
|
271 |
in str and restore it with set() if needed
|
|
272 |
*/
|
|
273 |
virtual void sql_type(String &str) const =0; |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
274 |
|
275 |
// For new field
|
|
276 |
virtual uint32_t size_of() const =0; |
|
277 |
||
278 |
bool is_null(my_ptrdiff_t row_offset= 0); |
|
279 |
bool is_real_null(my_ptrdiff_t row_offset= 0); |
|
280 |
bool is_null_in_record(const unsigned char *record); |
|
281 |
bool is_null_in_record_with_offset(my_ptrdiff_t offset); |
|
282 |
void set_null(my_ptrdiff_t row_offset= 0); |
|
283 |
void set_notnull(my_ptrdiff_t row_offset= 0); |
|
284 |
bool maybe_null(void); |
|
285 |
bool real_maybe_null(void); |
|
1
by brian
clean slate |
286 |
|
287 |
enum { |
|
288 |
LAST_NULL_BYTE_UNDEF= 0 |
|
289 |
};
|
|
290 |
||
291 |
/*
|
|
292 |
Find the position of the last null byte for the field.
|
|
293 |
||
294 |
SYNOPSIS
|
|
295 |
last_null_byte()
|
|
296 |
||
297 |
DESCRIPTION
|
|
298 |
Return a pointer to the last byte of the null bytes where the
|
|
299 |
field conceptually is placed.
|
|
300 |
||
301 |
RETURN VALUE
|
|
302 |
The position of the last null byte relative to the beginning of
|
|
303 |
the record. If the field does not use any bits of the null
|
|
304 |
bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
|
|
305 |
*/
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
306 |
size_t last_null_byte() const; |
1
by brian
clean slate |
307 |
|
308 |
virtual void make_field(Send_field *); |
|
481
by Brian Aker
Remove all of uchar. |
309 |
virtual void sort_string(unsigned char *buff,uint32_t length)=0; |
438.1.13
by Brian Aker
uint cleanup. |
310 |
virtual bool optimize_range(uint32_t idx, uint32_t part); |
1
by brian
clean slate |
311 |
/*
|
312 |
This should be true for fields which, when compared with constant
|
|
152
by Brian Aker
longlong replacement |
313 |
items, can be casted to int64_t. In this case we will at 'fix_fields'
|
314 |
stage cast the constant items to int64_ts and at the execution stage
|
|
1
by brian
clean slate |
315 |
use field->val_int() for comparison. Used to optimize clauses like
|
316 |
'a_column BETWEEN date_const, date_const'.
|
|
317 |
*/
|
|
152
by Brian Aker
longlong replacement |
318 |
virtual bool can_be_compared_as_int64_t() const { return false; } |
1
by brian
clean slate |
319 |
virtual void free() {} |
327.1.1
by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure). |
320 |
virtual Field *new_field(MEM_ROOT *root, Table *new_table, |
1
by brian
clean slate |
321 |
bool keep_type); |
327.1.1
by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure). |
322 |
virtual Field *new_key_field(MEM_ROOT *root, Table *new_table, |
481
by Brian Aker
Remove all of uchar. |
323 |
unsigned char *new_ptr, unsigned char *new_null_ptr, |
438.1.13
by Brian Aker
uint cleanup. |
324 |
uint32_t new_null_bit); |
327.1.1
by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure). |
325 |
Field *clone(MEM_ROOT *mem_root, Table *new_table); |
481
by Brian Aker
Remove all of uchar. |
326 |
inline void move_field(unsigned char *ptr_arg,unsigned char *null_ptr_arg,unsigned char null_bit_arg) |
1
by brian
clean slate |
327 |
{
|
328 |
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg; |
|
329 |
}
|
|
481
by Brian Aker
Remove all of uchar. |
330 |
inline void move_field(unsigned char *ptr_arg) { ptr=ptr_arg; } |
1
by brian
clean slate |
331 |
virtual void move_field_offset(my_ptrdiff_t ptr_diff) |
332 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
333 |
ptr=ADD_TO_PTR(ptr,ptr_diff, unsigned char*); |
1
by brian
clean slate |
334 |
if (null_ptr) |
481
by Brian Aker
Remove all of uchar. |
335 |
null_ptr=ADD_TO_PTR(null_ptr,ptr_diff,unsigned char*); |
1
by brian
clean slate |
336 |
}
|
481
by Brian Aker
Remove all of uchar. |
337 |
virtual void get_image(unsigned char *buff, uint32_t length, |
644
by Brian Aker
Clean up warnings for Solaris. |
338 |
const CHARSET_INFO * const) |
1
by brian
clean slate |
339 |
{ memcpy(buff,ptr,length); } |
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
340 |
virtual void get_image(std::basic_string<unsigned char> &buff, |
341 |
uint32_t length, |
|
342 |
const CHARSET_INFO * const) |
|
343 |
{ buff.append(ptr,length); } |
|
481
by Brian Aker
Remove all of uchar. |
344 |
virtual void set_image(const unsigned char *buff,uint32_t length, |
644
by Brian Aker
Clean up warnings for Solaris. |
345 |
const CHARSET_INFO * const) |
1
by brian
clean slate |
346 |
{ memcpy(ptr,buff,length); } |
347 |
||
348 |
||
349 |
/*
|
|
350 |
Copy a field part into an output buffer.
|
|
351 |
||
352 |
SYNOPSIS
|
|
353 |
Field::get_key_image()
|
|
354 |
buff [out] output buffer
|
|
355 |
length output buffer size
|
|
356 |
type itMBR for geometry blobs, otherwise itRAW
|
|
357 |
||
358 |
DESCRIPTION
|
|
359 |
This function makes a copy of field part of size equal to or
|
|
360 |
less than "length" parameter value.
|
|
361 |
For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
|
|
362 |
is padded by zero byte.
|
|
363 |
||
364 |
NOTES
|
|
365 |
For variable length character fields (i.e. UTF-8) the "length"
|
|
366 |
parameter means a number of output buffer bytes as if all field
|
|
367 |
characters have maximal possible size (mbmaxlen). In the other words,
|
|
368 |
"length" parameter is a number of characters multiplied by
|
|
369 |
field_charset->mbmaxlen.
|
|
370 |
||
371 |
RETURN
|
|
372 |
Number of copied bytes (excluding padded zero bytes -- see above).
|
|
373 |
*/
|
|
374 |
||
644
by Brian Aker
Clean up warnings for Solaris. |
375 |
virtual uint32_t get_key_image(unsigned char *buff, uint32_t length, imagetype) |
1
by brian
clean slate |
376 |
{
|
377 |
get_image(buff, length, &my_charset_bin); |
|
378 |
return length; |
|
379 |
}
|
|
656.1.1
by Monty Taylor
OOOh doggie. Got rid of my_alloca. |
380 |
virtual uint32_t get_key_image(std::basic_string<unsigned char> &buff, |
381 |
uint32_t length, imagetype) |
|
382 |
{
|
|
383 |
get_image(buff, length, &my_charset_bin); |
|
384 |
return length; |
|
385 |
}
|
|
481
by Brian Aker
Remove all of uchar. |
386 |
virtual void set_key_image(const unsigned char *buff,uint32_t length) |
779.3.18
by Monty Taylor
Cleaned up warnings up through innodb. |
387 |
{ set_image(buff,length, &my_charset_bin); } |
438.1.13
by Brian Aker
uint cleanup. |
388 |
inline int64_t val_int_offset(uint32_t row_offset) |
779.3.18
by Monty Taylor
Cleaned up warnings up through innodb. |
389 |
{
|
390 |
ptr+=row_offset; |
|
391 |
int64_t tmp=val_int(); |
|
392 |
ptr-=row_offset; |
|
393 |
return tmp; |
|
394 |
}
|
|
395 |
||
396 |
inline int64_t val_int(const unsigned char *new_ptr) |
|
397 |
{
|
|
398 |
unsigned char *old_ptr= ptr; |
|
399 |
int64_t return_value; |
|
400 |
ptr= (unsigned char*) new_ptr; |
|
401 |
return_value= val_int(); |
|
402 |
ptr= old_ptr; |
|
403 |
return return_value; |
|
404 |
}
|
|
405 |
inline String *val_str(String *str, const unsigned char *new_ptr) |
|
406 |
{
|
|
407 |
unsigned char *old_ptr= ptr; |
|
408 |
ptr= (unsigned char*) new_ptr; |
|
409 |
val_str(str); |
|
410 |
ptr= old_ptr; |
|
411 |
return str; |
|
412 |
}
|
|
413 |
||
1
by brian
clean slate |
414 |
virtual bool send_binary(Protocol *protocol); |
415 |
||
779.3.16
by Monty Taylor
Some Sun warning fixes. |
416 |
virtual unsigned char *pack(unsigned char *to, |
417 |
const unsigned char *from, |
|
418 |
uint32_t max_length, |
|
419 |
bool low_byte_first); |
|
420 |
||
779.3.18
by Monty Taylor
Cleaned up warnings up through innodb. |
421 |
unsigned char *pack(unsigned char *to, const unsigned char *from); |
1
by brian
clean slate |
422 |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
423 |
virtual const unsigned char *unpack(unsigned char* to, |
424 |
const unsigned char *from, |
|
425 |
uint32_t param_data, |
|
426 |
bool low_byte_first); |
|
1
by brian
clean slate |
427 |
/**
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
428 |
@overload Field::unpack(unsigned char*, const unsigned char*,
|
429 |
uint32_t, bool)
|
|
1
by brian
clean slate |
430 |
*/
|
779.3.18
by Monty Taylor
Cleaned up warnings up through innodb. |
431 |
const unsigned char *unpack(unsigned char* to, |
432 |
const unsigned char *from); |
|
1
by brian
clean slate |
433 |
|
481
by Brian Aker
Remove all of uchar. |
434 |
virtual unsigned char *pack_key(unsigned char* to, const unsigned char *from, |
438.1.13
by Brian Aker
uint cleanup. |
435 |
uint32_t max_length, bool low_byte_first) |
1
by brian
clean slate |
436 |
{
|
437 |
return pack(to, from, max_length, low_byte_first); |
|
438 |
}
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
439 |
virtual unsigned char *pack_key_from_key_image(unsigned char* to, |
440 |
const unsigned char *from, |
|
441 |
uint32_t max_length, |
|
442 |
bool low_byte_first) |
|
1
by brian
clean slate |
443 |
{
|
444 |
return pack(to, from, max_length, low_byte_first); |
|
445 |
}
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
446 |
virtual const unsigned char *unpack_key(unsigned char* to, |
447 |
const unsigned char *from, |
|
448 |
uint32_t max_length, |
|
449 |
bool low_byte_first) |
|
1
by brian
clean slate |
450 |
{
|
451 |
return unpack(to, from, max_length, low_byte_first); |
|
452 |
}
|
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
453 |
virtual uint32_t packed_col_length(const unsigned char *to, uint32_t length); |
438.1.13
by Brian Aker
uint cleanup. |
454 |
virtual uint32_t max_packed_col_length(uint32_t max_length) |
1
by brian
clean slate |
455 |
{ return max_length;} |
456 |
||
481
by Brian Aker
Remove all of uchar. |
457 |
virtual int pack_cmp(const unsigned char *a,const unsigned char *b, |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
458 |
uint32_t key_length_arg, |
459 |
bool insert_or_update); |
|
481
by Brian Aker
Remove all of uchar. |
460 |
virtual int pack_cmp(const unsigned char *b, |
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
461 |
uint32_t key_length_arg, |
462 |
bool insert_or_update); |
|
463 |
||
481
by Brian Aker
Remove all of uchar. |
464 |
uint32_t offset(unsigned char *record) |
1
by brian
clean slate |
465 |
{
|
438.1.13
by Brian Aker
uint cleanup. |
466 |
return (uint32_t) (ptr - record); |
1
by brian
clean slate |
467 |
}
|
468 |
void copy_from_tmp(int offset); |
|
438.1.13
by Brian Aker
uint cleanup. |
469 |
uint32_t fill_cache_field(struct st_cache_field *copy); |
470 |
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate); |
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
471 |
virtual bool get_time(DRIZZLE_TIME *ltime); |
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
472 |
virtual const CHARSET_INFO *charset(void) const { return &my_charset_bin; } |
473 |
virtual const CHARSET_INFO *sort_charset(void) const { return charset(); } |
|
51.1.58
by Jay Pipes
Replace/remove DBUG and standardize TRUE/FALSE. Remove ASSERT_COLUMN_XXX macros, that work will be done on another |
474 |
virtual bool has_charset(void) const { return false; } |
644
by Brian Aker
Clean up warnings for Solaris. |
475 |
virtual void set_charset(const CHARSET_INFO * const) |
53.2.32
by Monty Taylor
First large swath at getting handler stuff clean. |
476 |
{ } |
1
by brian
clean slate |
477 |
virtual enum Derivation derivation(void) const |
478 |
{ return DERIVATION_IMPLICIT; } |
|
644
by Brian Aker
Clean up warnings for Solaris. |
479 |
virtual void set_derivation(enum Derivation) |
53.2.32
by Monty Taylor
First large swath at getting handler stuff clean. |
480 |
{ } |
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
481 |
bool set_warning(DRIZZLE_ERROR::enum_warning_level, unsigned int code, |
1
by brian
clean slate |
482 |
int cuted_increment); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
483 |
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code, |
438.1.13
by Brian Aker
uint cleanup. |
484 |
const char *str, uint32_t str_len, |
398.1.1
by Monty Taylor
Remove typedef enum enum_drizzle_timestamp_type timestamp_type; |
485 |
enum enum_drizzle_timestamp_type ts_type, int cuted_increment); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
486 |
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, uint32_t code, |
398.1.1
by Monty Taylor
Remove typedef enum enum_drizzle_timestamp_type timestamp_type; |
487 |
int64_t nr, enum enum_drizzle_timestamp_type ts_type, |
1
by brian
clean slate |
488 |
int cuted_increment); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
489 |
void set_datetime_warning(DRIZZLE_ERROR::enum_warning_level, const uint32_t code, |
398.1.1
by Monty Taylor
Remove typedef enum enum_drizzle_timestamp_type timestamp_type; |
490 |
double nr, enum enum_drizzle_timestamp_type ts_type); |
1
by brian
clean slate |
491 |
inline bool check_overflow(int op_result) |
492 |
{
|
|
493 |
return (op_result == E_DEC_OVERFLOW); |
|
494 |
}
|
|
495 |
int warn_if_overflow(int op_result); |
|
584.1.13
by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes. |
496 |
void init(Table *table_arg); |
1
by brian
clean slate |
497 |
|
498 |
/* maximum possible display length */
|
|
205
by Brian Aker
uint32 -> uin32_t |
499 |
virtual uint32_t max_display_length()= 0; |
1
by brian
clean slate |
500 |
|
438.1.13
by Brian Aker
uint cleanup. |
501 |
virtual uint32_t is_equal(Create_field *new_field); |
152
by Brian Aker
longlong replacement |
502 |
/* convert decimal to int64_t with overflow check */
|
503 |
int64_t convert_decimal2int64_t(const my_decimal *val, bool unsigned_flag, |
|
1
by brian
clean slate |
504 |
int *err); |
505 |
/* The max. number of characters */
|
|
205
by Brian Aker
uint32 -> uin32_t |
506 |
inline uint32_t char_length() const |
1
by brian
clean slate |
507 |
{
|
508 |
return field_length / charset()->mbmaxlen; |
|
509 |
}
|
|
510 |
||
511 |
inline enum column_format_type column_format() const |
|
512 |
{
|
|
513 |
return (enum column_format_type) |
|
514 |
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK); |
|
515 |
}
|
|
516 |
||
517 |
/* Hash value */
|
|
290
by Brian Aker
Update for ulong change over. |
518 |
virtual void hash(uint32_t *nr, uint32_t *nr2); |
520.1.21
by Brian Aker
THD -> Session rename |
519 |
friend bool reopen_table(Session *,Table *,bool); |
438.1.13
by Brian Aker
uint cleanup. |
520 |
friend int cre_myisam(char * name, register Table *form, uint32_t options, |
1
by brian
clean slate |
521 |
uint64_t auto_increment_value); |
522 |
friend class Copy_field; |
|
523 |
friend class Item_avg_field; |
|
524 |
friend class Item_std_field; |
|
525 |
friend class Item_sum_num; |
|
526 |
friend class Item_sum_sum; |
|
527 |
friend class Item_sum_str; |
|
528 |
friend class Item_sum_count; |
|
529 |
friend class Item_sum_avg; |
|
530 |
friend class Item_sum_std; |
|
531 |
friend class Item_sum_min; |
|
532 |
friend class Item_sum_max; |
|
533 |
friend class Item_func_group_concat; |
|
534 |
||
535 |
private: |
|
536 |
/*
|
|
537 |
Primitive for implementing last_null_byte().
|
|
538 |
||
539 |
SYNOPSIS
|
|
540 |
do_last_null_byte()
|
|
541 |
||
542 |
DESCRIPTION
|
|
543 |
Primitive for the implementation of the last_null_byte()
|
|
544 |
function. This represents the inheritance interface and can be
|
|
545 |
overridden by subclasses.
|
|
546 |
*/
|
|
547 |
virtual size_t do_last_null_byte() const; |
|
548 |
||
549 |
/**
|
|
550 |
Retrieve the field metadata for fields.
|
|
551 |
||
552 |
This default implementation returns 0 and saves 0 in the metadata_ptr
|
|
553 |
value.
|
|
554 |
||
555 |
@param metadata_ptr First byte of field metadata
|
|
556 |
||
557 |
@returns 0 no bytes written.
|
|
558 |
*/
|
|
644
by Brian Aker
Clean up warnings for Solaris. |
559 |
virtual int do_save_field_metadata(unsigned char *) |
1
by brian
clean slate |
560 |
{ return 0; } |
561 |
};
|
|
562 |
||
563 |
/*
|
|
564 |
Create field class for CREATE TABLE
|
|
565 |
*/
|
|
566 |
||
567 |
class Create_field :public Sql_alloc |
|
568 |
{
|
|
569 |
public: |
|
570 |
const char *field_name; |
|
571 |
const char *change; // If done with alter table |
|
572 |
const char *after; // Put column after this one |
|
573 |
LEX_STRING comment; // Comment for field |
|
574 |
Item *def; // Default value |
|
575 |
enum enum_field_types sql_type; |
|
576 |
/*
|
|
577 |
At various stages in execution this can be length of field in bytes or
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
578 |
max number of characters.
|
1
by brian
clean slate |
579 |
*/
|
290
by Brian Aker
Update for ulong change over. |
580 |
uint32_t length; |
1
by brian
clean slate |
581 |
/*
|
582 |
The value of `length' as set by parser: is the number of characters
|
|
583 |
for most of the types, or of bytes for BLOBs or numeric types.
|
|
584 |
*/
|
|
205
by Brian Aker
uint32 -> uin32_t |
585 |
uint32_t char_length; |
438.1.13
by Brian Aker
uint cleanup. |
586 |
uint32_t decimals, flags, pack_length, key_length; |
1
by brian
clean slate |
587 |
Field::utype unireg_check; |
588 |
TYPELIB *interval; // Which interval to use |
|
589 |
TYPELIB *save_interval; // Temporary copy for the above |
|
590 |
// Used only for UCS2 intervals
|
|
591 |
List<String> interval_list; |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
592 |
const CHARSET_INFO *charset; |
1
by brian
clean slate |
593 |
Field *field; // For alter table |
594 |
||
206
by Brian Aker
Removed final uint dead types. |
595 |
uint8_t row,col,sc_length,interval_id; // For rea_create_table |
438.1.13
by Brian Aker
uint cleanup. |
596 |
uint32_t offset,pack_flag; |
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
597 |
|
598 |
/* Virtual column expression statement */
|
|
599 |
virtual_column_info *vcol_info; |
|
600 |
/*
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
601 |
Indication that the field is phycically stored in tables
|
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
602 |
rather than just generated on SQL queries.
|
603 |
As of now, FALSE can only be set for generated-only virtual columns.
|
|
604 |
*/
|
|
605 |
bool is_stored; |
|
606 |
||
1
by brian
clean slate |
607 |
Create_field() :after(0) {} |
608 |
Create_field(Field *field, Field *orig_field); |
|
609 |
/* Used to make a clone of this object for ALTER/CREATE TABLE */
|
|
610 |
Create_field *clone(MEM_ROOT *mem_root) const |
|
611 |
{ return new (mem_root) Create_field(*this); } |
|
612 |
void create_length_to_internal_length(void); |
|
613 |
||
614 |
inline enum column_format_type column_format() const |
|
615 |
{
|
|
616 |
return (enum column_format_type) |
|
617 |
((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK); |
|
618 |
}
|
|
619 |
||
620 |
/* Init for a tmp table field. To be extended if need be. */
|
|
621 |
void init_for_tmp_table(enum_field_types sql_type_arg, |
|
205
by Brian Aker
uint32 -> uin32_t |
622 |
uint32_t max_length, uint32_t decimals, |
1
by brian
clean slate |
623 |
bool maybe_null, bool is_unsigned); |
624 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
625 |
bool init(Session *session, char *field_name, enum_field_types type, char *length, |
438.1.13
by Brian Aker
uint cleanup. |
626 |
char *decimals, uint32_t type_modifier, Item *default_value, |
1
by brian
clean slate |
627 |
Item *on_update_value, LEX_STRING *comment, char *change, |
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
628 |
List<String> *interval_list, const CHARSET_INFO * const cs, |
438.1.13
by Brian Aker
uint cleanup. |
629 |
uint32_t uint_geom_type, |
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
630 |
enum column_format_type column_format, |
631 |
virtual_column_info *vcol_info); |
|
1
by brian
clean slate |
632 |
};
|
633 |
||
634 |
||
635 |
/*
|
|
636 |
A class for sending info to the client
|
|
637 |
*/
|
|
638 |
||
639 |
class Send_field { |
|
640 |
public: |
|
641 |
const char *db_name; |
|
642 |
const char *table_name,*org_table_name; |
|
643 |
const char *col_name,*org_col_name; |
|
290
by Brian Aker
Update for ulong change over. |
644 |
uint32_t length; |
438.1.13
by Brian Aker
uint cleanup. |
645 |
uint32_t charsetnr, flags, decimals; |
1
by brian
clean slate |
646 |
enum_field_types type; |
647 |
Send_field() {} |
|
648 |
};
|
|
649 |
||
650 |
||
651 |
/*
|
|
652 |
A class for quick copying data to fields
|
|
653 |
*/
|
|
654 |
||
655 |
class Copy_field :public Sql_alloc { |
|
656 |
/**
|
|
657 |
Convenience definition of a copy function returned by
|
|
658 |
get_copy_func.
|
|
659 |
*/
|
|
660 |
typedef void Copy_func(Copy_field*); |
|
661 |
Copy_func *get_copy_func(Field *to, Field *from); |
|
662 |
public: |
|
481
by Brian Aker
Remove all of uchar. |
663 |
unsigned char *from_ptr,*to_ptr; |
664 |
unsigned char *from_null_ptr,*to_null_ptr; |
|
274
by Brian Aker
my_bool conversion in Table |
665 |
bool *null_row; |
438.1.13
by Brian Aker
uint cleanup. |
666 |
uint32_t from_bit,to_bit; |
667 |
uint32_t from_length,to_length; |
|
1
by brian
clean slate |
668 |
Field *from_field,*to_field; |
669 |
String tmp; // For items |
|
670 |
||
671 |
Copy_field() {} |
|
672 |
~Copy_field() {} |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
673 |
void set(Field *to,Field *from,bool save); // Field to field |
481
by Brian Aker
Remove all of uchar. |
674 |
void set(unsigned char *to,Field *from); // Field to string |
1
by brian
clean slate |
675 |
void (*do_copy)(Copy_field *); |
676 |
void (*do_copy2)(Copy_field *); // Used to handle null values |
|
677 |
};
|
|
678 |
||
679 |
||
481
by Brian Aker
Remove all of uchar. |
680 |
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length, |
575.4.7
by Monty Taylor
More header cleanup. |
681 |
unsigned char *null_pos, unsigned char null_bit, |
682 |
uint32_t pack_flag, enum_field_types field_type, |
|
683 |
const CHARSET_INFO * cs, |
|
684 |
Field::utype unireg_check, |
|
685 |
TYPELIB *interval, const char *field_name); |
|
686 |
||
438.1.13
by Brian Aker
uint cleanup. |
687 |
uint32_t pack_length_to_packflag(uint32_t type); |
290
by Brian Aker
Update for ulong change over. |
688 |
enum_field_types get_blob_type_from_length(uint32_t length); |
205
by Brian Aker
uint32 -> uin32_t |
689 |
uint32_t calc_pack_length(enum_field_types type,uint32_t length); |
1
by brian
clean slate |
690 |
int set_field_to_null(Field *field); |
691 |
int set_field_to_null_with_conversions(Field *field, bool no_conversions); |
|
692 |
||
173.1.3
by Toru Maesaka
ripped out datetime and moved to field/ |
693 |
|
483.1.4
by Lee
break out Field_longstr |
694 |
bool
|
584.5.1
by Monty Taylor
Removed field includes from field.h. |
695 |
test_if_important_data(const CHARSET_INFO * const cs, |
696 |
const char *str, |
|
483.1.4
by Lee
break out Field_longstr |
697 |
const char *strend); |
698 |
||
520.8.2
by Monty Taylor
Moved sql_parse.h and sql_error.h out of common_includes. |
699 |
|
700 |
#endif /* DRIZZLED_FIELD_H */ |