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 */
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
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"
25
#include "drizzled/server_includes.h"
26
#include <drizzled/drizzled_error_messages.h>
28
// Maximum allowed exponent value for converting string to decimal
29
#define MAX_EXPONENT 1024
27
#include "drizzled/sql_select.h"
28
#include "drizzled/error.h"
29
#include "drizzled/field/str.h"
30
#include "drizzled/field/num.h"
31
#include "drizzled/field/blob.h"
32
#include "drizzled/field/enum.h"
33
#include "drizzled/field/null.h"
34
#include "drizzled/field/date.h"
35
#include "drizzled/field/decimal.h"
36
#include "drizzled/field/real.h"
37
#include "drizzled/field/double.h"
38
#include "drizzled/field/long.h"
39
#include "drizzled/field/int64_t.h"
40
#include "drizzled/field/num.h"
41
#include "drizzled/field/timestamp.h"
42
#include "drizzled/field/datetime.h"
43
#include "drizzled/field/varstring.h"
31
45
/*****************************************************************************
32
46
Instansiate templates and static variables
33
47
*****************************************************************************/
35
49
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
36
template class List<Create_field>;
37
template class List_iterator<Create_field>;
50
template class List<CreateField>;
51
template class List_iterator<CreateField>;
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,
54
static enum_field_types
55
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
84
57
/* DRIZZLE_TYPE_TINY -> */
86
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
87
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_TINY,
91
64
DRIZZLE_TYPE_DOUBLE,
92
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
93
DRIZZLE_TYPE_TINY, DRIZZLE_TYPE_VARCHAR,
94
//DRIZZLE_TYPE_LONGLONG
67
//DRIZZLE_TYPE_TIMESTAMP
69
//DRIZZLE_TYPE_LONGLONG
95
70
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,
71
//DRIZZLE_TYPE_DATETIME
75
//DRIZZLE_TYPE_VARCHAR
77
//DRIZZLE_TYPE_NEWDECIMAL
78
DRIZZLE_TYPE_NEWDECIMAL,
105
82
DRIZZLE_TYPE_BLOB,
107
84
/* DRIZZLE_TYPE_LONG -> */
109
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
110
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_LONG,
113
//DRIZZLE_TYPE_DOUBLE
114
91
DRIZZLE_TYPE_DOUBLE,
115
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
116
DRIZZLE_TYPE_LONG, DRIZZLE_TYPE_VARCHAR,
117
//DRIZZLE_TYPE_LONGLONG
94
//DRIZZLE_TYPE_TIMESTAMP
96
//DRIZZLE_TYPE_LONGLONG
118
97
DRIZZLE_TYPE_LONGLONG,
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,
98
//DRIZZLE_TYPE_DATETIME
101
DRIZZLE_TYPE_VARCHAR,
102
//DRIZZLE_TYPE_VARCHAR
103
DRIZZLE_TYPE_VARCHAR,
104
//DRIZZLE_TYPE_NEWDECIMAL
105
DRIZZLE_TYPE_NEWDECIMAL,
107
DRIZZLE_TYPE_VARCHAR,
128
109
DRIZZLE_TYPE_BLOB,
130
111
/* DRIZZLE_TYPE_DOUBLE -> */
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,
117
//DRIZZLE_TYPE_DOUBLE
121
//DRIZZLE_TYPE_TIMESTAMP
122
DRIZZLE_TYPE_VARCHAR,
123
//DRIZZLE_TYPE_LONGLONG
125
//DRIZZLE_TYPE_DATETIME
126
DRIZZLE_TYPE_VARCHAR,
128
DRIZZLE_TYPE_VARCHAR,
129
//DRIZZLE_TYPE_VARCHAR
130
DRIZZLE_TYPE_VARCHAR,
131
//DRIZZLE_TYPE_NEWDECIMAL
134
DRIZZLE_TYPE_VARCHAR,
151
136
DRIZZLE_TYPE_BLOB,
153
138
/* DRIZZLE_TYPE_NULL -> */
155
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
156
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_TINY,
158
143
DRIZZLE_TYPE_LONG,
159
//DRIZZLE_TYPE_DOUBLE
144
//DRIZZLE_TYPE_DOUBLE
160
145
DRIZZLE_TYPE_DOUBLE,
161
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
162
DRIZZLE_TYPE_NULL, DRIZZLE_TYPE_TIMESTAMP,
163
//DRIZZLE_TYPE_LONGLONG
148
//DRIZZLE_TYPE_TIMESTAMP
149
DRIZZLE_TYPE_TIMESTAMP,
150
//DRIZZLE_TYPE_LONGLONG
164
151
DRIZZLE_TYPE_LONGLONG,
167
//DRIZZLE_TYPE_DATETIME
152
//DRIZZLE_TYPE_DATETIME
168
153
DRIZZLE_TYPE_DATETIME,
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,
156
//DRIZZLE_TYPE_VARCHAR
157
DRIZZLE_TYPE_VARCHAR,
158
//DRIZZLE_TYPE_NEWDECIMAL
159
DRIZZLE_TYPE_NEWDECIMAL,
174
163
DRIZZLE_TYPE_BLOB,
176
165
/* DRIZZLE_TYPE_TIMESTAMP -> */
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,
168
DRIZZLE_TYPE_VARCHAR,
170
DRIZZLE_TYPE_VARCHAR,
171
//DRIZZLE_TYPE_DOUBLE
172
DRIZZLE_TYPE_VARCHAR,
174
DRIZZLE_TYPE_TIMESTAMP,
175
//DRIZZLE_TYPE_TIMESTAMP
176
DRIZZLE_TYPE_TIMESTAMP,
177
//DRIZZLE_TYPE_LONGLONG
178
DRIZZLE_TYPE_VARCHAR,
179
//DRIZZLE_TYPE_DATETIME
180
DRIZZLE_TYPE_DATETIME,
183
//DRIZZLE_TYPE_VARCHAR
184
DRIZZLE_TYPE_VARCHAR,
185
//DRIZZLE_TYPE_NEWDECIMAL
186
DRIZZLE_TYPE_VARCHAR,
188
DRIZZLE_TYPE_VARCHAR,
197
190
DRIZZLE_TYPE_BLOB,
199
192
/* DRIZZLE_TYPE_LONGLONG -> */
201
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
202
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_LONGLONG,
204
DRIZZLE_TYPE_LONGLONG,
205
//DRIZZLE_TYPE_DOUBLE
195
DRIZZLE_TYPE_LONGLONG,
197
DRIZZLE_TYPE_LONGLONG,
198
//DRIZZLE_TYPE_DOUBLE
206
199
DRIZZLE_TYPE_DOUBLE,
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,
201
DRIZZLE_TYPE_LONGLONG,
202
//DRIZZLE_TYPE_TIMESTAMP
203
DRIZZLE_TYPE_VARCHAR,
204
//DRIZZLE_TYPE_LONGLONG
205
DRIZZLE_TYPE_LONGLONG,
206
//DRIZZLE_TYPE_DATETIME
207
DRIZZLE_TYPE_VARCHAR,
210
//DRIZZLE_TYPE_VARCHAR
211
DRIZZLE_TYPE_VARCHAR,
212
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
213
DRIZZLE_TYPE_NEWDECIMAL,
214
DRIZZLE_TYPE_VARCHAR,
243
216
DRIZZLE_TYPE_BLOB,
245
218
/* DRIZZLE_TYPE_DATETIME -> */
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,
221
DRIZZLE_TYPE_VARCHAR,
223
DRIZZLE_TYPE_VARCHAR,
224
//DRIZZLE_TYPE_DOUBLE
225
DRIZZLE_TYPE_VARCHAR,
227
DRIZZLE_TYPE_DATETIME,
228
//DRIZZLE_TYPE_TIMESTAMP
229
DRIZZLE_TYPE_DATETIME,
230
//DRIZZLE_TYPE_LONGLONG
231
DRIZZLE_TYPE_VARCHAR,
232
//DRIZZLE_TYPE_DATETIME
233
DRIZZLE_TYPE_DATETIME,
236
//DRIZZLE_TYPE_VARCHAR
237
DRIZZLE_TYPE_VARCHAR,
238
//DRIZZLE_TYPE_NEWDECIMAL
239
DRIZZLE_TYPE_VARCHAR,
241
DRIZZLE_TYPE_VARCHAR,
266
243
DRIZZLE_TYPE_BLOB,
268
/* DRIZZLE_TYPE_NEWDATE -> */
245
/* DRIZZLE_TYPE_DATE -> */
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,
248
DRIZZLE_TYPE_VARCHAR,
250
DRIZZLE_TYPE_VARCHAR,
251
//DRIZZLE_TYPE_DOUBLE
252
DRIZZLE_TYPE_VARCHAR,
255
//DRIZZLE_TYPE_TIMESTAMP
256
DRIZZLE_TYPE_DATETIME,
257
//DRIZZLE_TYPE_LONGLONG
258
DRIZZLE_TYPE_VARCHAR,
259
//DRIZZLE_TYPE_DATETIME
260
DRIZZLE_TYPE_DATETIME,
263
//DRIZZLE_TYPE_VARCHAR
264
DRIZZLE_TYPE_VARCHAR,
265
//DRIZZLE_TYPE_NEWDECIMAL
266
DRIZZLE_TYPE_VARCHAR,
268
DRIZZLE_TYPE_VARCHAR,
289
270
DRIZZLE_TYPE_BLOB,
291
272
/* 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,
275
DRIZZLE_TYPE_VARCHAR,
277
DRIZZLE_TYPE_VARCHAR,
278
//DRIZZLE_TYPE_DOUBLE
279
DRIZZLE_TYPE_VARCHAR,
281
DRIZZLE_TYPE_VARCHAR,
282
//DRIZZLE_TYPE_TIMESTAMP
283
DRIZZLE_TYPE_VARCHAR,
284
//DRIZZLE_TYPE_LONGLONG
285
DRIZZLE_TYPE_VARCHAR,
286
//DRIZZLE_TYPE_DATETIME
287
DRIZZLE_TYPE_VARCHAR,
289
DRIZZLE_TYPE_VARCHAR,
290
//DRIZZLE_TYPE_VARCHAR
291
DRIZZLE_TYPE_VARCHAR,
292
//DRIZZLE_TYPE_NEWDECIMAL
293
DRIZZLE_TYPE_VARCHAR,
295
DRIZZLE_TYPE_VARCHAR,
312
297
DRIZZLE_TYPE_BLOB,
314
299
/* DRIZZLE_TYPE_NEWDECIMAL -> */
316
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
317
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_NEWDECIMAL,
319
DRIZZLE_TYPE_NEWDECIMAL,
320
//DRIZZLE_TYPE_DOUBLE
302
DRIZZLE_TYPE_NEWDECIMAL,
304
DRIZZLE_TYPE_NEWDECIMAL,
305
//DRIZZLE_TYPE_DOUBLE
321
306
DRIZZLE_TYPE_DOUBLE,
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,
308
DRIZZLE_TYPE_NEWDECIMAL,
309
//DRIZZLE_TYPE_TIMESTAMP
310
DRIZZLE_TYPE_VARCHAR,
311
//DRIZZLE_TYPE_LONGLONG
312
DRIZZLE_TYPE_NEWDECIMAL,
313
//DRIZZLE_TYPE_DATETIME
314
DRIZZLE_TYPE_VARCHAR,
316
DRIZZLE_TYPE_VARCHAR,
317
//DRIZZLE_TYPE_VARCHAR
318
DRIZZLE_TYPE_VARCHAR,
319
//DRIZZLE_TYPE_NEWDECIMAL
320
DRIZZLE_TYPE_NEWDECIMAL,
322
DRIZZLE_TYPE_VARCHAR,
335
324
DRIZZLE_TYPE_BLOB,
337
326
/* DRIZZLE_TYPE_ENUM -> */
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,
329
DRIZZLE_TYPE_VARCHAR,
331
DRIZZLE_TYPE_VARCHAR,
332
//DRIZZLE_TYPE_DOUBLE
333
DRIZZLE_TYPE_VARCHAR,
336
//DRIZZLE_TYPE_TIMESTAMP
337
DRIZZLE_TYPE_VARCHAR,
338
//DRIZZLE_TYPE_LONGLONG
339
DRIZZLE_TYPE_VARCHAR,
340
//DRIZZLE_TYPE_DATETIME
341
DRIZZLE_TYPE_VARCHAR,
343
DRIZZLE_TYPE_VARCHAR,
344
//DRIZZLE_TYPE_VARCHAR
345
DRIZZLE_TYPE_VARCHAR,
346
//DRIZZLE_TYPE_NEWDECIMAL
347
DRIZZLE_TYPE_VARCHAR,
349
DRIZZLE_TYPE_VARCHAR,
358
351
DRIZZLE_TYPE_BLOB,
360
353
/* DRIZZLE_TYPE_BLOB -> */
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,
359
//DRIZZLE_TYPE_DOUBLE
363
//DRIZZLE_TYPE_TIMESTAMP
365
//DRIZZLE_TYPE_LONGLONG
367
//DRIZZLE_TYPE_DATETIME
371
//DRIZZLE_TYPE_VARCHAR
373
//DRIZZLE_TYPE_NEWDECIMAL
381
378
DRIZZLE_TYPE_BLOB,
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,
382
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
409
386
//DRIZZLE_TYPE_LONG
411
388
//DRIZZLE_TYPE_DOUBLE
413
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
414
STRING_RESULT, STRING_RESULT,
392
//DRIZZLE_TYPE_TIMESTAMP
415
394
//DRIZZLE_TYPE_LONGLONG
419
396
//DRIZZLE_TYPE_DATETIME
421
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
422
STRING_RESULT, STRING_RESULT,
423
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
424
DECIMAL_RESULT, STRING_RESULT,
400
//DRIZZLE_TYPE_VARCHAR
402
//DRIZZLE_TYPE_NEWDECIMAL
425
406
//DRIZZLE_TYPE_BLOB
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,
410
bool test_if_important_data(const CHARSET_INFO * const cs,
450
414
if (cs != &my_charset_bin)
451
415
str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
452
416
return (str < strend);
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)
419
enum_field_types Field::field_type_merge(enum_field_types a,
422
assert(a <= DRIZZLE_TYPE_MAX);
423
assert(b <= DRIZZLE_TYPE_MAX);
424
return field_types_merge_rules[a][b];
465
427
Item_result Field::result_merge_type(enum_field_types field_type)
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
429
assert(field_type <= DRIZZLE_TYPE_MAX);
430
return field_types_result_type[field_type];
433
bool Field::eq(Field *field)
435
return (ptr == field->ptr && null_ptr == field->null_ptr &&
436
null_bit == field->null_bit);
439
uint32_t Field::pack_length() const
444
uint32_t Field::pack_length_in_rec() const
446
return pack_length();
449
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
451
return field_metadata;
454
uint32_t Field::row_pack_length()
459
int Field::save_field_metadata(unsigned char *first_byte)
461
return do_save_field_metadata(first_byte);
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->record[0]);
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(my_ptrdiff_t row_offset)
567
(null_ptr[row_offset] & null_bit ? true : false) :
571
bool Field::is_real_null(my_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->record[0])] & null_bit);
583
bool Field::is_null_in_record_with_offset(my_ptrdiff_t with_offset)
587
return test(null_ptr[with_offset] & null_bit);
590
void Field::set_null(my_ptrdiff_t row_offset)
593
null_ptr[row_offset]|= null_bit;
596
void Field::set_notnull(my_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;
491
612
bool Field::type_can_have_key_part(enum enum_field_types type)
504
Numeric fields base class constructor.
506
Field_num::Field_num(unsigned char *ptr_arg,uint32_t len_arg, unsigned char *null_ptr_arg,
507
unsigned char null_bit_arg, utype unireg_check_arg,
508
const char *field_name_arg,
509
uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
510
:Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
511
unireg_check_arg, field_name_arg),
512
dec(dec_arg),decimal_precision(zero_arg),unsigned_flag(unsigned_arg)
515
flags|=UNSIGNED_FLAG;
520
Test if given number is a int.
523
Make this multi-byte-character safe
525
@param str String to test
526
@param length Length of 'str'
527
@param int_end Pointer to char after last used digit
528
@param cs Character set
531
This is called after one has called strntoull10rnd() function.
536
1 error: empty string or wrong integer.
538
2 error: garbage at the end of string.
541
int Field_num::check_int(const CHARSET_INFO * const cs, const char *str, int length,
542
const char *int_end, int error)
544
/* Test if we get an empty string or wrong integer */
545
if (str == int_end || error == MY_ERRNO_EDOM)
548
String tmp(buff, (uint32_t) sizeof(buff), system_charset_info);
549
tmp.copy(str, length, system_charset_info);
550
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
551
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
552
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
553
"integer", tmp.c_ptr(), field_name,
554
(uint32_t) table->in_use->row_count);
557
/* Test if we have garbage at the end of the given string. */
558
if (test_if_important_data(cs, int_end, str + length))
560
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
568
Conver a string to an integer then check bounds.
573
from String to convert
574
len Length of the string
575
rnd OUT int64_t value
576
unsigned_max max unsigned value
577
signed_min min signed value
578
signed_max max signed value
581
The function calls strntoull10rnd() to get an integer value then
582
check bounds and errors returned. In case of any error a warning
590
bool Field_num::get_int(const CHARSET_INFO * const cs, const char *from, uint32_t len,
591
int64_t *rnd, uint64_t unsigned_max,
592
int64_t signed_min, int64_t signed_max)
597
*rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len,
603
if ((((uint64_t) *rnd > unsigned_max) && (*rnd= (int64_t) unsigned_max)) ||
604
error == MY_ERRNO_ERANGE)
611
if (*rnd < signed_min)
616
else if (*rnd > signed_max)
622
if (table->in_use->count_cuted_fields &&
623
check_int(cs, from, len, end, error))
628
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
633
Process decimal library return codes and issue warnings for overflow and
636
@param op_result decimal library return code (E_DEC_* see include/decimal.h)
641
0 no error or some other errors except overflow
644
623
int Field::warn_if_overflow(int op_result)
646
625
if (op_result == E_DEC_OVERFLOW)
648
627
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
628
return E_DEC_OVERFLOW;
651
630
if (op_result == E_DEC_TRUNCATED)
653
set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
654
/* We return 0 here as this is not a critical issue */
632
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
633
return E_DEC_TRUNCATED;
661
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
638
void Field::init(Table *table_arg)
663
cs= system_charset_info; // QQ move test_if_real into CHARSET_INFO struct
665
while (length && my_isspace(cs,*str))
666
{ // Allow start space
671
if (*str == '+' || *str == '-')
674
if (!length || !(my_isdigit(cs,*str) || *str == '.'))
677
while (length && my_isdigit(cs,*str))
686
while (length && my_isdigit(cs,*str))
693
if (*str == 'E' || *str == 'e')
695
if (length < 3 || (str[1] != '+' && str[1] != '-') ||
696
!my_isdigit(cs,str[2]))
700
while (length && my_isdigit(cs,*str))
705
for (; length ; length--, str++)
707
if (!my_isspace(cs,*str))
640
orig_table= table= table_arg;
641
table_name= &table_arg->alias;
716
Interpret field value as an integer but return the result as a string.
718
This is used for printing bit_fields as numbers while debugging.
721
644
String *Field::val_int_as_str(String *val_buffer, bool unsigned_val)
1244
/****************************************************************************
1246
****************************************************************************/
1248
int Field_tiny::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
1253
error= get_int(cs, from, len, &rnd, 255, -128, 127);
1254
ptr[0]= unsigned_flag ? (char) (uint64_t) rnd : (char) rnd;
1259
int Field_tiny::store(double nr)
1268
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1271
else if (nr > 255.0)
1274
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1285
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1288
else if (nr > 127.0)
1291
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1295
*ptr=(char) (int) nr;
1301
int Field_tiny::store(int64_t nr, bool unsigned_val)
1307
if (nr < 0 && !unsigned_val)
1310
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1313
else if ((uint64_t) nr > (uint64_t) 255)
1316
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1324
if (nr < 0 && unsigned_val)
1325
nr= 256; // Generate overflow
1329
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1335
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1345
double Field_tiny::val_real(void)
1347
int tmp= unsigned_flag ? (int) ptr[0] :
1348
(int) ((signed char*) ptr)[0];
1349
return (double) tmp;
1353
int64_t Field_tiny::val_int(void)
1355
int tmp= unsigned_flag ? (int) ptr[0] :
1356
(int) ((signed char*) ptr)[0];
1357
return (int64_t) tmp;
1361
String *Field_tiny::val_str(String *val_buffer,
1362
String *val_ptr __attribute__((unused)))
1364
const CHARSET_INFO * const cs= &my_charset_bin;
1366
uint32_t mlength=cmax(field_length+1,5*cs->mbmaxlen);
1367
val_buffer->alloc(mlength);
1368
char *to=(char*) val_buffer->ptr();
1371
length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength, 10,
1374
length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength,-10,
1375
(long) *((signed char*) ptr));
1377
val_buffer->length(length);
1382
bool Field_tiny::send_binary(Protocol *protocol)
1384
return protocol->store_tiny((int64_t) (int8_t) ptr[0]);
1387
int Field_tiny::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
1390
a=(signed char) a_ptr[0]; b= (signed char) b_ptr[0];
1392
return ((unsigned char) a < (unsigned char) b) ? -1 : ((unsigned char) a > (unsigned char) b) ? 1 : 0;
1393
return (a < b) ? -1 : (a > b) ? 1 : 0;
1396
void Field_tiny::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
1401
to[0] = (char) (ptr[0] ^ (unsigned char) 128); /* Revers signbit */
1404
void Field_tiny::sql_type(String &res) const
1406
const CHARSET_INFO * const cs=res.charset();
1407
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
1408
"tinyint(%d)",(int) field_length));
1414
Report "not well formed" or "cannot convert" error
1415
after storing a character string info a field.
1418
check_string_copy_error()
1420
well_formed_error_pos - where not well formed data was first met
1421
cannot_convert_error_pos - where a not-convertable character was first met
1422
end - end of the string
1423
cs - character set of the string
1426
As of version 5.0 both cases return the same error:
1428
"Invalid string value: 'xxx' for column 't' at row 1"
1430
Future versions will possibly introduce a new error message:
1432
"Cannot convert character string: 'xxx' for column 't' at row 1"
1435
false - If errors didn't happen
1436
true - If an error happened
1440
check_string_copy_error(Field_str *field,
1441
const char *well_formed_error_pos,
1442
const char *cannot_convert_error_pos,
1444
const CHARSET_INFO * const cs)
1446
const char *pos, *end_orig;
1449
if (!(pos= well_formed_error_pos) &&
1450
!(pos= cannot_convert_error_pos))
1454
set_if_smaller(end, pos + 6);
1456
for (t= tmp; pos < end; pos++)
1459
If the source string is ASCII compatible (mbminlen==1)
1460
and the source character is in ASCII printable range (0x20..0x7F),
1461
then display the character as is.
1463
Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
1464
or the source character is not in the printable range,
1465
then print the character using HEX notation.
1467
if (((unsigned char) *pos) >= 0x20 &&
1468
((unsigned char) *pos) <= 0x7F &&
1477
*t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
1478
*t++= _dig_vec_upper[((unsigned char) *pos) & 15];
1488
push_warning_printf(field->table->in_use,
1489
field->table->in_use->abort_on_warning ?
1490
DRIZZLE_ERROR::WARN_LEVEL_ERROR :
1491
DRIZZLE_ERROR::WARN_LEVEL_WARN,
1492
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1493
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1494
"string", tmp, field->field_name,
1495
(uint32_t) field->table->in_use->row_count);
1501
Check if we lost any important data and send a truncation error/warning
1504
Field_longstr::report_if_important_data()
1505
ptr - Truncated rest of string
1506
end - End of truncated string
1509
0 - None was truncated (or we don't count cut fields)
1510
2 - Some bytes was truncated
1513
Check if we lost any important data (anything in a binary string,
1514
or any non-space in others). If only trailing spaces was lost,
1515
send a truncation note, otherwise send a truncation error.
1519
Field_longstr::report_if_important_data(const char *ptr, const char *end)
1521
if ((ptr < end) && table->in_use->count_cuted_fields)
1523
if (test_if_important_data(field_charset, ptr, end))
1525
if (table->in_use->abort_on_warning)
1526
set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
1528
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
1530
else /* If we lost only spaces then produce a NOTE, not a WARNING */
1531
set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
1539
Store double value in Field_varstring.
1541
Pretty prints double number into field_length characters buffer.
1546
int Field_str::store(double nr)
1548
char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
1549
uint32_t local_char_length= field_length / charset()->mbmaxlen;
1553
length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error);
1556
if (table->in_use->abort_on_warning)
1557
set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
1559
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
1561
return store(buff, length, charset());
1565
uint32_t Field::is_equal(Create_field *new_field)
1567
return (new_field->sql_type == real_type());
1571
/* If one of the fields is binary and the other one isn't return 1 else 0 */
1573
bool Field_str::compare_str_field_flags(Create_field *new_field, uint32_t flag_arg)
1575
return (((new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
1576
!(flag_arg & (BINCMP_FLAG | BINARY_FLAG))) ||
1577
(!(new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
1578
(flag_arg & (BINCMP_FLAG | BINARY_FLAG))));
1582
uint32_t Field_str::is_equal(Create_field *new_field)
1584
if (compare_str_field_flags(new_field, flags))
1587
return ((new_field->sql_type == real_type()) &&
1588
new_field->charset == field_charset &&
1589
new_field->length == max_display_length());
1593
int Field_longstr::store_decimal(const my_decimal *d)
1595
char buff[DECIMAL_MAX_STR_LENGTH+1];
1596
String str(buff, sizeof(buff), &my_charset_bin);
1597
my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
1598
return store(str.ptr(), str.length(), str.charset());
1601
uint32_t Field_longstr::max_data_length() const
1603
return field_length + (field_length > 255 ? 2 : 1);
1609
1 if the fields are equally defined
1611
0 if the fields are unequally defined
951
uint32_t Field::is_equal(CreateField *new_field_ptr)
953
return (new_field_ptr->sql_type == real_type());
1614
956
bool Field::eq_def(Field *field)
1646
returns 1 if the fields are equally defined
1648
bool Field_num::eq_def(Field *field)
1650
if (!Field::eq_def(field))
1652
Field_num *from_num= (Field_num*) field;
1654
if (unsigned_flag != from_num->unsigned_flag ||
1655
dec != from_num->dec)
1661
uint32_t Field_num::is_equal(Create_field *new_field)
1663
return ((new_field->sql_type == real_type()) &&
1664
((new_field->flags & UNSIGNED_FLAG) == (uint32_t) (flags &
1666
((new_field->flags & AUTO_INCREMENT_FLAG) ==
1667
(uint32_t) (flags & AUTO_INCREMENT_FLAG)) &&
1668
(new_field->length <= max_display_length()));
1672
/*****************************************************************************
1673
Handling of field and Create_field
1674
*****************************************************************************/
1677
Convert create_field::length from number of characters to number of bytes.
1680
void Create_field::create_length_to_internal_length(void)
1683
case DRIZZLE_TYPE_BLOB:
1684
case DRIZZLE_TYPE_VARCHAR:
1685
length*= charset->mbmaxlen;
1687
pack_length= calc_pack_length(sql_type, length);
1689
case DRIZZLE_TYPE_ENUM:
1690
/* Pack_length already calculated in sql_parse.cc */
1691
length*= charset->mbmaxlen;
1692
key_length= pack_length;
1694
case DRIZZLE_TYPE_NEWDECIMAL:
1695
key_length= pack_length=
1696
my_decimal_get_binary_size(my_decimal_length_to_precision(length,
1703
key_length= pack_length= calc_pack_length(sql_type, length);
1710
Init for a tmp table field. To be extended if need be.
1712
void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
1713
uint32_t length_arg, uint32_t decimals_arg,
1714
bool maybe_null, bool is_unsigned)
1717
sql_type= sql_type_arg;
1718
char_length= length= length_arg;;
1719
unireg_check= Field::NONE;
1721
charset= &my_charset_bin;
1722
pack_flag= (FIELDFLAG_NUMBER |
1723
((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
1724
(maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
1725
(is_unsigned ? 0 : FIELDFLAG_DECIMAL));
1730
Initialize field definition for create.
1732
@param thd Thread handle
1733
@param fld_name Field name
1734
@param fld_type Field type
1735
@param fld_length Field length
1736
@param fld_decimals Decimal (if any)
1737
@param fld_type_modifier Additional type information
1738
@param fld_default_value Field default value (if any)
1739
@param fld_on_update_value The value of ON UPDATE clause
1740
@param fld_comment Field comment
1741
@param fld_change Field change
1742
@param fld_interval_list Interval list (if any)
1743
@param fld_charset Field charset
1751
bool Create_field::init(THD *thd __attribute__((unused)), char *fld_name, enum_field_types fld_type,
1752
char *fld_length, char *fld_decimals,
1753
uint32_t fld_type_modifier, Item *fld_default_value,
1754
Item *fld_on_update_value, LEX_STRING *fld_comment,
1755
char *fld_change, List<String> *fld_interval_list,
1756
const CHARSET_INFO * const fld_charset,
1757
uint32_t fld_geom_type __attribute__((unused)),
1758
enum column_format_type column_format)
1760
uint32_t sign_len, allowed_type_modifier= 0;
1761
uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
1764
field_name= fld_name;
1765
def= fld_default_value;
1766
flags= fld_type_modifier;
1767
flags|= (((uint32_t)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
1768
unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
1769
Field::NEXT_NUMBER : Field::NONE);
1770
decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
1771
if (decimals >= NOT_FIXED_DEC)
1773
my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
1782
pack_length= key_length= 0;
1783
charset= fld_charset;
1784
interval_list.empty();
1786
comment= *fld_comment;
1788
Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
1789
it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
1791
if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
1792
(fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
1793
flags|= NO_DEFAULT_VALUE_FLAG;
1795
if (fld_length && !(length= (uint32_t) atoi(fld_length)))
1796
fld_length= 0; /* purecov: inspected */
1797
sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
1800
case DRIZZLE_TYPE_TINY:
1802
length= MAX_TINYINT_WIDTH+sign_len;
1803
allowed_type_modifier= AUTO_INCREMENT_FLAG;
1805
case DRIZZLE_TYPE_LONG:
1807
length= MAX_INT_WIDTH+sign_len;
1808
allowed_type_modifier= AUTO_INCREMENT_FLAG;
1810
case DRIZZLE_TYPE_LONGLONG:
1812
length= MAX_BIGINT_WIDTH;
1813
allowed_type_modifier= AUTO_INCREMENT_FLAG;
1815
case DRIZZLE_TYPE_NULL:
1817
case DRIZZLE_TYPE_NEWDECIMAL:
1818
my_decimal_trim(&length, &decimals);
1819
if (length > DECIMAL_MAX_PRECISION)
1821
my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
1822
DECIMAL_MAX_PRECISION);
1825
if (length < decimals)
1827
my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
1831
my_decimal_precision_to_length(length, decimals,
1832
fld_type_modifier & UNSIGNED_FLAG);
1834
my_decimal_get_binary_size(length, decimals);
1836
case DRIZZLE_TYPE_VARCHAR:
1838
Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table
1839
if they don't have a default value
1841
max_field_charlength= MAX_FIELD_VARCHARLENGTH;
1843
case DRIZZLE_TYPE_BLOB:
1844
if (fld_default_value)
1846
/* Allow empty as default value. */
1848
res= fld_default_value->val_str(&str);
1852
case DRIZZLE_TYPE_DOUBLE:
1853
allowed_type_modifier= AUTO_INCREMENT_FLAG;
1854
if (!fld_length && !fld_decimals)
1857
decimals= NOT_FIXED_DEC;
1859
if (length < decimals &&
1860
decimals != NOT_FIXED_DEC)
1862
my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
1866
case DRIZZLE_TYPE_TIMESTAMP:
1869
/* Compressed date YYYYMMDDHHMMSS */
1870
length= MAX_DATETIME_COMPRESSED_WIDTH;
1872
else if (length != MAX_DATETIME_WIDTH)
1875
We support only even TIMESTAMP lengths less or equal than 14
1876
and 19 as length of 4.1 compatible representation.
1878
length= ((length+1)/2)*2; /* purecov: inspected */
1879
length= cmin(length, (uint32_t)MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
1881
flags|= UNSIGNED_FLAG;
1882
if (fld_default_value)
1884
/* Grammar allows only NOW() value for ON UPDATE clause */
1885
if (fld_default_value->type() == Item::FUNC_ITEM &&
1886
((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
1888
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
1889
Field::TIMESTAMP_DN_FIELD);
1891
We don't need default value any longer moreover it is dangerous.
1892
Everything handled by unireg_check further.
1897
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
1903
If we have default TIMESTAMP NOT NULL column without explicit DEFAULT
1904
or ON UPDATE values then for the sake of compatiblity we should treat
1905
this column as having DEFAULT NOW() ON UPDATE NOW() (when we don't
1906
have another TIMESTAMP column with auto-set option before this one)
1907
or DEFAULT 0 (in other cases).
1908
So here we are setting TIMESTAMP_OLD_FIELD only temporary, and will
1909
replace this value by TIMESTAMP_DNUN_FIELD or NONE later when
1910
information about all TIMESTAMP fields in table will be availiable.
1912
If we have TIMESTAMP NULL column without explicit DEFAULT value
1913
we treat it as having DEFAULT NULL attribute.
1915
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD :
1916
(flags & NOT_NULL_FLAG ? Field::TIMESTAMP_OLD_FIELD :
1920
case DRIZZLE_TYPE_NEWDATE:
1923
case DRIZZLE_TYPE_TIME:
1926
case DRIZZLE_TYPE_DATETIME:
1927
length= MAX_DATETIME_WIDTH;
1929
case DRIZZLE_TYPE_ENUM:
1931
/* Should be safe. */
1932
pack_length= get_enum_pack_length(fld_interval_list->elements);
1934
List_iterator<String> it(*fld_interval_list);
1937
interval_list.push_back(tmp);
1938
length= 1; /* See comment for DRIZZLE_TYPE_SET above. */
1942
/* Remember the value of length */
1943
char_length= length;
1945
if (!(flags & BLOB_FLAG) &&
1946
((length > max_field_charlength &&
1947
fld_type != DRIZZLE_TYPE_ENUM &&
1948
(fld_type != DRIZZLE_TYPE_VARCHAR || fld_default_value)) ||
1949
(!length && fld_type != DRIZZLE_TYPE_VARCHAR)))
1951
my_error((fld_type == DRIZZLE_TYPE_VARCHAR) ? ER_TOO_BIG_FIELDLENGTH : ER_TOO_BIG_DISPLAYWIDTH,
1953
fld_name, max_field_charlength); /* purecov: inspected */
1956
fld_type_modifier&= AUTO_INCREMENT_FLAG;
1957
if ((~allowed_type_modifier) & fld_type_modifier)
1959
my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
1963
return(false); /* success */
1967
enum_field_types get_blob_type_from_length(uint32_t length __attribute__((unused)))
1969
enum_field_types type;
1971
type= DRIZZLE_TYPE_BLOB;
1978
983
Make a field from the .frm file info
1981
985
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
1984
case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
1985
case DRIZZLE_TYPE_TINY : return 1;
1986
case DRIZZLE_TYPE_NEWDATE:
1987
case DRIZZLE_TYPE_TIME: return 3;
988
case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
989
case DRIZZLE_TYPE_TINY: return 1;
990
case DRIZZLE_TYPE_DATE: return 3;
1988
991
case DRIZZLE_TYPE_TIMESTAMP:
1989
case DRIZZLE_TYPE_LONG : return 4;
992
case DRIZZLE_TYPE_LONG: return 4;
1990
993
case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1991
994
case DRIZZLE_TYPE_DATETIME:
1992
995
case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
1993
case DRIZZLE_TYPE_NULL : return 0;
1994
case DRIZZLE_TYPE_BLOB: return 4+portable_sizeof_char_ptr;
996
case DRIZZLE_TYPE_NULL: return 0;
997
case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
1995
998
case DRIZZLE_TYPE_ENUM:
1996
999
case DRIZZLE_TYPE_NEWDECIMAL:
1997
abort(); return 0; // This shouldn't happen
2004
1006
uint32_t pack_length_to_packflag(uint32_t type)
2006
1008
switch (type) {
2007
case 1: return f_settype((uint32_t) DRIZZLE_TYPE_TINY);
1009
case 1: return 1 << FIELDFLAG_PACK_SHIFT;
2008
1010
case 2: assert(1);
2009
1011
case 3: assert(1);
2010
1012
case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
2063
1070
if (f_is_blob(pack_flag))
2064
return new Field_blob(ptr,null_pos,null_bit,
1071
return new (root) Field_blob(ptr,null_pos,null_bit,
2065
1072
unireg_check, field_name, share,
2066
1073
pack_length, field_charset);
2069
1076
if (f_is_enum(pack_flag))
2070
return new Field_enum(ptr,field_length,null_pos,null_bit,
1078
return new (root) Field_enum(ptr,field_length,null_pos,null_bit,
2071
1079
unireg_check, field_name,
2072
pack_length, interval, field_charset);
1080
get_enum_pack_length(interval->count),
1081
interval, field_charset);
2076
1086
switch (field_type) {
2077
1087
case DRIZZLE_TYPE_NEWDECIMAL:
2078
return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
1088
return new (root) Field_new_decimal(ptr,field_length,null_pos,null_bit,
2079
1089
unireg_check, field_name,
2080
1090
f_decimals(pack_flag),
2081
1091
f_is_decimal_precision(pack_flag) != 0,
2082
1092
f_is_dec(pack_flag) == 0);
2083
1093
case DRIZZLE_TYPE_DOUBLE:
2084
return new Field_double(ptr,field_length,null_pos,null_bit,
1094
return new (root) Field_double(ptr,field_length,null_pos,null_bit,
2085
1095
unireg_check, field_name,
2086
1096
f_decimals(pack_flag),
2088
1098
f_is_dec(pack_flag)== 0);
2089
1099
case DRIZZLE_TYPE_TINY:
2090
return new Field_tiny(ptr,field_length,null_pos,null_bit,
2091
unireg_check, field_name,
2093
f_is_dec(pack_flag) == 0);
2094
1101
case DRIZZLE_TYPE_LONG:
2095
return new Field_long(ptr,field_length,null_pos,null_bit,
1102
return new (root) Field_long(ptr,field_length,null_pos,null_bit,
2096
1103
unireg_check, field_name,
2098
1105
f_is_dec(pack_flag) == 0);
2099
1106
case DRIZZLE_TYPE_LONGLONG:
2100
return new Field_int64_t(ptr,field_length,null_pos,null_bit,
1107
return new (root) Field_int64_t(ptr,field_length,null_pos,null_bit,
2101
1108
unireg_check, field_name,
2103
1110
f_is_dec(pack_flag) == 0);
2104
1111
case DRIZZLE_TYPE_TIMESTAMP:
2105
return new Field_timestamp(ptr,field_length, null_pos, null_bit,
1112
return new (root) Field_timestamp(ptr,field_length, null_pos, null_bit,
2106
1113
unireg_check, field_name, share,
2107
1114
field_charset);
2108
case DRIZZLE_TYPE_NEWDATE:
2109
return new Field_newdate(ptr,null_pos,null_bit,
1115
case DRIZZLE_TYPE_DATE:
1116
return new (root) Field_date(ptr,null_pos,null_bit,
2110
1117
unireg_check, field_name, field_charset);
2111
case DRIZZLE_TYPE_TIME:
2112
return new Field_time(ptr,null_pos,null_bit,
2113
unireg_check, field_name, field_charset);
2114
1118
case DRIZZLE_TYPE_DATETIME:
2115
return new Field_datetime(ptr,null_pos,null_bit,
1119
return new (root) Field_datetime(ptr,null_pos,null_bit,
2116
1120
unireg_check, field_name, field_charset);
2117
1121
case DRIZZLE_TYPE_NULL:
2118
return new Field_null(ptr, field_length, unireg_check, field_name,
1122
return new (root) Field_null(ptr, field_length, unireg_check, field_name,
2119
1123
field_charset);
2120
1124
default: // Impossible (Wrong version)
2127
/** Create a field suitable for create of table. */
2129
Create_field::Create_field(Field *old_field,Field *orig_field)
2132
field_name=change=old_field->field_name;
2133
length= old_field->field_length;
2134
flags= old_field->flags;
2135
unireg_check=old_field->unireg_check;
2136
pack_length=old_field->pack_length();
2137
key_length= old_field->key_length();
2138
sql_type= old_field->real_type();
2139
charset= old_field->charset(); // May be NULL ptr
2140
comment= old_field->comment;
2141
decimals= old_field->decimals();
2143
/* Fix if the original table had 4 byte pointer blobs */
2144
if (flags & BLOB_FLAG)
2145
pack_length= (pack_length- old_field->table->s->blob_ptr_size +
2146
portable_sizeof_char_ptr);
2149
case DRIZZLE_TYPE_BLOB:
2150
sql_type= DRIZZLE_TYPE_BLOB;
2151
length/= charset->mbmaxlen;
2152
key_length/= charset->mbmaxlen;
2154
/* Change CHAR -> VARCHAR if dynamic record length */
2155
case DRIZZLE_TYPE_ENUM:
2156
case DRIZZLE_TYPE_VARCHAR:
2157
/* This is corrected in create_length_to_internal_length */
2158
length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
2164
if (flags & (ENUM_FLAG | SET_FLAG))
2165
interval= ((Field_enum*) old_field)->typelib;
2169
char_length= length;
2171
if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
2172
old_field->ptr && orig_field &&
2173
(sql_type != DRIZZLE_TYPE_TIMESTAMP || /* set def only if */
2174
old_field->table->timestamp_field != old_field || /* timestamp field */
2175
unireg_check == Field::TIMESTAMP_UN_FIELD)) /* has default val */
2177
char buff[MAX_FIELD_WIDTH];
2178
String tmp(buff,sizeof(buff), charset);
2181
/* Get the value from default_values */
2182
diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
2183
orig_field->table->record[0]);
2184
orig_field->move_field_offset(diff); // Points now at default_values
2185
if (!orig_field->is_real_null())
2187
char buff[MAX_FIELD_WIDTH], *pos;
2188
String tmp(buff, sizeof(buff), charset), *res;
2189
res= orig_field->val_str(&tmp);
2190
pos= (char*) sql_strmake(res->ptr(), res->length());
2191
def= new Item_string(pos, res->length(), charset);
2193
orig_field->move_field_offset(-diff); // Back to record[0]
2198
1130
/*****************************************************************************
2199
1131
Warning handling
2200
1132
*****************************************************************************/
2203
Produce warning or note about data saved into field.
2205
@param level - level of message (Note/Warning/Error)
2206
@param code - error code of message to be produced
2207
@param cuted_increment - whenever we should increase cut fields count or not
2210
This function won't produce warning and increase cut fields counter
2211
if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
2213
if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
2214
This allows us to avoid notes in optimisation, like convert_constant_item().
2217
1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
2223
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2224
int cuted_increment)
1134
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
1136
int cuted_increment)
2227
1139
If this field was created only for type conversion purposes it
2228
1140
will have table == NULL.
2230
THD *thd= table ? table->in_use : current_thd;
2231
if (thd->count_cuted_fields)
1142
Session *session= table ? table->in_use : current_session;
1143
if (session->count_cuted_fields)
2233
thd->cuted_fields+= cuted_increment;
2234
push_warning_printf(thd, level, code, ER(code), field_name,
1145
session->cuted_fields+= cuted_increment;
1146
push_warning_printf(session, level, code, ER(code), field_name,
1147
session->row_count);
2238
1150
return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
2243
Produce warning or note about datetime string data saved into field.
2245
@param level level of message (Note/Warning/Error)
2246
@param code error code of message to be produced
2247
@param str string value which we tried to save
2248
@param str_length length of string which we tried to save
2249
@param ts_type type of datetime value (datetime/date/time)
2250
@param cuted_increment whenever we should increase cut fields count or not
2253
This function will always produce some warning but won't increase cut
2254
fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
2259
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
2261
const char *str, uint32_t str_length,
2262
enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
1154
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1157
uint32_t str_length,
1158
enum enum_drizzle_timestamp_type ts_type,
1159
int cuted_increment)
2264
THD *thd= table ? table->in_use : current_thd;
2265
if ((thd->really_abort_on_warning() &&
1161
Session *session= table ? table->in_use : current_session;
1162
if ((session->really_abort_on_warning() &&
2266
1163
level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
2267
1164
set_warning(level, code, cuted_increment))
2268
make_truncated_value_warning(thd, level, str, str_length, ts_type,
1165
make_truncated_value_warning(session, level, str, str_length, ts_type,
2274
Produce warning or note about integer datetime value saved into field.
2276
@param level level of message (Note/Warning/Error)
2277
@param code error code of message to be produced
2278
@param nr numeric value which we tried to save
2279
@param ts_type type of datetime value (datetime/date/time)
2280
@param cuted_increment whenever we should increase cut fields count or not
2283
This function will always produce some warning but won't increase cut
2284
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
2289
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2290
int64_t nr, enum enum_drizzle_timestamp_type ts_type,
2291
int cuted_increment)
1169
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1172
enum enum_drizzle_timestamp_type ts_type,
1173
int cuted_increment)
2293
THD *thd= table ? table->in_use : current_thd;
2294
if (thd->really_abort_on_warning() ||
1175
Session *session= table ? table->in_use : current_session;
1176
if (session->really_abort_on_warning() ||
2295
1177
set_warning(level, code, cuted_increment))
2297
1179
char str_nr[22];
2298
1180
char *str_end= int64_t10_to_str(nr, str_nr, -10);
2299
make_truncated_value_warning(thd, level, str_nr, (uint32_t) (str_end - str_nr),
1181
make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
2300
1182
ts_type, field_name);
2306
Produce warning or note about double datetime data saved into field.
2308
@param level level of message (Note/Warning/Error)
2309
@param code error code of message to be produced
2310
@param nr double value which we tried to save
2311
@param ts_type type of datetime value (datetime/date/time)
2314
This function will always produce some warning but won't increase cut
2315
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
2320
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2321
double nr, enum enum_drizzle_timestamp_type ts_type)
1186
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1187
const uint32_t code,
1189
enum enum_drizzle_timestamp_type ts_type)
2323
THD *thd= table ? table->in_use : current_thd;
2324
if (thd->really_abort_on_warning() ||
1191
Session *session= table ? table->in_use : current_session;
1192
if (session->really_abort_on_warning() ||
2325
1193
set_warning(level, code, 1))
2327
1195
/* DBL_DIG is enough to print '-[digits].E+###' */
2328
1196
char str_nr[DBL_DIG + 8];
2329
1197
uint32_t str_len= sprintf(str_nr, "%g", nr);
2330
make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
1198
make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
1203
bool Field::isReadSet()
1205
return table->isReadSet(field_index);
1208
bool Field::isWriteSet()
1210
return table->isWriteSet(field_index);
1213
void Field::setReadSet(bool arg)
1216
table->setReadSet(field_index);
1218
table->clearReadSet(field_index);
1221
void Field::setWriteSet(bool arg)
1224
table->setWriteSet(field_index);
1226
table->clearWriteSet(field_index);