1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL
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; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
22
* @file This file implements the Field class and API
21
This file implements classes defined in field.h
23
#include <drizzled/server_includes.h>
24
#include "sql_select.h"
29
#include "drizzled/sql_select.h"
30
#include "drizzled/error.h"
31
#include "drizzled/field/str.h"
32
#include "drizzled/field/num.h"
33
#include "drizzled/field/blob.h"
34
#include "drizzled/field/enum.h"
35
#include "drizzled/field/null.h"
36
#include "drizzled/field/date.h"
37
#include "drizzled/field/decimal.h"
38
#include "drizzled/field/real.h"
39
#include "drizzled/field/double.h"
40
#include "drizzled/field/int32.h"
41
#include "drizzled/field/int64.h"
42
#include "drizzled/field/num.h"
43
#include "drizzled/field/timestamp.h"
44
#include "drizzled/field/datetime.h"
45
#include "drizzled/field/varstring.h"
46
#include "drizzled/field/uuid.h"
47
#include "drizzled/time_functions.h"
48
#include "drizzled/internal/m_string.h"
50
#include "drizzled/display.h"
26
#include <drizzled/drizzled_error_messages.h>
28
// Maximum allowed exponent value for converting string to decimal
29
#define MAX_EXPONENT 1024
55
31
/*****************************************************************************
56
32
Instansiate templates and static variables
57
33
*****************************************************************************/
59
static enum_field_types
60
field_types_merge_rules [enum_field_types_size][enum_field_types_size]=
35
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
36
template class List<Create_field>;
37
template class List_iterator<Create_field>;
42
Rules for merging different types of fields in UNION
44
NOTE: to avoid 256*256 table, gap in table types numeration is skiped
45
following #defines describe that gap and how to canculate number of fields
46
and index of field in thia array.
48
#define FIELDTYPE_TEAR_FROM (DRIZZLE_TYPE_VARCHAR + 1)
49
#define FIELDTYPE_TEAR_TO (DRIZZLE_TYPE_NEWDECIMAL - 1)
50
#define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO))
51
inline int field_type2index (enum_field_types field_type)
53
return (field_type < FIELDTYPE_TEAR_FROM ?
55
((int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) - 1);
59
static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]=
61
/* DRIZZLE_TYPE_DECIMAL -> */
63
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
64
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_NEWDECIMAL,
66
DRIZZLE_TYPE_NEWDECIMAL,
69
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
70
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
71
//DRIZZLE_TYPE_LONGLONG
72
DRIZZLE_TYPE_NEWDECIMAL,
75
//DRIZZLE_TYPE_DATETIME
77
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
78
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
79
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
80
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
84
/* DRIZZLE_TYPE_TINY -> */
86
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
87
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_TINY,
92
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
93
DRIZZLE_TYPE_TINY, DRIZZLE_TYPE_VARCHAR,
94
//DRIZZLE_TYPE_LONGLONG
95
DRIZZLE_TYPE_LONGLONG,
98
//DRIZZLE_TYPE_DATETIME
100
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
101
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
102
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
103
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
62
107
/* DRIZZLE_TYPE_LONG -> */
109
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
110
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_LONG,
65
112
DRIZZLE_TYPE_LONG,
113
//DRIZZLE_TYPE_DOUBLE
67
114
DRIZZLE_TYPE_DOUBLE,
70
//DRIZZLE_TYPE_TIMESTAMP
72
//DRIZZLE_TYPE_LONGLONG
115
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
116
DRIZZLE_TYPE_LONG, DRIZZLE_TYPE_VARCHAR,
117
//DRIZZLE_TYPE_LONGLONG
73
118
DRIZZLE_TYPE_LONGLONG,
74
//DRIZZLE_TYPE_DATETIME
78
//DRIZZLE_TYPE_VARCHAR
80
//DRIZZLE_TYPE_DECIMAL
120
DRIZZLE_TYPE_VARCHAR,
121
//DRIZZLE_TYPE_DATETIME
122
DRIZZLE_TYPE_VARCHAR,
123
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
124
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
125
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
126
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
85
128
DRIZZLE_TYPE_BLOB,
89
130
/* DRIZZLE_TYPE_DOUBLE -> */
97
//DRIZZLE_TYPE_TIMESTAMP
99
//DRIZZLE_TYPE_LONGLONG
101
//DRIZZLE_TYPE_DATETIME
102
DRIZZLE_TYPE_VARCHAR,
104
DRIZZLE_TYPE_VARCHAR,
105
//DRIZZLE_TYPE_VARCHAR
106
DRIZZLE_TYPE_VARCHAR,
107
//DRIZZLE_TYPE_DECIMAL
110
DRIZZLE_TYPE_VARCHAR,
132
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
133
DRIZZLE_TYPE_DOUBLE, DRIZZLE_TYPE_DOUBLE,
136
//DRIZZLE_TYPE_DOUBLE
138
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
139
DRIZZLE_TYPE_DOUBLE, DRIZZLE_TYPE_VARCHAR,
140
//DRIZZLE_TYPE_LONGLONG
143
DRIZZLE_TYPE_VARCHAR,
144
//DRIZZLE_TYPE_DATETIME
145
DRIZZLE_TYPE_VARCHAR,
146
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
147
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
148
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
149
DRIZZLE_TYPE_DOUBLE, DRIZZLE_TYPE_VARCHAR,
112
151
DRIZZLE_TYPE_BLOB,
114
DRIZZLE_TYPE_VARCHAR,
116
153
/* DRIZZLE_TYPE_NULL -> */
155
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
156
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_TINY,
119
158
DRIZZLE_TYPE_LONG,
120
//DRIZZLE_TYPE_DOUBLE
159
//DRIZZLE_TYPE_DOUBLE
121
160
DRIZZLE_TYPE_DOUBLE,
124
//DRIZZLE_TYPE_TIMESTAMP
125
DRIZZLE_TYPE_TIMESTAMP,
126
//DRIZZLE_TYPE_LONGLONG
161
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
162
DRIZZLE_TYPE_NULL, DRIZZLE_TYPE_TIMESTAMP,
163
//DRIZZLE_TYPE_LONGLONG
127
164
DRIZZLE_TYPE_LONGLONG,
128
//DRIZZLE_TYPE_DATETIME
167
//DRIZZLE_TYPE_DATETIME
129
168
DRIZZLE_TYPE_DATETIME,
132
//DRIZZLE_TYPE_VARCHAR
133
DRIZZLE_TYPE_VARCHAR,
134
//DRIZZLE_TYPE_DECIMAL
135
DRIZZLE_TYPE_DECIMAL,
169
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
170
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
171
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
172
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_ENUM,
139
174
DRIZZLE_TYPE_BLOB,
143
176
/* DRIZZLE_TYPE_TIMESTAMP -> */
146
DRIZZLE_TYPE_VARCHAR,
147
//DRIZZLE_TYPE_DOUBLE
148
DRIZZLE_TYPE_VARCHAR,
150
DRIZZLE_TYPE_TIMESTAMP,
151
//DRIZZLE_TYPE_TIMESTAMP
152
DRIZZLE_TYPE_TIMESTAMP,
153
//DRIZZLE_TYPE_LONGLONG
154
DRIZZLE_TYPE_VARCHAR,
155
//DRIZZLE_TYPE_DATETIME
156
DRIZZLE_TYPE_DATETIME,
159
//DRIZZLE_TYPE_VARCHAR
160
DRIZZLE_TYPE_VARCHAR,
161
//DRIZZLE_TYPE_DECIMAL
162
DRIZZLE_TYPE_VARCHAR,
164
DRIZZLE_TYPE_VARCHAR,
178
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
179
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
181
DRIZZLE_TYPE_VARCHAR,
182
//DRIZZLE_TYPE_DOUBLE
183
DRIZZLE_TYPE_VARCHAR,
184
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
185
DRIZZLE_TYPE_TIMESTAMP, DRIZZLE_TYPE_TIMESTAMP,
186
//DRIZZLE_TYPE_LONGLONG
187
DRIZZLE_TYPE_VARCHAR,
189
DRIZZLE_TYPE_DATETIME,
190
//DRIZZLE_TYPE_DATETIME
191
DRIZZLE_TYPE_DATETIME,
192
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
193
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
194
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
195
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
166
197
DRIZZLE_TYPE_BLOB,
168
DRIZZLE_TYPE_VARCHAR,
170
199
/* DRIZZLE_TYPE_LONGLONG -> */
201
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
202
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_LONGLONG,
173
204
DRIZZLE_TYPE_LONGLONG,
174
//DRIZZLE_TYPE_DOUBLE
205
//DRIZZLE_TYPE_DOUBLE
175
206
DRIZZLE_TYPE_DOUBLE,
177
DRIZZLE_TYPE_LONGLONG,
178
//DRIZZLE_TYPE_TIMESTAMP
179
DRIZZLE_TYPE_VARCHAR,
180
//DRIZZLE_TYPE_LONGLONG
181
DRIZZLE_TYPE_LONGLONG,
182
//DRIZZLE_TYPE_DATETIME
183
DRIZZLE_TYPE_VARCHAR,
186
//DRIZZLE_TYPE_VARCHAR
187
DRIZZLE_TYPE_VARCHAR,
188
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_ENUM
189
DRIZZLE_TYPE_DECIMAL,
190
DRIZZLE_TYPE_VARCHAR,
194
DRIZZLE_TYPE_VARCHAR,
207
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
208
DRIZZLE_TYPE_LONGLONG, DRIZZLE_TYPE_VARCHAR,
209
//DRIZZLE_TYPE_LONGLONG
210
DRIZZLE_TYPE_LONGLONG,
212
DRIZZLE_TYPE_VARCHAR,
213
//DRIZZLE_TYPE_DATETIME
214
DRIZZLE_TYPE_VARCHAR,
215
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
216
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
217
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
218
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
222
/* DRIZZLE_TYPE_TIME -> */
224
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
225
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
227
DRIZZLE_TYPE_VARCHAR,
228
//DRIZZLE_TYPE_DOUBLE
229
DRIZZLE_TYPE_VARCHAR,
230
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
231
DRIZZLE_TYPE_TIME, DRIZZLE_TYPE_DATETIME,
232
//DRIZZLE_TYPE_LONGLONG
233
DRIZZLE_TYPE_VARCHAR,
236
//DRIZZLE_TYPE_DATETIME
237
DRIZZLE_TYPE_DATETIME,
238
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
239
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
240
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
241
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
196
245
/* DRIZZLE_TYPE_DATETIME -> */
199
DRIZZLE_TYPE_VARCHAR,
200
//DRIZZLE_TYPE_DOUBLE
201
DRIZZLE_TYPE_VARCHAR,
203
DRIZZLE_TYPE_DATETIME,
204
//DRIZZLE_TYPE_TIMESTAMP
205
DRIZZLE_TYPE_DATETIME,
206
//DRIZZLE_TYPE_LONGLONG
207
DRIZZLE_TYPE_VARCHAR,
208
//DRIZZLE_TYPE_DATETIME
209
DRIZZLE_TYPE_DATETIME,
212
//DRIZZLE_TYPE_VARCHAR
213
DRIZZLE_TYPE_VARCHAR,
214
//DRIZZLE_TYPE_DECIMAL
215
DRIZZLE_TYPE_VARCHAR,
217
DRIZZLE_TYPE_VARCHAR,
247
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
248
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
250
DRIZZLE_TYPE_VARCHAR,
251
//DRIZZLE_TYPE_DOUBLE
252
DRIZZLE_TYPE_VARCHAR,
253
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
254
DRIZZLE_TYPE_DATETIME, DRIZZLE_TYPE_DATETIME,
255
//DRIZZLE_TYPE_LONGLONG
256
DRIZZLE_TYPE_VARCHAR,
258
DRIZZLE_TYPE_DATETIME,
259
//DRIZZLE_TYPE_DATETIME
260
DRIZZLE_TYPE_DATETIME,
261
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
262
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
263
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
264
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
219
266
DRIZZLE_TYPE_BLOB,
221
DRIZZLE_TYPE_VARCHAR,
223
/* DRIZZLE_TYPE_DATE -> */
268
/* DRIZZLE_TYPE_NEWDATE -> */
226
DRIZZLE_TYPE_VARCHAR,
227
//DRIZZLE_TYPE_DOUBLE
228
DRIZZLE_TYPE_VARCHAR,
231
//DRIZZLE_TYPE_TIMESTAMP
232
DRIZZLE_TYPE_DATETIME,
233
//DRIZZLE_TYPE_LONGLONG
234
DRIZZLE_TYPE_VARCHAR,
235
//DRIZZLE_TYPE_DATETIME
236
DRIZZLE_TYPE_DATETIME,
239
//DRIZZLE_TYPE_VARCHAR
240
DRIZZLE_TYPE_VARCHAR,
241
//DRIZZLE_TYPE_DECIMAL
242
DRIZZLE_TYPE_VARCHAR,
244
DRIZZLE_TYPE_VARCHAR,
270
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
271
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
273
DRIZZLE_TYPE_VARCHAR,
274
//DRIZZLE_TYPE_DOUBLE
275
DRIZZLE_TYPE_VARCHAR,
276
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
277
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_DATETIME,
278
//DRIZZLE_TYPE_LONGLONG
279
DRIZZLE_TYPE_VARCHAR,
281
DRIZZLE_TYPE_DATETIME,
282
//DRIZZLE_TYPE_DATETIME
283
DRIZZLE_TYPE_DATETIME,
284
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
285
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
286
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
287
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
246
289
DRIZZLE_TYPE_BLOB,
248
DRIZZLE_TYPE_VARCHAR,
250
291
/* DRIZZLE_TYPE_VARCHAR -> */
253
DRIZZLE_TYPE_VARCHAR,
254
//DRIZZLE_TYPE_DOUBLE
255
DRIZZLE_TYPE_VARCHAR,
257
DRIZZLE_TYPE_VARCHAR,
258
//DRIZZLE_TYPE_TIMESTAMP
259
DRIZZLE_TYPE_VARCHAR,
260
//DRIZZLE_TYPE_LONGLONG
261
DRIZZLE_TYPE_VARCHAR,
262
//DRIZZLE_TYPE_DATETIME
263
DRIZZLE_TYPE_VARCHAR,
265
DRIZZLE_TYPE_VARCHAR,
266
//DRIZZLE_TYPE_VARCHAR
267
DRIZZLE_TYPE_VARCHAR,
268
//DRIZZLE_TYPE_DECIMAL
269
DRIZZLE_TYPE_VARCHAR,
271
DRIZZLE_TYPE_VARCHAR,
293
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
294
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
296
DRIZZLE_TYPE_VARCHAR,
297
//DRIZZLE_TYPE_DOUBLE
298
DRIZZLE_TYPE_VARCHAR,
299
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
300
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
301
//DRIZZLE_TYPE_LONGLONG
302
DRIZZLE_TYPE_VARCHAR,
304
DRIZZLE_TYPE_VARCHAR,
305
//DRIZZLE_TYPE_DATETIME
306
DRIZZLE_TYPE_VARCHAR,
307
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
308
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
309
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
310
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
273
312
DRIZZLE_TYPE_BLOB,
275
DRIZZLE_TYPE_VARCHAR,
277
/* DRIZZLE_TYPE_DECIMAL -> */
314
/* DRIZZLE_TYPE_NEWDECIMAL -> */
280
DRIZZLE_TYPE_DECIMAL,
281
//DRIZZLE_TYPE_DOUBLE
316
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
317
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_NEWDECIMAL,
319
DRIZZLE_TYPE_NEWDECIMAL,
320
//DRIZZLE_TYPE_DOUBLE
282
321
DRIZZLE_TYPE_DOUBLE,
284
DRIZZLE_TYPE_DECIMAL,
285
//DRIZZLE_TYPE_TIMESTAMP
286
DRIZZLE_TYPE_VARCHAR,
287
//DRIZZLE_TYPE_LONGLONG
288
DRIZZLE_TYPE_DECIMAL,
289
//DRIZZLE_TYPE_DATETIME
290
DRIZZLE_TYPE_VARCHAR,
292
DRIZZLE_TYPE_VARCHAR,
293
//DRIZZLE_TYPE_VARCHAR
294
DRIZZLE_TYPE_VARCHAR,
295
//DRIZZLE_TYPE_DECIMAL
296
DRIZZLE_TYPE_DECIMAL,
298
DRIZZLE_TYPE_VARCHAR,
322
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
323
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
324
//DRIZZLE_TYPE_LONGLONG
325
DRIZZLE_TYPE_NEWDECIMAL,
327
DRIZZLE_TYPE_VARCHAR,
328
//DRIZZLE_TYPE_DATETIME
329
DRIZZLE_TYPE_VARCHAR,
330
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
331
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
332
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
333
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
300
335
DRIZZLE_TYPE_BLOB,
302
DRIZZLE_TYPE_VARCHAR,
304
337
/* DRIZZLE_TYPE_ENUM -> */
307
DRIZZLE_TYPE_VARCHAR,
308
//DRIZZLE_TYPE_DOUBLE
309
DRIZZLE_TYPE_VARCHAR,
312
//DRIZZLE_TYPE_TIMESTAMP
313
DRIZZLE_TYPE_VARCHAR,
314
//DRIZZLE_TYPE_LONGLONG
315
DRIZZLE_TYPE_VARCHAR,
316
//DRIZZLE_TYPE_DATETIME
317
DRIZZLE_TYPE_VARCHAR,
319
DRIZZLE_TYPE_VARCHAR,
320
//DRIZZLE_TYPE_VARCHAR
321
DRIZZLE_TYPE_VARCHAR,
322
//DRIZZLE_TYPE_DECIMAL
323
DRIZZLE_TYPE_VARCHAR,
325
DRIZZLE_TYPE_VARCHAR,
339
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
340
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
342
DRIZZLE_TYPE_VARCHAR,
343
//DRIZZLE_TYPE_DOUBLE
344
DRIZZLE_TYPE_VARCHAR,
345
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
346
DRIZZLE_TYPE_ENUM, DRIZZLE_TYPE_VARCHAR,
347
//DRIZZLE_TYPE_LONGLONG
348
DRIZZLE_TYPE_VARCHAR,
350
DRIZZLE_TYPE_VARCHAR,
351
//DRIZZLE_TYPE_DATETIME
352
DRIZZLE_TYPE_VARCHAR,
353
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
354
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
355
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
356
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
327
358
DRIZZLE_TYPE_BLOB,
329
DRIZZLE_TYPE_VARCHAR,
331
360
/* DRIZZLE_TYPE_BLOB -> */
335
//DRIZZLE_TYPE_DOUBLE
339
//DRIZZLE_TYPE_TIMESTAMP
341
//DRIZZLE_TYPE_LONGLONG
343
//DRIZZLE_TYPE_DATETIME
347
//DRIZZLE_TYPE_VARCHAR
349
//DRIZZLE_TYPE_DECIMAL
356
DRIZZLE_TYPE_VARCHAR,
358
/* DRIZZLE_TYPE_UUID -> */
361
DRIZZLE_TYPE_VARCHAR,
362
//DRIZZLE_TYPE_DOUBLE
363
DRIZZLE_TYPE_VARCHAR,
366
//DRIZZLE_TYPE_TIMESTAMP
367
DRIZZLE_TYPE_VARCHAR,
368
//DRIZZLE_TYPE_LONGLONG
369
DRIZZLE_TYPE_VARCHAR,
370
//DRIZZLE_TYPE_DATETIME
371
DRIZZLE_TYPE_VARCHAR,
373
DRIZZLE_TYPE_VARCHAR,
374
//DRIZZLE_TYPE_VARCHAR
375
DRIZZLE_TYPE_VARCHAR,
376
//DRIZZLE_TYPE_DECIMAL
377
DRIZZLE_TYPE_VARCHAR,
378
//DRIZZLE_TYPE_VARCHAR,
379
DRIZZLE_TYPE_VARCHAR,
362
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
363
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
366
//DRIZZLE_TYPE_DOUBLE
368
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
369
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
370
//DRIZZLE_TYPE_LONGLONG
374
//DRIZZLE_TYPE_DATETIME
376
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
377
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
378
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
379
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
387
static Item_result field_types_result_type [enum_field_types_size]=
386
Return type of which can carry value of both given types in UNION result.
388
@param a type for merging
389
@param b type for merging
395
enum_field_types Field::field_type_merge(enum_field_types a,
398
assert(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
399
assert(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
400
return field_types_merge_rules[field_type2index(a)]
401
[field_type2index(b)];
405
static Item_result field_types_result_type [FIELDTYPE_NUM]=
407
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
408
DECIMAL_RESULT, INT_RESULT,
389
409
//DRIZZLE_TYPE_LONG
391
411
//DRIZZLE_TYPE_DOUBLE
395
//DRIZZLE_TYPE_TIMESTAMP
413
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
414
STRING_RESULT, STRING_RESULT,
397
415
//DRIZZLE_TYPE_LONGLONG
399
419
//DRIZZLE_TYPE_DATETIME
403
//DRIZZLE_TYPE_VARCHAR
405
//DRIZZLE_TYPE_DECIMAL
421
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
422
STRING_RESULT, STRING_RESULT,
423
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
424
DECIMAL_RESULT, STRING_RESULT,
409
425
//DRIZZLE_TYPE_BLOB
415
bool test_if_important_data(const CHARSET_INFO * const cs,
431
Test if the given string contains important data:
432
not spaces for character string,
433
or any data for binary string.
436
test_if_important_data()
442
false - If string does not have important data
443
true - If string has some important data
447
test_if_important_data(const CHARSET_INFO * const cs, const char *str,
419
450
if (cs != &my_charset_bin)
420
451
str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
421
452
return (str < strend);
424
void *Field::operator new(size_t size)
426
return memory::sql_alloc(size);
429
void *Field::operator new(size_t size, memory::Root *mem_root)
431
return mem_root->alloc_root(static_cast<uint32_t>(size));
434
enum_field_types Field::field_type_merge(enum_field_types a,
437
assert(a < enum_field_types_size);
438
assert(b < enum_field_types_size);
439
return field_types_merge_rules[a][b];
457
Detect Item_result by given field type of UNION merge result.
459
@param field_type given field type
462
Item_result (type of internal MySQL expression result)
442
465
Item_result Field::result_merge_type(enum_field_types field_type)
444
assert(field_type < enum_field_types_size);
445
return field_types_result_type[field_type];
448
bool Field::eq(Field *field)
450
return (ptr == field->ptr && null_ptr == field->null_ptr &&
451
null_bit == field->null_bit);
454
uint32_t Field::pack_length() const
459
uint32_t Field::pack_length_in_rec() const
461
return pack_length();
464
uint32_t Field::data_length()
466
return pack_length();
469
uint32_t Field::used_length()
471
return pack_length();
474
uint32_t Field::sort_length() const
476
return pack_length();
479
uint32_t Field::max_data_length() const
481
return pack_length();
484
int Field::reset(void)
486
memset(ptr, 0, pack_length());
490
void Field::reset_fields()
493
void Field::set_default()
495
ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->getInsertRecord());
496
memcpy(ptr, ptr + l_offset, pack_length());
498
*null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
500
if (this == table->next_number_field)
501
table->auto_increment_field_not_null= false;
504
bool Field::binary() const
509
bool Field::zero_pack() const
514
enum ha_base_keytype Field::key_type() const
516
return HA_KEYTYPE_BINARY;
519
uint32_t Field::key_length() const
521
return pack_length();
524
enum_field_types Field::real_type() const
529
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
534
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
536
return memcmp(a,b,pack_length());
539
int Field::cmp_offset(uint32_t row_offset)
541
return cmp(ptr,ptr+row_offset);
544
int Field::cmp_binary_offset(uint32_t row_offset)
546
return cmp_binary(ptr, ptr+row_offset);
549
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
554
int Field::key_cmp(const unsigned char *str, uint32_t)
559
uint32_t Field::decimals() const
564
bool Field::is_null(ptrdiff_t row_offset)
567
(null_ptr[row_offset] & null_bit ? true : false) :
571
bool Field::is_real_null(ptrdiff_t row_offset)
573
return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
576
bool Field::is_null_in_record(const unsigned char *record)
580
return test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
583
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset)
587
return test(null_ptr[with_offset] & null_bit);
590
void Field::set_null(ptrdiff_t row_offset)
593
null_ptr[row_offset]|= null_bit;
596
void Field::set_notnull(ptrdiff_t row_offset)
599
null_ptr[row_offset]&= (unsigned char) ~null_bit;
602
bool Field::maybe_null(void)
604
return null_ptr != 0 || table->maybe_null;
607
bool Field::real_maybe_null(void)
609
return null_ptr != 0;
467
assert(field_type < FIELDTYPE_TEAR_FROM || field_type
468
> FIELDTYPE_TEAR_TO);
469
return field_types_result_type[field_type2index(field_type)];
472
/*****************************************************************************
473
Static help functions
474
*****************************************************************************/
478
Check whether a field type can be partially indexed by a key.
480
This is a static method, rather than a virtual function, because we need
481
to check the type of a non-Field in mysql_alter_table().
483
@param type field type
486
true Type can have a prefixed key
488
false Type can not have a prefixed key
612
491
bool Field::type_can_have_key_part(enum enum_field_types type)
848
926
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
850
if (!(res=val_str_internal(&tmp)) || str_to_time_with_warn(res->ptr(), res->length(), ltime))
927
if (!(res=val_str(&tmp)) ||
928
str_to_time_with_warn(res->ptr(), res->length(), ltime))
858
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
934
This is called when storing a date in a string.
937
Needs to be changed if/when we want to support different time formats.
940
int Field::store_time(DRIZZLE_TIME *ltime,
941
enum enum_drizzle_timestamp_type type_arg __attribute__((unused)))
860
943
char buff[MAX_DATE_STRING_REP_LENGTH];
861
944
uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
862
945
return store(buff, length, &my_charset_bin);
865
bool Field::optimize_range(uint32_t idx, uint32_t)
949
bool Field::optimize_range(uint32_t idx, uint32_t part)
867
return test(table->index_flags(idx) & HA_READ_RANGE);
951
return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
870
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
955
Field *Field::new_field(MEM_ROOT *root, Table *new_table,
956
bool keep_type __attribute__((unused)))
873
if (!(tmp= (Field*) root->memdup_root((char*) this,size_of())))
959
if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
876
962
if (tmp->table->maybe_null)
877
963
tmp->flags&= ~NOT_NULL_FLAG;
878
964
tmp->table= new_table;
879
tmp->key_start.reset();
880
tmp->part_of_key.reset();
881
tmp->part_of_sortkey.reset();
965
tmp->key_start.init(0);
966
tmp->part_of_key.init(0);
967
tmp->part_of_sortkey.init(0);
882
968
tmp->unireg_check= Field::NONE;
883
tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
969
tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
884
970
tmp->reset_fields();
888
Field *Field::new_key_field(memory::Root *root, Table *new_table,
889
unsigned char *new_ptr,
890
unsigned char *new_null_ptr,
975
Field *Field::new_key_field(MEM_ROOT *root, Table *new_table,
976
unsigned char *new_ptr, unsigned char *new_null_ptr,
891
977
uint32_t new_null_bit)
894
980
if ((tmp= new_field(root, new_table, table == new_table)))
897
983
tmp->null_ptr= new_null_ptr;
898
984
tmp->null_bit= new_null_bit;
903
Field *Field::clone(memory::Root *root, Table *new_table)
990
/* This is used to generate a field in Table from TABLE_SHARE */
992
Field *Field::clone(MEM_ROOT *root, Table *new_table)
906
if ((tmp= (Field*) root->memdup_root((char*) this,size_of())))
995
if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
908
997
tmp->init(new_table);
909
tmp->move_field_offset((ptrdiff_t) (new_table->getInsertRecord() -
910
new_table->getDefaultValues()));
998
tmp->move_field_offset((my_ptrdiff_t) (new_table->record[0] -
999
new_table->s->default_values));
916
uint32_t Field::is_equal(CreateField *new_field_ptr)
918
return (new_field_ptr->sql_type == real_type());
1005
/****************************************************************************
1007
****************************************************************************/
1009
int Field_tiny::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
1014
error= get_int(cs, from, len, &rnd, 255, -128, 127);
1015
ptr[0]= unsigned_flag ? (char) (uint64_t) rnd : (char) rnd;
1020
int Field_tiny::store(double nr)
1029
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1032
else if (nr > 255.0)
1035
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1046
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1049
else if (nr > 127.0)
1052
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1056
*ptr=(char) (int) nr;
1062
int Field_tiny::store(int64_t nr, bool unsigned_val)
1068
if (nr < 0 && !unsigned_val)
1071
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1074
else if ((uint64_t) nr > (uint64_t) 255)
1077
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1085
if (nr < 0 && unsigned_val)
1086
nr= 256; // Generate overflow
1090
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1096
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1106
double Field_tiny::val_real(void)
1108
int tmp= unsigned_flag ? (int) ptr[0] :
1109
(int) ((signed char*) ptr)[0];
1110
return (double) tmp;
1114
int64_t Field_tiny::val_int(void)
1116
int tmp= unsigned_flag ? (int) ptr[0] :
1117
(int) ((signed char*) ptr)[0];
1118
return (int64_t) tmp;
1122
String *Field_tiny::val_str(String *val_buffer,
1123
String *val_ptr __attribute__((unused)))
1125
const CHARSET_INFO * const cs= &my_charset_bin;
1127
uint32_t mlength=cmax(field_length+1,5*cs->mbmaxlen);
1128
val_buffer->alloc(mlength);
1129
char *to=(char*) val_buffer->ptr();
1132
length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength, 10,
1135
length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength,-10,
1136
(long) *((signed char*) ptr));
1138
val_buffer->length(length);
1143
bool Field_tiny::send_binary(Protocol *protocol)
1145
return protocol->store_tiny((int64_t) (int8_t) ptr[0]);
1148
int Field_tiny::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
1151
a=(signed char) a_ptr[0]; b= (signed char) b_ptr[0];
1153
return ((unsigned char) a < (unsigned char) b) ? -1 : ((unsigned char) a > (unsigned char) b) ? 1 : 0;
1154
return (a < b) ? -1 : (a > b) ? 1 : 0;
1157
void Field_tiny::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
1162
to[0] = (char) (ptr[0] ^ (unsigned char) 128); /* Revers signbit */
1165
void Field_tiny::sql_type(String &res) const
1167
const CHARSET_INFO * const cs=res.charset();
1168
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
1169
"tinyint(%d)",(int) field_length));
1174
Report "not well formed" or "cannot convert" error
1175
after storing a character string info a field.
1178
check_string_copy_error()
1180
well_formed_error_pos - where not well formed data was first met
1181
cannot_convert_error_pos - where a not-convertable character was first met
1182
end - end of the string
1183
cs - character set of the string
1186
As of version 5.0 both cases return the same error:
1188
"Invalid string value: 'xxx' for column 't' at row 1"
1190
Future versions will possibly introduce a new error message:
1192
"Cannot convert character string: 'xxx' for column 't' at row 1"
1195
false - If errors didn't happen
1196
true - If an error happened
1200
check_string_copy_error(Field_str *field,
1201
const char *well_formed_error_pos,
1202
const char *cannot_convert_error_pos,
1204
const CHARSET_INFO * const cs)
1206
const char *pos, *end_orig;
1209
if (!(pos= well_formed_error_pos) &&
1210
!(pos= cannot_convert_error_pos))
1214
set_if_smaller(end, pos + 6);
1216
for (t= tmp; pos < end; pos++)
1219
If the source string is ASCII compatible (mbminlen==1)
1220
and the source character is in ASCII printable range (0x20..0x7F),
1221
then display the character as is.
1223
Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
1224
or the source character is not in the printable range,
1225
then print the character using HEX notation.
1227
if (((unsigned char) *pos) >= 0x20 &&
1228
((unsigned char) *pos) <= 0x7F &&
1237
*t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
1238
*t++= _dig_vec_upper[((unsigned char) *pos) & 15];
1248
push_warning_printf(field->table->in_use,
1249
field->table->in_use->abort_on_warning ?
1250
DRIZZLE_ERROR::WARN_LEVEL_ERROR :
1251
DRIZZLE_ERROR::WARN_LEVEL_WARN,
1252
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1253
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1254
"string", tmp, field->field_name,
1255
(uint32_t) field->table->in_use->row_count);
1259
uint32_t Field::is_equal(Create_field *new_field)
1261
return (new_field->sql_type == real_type());
1266
1 if the fields are equally defined
1268
0 if the fields are unequally defined
921
1271
bool Field::eq_def(Field *field)
1301
/*****************************************************************************
1302
Handling of field and Create_field
1303
*****************************************************************************/
1306
Convert create_field::length from number of characters to number of bytes.
1309
void Create_field::create_length_to_internal_length(void)
1312
case DRIZZLE_TYPE_BLOB:
1313
case DRIZZLE_TYPE_VARCHAR:
1314
length*= charset->mbmaxlen;
1316
pack_length= calc_pack_length(sql_type, length);
1318
case DRIZZLE_TYPE_ENUM:
1319
/* Pack_length already calculated in sql_parse.cc */
1320
length*= charset->mbmaxlen;
1321
key_length= pack_length;
1323
case DRIZZLE_TYPE_NEWDECIMAL:
1324
key_length= pack_length=
1325
my_decimal_get_binary_size(my_decimal_length_to_precision(length,
1332
key_length= pack_length= calc_pack_length(sql_type, length);
1339
Init for a tmp table field. To be extended if need be.
1341
void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
1342
uint32_t length_arg, uint32_t decimals_arg,
1343
bool maybe_null, bool is_unsigned)
1346
sql_type= sql_type_arg;
1347
char_length= length= length_arg;;
1348
unireg_check= Field::NONE;
1350
charset= &my_charset_bin;
1351
pack_flag= (FIELDFLAG_NUMBER |
1352
((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
1353
(maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
1354
(is_unsigned ? 0 : FIELDFLAG_DECIMAL));
1359
Initialize field definition for create.
1361
@param thd Thread handle
1362
@param fld_name Field name
1363
@param fld_type Field type
1364
@param fld_length Field length
1365
@param fld_decimals Decimal (if any)
1366
@param fld_type_modifier Additional type information
1367
@param fld_default_value Field default value (if any)
1368
@param fld_on_update_value The value of ON UPDATE clause
1369
@param fld_comment Field comment
1370
@param fld_change Field change
1371
@param fld_interval_list Interval list (if any)
1372
@param fld_charset Field charset
1380
bool Create_field::init(THD *thd __attribute__((unused)), char *fld_name, enum_field_types fld_type,
1381
char *fld_length, char *fld_decimals,
1382
uint32_t fld_type_modifier, Item *fld_default_value,
1383
Item *fld_on_update_value, LEX_STRING *fld_comment,
1384
char *fld_change, List<String> *fld_interval_list,
1385
const CHARSET_INFO * const fld_charset,
1386
uint32_t fld_geom_type __attribute__((unused)),
1387
enum column_format_type column_format)
1389
uint32_t sign_len, allowed_type_modifier= 0;
1390
uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
1393
field_name= fld_name;
1394
def= fld_default_value;
1395
flags= fld_type_modifier;
1396
flags|= (((uint32_t)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
1397
unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
1398
Field::NEXT_NUMBER : Field::NONE);
1399
decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
1400
if (decimals >= NOT_FIXED_DEC)
1402
my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
1411
pack_length= key_length= 0;
1412
charset= fld_charset;
1413
interval_list.empty();
1415
comment= *fld_comment;
1417
Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
1418
it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
1420
if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
1421
(fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
1422
flags|= NO_DEFAULT_VALUE_FLAG;
1424
if (fld_length && !(length= (uint32_t) atoi(fld_length)))
1425
fld_length= 0; /* purecov: inspected */
1426
sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
1429
case DRIZZLE_TYPE_TINY:
1431
length= MAX_TINYINT_WIDTH+sign_len;
1432
allowed_type_modifier= AUTO_INCREMENT_FLAG;
1434
case DRIZZLE_TYPE_LONG:
1436
length= MAX_INT_WIDTH+sign_len;
1437
allowed_type_modifier= AUTO_INCREMENT_FLAG;
1439
case DRIZZLE_TYPE_LONGLONG:
1441
length= MAX_BIGINT_WIDTH;
1442
allowed_type_modifier= AUTO_INCREMENT_FLAG;
1444
case DRIZZLE_TYPE_NULL:
1446
case DRIZZLE_TYPE_NEWDECIMAL:
1447
my_decimal_trim(&length, &decimals);
1448
if (length > DECIMAL_MAX_PRECISION)
1450
my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
1451
DECIMAL_MAX_PRECISION);
1454
if (length < decimals)
1456
my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
1460
my_decimal_precision_to_length(length, decimals,
1461
fld_type_modifier & UNSIGNED_FLAG);
1463
my_decimal_get_binary_size(length, decimals);
1465
case DRIZZLE_TYPE_VARCHAR:
1467
Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table
1468
if they don't have a default value
1470
max_field_charlength= MAX_FIELD_VARCHARLENGTH;
1472
case DRIZZLE_TYPE_BLOB:
1473
if (fld_default_value)
1475
/* Allow empty as default value. */
1477
res= fld_default_value->val_str(&str);
1481
case DRIZZLE_TYPE_DOUBLE:
1482
allowed_type_modifier= AUTO_INCREMENT_FLAG;
1483
if (!fld_length && !fld_decimals)
1486
decimals= NOT_FIXED_DEC;
1488
if (length < decimals &&
1489
decimals != NOT_FIXED_DEC)
1491
my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
1495
case DRIZZLE_TYPE_TIMESTAMP:
1498
/* Compressed date YYYYMMDDHHMMSS */
1499
length= MAX_DATETIME_COMPRESSED_WIDTH;
1501
else if (length != MAX_DATETIME_WIDTH)
1504
We support only even TIMESTAMP lengths less or equal than 14
1505
and 19 as length of 4.1 compatible representation.
1507
length= ((length+1)/2)*2; /* purecov: inspected */
1508
length= cmin(length, (uint32_t)MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
1510
flags|= UNSIGNED_FLAG;
1511
if (fld_default_value)
1513
/* Grammar allows only NOW() value for ON UPDATE clause */
1514
if (fld_default_value->type() == Item::FUNC_ITEM &&
1515
((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
1517
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
1518
Field::TIMESTAMP_DN_FIELD);
1520
We don't need default value any longer moreover it is dangerous.
1521
Everything handled by unireg_check further.
1526
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
1532
If we have default TIMESTAMP NOT NULL column without explicit DEFAULT
1533
or ON UPDATE values then for the sake of compatiblity we should treat
1534
this column as having DEFAULT NOW() ON UPDATE NOW() (when we don't
1535
have another TIMESTAMP column with auto-set option before this one)
1536
or DEFAULT 0 (in other cases).
1537
So here we are setting TIMESTAMP_OLD_FIELD only temporary, and will
1538
replace this value by TIMESTAMP_DNUN_FIELD or NONE later when
1539
information about all TIMESTAMP fields in table will be availiable.
1541
If we have TIMESTAMP NULL column without explicit DEFAULT value
1542
we treat it as having DEFAULT NULL attribute.
1544
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD :
1545
(flags & NOT_NULL_FLAG ? Field::TIMESTAMP_OLD_FIELD :
1549
case DRIZZLE_TYPE_NEWDATE:
1552
case DRIZZLE_TYPE_TIME:
1555
case DRIZZLE_TYPE_DATETIME:
1556
length= MAX_DATETIME_WIDTH;
1558
case DRIZZLE_TYPE_ENUM:
1560
/* Should be safe. */
1561
pack_length= get_enum_pack_length(fld_interval_list->elements);
1563
List_iterator<String> it(*fld_interval_list);
1566
interval_list.push_back(tmp);
1567
length= 1; /* See comment for DRIZZLE_TYPE_SET above. */
1571
/* Remember the value of length */
1572
char_length= length;
1574
if (!(flags & BLOB_FLAG) &&
1575
((length > max_field_charlength &&
1576
fld_type != DRIZZLE_TYPE_ENUM &&
1577
(fld_type != DRIZZLE_TYPE_VARCHAR || fld_default_value)) ||
1578
(!length && fld_type != DRIZZLE_TYPE_VARCHAR)))
1580
my_error((fld_type == DRIZZLE_TYPE_VARCHAR) ? ER_TOO_BIG_FIELDLENGTH : ER_TOO_BIG_DISPLAYWIDTH,
1582
fld_name, max_field_charlength); /* purecov: inspected */
1585
fld_type_modifier&= AUTO_INCREMENT_FLAG;
1586
if ((~allowed_type_modifier) & fld_type_modifier)
1588
my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
1592
return(false); /* success */
1596
enum_field_types get_blob_type_from_length(uint32_t length __attribute__((unused)))
1598
enum_field_types type;
1600
type= DRIZZLE_TYPE_BLOB;
1607
Make a field from the .frm file info
947
1610
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
950
case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
951
case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
952
case DRIZZLE_TYPE_DATE:
953
case DRIZZLE_TYPE_ENUM:
954
case DRIZZLE_TYPE_LONG: return 4;
1613
case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
1614
case DRIZZLE_TYPE_TINY : return 1;
1615
case DRIZZLE_TYPE_NEWDATE:
1616
case DRIZZLE_TYPE_TIME: return 3;
1617
case DRIZZLE_TYPE_TIMESTAMP:
1618
case DRIZZLE_TYPE_LONG : return 4;
955
1619
case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
956
1620
case DRIZZLE_TYPE_DATETIME:
957
case DRIZZLE_TYPE_TIMESTAMP:
958
1621
case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
959
case DRIZZLE_TYPE_NULL: return 0;
960
case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
961
case DRIZZLE_TYPE_DECIMAL:
1622
case DRIZZLE_TYPE_NULL : return 0;
1623
case DRIZZLE_TYPE_BLOB: return 4+portable_sizeof_char_ptr;
1624
case DRIZZLE_TYPE_ENUM:
1625
case DRIZZLE_TYPE_NEWDECIMAL:
1626
abort(); return 0; // This shouldn't happen
970
1633
uint32_t pack_length_to_packflag(uint32_t type)
973
case 1: return 1 << FIELDFLAG_PACK_SHIFT;
1636
case 1: return f_settype((uint32_t) DRIZZLE_TYPE_TINY);
974
1637
case 2: assert(1);
975
1638
case 3: assert(1);
976
case 4: return f_settype(DRIZZLE_TYPE_LONG);
977
case 8: return f_settype(DRIZZLE_TYPE_LONGLONG);
1639
case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
1640
case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
979
1642
return 0; // This shouldn't happen
1646
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
1647
unsigned char *null_pos, unsigned char null_bit,
1649
enum_field_types field_type,
1650
const CHARSET_INFO * field_charset,
1651
Field::utype unireg_check,
1653
const char *field_name)
1655
if (!f_maybe_null(pack_flag))
1662
null_bit= ((unsigned char) 1) << null_bit;
1665
switch (field_type) {
1666
case DRIZZLE_TYPE_NEWDATE:
1667
case DRIZZLE_TYPE_TIME:
1668
case DRIZZLE_TYPE_DATETIME:
1669
case DRIZZLE_TYPE_TIMESTAMP:
1670
field_charset= &my_charset_bin;
1674
if (f_is_alpha(pack_flag))
1676
if (!f_is_packed(pack_flag))
1678
if (field_type == DRIZZLE_TYPE_VARCHAR)
1679
return new Field_varstring(ptr,field_length,
1680
HA_VARCHAR_PACKLENGTH(field_length),
1682
unireg_check, field_name,
1688
uint32_t pack_length=calc_pack_length((enum_field_types)
1689
f_packtype(pack_flag),
1692
if (f_is_blob(pack_flag))
1693
return new Field_blob(ptr,null_pos,null_bit,
1694
unireg_check, field_name, share,
1695
pack_length, field_charset);
1698
if (f_is_enum(pack_flag))
1699
return new Field_enum(ptr,field_length,null_pos,null_bit,
1700
unireg_check, field_name,
1701
pack_length, interval, field_charset);
1705
switch (field_type) {
1706
case DRIZZLE_TYPE_NEWDECIMAL:
1707
return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
1708
unireg_check, field_name,
1709
f_decimals(pack_flag),
1710
f_is_decimal_precision(pack_flag) != 0,
1711
f_is_dec(pack_flag) == 0);
1712
case DRIZZLE_TYPE_DOUBLE:
1713
return new Field_double(ptr,field_length,null_pos,null_bit,
1714
unireg_check, field_name,
1715
f_decimals(pack_flag),
1717
f_is_dec(pack_flag)== 0);
1718
case DRIZZLE_TYPE_TINY:
1719
return new Field_tiny(ptr,field_length,null_pos,null_bit,
1720
unireg_check, field_name,
1722
f_is_dec(pack_flag) == 0);
1723
case DRIZZLE_TYPE_LONG:
1724
return new Field_long(ptr,field_length,null_pos,null_bit,
1725
unireg_check, field_name,
1727
f_is_dec(pack_flag) == 0);
1728
case DRIZZLE_TYPE_LONGLONG:
1729
return new Field_int64_t(ptr,field_length,null_pos,null_bit,
1730
unireg_check, field_name,
1732
f_is_dec(pack_flag) == 0);
1733
case DRIZZLE_TYPE_TIMESTAMP:
1734
return new Field_timestamp(ptr,field_length, null_pos, null_bit,
1735
unireg_check, field_name, share,
1737
case DRIZZLE_TYPE_NEWDATE:
1738
return new Field_newdate(ptr,null_pos,null_bit,
1739
unireg_check, field_name, field_charset);
1740
case DRIZZLE_TYPE_TIME:
1741
return new Field_time(ptr,null_pos,null_bit,
1742
unireg_check, field_name, field_charset);
1743
case DRIZZLE_TYPE_DATETIME:
1744
return new Field_datetime(ptr,null_pos,null_bit,
1745
unireg_check, field_name, field_charset);
1746
case DRIZZLE_TYPE_NULL:
1747
return new Field_null(ptr, field_length, unireg_check, field_name,
1749
default: // Impossible (Wrong version)
1756
/** Create a field suitable for create of table. */
1758
Create_field::Create_field(Field *old_field,Field *orig_field)
1761
field_name=change=old_field->field_name;
1762
length= old_field->field_length;
1763
flags= old_field->flags;
1764
unireg_check=old_field->unireg_check;
1765
pack_length=old_field->pack_length();
1766
key_length= old_field->key_length();
1767
sql_type= old_field->real_type();
1768
charset= old_field->charset(); // May be NULL ptr
1769
comment= old_field->comment;
1770
decimals= old_field->decimals();
1772
/* Fix if the original table had 4 byte pointer blobs */
1773
if (flags & BLOB_FLAG)
1774
pack_length= (pack_length- old_field->table->s->blob_ptr_size +
1775
portable_sizeof_char_ptr);
1778
case DRIZZLE_TYPE_BLOB:
1779
sql_type= DRIZZLE_TYPE_BLOB;
1780
length/= charset->mbmaxlen;
1781
key_length/= charset->mbmaxlen;
1783
/* Change CHAR -> VARCHAR if dynamic record length */
1784
case DRIZZLE_TYPE_ENUM:
1785
case DRIZZLE_TYPE_VARCHAR:
1786
/* This is corrected in create_length_to_internal_length */
1787
length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
1793
if (flags & (ENUM_FLAG | SET_FLAG))
1794
interval= ((Field_enum*) old_field)->typelib;
1798
char_length= length;
1800
if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
1801
old_field->ptr && orig_field &&
1802
(sql_type != DRIZZLE_TYPE_TIMESTAMP || /* set def only if */
1803
old_field->table->timestamp_field != old_field || /* timestamp field */
1804
unireg_check == Field::TIMESTAMP_UN_FIELD)) /* has default val */
1806
char buff[MAX_FIELD_WIDTH];
1807
String tmp(buff,sizeof(buff), charset);
1810
/* Get the value from default_values */
1811
diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
1812
orig_field->table->record[0]);
1813
orig_field->move_field_offset(diff); // Points now at default_values
1814
if (!orig_field->is_real_null())
1816
char buff[MAX_FIELD_WIDTH], *pos;
1817
String tmp(buff, sizeof(buff), charset), *res;
1818
res= orig_field->val_str(&tmp);
1819
pos= (char*) sql_strmake(res->ptr(), res->length());
1820
def= new Item_string(pos, res->length(), charset);
1822
orig_field->move_field_offset(-diff); // Back to record[0]
982
1827
/*****************************************************************************
983
1828
Warning handling
984
1829
*****************************************************************************/
986
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
1832
Produce warning or note about data saved into field.
1834
@param level - level of message (Note/Warning/Error)
1835
@param code - error code of message to be produced
1836
@param cuted_increment - whenever we should increase cut fields count or not
1839
This function won't produce warning and increase cut fields counter
1840
if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
1842
if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
1843
This allows us to avoid notes in optimisation, like convert_constant_item().
1846
1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
1852
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
1853
int cuted_increment)
991
1856
If this field was created only for type conversion purposes it
992
1857
will have table == NULL.
994
Session *session= table ? table->in_use : current_session;
995
if (session->count_cuted_fields)
1859
THD *thd= table ? table->in_use : current_thd;
1860
if (thd->count_cuted_fields)
997
session->cuted_fields+= cuted_increment;
998
push_warning_printf(session, level, code, ER(code), field_name,
1862
thd->cuted_fields+= cuted_increment;
1863
push_warning_printf(thd, level, code, ER(code), field_name,
1002
1867
return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
1006
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1009
uint32_t str_length,
1010
enum enum_drizzle_timestamp_type ts_type,
1011
int cuted_increment)
1872
Produce warning or note about datetime string data saved into field.
1874
@param level level of message (Note/Warning/Error)
1875
@param code error code of message to be produced
1876
@param str string value which we tried to save
1877
@param str_length length of string which we tried to save
1878
@param ts_type type of datetime value (datetime/date/time)
1879
@param cuted_increment whenever we should increase cut fields count or not
1882
This function will always produce some warning but won't increase cut
1883
fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
1888
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1890
const char *str, uint32_t str_length,
1891
enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
1013
Session *session= table ? table->in_use : current_session;
1014
if ((session->really_abort_on_warning() &&
1893
THD *thd= table ? table->in_use : current_thd;
1894
if ((thd->really_abort_on_warning() &&
1015
1895
level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
1016
1896
set_warning(level, code, cuted_increment))
1017
make_truncated_value_warning(session, level, str, str_length, ts_type,
1897
make_truncated_value_warning(thd, level, str, str_length, ts_type,
1021
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1024
enum enum_drizzle_timestamp_type ts_type,
1025
int cuted_increment)
1903
Produce warning or note about integer datetime value saved into field.
1905
@param level level of message (Note/Warning/Error)
1906
@param code error code of message to be produced
1907
@param nr numeric value which we tried to save
1908
@param ts_type type of datetime value (datetime/date/time)
1909
@param cuted_increment whenever we should increase cut fields count or not
1912
This function will always produce some warning but won't increase cut
1913
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
1918
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
1919
int64_t nr, enum enum_drizzle_timestamp_type ts_type,
1920
int cuted_increment)
1027
Session *session= table ? table->in_use : current_session;
1028
if (session->really_abort_on_warning() ||
1922
THD *thd= table ? table->in_use : current_thd;
1923
if (thd->really_abort_on_warning() ||
1029
1924
set_warning(level, code, cuted_increment))
1031
1926
char str_nr[22];
1032
char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
1033
make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
1927
char *str_end= int64_t10_to_str(nr, str_nr, -10);
1928
make_truncated_value_warning(thd, level, str_nr, (uint32_t) (str_end - str_nr),
1034
1929
ts_type, field_name);
1038
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1039
const uint32_t code,
1041
enum enum_drizzle_timestamp_type ts_type)
1935
Produce warning or note about double datetime data saved into field.
1937
@param level level of message (Note/Warning/Error)
1938
@param code error code of message to be produced
1939
@param nr double value which we tried to save
1940
@param ts_type type of datetime value (datetime/date/time)
1943
This function will always produce some warning but won't increase cut
1944
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
1949
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
1950
double nr, enum enum_drizzle_timestamp_type ts_type)
1043
Session *session= table ? table->in_use : current_session;
1044
if (session->really_abort_on_warning() ||
1952
THD *thd= table ? table->in_use : current_thd;
1953
if (thd->really_abort_on_warning() ||
1045
1954
set_warning(level, code, 1))
1047
1956
/* DBL_DIG is enough to print '-[digits].E+###' */
1048
1957
char str_nr[DBL_DIG + 8];
1049
uint32_t str_len= snprintf(str_nr, sizeof(str_nr), "%g", nr);
1050
make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
1958
uint32_t str_len= sprintf(str_nr, "%g", nr);
1959
make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
1055
bool Field::isReadSet()
1057
return table->isReadSet(field_index);
1060
bool Field::isWriteSet()
1062
return table->isWriteSet(field_index);
1065
void Field::setReadSet(bool arg)
1068
table->setReadSet(field_index);
1070
table->clearReadSet(field_index);
1073
void Field::setWriteSet(bool arg)
1076
table->setWriteSet(field_index);
1078
table->clearWriteSet(field_index);
1081
std::ostream& operator<<(std::ostream& output, const Field &field)
1083
output << "Field:(";
1084
output << field.field_name;
1086
output << drizzled::display::type(field.real_type());
1089
return output; // for multiple << operators.
1092
} /* namespace drizzled */