1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
5
* Copyright (C) 2008 MySQL
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* 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 */
23
* @file This file implements the Field class and API
21
This file implements classes defined in field.h
24
#ifdef USE_PRAGMA_IMPLEMENTATION
25
#pragma implementation // gcc: Class implementation
28
#include "mysql_priv.h"
29
#include "sql_select.h"
30
#include <drizzled/sql_select.h>
31
#include <drizzled/error.h>
32
#include <drizzled/field/str.h>
33
#include <drizzled/field/num.h>
34
#include <drizzled/field/blob.h>
35
#include <drizzled/field/boolean.h>
36
#include <drizzled/field/enum.h>
37
#include <drizzled/field/null.h>
38
#include <drizzled/field/date.h>
39
#include <drizzled/field/decimal.h>
40
#include <drizzled/field/real.h>
41
#include <drizzled/field/double.h>
42
#include <drizzled/field/int32.h>
43
#include <drizzled/field/int64.h>
44
#include <drizzled/field/num.h>
45
#include <drizzled/field/time.h>
46
#include <drizzled/field/epoch.h>
47
#include <drizzled/field/datetime.h>
48
#include <drizzled/field/microtime.h>
49
#include <drizzled/field/varstring.h>
50
#include <drizzled/field/uuid.h>
51
#include <drizzled/time_functions.h>
52
#include <drizzled/internal/m_string.h>
53
#include <drizzled/table.h>
54
#include <drizzled/util/test.h>
55
#include <drizzled/session.h>
56
#include <drizzled/current_session.h>
57
#include <drizzled/display.h>
58
#include <drizzled/typelib.h>
33
// Maximum allowed exponent value for converting string to decimal
34
#define MAX_EXPONENT 1024
63
36
/*****************************************************************************
64
37
Instansiate templates and static variables
65
38
*****************************************************************************/
67
static enum_field_types
68
field_types_merge_rules [enum_field_types_size][enum_field_types_size]=
70
/* DRIZZLE_TYPE_LONG -> */
78
//DRIZZLE_TYPE_TIMESTAMP
80
//DRIZZLE_TYPE_LONGLONG
81
DRIZZLE_TYPE_LONGLONG,
82
//DRIZZLE_TYPE_DATETIME
86
//DRIZZLE_TYPE_VARCHAR
88
//DRIZZLE_TYPE_DECIMAL
96
//DRIZZLE_TYPE_BOOLEAN
100
//DRIZZLE_TYPE_MICROTIME
101
DRIZZLE_TYPE_VARCHAR,
103
/* DRIZZLE_TYPE_DOUBLE -> */
107
//DRIZZLE_TYPE_DOUBLE
111
//DRIZZLE_TYPE_TIMESTAMP
112
DRIZZLE_TYPE_VARCHAR,
113
//DRIZZLE_TYPE_LONGLONG
115
//DRIZZLE_TYPE_DATETIME
116
DRIZZLE_TYPE_VARCHAR,
118
DRIZZLE_TYPE_VARCHAR,
119
//DRIZZLE_TYPE_VARCHAR
120
DRIZZLE_TYPE_VARCHAR,
121
//DRIZZLE_TYPE_DECIMAL
124
DRIZZLE_TYPE_VARCHAR,
129
//DRIZZLE_TYPE_BOOLEAN
130
DRIZZLE_TYPE_VARCHAR,
132
DRIZZLE_TYPE_VARCHAR,
133
//DRIZZLE_TYPE_MICROTIME
134
DRIZZLE_TYPE_VARCHAR,
136
/* DRIZZLE_TYPE_NULL -> */
140
//DRIZZLE_TYPE_DOUBLE
144
//DRIZZLE_TYPE_TIMESTAMP
145
DRIZZLE_TYPE_TIMESTAMP,
146
//DRIZZLE_TYPE_LONGLONG
147
DRIZZLE_TYPE_LONGLONG,
148
//DRIZZLE_TYPE_DATETIME
149
DRIZZLE_TYPE_DATETIME,
152
//DRIZZLE_TYPE_VARCHAR
153
DRIZZLE_TYPE_VARCHAR,
154
//DRIZZLE_TYPE_DECIMAL
155
DRIZZLE_TYPE_DECIMAL,
162
//DRIZZLE_TYPE_BOOLEAN
163
DRIZZLE_TYPE_BOOLEAN,
166
//DRIZZLE_TYPE_MICROTIME
167
DRIZZLE_TYPE_MICROTIME,
169
/* DRIZZLE_TYPE_TIMESTAMP -> */
172
DRIZZLE_TYPE_VARCHAR,
173
//DRIZZLE_TYPE_DOUBLE
174
DRIZZLE_TYPE_VARCHAR,
176
DRIZZLE_TYPE_TIMESTAMP,
177
//DRIZZLE_TYPE_TIMESTAMP
178
DRIZZLE_TYPE_TIMESTAMP,
179
//DRIZZLE_TYPE_LONGLONG
180
DRIZZLE_TYPE_VARCHAR,
181
//DRIZZLE_TYPE_DATETIME
182
DRIZZLE_TYPE_DATETIME,
185
//DRIZZLE_TYPE_VARCHAR
186
DRIZZLE_TYPE_VARCHAR,
187
//DRIZZLE_TYPE_DECIMAL
188
DRIZZLE_TYPE_VARCHAR,
190
DRIZZLE_TYPE_VARCHAR,
195
//DRIZZLE_TYPE_BOOLEAN
196
DRIZZLE_TYPE_VARCHAR,
198
DRIZZLE_TYPE_VARCHAR,
199
//DRIZZLE_TYPE_MICROTIME
200
DRIZZLE_TYPE_VARCHAR,
202
/* DRIZZLE_TYPE_LONGLONG -> */
205
DRIZZLE_TYPE_LONGLONG,
206
//DRIZZLE_TYPE_DOUBLE
209
DRIZZLE_TYPE_LONGLONG,
210
//DRIZZLE_TYPE_TIMESTAMP
211
DRIZZLE_TYPE_VARCHAR,
212
//DRIZZLE_TYPE_LONGLONG
213
DRIZZLE_TYPE_LONGLONG,
214
//DRIZZLE_TYPE_DATETIME
215
DRIZZLE_TYPE_VARCHAR,
218
//DRIZZLE_TYPE_VARCHAR
219
DRIZZLE_TYPE_VARCHAR,
220
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_ENUM
221
DRIZZLE_TYPE_DECIMAL,
222
DRIZZLE_TYPE_VARCHAR,
227
//DRIZZLE_TYPE_BOOLEAN
228
DRIZZLE_TYPE_VARCHAR,
230
DRIZZLE_TYPE_VARCHAR,
231
//DRIZZLE_TYPE_MICROTIME
232
DRIZZLE_TYPE_VARCHAR,
234
/* DRIZZLE_TYPE_DATETIME -> */
237
DRIZZLE_TYPE_VARCHAR,
238
//DRIZZLE_TYPE_DOUBLE
239
DRIZZLE_TYPE_VARCHAR,
241
DRIZZLE_TYPE_DATETIME,
242
//DRIZZLE_TYPE_TIMESTAMP
243
DRIZZLE_TYPE_DATETIME,
244
//DRIZZLE_TYPE_LONGLONG
245
DRIZZLE_TYPE_VARCHAR,
246
//DRIZZLE_TYPE_DATETIME
247
DRIZZLE_TYPE_DATETIME,
250
//DRIZZLE_TYPE_VARCHAR
251
DRIZZLE_TYPE_VARCHAR,
252
//DRIZZLE_TYPE_DECIMAL
253
DRIZZLE_TYPE_VARCHAR,
255
DRIZZLE_TYPE_VARCHAR,
260
//DRIZZLE_TYPE_BOOLEAN
261
DRIZZLE_TYPE_VARCHAR,
263
DRIZZLE_TYPE_VARCHAR,
264
//DRIZZLE_TYPE_MICROTIME
265
DRIZZLE_TYPE_VARCHAR,
267
/* DRIZZLE_TYPE_DATE -> */
270
DRIZZLE_TYPE_VARCHAR,
271
//DRIZZLE_TYPE_DOUBLE
272
DRIZZLE_TYPE_VARCHAR,
275
//DRIZZLE_TYPE_TIMESTAMP
276
DRIZZLE_TYPE_DATETIME,
277
//DRIZZLE_TYPE_LONGLONG
278
DRIZZLE_TYPE_VARCHAR,
279
//DRIZZLE_TYPE_DATETIME
280
DRIZZLE_TYPE_DATETIME,
283
//DRIZZLE_TYPE_VARCHAR
284
DRIZZLE_TYPE_VARCHAR,
285
//DRIZZLE_TYPE_DECIMAL
286
DRIZZLE_TYPE_VARCHAR,
288
DRIZZLE_TYPE_VARCHAR,
293
//DRIZZLE_TYPE_BOOLEAN
294
DRIZZLE_TYPE_VARCHAR,
296
DRIZZLE_TYPE_VARCHAR,
297
//DRIZZLE_TYPE_MICROTIME
298
DRIZZLE_TYPE_VARCHAR,
300
/* DRIZZLE_TYPE_VARCHAR -> */
303
DRIZZLE_TYPE_VARCHAR,
304
//DRIZZLE_TYPE_DOUBLE
305
DRIZZLE_TYPE_VARCHAR,
307
DRIZZLE_TYPE_VARCHAR,
308
//DRIZZLE_TYPE_TIMESTAMP
309
DRIZZLE_TYPE_VARCHAR,
310
//DRIZZLE_TYPE_LONGLONG
311
DRIZZLE_TYPE_VARCHAR,
312
//DRIZZLE_TYPE_DATETIME
313
DRIZZLE_TYPE_VARCHAR,
315
DRIZZLE_TYPE_VARCHAR,
316
//DRIZZLE_TYPE_VARCHAR
317
DRIZZLE_TYPE_VARCHAR,
318
//DRIZZLE_TYPE_DECIMAL
319
DRIZZLE_TYPE_VARCHAR,
321
DRIZZLE_TYPE_VARCHAR,
326
//DRIZZLE_TYPE_BOOLEAN
327
DRIZZLE_TYPE_VARCHAR,
329
DRIZZLE_TYPE_VARCHAR,
330
//DRIZZLE_TYPE_MICROTIME
331
DRIZZLE_TYPE_VARCHAR,
333
/* DRIZZLE_TYPE_DECIMAL -> */
336
DRIZZLE_TYPE_DECIMAL,
337
//DRIZZLE_TYPE_DOUBLE
340
DRIZZLE_TYPE_DECIMAL,
341
//DRIZZLE_TYPE_TIMESTAMP
342
DRIZZLE_TYPE_VARCHAR,
343
//DRIZZLE_TYPE_LONGLONG
344
DRIZZLE_TYPE_DECIMAL,
345
//DRIZZLE_TYPE_DATETIME
346
DRIZZLE_TYPE_VARCHAR,
348
DRIZZLE_TYPE_VARCHAR,
349
//DRIZZLE_TYPE_VARCHAR
350
DRIZZLE_TYPE_VARCHAR,
351
//DRIZZLE_TYPE_DECIMAL
352
DRIZZLE_TYPE_DECIMAL,
354
DRIZZLE_TYPE_VARCHAR,
359
//DRIZZLE_TYPE_BOOLEAN
360
DRIZZLE_TYPE_VARCHAR,
362
DRIZZLE_TYPE_VARCHAR,
363
//DRIZZLE_TYPE_MICROTIME
364
DRIZZLE_TYPE_VARCHAR,
366
/* DRIZZLE_TYPE_ENUM -> */
369
DRIZZLE_TYPE_VARCHAR,
370
//DRIZZLE_TYPE_DOUBLE
371
DRIZZLE_TYPE_VARCHAR,
374
//DRIZZLE_TYPE_TIMESTAMP
375
DRIZZLE_TYPE_VARCHAR,
376
//DRIZZLE_TYPE_LONGLONG
377
DRIZZLE_TYPE_VARCHAR,
378
//DRIZZLE_TYPE_DATETIME
379
DRIZZLE_TYPE_VARCHAR,
381
DRIZZLE_TYPE_VARCHAR,
382
//DRIZZLE_TYPE_VARCHAR
383
DRIZZLE_TYPE_VARCHAR,
384
//DRIZZLE_TYPE_DECIMAL
385
DRIZZLE_TYPE_VARCHAR,
387
DRIZZLE_TYPE_VARCHAR,
392
//DRIZZLE_TYPE_BOOLEAN
393
DRIZZLE_TYPE_VARCHAR,
395
DRIZZLE_TYPE_VARCHAR,
396
//DRIZZLE_TYPE_MICROTIME
397
DRIZZLE_TYPE_VARCHAR,
399
/* DRIZZLE_TYPE_BLOB -> */
403
//DRIZZLE_TYPE_DOUBLE
407
//DRIZZLE_TYPE_TIMESTAMP
409
//DRIZZLE_TYPE_LONGLONG
411
//DRIZZLE_TYPE_DATETIME
415
//DRIZZLE_TYPE_VARCHAR
417
//DRIZZLE_TYPE_DECIMAL
425
//DRIZZLE_TYPE_BOOLEAN
426
DRIZZLE_TYPE_VARCHAR,
428
DRIZZLE_TYPE_VARCHAR,
429
//DRIZZLE_TYPE_MICROTIME
430
DRIZZLE_TYPE_VARCHAR,
432
/* DRIZZLE_TYPE_TIME -> */
435
DRIZZLE_TYPE_VARCHAR,
436
//DRIZZLE_TYPE_DOUBLE
437
DRIZZLE_TYPE_VARCHAR,
440
//DRIZZLE_TYPE_TIMESTAMP
441
DRIZZLE_TYPE_VARCHAR,
442
//DRIZZLE_TYPE_LONGLONG
443
DRIZZLE_TYPE_VARCHAR,
444
//DRIZZLE_TYPE_DATETIME
445
DRIZZLE_TYPE_VARCHAR,
447
DRIZZLE_TYPE_VARCHAR,
448
//DRIZZLE_TYPE_VARCHAR
449
DRIZZLE_TYPE_VARCHAR,
450
//DRIZZLE_TYPE_DECIMAL
451
DRIZZLE_TYPE_VARCHAR,
452
//DRIZZLE_TYPE_VARCHAR,
453
DRIZZLE_TYPE_VARCHAR,
458
//DRIZZLE_TYPE_BOOLEAN
459
DRIZZLE_TYPE_VARCHAR,
462
//DRIZZLE_TYPE_MICROTIME
463
DRIZZLE_TYPE_VARCHAR,
465
/* DRIZZLE_TYPE_BOOLEAN -> */
468
DRIZZLE_TYPE_VARCHAR,
469
//DRIZZLE_TYPE_DOUBLE
470
DRIZZLE_TYPE_VARCHAR,
472
DRIZZLE_TYPE_BOOLEAN,
473
//DRIZZLE_TYPE_TIMESTAMP
474
DRIZZLE_TYPE_VARCHAR,
475
//DRIZZLE_TYPE_LONGLONG
476
DRIZZLE_TYPE_VARCHAR,
477
//DRIZZLE_TYPE_DATETIME
478
DRIZZLE_TYPE_VARCHAR,
480
DRIZZLE_TYPE_VARCHAR,
481
//DRIZZLE_TYPE_VARCHAR
482
DRIZZLE_TYPE_VARCHAR,
483
//DRIZZLE_TYPE_DECIMAL
484
DRIZZLE_TYPE_VARCHAR,
485
//DRIZZLE_TYPE_VARCHAR,
486
DRIZZLE_TYPE_VARCHAR,
491
//DRIZZLE_TYPE_BOOLEAN
492
DRIZZLE_TYPE_BOOLEAN,
494
DRIZZLE_TYPE_VARCHAR,
495
//DRIZZLE_TYPE_MICROTIME
496
DRIZZLE_TYPE_VARCHAR,
498
/* DRIZZLE_TYPE_UUID -> */
501
DRIZZLE_TYPE_VARCHAR,
502
//DRIZZLE_TYPE_DOUBLE
503
DRIZZLE_TYPE_VARCHAR,
506
//DRIZZLE_TYPE_TIMESTAMP
507
DRIZZLE_TYPE_VARCHAR,
508
//DRIZZLE_TYPE_LONGLONG
509
DRIZZLE_TYPE_VARCHAR,
510
//DRIZZLE_TYPE_DATETIME
511
DRIZZLE_TYPE_VARCHAR,
513
DRIZZLE_TYPE_VARCHAR,
514
//DRIZZLE_TYPE_VARCHAR
515
DRIZZLE_TYPE_VARCHAR,
516
//DRIZZLE_TYPE_DECIMAL
517
DRIZZLE_TYPE_VARCHAR,
518
//DRIZZLE_TYPE_VARCHAR,
519
DRIZZLE_TYPE_VARCHAR,
524
//DRIZZLE_TYPE_BOOLEAN
525
DRIZZLE_TYPE_VARCHAR,
528
//DRIZZLE_TYPE_MICROTIME
529
DRIZZLE_TYPE_VARCHAR,
531
/* DRIZZLE_TYPE_MICROTIME -> */
534
DRIZZLE_TYPE_VARCHAR,
535
//DRIZZLE_TYPE_DOUBLE
536
DRIZZLE_TYPE_VARCHAR,
538
DRIZZLE_TYPE_MICROTIME,
539
//DRIZZLE_TYPE_TIMESTAMP
540
DRIZZLE_TYPE_VARCHAR,
541
//DRIZZLE_TYPE_LONGLONG
542
DRIZZLE_TYPE_VARCHAR,
543
//DRIZZLE_TYPE_DATETIME
544
DRIZZLE_TYPE_VARCHAR,
546
DRIZZLE_TYPE_VARCHAR,
547
//DRIZZLE_TYPE_VARCHAR
548
DRIZZLE_TYPE_VARCHAR,
549
//DRIZZLE_TYPE_DECIMAL
550
DRIZZLE_TYPE_VARCHAR,
551
//DRIZZLE_TYPE_VARCHAR,
552
DRIZZLE_TYPE_VARCHAR,
557
//DRIZZLE_TYPE_BOOLEAN
558
DRIZZLE_TYPE_VARCHAR,
561
//DRIZZLE_TYPE_MICROTIME
562
DRIZZLE_TYPE_MICROTIME,
40
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
41
template class List<Create_field>;
42
template class List_iterator<Create_field>;
45
uchar Field_null::null[1]={1};
46
const char field_separator=',';
48
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
49
#define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128
50
#define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128
51
#define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
52
((ulong) ((1LL << min(arg, 4) * 8) - 1LL))
55
Rules for merging different types of fields in UNION
57
NOTE: to avoid 256*256 table, gap in table types numeration is skiped
58
following #defines describe that gap and how to canculate number of fields
59
and index of field in thia array.
61
#define FIELDTYPE_TEAR_FROM (MYSQL_TYPE_VARCHAR + 1)
62
#define FIELDTYPE_TEAR_TO (MYSQL_TYPE_NEWDECIMAL - 1)
63
#define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO))
64
inline int field_type2index (enum_field_types field_type)
66
return (field_type < FIELDTYPE_TEAR_FROM ?
68
((int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) - 1);
72
static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]=
74
/* MYSQL_TYPE_DECIMAL -> */
76
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
77
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
78
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
79
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
82
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
83
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
85
MYSQL_TYPE_NEWDECIMAL,
86
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
87
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
88
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
89
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
90
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
91
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
92
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
93
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
96
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
97
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
101
/* MYSQL_TYPE_TINY -> */
103
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
104
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
105
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
106
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
109
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
110
MYSQL_TYPE_TINY, MYSQL_TYPE_VARCHAR,
111
//MYSQL_TYPE_LONGLONG
113
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
114
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
115
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
116
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY,
117
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
118
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
119
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
120
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
123
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
124
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
128
/* MYSQL_TYPE_SHORT -> */
130
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
131
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_SHORT,
132
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
133
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
136
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
137
MYSQL_TYPE_SHORT, MYSQL_TYPE_VARCHAR,
138
//MYSQL_TYPE_LONGLONG
140
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
141
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
142
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
143
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_SHORT,
144
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
145
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
146
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
147
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
150
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
151
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
155
/* MYSQL_TYPE_LONG -> */
157
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
158
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONG,
159
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
160
MYSQL_TYPE_LONG, MYSQL_TYPE_LONG,
163
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
164
MYSQL_TYPE_LONG, MYSQL_TYPE_VARCHAR,
165
//MYSQL_TYPE_LONGLONG
167
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
168
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
169
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
170
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONG,
171
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
172
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
173
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
174
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
177
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
178
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
182
/* MYSQL_TYPE_DOUBLE -> */
184
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
185
MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
186
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
187
MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
190
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
191
MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
192
//MYSQL_TYPE_LONGLONG
194
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
195
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
196
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
197
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_DOUBLE,
198
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
199
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
200
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
201
MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
204
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
205
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
209
/* MYSQL_TYPE_NULL -> */
211
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
212
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
213
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
214
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
217
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
218
MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
219
//MYSQL_TYPE_LONGLONG
221
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
222
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_TIME,
223
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
224
MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
225
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
226
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
227
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
228
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_ENUM,
231
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
232
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
236
/* MYSQL_TYPE_TIMESTAMP -> */
238
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
239
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
240
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
241
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
244
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
245
MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_TIMESTAMP,
246
//MYSQL_TYPE_LONGLONG
248
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
249
MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
250
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
251
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
252
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
253
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
254
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
255
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
258
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
259
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
263
/* MYSQL_TYPE_LONGLONG -> */
265
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
266
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONGLONG,
267
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
268
MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
271
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
272
MYSQL_TYPE_LONGLONG, MYSQL_TYPE_VARCHAR,
273
//MYSQL_TYPE_LONGLONG
275
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
276
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
277
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
278
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONGLONG,
279
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
280
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
281
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
282
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
285
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
286
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
290
/* MYSQL_TYPE_DATE -> */
292
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
293
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
294
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
295
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
298
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
299
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
300
//MYSQL_TYPE_LONGLONG
302
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
303
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
304
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
305
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
306
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
307
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
308
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
309
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
312
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
313
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
317
/* MYSQL_TYPE_TIME -> */
319
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
320
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
321
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
322
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
325
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
326
MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME,
327
//MYSQL_TYPE_LONGLONG
329
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
330
MYSQL_TYPE_DATETIME, MYSQL_TYPE_TIME,
331
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
332
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
333
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
334
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
335
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
336
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
339
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
340
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
344
/* MYSQL_TYPE_DATETIME -> */
346
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
347
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
348
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
349
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
352
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
353
MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
354
//MYSQL_TYPE_LONGLONG
356
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
357
MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
358
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
359
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
360
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
361
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
362
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
363
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
366
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
367
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
371
/* MYSQL_TYPE_YEAR -> */
373
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
374
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
375
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
376
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
379
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
380
MYSQL_TYPE_YEAR, MYSQL_TYPE_VARCHAR,
381
//MYSQL_TYPE_LONGLONG
383
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
384
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
385
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
386
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_YEAR,
387
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
388
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
389
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
390
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
393
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
394
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
398
/* MYSQL_TYPE_NEWDATE -> */
400
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
401
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
402
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
403
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
406
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
407
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
408
//MYSQL_TYPE_LONGLONG
410
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
411
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
412
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
413
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
414
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
415
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
416
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
417
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
420
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
421
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
425
/* MYSQL_TYPE_VARCHAR -> */
427
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
428
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
429
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
430
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
433
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
434
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
435
//MYSQL_TYPE_LONGLONG
437
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
438
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
439
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
440
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
441
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
442
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
443
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
444
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
447
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
448
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
452
/* MYSQL_TYPE_NEWDECIMAL -> */
454
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
455
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
456
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
457
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
460
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
461
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
462
//MYSQL_TYPE_LONGLONG
463
MYSQL_TYPE_NEWDECIMAL,
464
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
465
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
466
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
467
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_NEWDECIMAL,
468
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
469
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
470
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
471
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
474
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
475
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
479
/* MYSQL_TYPE_ENUM -> */
481
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
482
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
483
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
484
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
487
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
488
MYSQL_TYPE_ENUM, MYSQL_TYPE_VARCHAR,
489
//MYSQL_TYPE_LONGLONG
491
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
492
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
493
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
494
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
495
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
496
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
497
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
498
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
501
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
502
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
506
/* MYSQL_TYPE_SET -> */
508
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
509
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
510
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
511
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
514
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
515
MYSQL_TYPE_SET, MYSQL_TYPE_VARCHAR,
516
//MYSQL_TYPE_LONGLONG
518
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
519
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
520
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
521
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
522
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
523
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
524
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
525
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
528
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
529
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
533
/* MYSQL_TYPE_BLOB -> */
535
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
536
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
537
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
538
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
541
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
542
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
543
//MYSQL_TYPE_LONGLONG
545
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
546
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
547
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
548
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
549
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
550
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
551
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
552
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
555
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
556
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
560
/* MYSQL_TYPE_VAR_STRING -> */
562
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
563
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
564
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
565
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
568
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
569
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
570
//MYSQL_TYPE_LONGLONG
572
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
573
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
574
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
575
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
576
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
577
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
578
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
579
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
582
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
583
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
587
/* MYSQL_TYPE_STRING -> */
589
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
590
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
591
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
592
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
595
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
596
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
597
//MYSQL_TYPE_LONGLONG
599
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
600
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
601
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
602
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
603
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
604
MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR,
605
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
606
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
609
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
610
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
566
static Item_result field_types_result_type [enum_field_types_size]=
570
//DRIZZLE_TYPE_DOUBLE
617
Return type of which can carry value of both given types in UNION result.
619
@param a type for merging
620
@param b type for merging
626
enum_field_types Field::field_type_merge(enum_field_types a,
629
assert(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
630
assert(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
631
return field_types_merge_rules[field_type2index(a)]
632
[field_type2index(b)];
636
static Item_result field_types_result_type [FIELDTYPE_NUM]=
638
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
639
DECIMAL_RESULT, INT_RESULT,
640
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
641
INT_RESULT, INT_RESULT,
574
//DRIZZLE_TYPE_TIMESTAMP
576
//DRIZZLE_TYPE_LONGLONG
644
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
645
STRING_RESULT, STRING_RESULT,
646
//MYSQL_TYPE_LONGLONG
578
//DRIZZLE_TYPE_DATETIME
582
//DRIZZLE_TYPE_VARCHAR
584
//DRIZZLE_TYPE_DECIMAL
592
//DRIZZLE_TYPE_BOOLEAN
596
//DRIZZLE_TYPE_MICROTIME
648
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
649
STRING_RESULT, STRING_RESULT,
650
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
651
STRING_RESULT, INT_RESULT,
652
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
653
STRING_RESULT, STRING_RESULT,
654
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
655
DECIMAL_RESULT, STRING_RESULT,
658
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
659
STRING_RESULT, STRING_RESULT,
600
bool test_if_important_data(const CHARSET_INFO * const cs,
666
Test if the given string contains important data:
667
not spaces for character string,
668
or any data for binary string.
671
test_if_important_data()
677
false - If string does not have important data
678
true - If string has some important data
682
test_if_important_data(CHARSET_INFO *cs, const char *str, const char *strend)
604
684
if (cs != &my_charset_bin)
605
685
str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
606
686
return (str < strend);
609
void *Field::operator new(size_t size)
611
return memory::sql_alloc(size);
614
void *Field::operator new(size_t size, memory::Root *mem_root)
616
return mem_root->alloc_root(static_cast<uint32_t>(size));
619
enum_field_types Field::field_type_merge(enum_field_types a,
622
assert(a < enum_field_types_size);
623
assert(b < enum_field_types_size);
624
return field_types_merge_rules[a][b];
691
Detect Item_result by given field type of UNION merge result.
693
@param field_type given field type
696
Item_result (type of internal MySQL expression result)
627
699
Item_result Field::result_merge_type(enum_field_types field_type)
629
assert(field_type < enum_field_types_size);
630
return field_types_result_type[field_type];
633
bool Field::eq(Field *field)
635
return (ptr == field->ptr && null_ptr == field->null_ptr &&
636
null_bit == field->null_bit);
639
uint32_t Field::pack_length() const
644
uint32_t Field::pack_length_in_rec() const
646
return pack_length();
649
uint32_t Field::data_length()
651
return pack_length();
654
uint32_t Field::used_length()
656
return pack_length();
659
uint32_t Field::sort_length() const
661
return pack_length();
664
uint32_t Field::max_data_length() const
666
return pack_length();
669
int Field::reset(void)
671
memset(ptr, 0, pack_length());
675
void Field::reset_fields()
678
void Field::set_default()
680
ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->getInsertRecord());
681
memcpy(ptr, ptr + l_offset, pack_length());
683
*null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
685
if (this == table->next_number_field)
686
table->auto_increment_field_not_null= false;
689
bool Field::binary() const
694
bool Field::zero_pack() const
699
enum ha_base_keytype Field::key_type() const
701
return HA_KEYTYPE_BINARY;
704
uint32_t Field::key_length() const
706
return pack_length();
709
enum_field_types Field::real_type() const
714
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
719
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
721
return memcmp(a,b,pack_length());
724
int Field::cmp_offset(uint32_t row_offset)
726
return cmp(ptr,ptr+row_offset);
729
int Field::cmp_binary_offset(uint32_t row_offset)
731
return cmp_binary(ptr, ptr+row_offset);
734
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
739
int Field::key_cmp(const unsigned char *str, uint32_t)
744
uint32_t Field::decimals() const
749
bool Field::is_null(ptrdiff_t row_offset) const
752
(null_ptr[row_offset] & null_bit ? true : false) :
756
bool Field::is_real_null(ptrdiff_t row_offset) const
758
return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
761
bool Field::is_null_in_record(const unsigned char *record) const
765
return test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
768
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset) const
772
return test(null_ptr[with_offset] & null_bit);
775
void Field::set_null(ptrdiff_t row_offset)
778
null_ptr[row_offset]|= null_bit;
781
void Field::set_notnull(ptrdiff_t row_offset)
784
null_ptr[row_offset]&= (unsigned char) ~null_bit;
787
bool Field::maybe_null(void) const
789
return null_ptr != 0 || table->maybe_null;
792
bool Field::real_maybe_null(void) const
794
return null_ptr != 0;
701
assert(field_type < FIELDTYPE_TEAR_FROM || field_type
702
> FIELDTYPE_TEAR_TO);
703
return field_types_result_type[field_type2index(field_type)];
706
/*****************************************************************************
707
Static help functions
708
*****************************************************************************/
712
Check whether a field type can be partially indexed by a key.
714
This is a static method, rather than a virtual function, because we need
715
to check the type of a non-Field in mysql_alter_table().
717
@param type field type
720
true Type can have a prefixed key
722
false Type can not have a prefixed key
797
725
bool Field::type_can_have_key_part(enum enum_field_types type)
800
case DRIZZLE_TYPE_VARCHAR:
801
case DRIZZLE_TYPE_BLOB:
728
case MYSQL_TYPE_VARCHAR:
729
case MYSQL_TYPE_BLOB:
730
case MYSQL_TYPE_VAR_STRING:
731
case MYSQL_TYPE_STRING:
740
Numeric fields base class constructor.
742
Field_num::Field_num(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
743
uchar null_bit_arg, utype unireg_check_arg,
744
const char *field_name_arg,
745
uint8 dec_arg, bool zero_arg, bool unsigned_arg)
746
:Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
747
unireg_check_arg, field_name_arg),
748
dec(dec_arg),zerofill(zero_arg),unsigned_flag(unsigned_arg)
751
flags|=ZEROFILL_FLAG;
753
flags|=UNSIGNED_FLAG;
757
void Field_num::prepend_zeros(String *value)
760
if ((diff= (int) (field_length - value->length())) > 0)
762
bmove_upp((uchar*) value->ptr()+field_length,
763
(uchar*) value->ptr()+value->length(),
765
bfill((uchar*) value->ptr(),diff,'0');
766
value->length(field_length);
767
(void) value->c_ptr_quick(); // Avoid warnings in purify
772
Test if given number is a int.
775
Make this multi-byte-character safe
777
@param str String to test
778
@param length Length of 'str'
779
@param int_end Pointer to char after last used digit
780
@param cs Character set
783
This is called after one has called strntoull10rnd() function.
788
1 error: empty string or wrong integer.
790
2 error: garbage at the end of string.
793
int Field_num::check_int(CHARSET_INFO *cs, const char *str, int length,
794
const char *int_end, int error)
796
/* Test if we get an empty string or wrong integer */
797
if (str == int_end || error == MY_ERRNO_EDOM)
800
String tmp(buff, (uint32) sizeof(buff), system_charset_info);
801
tmp.copy(str, length, system_charset_info);
802
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
803
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
804
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
805
"integer", tmp.c_ptr(), field_name,
806
(ulong) table->in_use->row_count);
809
/* Test if we have garbage at the end of the given string. */
810
if (test_if_important_data(cs, int_end, str + length))
812
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
820
Conver a string to an integer then check bounds.
825
from String to convert
826
len Length of the string
827
rnd OUT int64_t value
828
unsigned_max max unsigned value
829
signed_min min signed value
830
signed_max max signed value
833
The function calls strntoull10rnd() to get an integer value then
834
check bounds and errors returned. In case of any error a warning
842
bool Field_num::get_int(CHARSET_INFO *cs, const char *from, uint len,
843
int64_t *rnd, uint64_t unsigned_max,
844
int64_t signed_min, int64_t signed_max)
849
*rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len,
855
if ((((uint64_t) *rnd > unsigned_max) && (*rnd= (int64_t) unsigned_max)) ||
856
error == MY_ERRNO_ERANGE)
863
if (*rnd < signed_min)
868
else if (*rnd > signed_max)
874
if (table->in_use->count_cuted_fields &&
875
check_int(cs, from, len, end, error))
880
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
885
Process decimal library return codes and issue warnings for overflow and
888
@param op_result decimal library return code (E_DEC_* see include/decimal.h)
893
0 no error or some other errors except overflow
808
896
int Field::warn_if_overflow(int op_result)
810
898
if (op_result == E_DEC_OVERFLOW)
812
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
813
return E_DEC_OVERFLOW;
900
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
815
903
if (op_result == E_DEC_TRUNCATED)
817
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
818
return E_DEC_TRUNCATED;
905
set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
906
/* We return 0 here as this is not a critical issue */
823
void Field::init(Table *table_arg)
825
orig_table= table= table_arg;
913
static bool test_if_real(const char *str,int length, CHARSET_INFO *cs)
915
cs= system_charset_info; // QQ move test_if_real into CHARSET_INFO struct
917
while (length && my_isspace(cs,*str))
918
{ // Allow start space
923
if (*str == '+' || *str == '-')
926
if (!length || !(my_isdigit(cs,*str) || *str == '.'))
929
while (length && my_isdigit(cs,*str))
938
while (length && my_isdigit(cs,*str))
945
if (*str == 'E' || *str == 'e')
947
if (length < 3 || (str[1] != '+' && str[1] != '-') ||
948
!my_isdigit(cs,str[2]))
952
while (length && my_isdigit(cs,*str))
957
for (; length ; length--, str++)
959
if (!my_isspace(cs,*str))
968
Interpret field value as an integer but return the result as a string.
970
This is used for printing bit_fields as numbers while debugging.
973
String *Field::val_int_as_str(String *val_buffer, my_bool unsigned_val)
975
CHARSET_INFO *cs= &my_charset_bin;
977
int64_t value= val_int();
979
if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
981
length= (uint) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
982
MY_INT64_NUM_DECIMAL_DIGITS,
983
unsigned_val ? 10 : -10,
985
val_buffer->length(length);
828
990
/// This is used as a table name when the table structure is not set up
829
Field::Field(unsigned char *ptr_arg,
831
unsigned char *null_ptr_arg,
832
unsigned char null_bit_arg,
833
utype unireg_check_arg,
834
const char *field_name_arg) :
836
null_ptr(null_ptr_arg),
839
field_name(field_name_arg),
840
comment(NULL_LEX_STRING),
843
part_of_key_not_clustered(0),
845
unireg_check(unireg_check_arg),
846
field_length(length_arg),
847
flags(null_ptr ? 0: NOT_NULL_FLAG),
849
null_bit(null_bit_arg),
850
is_created_from_null_item(false)
991
Field::Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
993
utype unireg_check_arg, const char *field_name_arg)
994
:ptr(ptr_arg), null_ptr(null_ptr_arg),
995
table(0), orig_table(0), table_name(0),
996
field_name(field_name_arg),
997
key_start(0), part_of_key(0), part_of_key_not_clustered(0),
998
part_of_sortkey(0), unireg_check(unireg_check_arg),
999
field_length(length_arg), null_bit(null_bit_arg),
1000
is_created_from_null_item(false)
1002
flags=null_ptr ? 0: NOT_NULL_FLAG;
1003
comment.str= (char*) "";
854
void Field::hash(uint32_t *nr, uint32_t *nr2) const
1009
void Field::hash(ulong *nr, ulong *nr2)
1012
1408
return copy->length+ store_length;
1015
bool Field::get_date(type::Time <ime, uint32_t fuzzydate) const
1017
char buff[type::Time::MAX_STRING_LENGTH];
1018
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1020
assert(getTable() and getTable()->getSession());
1022
if (not (res= val_str_internal(&tmp)) or
1023
str_to_datetime_with_warn(getTable()->getSession(),
1024
res->ptr(), res->length(),
1025
<ime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
1033
bool Field::get_time(type::Time <ime) const
1035
char buff[type::Time::MAX_STRING_LENGTH];
1036
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1038
if (not (res= val_str_internal(&tmp)) or
1039
str_to_time_with_warn(getTable()->getSession(), res->ptr(), res->length(), <ime))
1047
int Field::store_time(type::Time <ime, type::timestamp_t)
1053
return store(tmp.ptr(), tmp.length(), &my_charset_bin);
1056
bool Field::optimize_range(uint32_t idx, uint32_t)
1058
return test(table->index_flags(idx) & HA_READ_RANGE);
1061
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
1412
bool Field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
1415
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1416
if (!(res=val_str(&tmp)) ||
1417
str_to_datetime_with_warn(res->ptr(), res->length(),
1418
ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
1423
bool Field::get_time(MYSQL_TIME *ltime)
1426
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1427
if (!(res=val_str(&tmp)) ||
1428
str_to_time_with_warn(res->ptr(), res->length(), ltime))
1434
This is called when storing a date in a string.
1437
Needs to be changed if/when we want to support different time formats.
1440
int Field::store_time(MYSQL_TIME *ltime,
1441
timestamp_type type_arg __attribute__((__unused__)))
1443
char buff[MAX_DATE_STRING_REP_LENGTH];
1444
uint length= (uint) my_TIME_to_str(ltime, buff);
1445
return store(buff, length, &my_charset_bin);
1449
bool Field::optimize_range(uint idx, uint part)
1451
return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
1455
Field *Field::new_field(MEM_ROOT *root, struct st_table *new_table,
1456
bool keep_type __attribute__((unused)))
1064
if (!(tmp= (Field*) root->memdup_root((char*) this,size_of())))
1459
if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1067
1462
if (tmp->table->maybe_null)
1068
1463
tmp->flags&= ~NOT_NULL_FLAG;
1069
1464
tmp->table= new_table;
1070
tmp->key_start.reset();
1071
tmp->part_of_key.reset();
1072
tmp->part_of_sortkey.reset();
1465
tmp->key_start.init(0);
1466
tmp->part_of_key.init(0);
1467
tmp->part_of_sortkey.init(0);
1073
1468
tmp->unireg_check= Field::NONE;
1074
tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
1469
tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG |
1470
ZEROFILL_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
1075
1471
tmp->reset_fields();
1079
Field *Field::new_key_field(memory::Root *root, Table *new_table,
1080
unsigned char *new_ptr,
1081
unsigned char *new_null_ptr,
1082
uint32_t new_null_bit)
1476
Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table,
1477
uchar *new_ptr, uchar *new_null_ptr,
1085
1481
if ((tmp= new_field(root, new_table, table == new_table)))
1088
1484
tmp->null_ptr= new_null_ptr;
1089
1485
tmp->null_bit= new_null_bit;
1094
Field *Field::clone(memory::Root *root, Table *new_table)
1491
/* This is used to generate a field in TABLE from TABLE_SHARE */
1493
Field *Field::clone(MEM_ROOT *root, struct st_table *new_table)
1097
if ((tmp= (Field*) root->memdup_root((char*) this,size_of())))
1496
if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1099
1498
tmp->init(new_table);
1100
tmp->move_field_offset((ptrdiff_t) (new_table->getInsertRecord() -
1101
new_table->getDefaultValues()));
1499
tmp->move_field_offset((my_ptrdiff_t) (new_table->record[0] -
1500
new_table->s->default_values));
1107
uint32_t Field::is_equal(CreateField *new_field_ptr)
1109
return (new_field_ptr->sql_type == real_type());
1506
/****************************************************************************
1507
Field_null, a field that always return NULL
1508
****************************************************************************/
1510
void Field_null::sql_type(String &res) const
1512
res.set_ascii(STRING_WITH_LEN("null"));
1516
/****************************************************************************
1517
** Field_new_decimal
1518
****************************************************************************/
1520
Field_new_decimal::Field_new_decimal(uchar *ptr_arg,
1521
uint32 len_arg, uchar *null_ptr_arg,
1523
enum utype unireg_check_arg,
1524
const char *field_name_arg,
1525
uint8 dec_arg,bool zero_arg,
1527
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1528
unireg_check_arg, field_name_arg, dec_arg, zero_arg, unsigned_arg)
1530
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
1531
set_if_smaller(precision, DECIMAL_MAX_PRECISION);
1532
assert((precision <= DECIMAL_MAX_PRECISION) &&
1533
(dec <= DECIMAL_MAX_SCALE));
1534
bin_size= my_decimal_get_binary_size(precision, dec);
1538
Field_new_decimal::Field_new_decimal(uint32 len_arg,
1539
bool maybe_null_arg,
1543
:Field_num((uchar*) 0, len_arg,
1544
maybe_null_arg ? (uchar*) "": 0, 0,
1545
NONE, name, dec_arg, 0, unsigned_arg)
1547
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
1548
set_if_smaller(precision, DECIMAL_MAX_PRECISION);
1549
assert((precision <= DECIMAL_MAX_PRECISION) &&
1550
(dec <= DECIMAL_MAX_SCALE));
1551
bin_size= my_decimal_get_binary_size(precision, dec);
1555
int Field_new_decimal::reset(void)
1557
store_value(&decimal_zero);
1563
Generate max/min decimal value in case of overflow.
1565
@param decimal_value buffer for value
1566
@param sign sign of value which caused overflow
1569
void Field_new_decimal::set_value_on_overflow(my_decimal *decimal_value,
1572
max_my_decimal(decimal_value, precision, decimals());
1576
my_decimal_set_zero(decimal_value);
1578
decimal_value->sign(true);
1585
Store decimal value in the binary buffer.
1587
Checks if decimal_value fits into field size.
1588
If it does, stores the decimal in the buffer using binary format.
1589
Otherwise sets maximal number that can be stored in the field.
1591
@param decimal_value my_decimal
1599
bool Field_new_decimal::store_value(const my_decimal *decimal_value)
1603
/* check that we do not try to write negative value in unsigned field */
1604
if (unsigned_flag && decimal_value->sign())
1606
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1608
decimal_value= &decimal_zero;
1611
if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
1612
decimal_value, ptr, precision, dec)))
1615
set_value_on_overflow(&buff, decimal_value->sign());
1616
my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
1623
int Field_new_decimal::store(const char *from, uint length,
1624
CHARSET_INFO *charset_arg)
1627
my_decimal decimal_value;
1629
if ((err= str2my_decimal(E_DEC_FATAL_ERROR &
1630
~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
1631
from, length, charset_arg,
1633
table->in_use->abort_on_warning)
1635
/* Because "from" is not NUL-terminated and we use %s in the ER() */
1637
from_as_str.copy(from, length, &my_charset_bin);
1639
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_ERROR,
1640
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1641
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1642
"decimal", from_as_str.c_ptr(), field_name,
1643
(ulong) table->in_use->row_count);
1649
case E_DEC_TRUNCATED:
1650
set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
1652
case E_DEC_OVERFLOW:
1653
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1654
set_value_on_overflow(&decimal_value, decimal_value.sign());
1658
/* Because "from" is not NUL-terminated and we use %s in the ER() */
1660
from_as_str.copy(from, length, &my_charset_bin);
1662
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
1663
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1664
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1665
"decimal", from_as_str.c_ptr(), field_name,
1666
(ulong) table->in_use->row_count);
1667
my_decimal_set_zero(&decimal_value);
1673
store_value(&decimal_value);
1680
Fix following when double2my_decimal when double2decimal
1681
will return E_DEC_TRUNCATED always correctly
1684
int Field_new_decimal::store(double nr)
1686
my_decimal decimal_value;
1689
err= double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
1693
if (check_overflow(err))
1694
set_value_on_overflow(&decimal_value, decimal_value.sign());
1695
/* Only issue a warning if store_value doesn't issue an warning */
1696
table->in_use->got_warning= 0;
1698
if (store_value(&decimal_value))
1700
else if (err && !table->in_use->got_warning)
1701
err= warn_if_overflow(err);
1706
int Field_new_decimal::store(int64_t nr, bool unsigned_val)
1708
my_decimal decimal_value;
1711
if ((err= int2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
1712
nr, unsigned_val, &decimal_value)))
1714
if (check_overflow(err))
1715
set_value_on_overflow(&decimal_value, decimal_value.sign());
1716
/* Only issue a warning if store_value doesn't issue an warning */
1717
table->in_use->got_warning= 0;
1719
if (store_value(&decimal_value))
1721
else if (err && !table->in_use->got_warning)
1722
err= warn_if_overflow(err);
1727
int Field_new_decimal::store_decimal(const my_decimal *decimal_value)
1729
return store_value(decimal_value);
1733
int Field_new_decimal::store_time(MYSQL_TIME *ltime,
1734
timestamp_type t_type __attribute__((__unused__)))
1736
my_decimal decimal_value;
1737
return store_value(date2my_decimal(ltime, &decimal_value));
1741
double Field_new_decimal::val_real(void)
1744
my_decimal decimal_value;
1745
my_decimal2double(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), &dbl);
1750
int64_t Field_new_decimal::val_int(void)
1753
my_decimal decimal_value;
1754
my_decimal2int(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
1760
my_decimal* Field_new_decimal::val_decimal(my_decimal *decimal_value)
1762
binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value,
1764
return(decimal_value);
1768
String *Field_new_decimal::val_str(String *val_buffer,
1769
String *val_ptr __attribute__((unused)))
1771
my_decimal decimal_value;
1772
uint fixed_precision= zerofill ? precision : 0;
1773
my_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
1774
fixed_precision, dec, '0', val_buffer);
1779
int Field_new_decimal::cmp(const uchar *a,const uchar*b)
1781
return memcmp(a, b, bin_size);
1785
void Field_new_decimal::sort_string(uchar *buff,
1786
uint length __attribute__((unused)))
1788
memcpy(buff, ptr, bin_size);
1792
void Field_new_decimal::sql_type(String &str) const
1794
CHARSET_INFO *cs= str.charset();
1795
str.length(cs->cset->snprintf(cs, (char*) str.ptr(), str.alloced_length(),
1796
"decimal(%d,%d)", precision, (int)dec));
1797
add_zerofill_and_unsigned(str);
1802
Save the field metadata for new decimal fields.
1804
Saves the precision in the first byte and decimals() in the second
1805
byte of the field metadata array at index of *metadata_ptr and
1806
*(metadata_ptr + 1).
1808
@param metadata_ptr First byte of field metadata
1810
@returns number of bytes written to metadata_ptr
1812
int Field_new_decimal::do_save_field_metadata(uchar *metadata_ptr)
1814
*metadata_ptr= precision;
1815
*(metadata_ptr + 1)= decimals();
1821
Returns the number of bytes field uses in row-based replication
1824
This method is used in row-based replication to determine the number
1825
of bytes that the field consumes in the row record format. This is
1826
used to skip fields in the master that do not exist on the slave.
1828
@param field_metadata Encoded size in field metadata
1830
@returns The size of the field based on the field metadata.
1832
uint Field_new_decimal::pack_length_from_metadata(uint field_metadata)
1834
uint const source_precision= (field_metadata >> 8U) & 0x00ff;
1835
uint const source_decimal= field_metadata & 0x00ff;
1836
uint const source_size= my_decimal_get_binary_size(source_precision,
1838
return (source_size);
1843
Check to see if field size is compatible with destination.
1845
This method is used in row-based replication to verify that the slave's
1846
field size is less than or equal to the master's field size. The
1847
encoded field metadata (from the master or source) is decoded and compared
1848
to the size of this field (the slave or destination).
1850
@param field_metadata Encoded size in field metadata
1852
@retval 0 if this field's size is < the source field's size
1853
@retval 1 if this field's size is >= the source field's size
1855
int Field_new_decimal::compatible_field_size(uint field_metadata)
1858
uint const source_precision= (field_metadata >> 8U) & 0x00ff;
1859
uint const source_decimal= field_metadata & 0x00ff;
1860
uint const source_size= my_decimal_get_binary_size(source_precision,
1862
uint const destination_size= row_pack_length();
1863
compatible= (source_size <= destination_size);
1865
compatible= (source_precision <= precision) &&
1866
(source_decimal <= decimals());
1867
return (compatible);
1871
uint Field_new_decimal::is_equal(Create_field *new_field)
1873
return ((new_field->sql_type == real_type()) &&
1874
((new_field->flags & UNSIGNED_FLAG) ==
1875
(uint) (flags & UNSIGNED_FLAG)) &&
1876
((new_field->flags & AUTO_INCREMENT_FLAG) ==
1877
(uint) (flags & AUTO_INCREMENT_FLAG)) &&
1878
(new_field->length == max_display_length()) &&
1879
(new_field->decimals == dec));
1884
Unpack a decimal field from row data.
1886
This method is used to unpack a decimal or numeric field from a master
1887
whose size of the field is less than that of the slave.
1889
@param to Destination of the data
1890
@param from Source of the data
1891
@param param_data Precision (upper) and decimal (lower) values
1893
@return New pointer into memory based on from + length of the data
1896
Field_new_decimal::unpack(uchar* to,
1899
bool low_byte_first)
1901
if (param_data == 0)
1902
return Field::unpack(to, from, param_data, low_byte_first);
1904
uint from_precision= (param_data & 0xff00) >> 8U;
1905
uint from_decimal= param_data & 0x00ff;
1906
uint length=pack_length();
1907
uint from_pack_len= my_decimal_get_binary_size(from_precision, from_decimal);
1908
uint len= (param_data && (from_pack_len < length)) ?
1909
from_pack_len : length;
1910
if ((from_pack_len && (from_pack_len < length)) ||
1911
(from_precision < precision) ||
1912
(from_decimal < decimals()))
1915
If the master's data is smaller than the slave, we need to convert
1916
the binary to decimal then resize the decimal converting it back to
1917
a decimal and write that to the raw data buffer.
1919
decimal_digit_t dec_buf[DECIMAL_MAX_PRECISION];
1921
dec.len= from_precision;
1924
Note: bin2decimal does not change the length of the field. So it is
1925
just the first step the resizing operation. The second step does the
1926
resizing using the precision and decimals from the slave.
1928
bin2decimal((uchar *)from, &dec, from_precision, from_decimal);
1929
decimal2bin(&dec, to, precision, decimals());
1932
memcpy(to, from, len); // Sizes are the same, just copy the data.
1936
/****************************************************************************
1938
****************************************************************************/
1940
int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
1945
error= get_int(cs, from, len, &rnd, 255, -128, 127);
1946
ptr[0]= unsigned_flag ? (char) (uint64_t) rnd : (char) rnd;
1951
int Field_tiny::store(double nr)
1960
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1963
else if (nr > 255.0)
1966
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1977
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1980
else if (nr > 127.0)
1983
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1987
*ptr=(char) (int) nr;
1993
int Field_tiny::store(int64_t nr, bool unsigned_val)
1999
if (nr < 0 && !unsigned_val)
2002
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2005
else if ((uint64_t) nr > (uint64_t) 255)
2008
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2016
if (nr < 0 && unsigned_val)
2017
nr= 256; // Generate overflow
2021
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2027
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2037
double Field_tiny::val_real(void)
2039
int tmp= unsigned_flag ? (int) ptr[0] :
2040
(int) ((signed char*) ptr)[0];
2041
return (double) tmp;
2045
int64_t Field_tiny::val_int(void)
2047
int tmp= unsigned_flag ? (int) ptr[0] :
2048
(int) ((signed char*) ptr)[0];
2049
return (int64_t) tmp;
2053
String *Field_tiny::val_str(String *val_buffer,
2054
String *val_ptr __attribute__((unused)))
2056
CHARSET_INFO *cs= &my_charset_bin;
2058
uint mlength=max(field_length+1,5*cs->mbmaxlen);
2059
val_buffer->alloc(mlength);
2060
char *to=(char*) val_buffer->ptr();
2063
length= (uint) cs->cset->long10_to_str(cs,to,mlength, 10,
2066
length= (uint) cs->cset->long10_to_str(cs,to,mlength,-10,
2067
(long) *((signed char*) ptr));
2069
val_buffer->length(length);
2071
prepend_zeros(val_buffer);
2075
bool Field_tiny::send_binary(Protocol *protocol)
2077
return protocol->store_tiny((int64_t) (int8) ptr[0]);
2080
int Field_tiny::cmp(const uchar *a_ptr, const uchar *b_ptr)
2083
a=(signed char) a_ptr[0]; b= (signed char) b_ptr[0];
2085
return ((uchar) a < (uchar) b) ? -1 : ((uchar) a > (uchar) b) ? 1 : 0;
2086
return (a < b) ? -1 : (a > b) ? 1 : 0;
2089
void Field_tiny::sort_string(uchar *to,uint length __attribute__((unused)))
2094
to[0] = (char) (ptr[0] ^ (uchar) 128); /* Revers signbit */
2097
void Field_tiny::sql_type(String &res) const
2099
CHARSET_INFO *cs=res.charset();
2100
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
2101
"tinyint(%d)",(int) field_length));
2102
add_zerofill_and_unsigned(res);
2105
/****************************************************************************
2106
Field type short int (2 byte)
2107
****************************************************************************/
2109
int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
2115
error= get_int(cs, from, len, &rnd, UINT16_MAX, INT16_MIN, INT16_MAX);
2116
store_tmp= unsigned_flag ? (int) (uint64_t) rnd : (int) rnd;
2117
#ifdef WORDS_BIGENDIAN
2118
if (table->s->db_low_byte_first)
2120
int2store(ptr, store_tmp);
2124
shortstore(ptr, (short) store_tmp);
2129
int Field_short::store(double nr)
2139
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2142
else if (nr > (double) UINT16_MAX)
2144
res=(int16) UINT16_MAX;
2145
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2149
res=(int16) (uint16) nr;
2153
if (nr < (double) INT16_MIN)
2156
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2159
else if (nr > (double) INT16_MAX)
2162
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2166
res=(int16) (int) nr;
2168
#ifdef WORDS_BIGENDIAN
2169
if (table->s->db_low_byte_first)
2175
shortstore(ptr,res);
2180
int Field_short::store(int64_t nr, bool unsigned_val)
2187
if (nr < 0L && !unsigned_val)
2190
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2193
else if ((uint64_t) nr > (uint64_t) UINT16_MAX)
2195
res=(int16) UINT16_MAX;
2196
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2200
res=(int16) (uint16) nr;
2204
if (nr < 0 && unsigned_val)
2205
nr= UINT16_MAX+1; // Generate overflow
2210
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2213
else if (nr > (int64_t) INT16_MAX)
2216
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2222
#ifdef WORDS_BIGENDIAN
2223
if (table->s->db_low_byte_first)
2229
shortstore(ptr,res);
2234
double Field_short::val_real(void)
2237
#ifdef WORDS_BIGENDIAN
2238
if (table->s->db_low_byte_first)
2243
return unsigned_flag ? (double) (unsigned short) j : (double) j;
2246
int64_t Field_short::val_int(void)
2249
#ifdef WORDS_BIGENDIAN
2250
if (table->s->db_low_byte_first)
2255
return unsigned_flag ? (int64_t) (unsigned short) j : (int64_t) j;
2259
String *Field_short::val_str(String *val_buffer,
2260
String *val_ptr __attribute__((unused)))
2262
CHARSET_INFO *cs= &my_charset_bin;
2264
uint mlength=max(field_length+1,7*cs->mbmaxlen);
2265
val_buffer->alloc(mlength);
2266
char *to=(char*) val_buffer->ptr();
2268
#ifdef WORDS_BIGENDIAN
2269
if (table->s->db_low_byte_first)
2276
length=(uint) cs->cset->long10_to_str(cs, to, mlength, 10,
2279
length=(uint) cs->cset->long10_to_str(cs, to, mlength,-10, (long) j);
2280
val_buffer->length(length);
2282
prepend_zeros(val_buffer);
2287
bool Field_short::send_binary(Protocol *protocol)
2289
return protocol->store_short(Field_short::val_int());
2293
int Field_short::cmp(const uchar *a_ptr, const uchar *b_ptr)
2296
#ifdef WORDS_BIGENDIAN
2297
if (table->s->db_low_byte_first)
2310
return ((unsigned short) a < (unsigned short) b) ? -1 :
2311
((unsigned short) a > (unsigned short) b) ? 1 : 0;
2312
return (a < b) ? -1 : (a > b) ? 1 : 0;
2315
void Field_short::sort_string(uchar *to,uint length __attribute__((unused)))
2317
#ifdef WORDS_BIGENDIAN
2318
if (!table->s->db_low_byte_first)
2323
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
2332
to[0] = (char) (ptr[1] ^ 128); /* Revers signbit */
2337
void Field_short::sql_type(String &res) const
2339
CHARSET_INFO *cs=res.charset();
2340
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
2341
"smallint(%d)",(int) field_length));
2342
add_zerofill_and_unsigned(res);
2346
/****************************************************************************
2348
****************************************************************************/
2350
int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
2356
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
2357
store_tmp= unsigned_flag ? (long) (uint64_t) rnd : (long) rnd;
2358
#ifdef WORDS_BIGENDIAN
2359
if (table->s->db_low_byte_first)
2361
int4store(ptr, store_tmp);
2365
longstore(ptr, store_tmp);
2370
int Field_long::store(double nr)
2382
else if (nr > (double) UINT32_MAX)
2385
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2389
res=(int32) (ulong) nr;
2393
if (nr < (double) INT32_MIN)
2395
res=(int32) INT32_MIN;
2398
else if (nr > (double) INT32_MAX)
2400
res=(int32) INT32_MAX;
2404
res=(int32) (int64_t) nr;
2407
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2409
#ifdef WORDS_BIGENDIAN
2410
if (table->s->db_low_byte_first)
2421
int Field_long::store(int64_t nr, bool unsigned_val)
2428
if (nr < 0 && !unsigned_val)
2433
else if ((uint64_t) nr >= (1LL << 32))
2435
res=(int32) (uint32) ~0L;
2439
res=(int32) (uint32) nr;
2443
if (nr < 0 && unsigned_val)
2444
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
2445
if (nr < (int64_t) INT32_MIN)
2447
res=(int32) INT32_MIN;
2450
else if (nr > (int64_t) INT32_MAX)
2452
res=(int32) INT32_MAX;
2459
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2461
#ifdef WORDS_BIGENDIAN
2462
if (table->s->db_low_byte_first)
2473
double Field_long::val_real(void)
2476
#ifdef WORDS_BIGENDIAN
2477
if (table->s->db_low_byte_first)
2482
return unsigned_flag ? (double) (uint32) j : (double) j;
2485
int64_t Field_long::val_int(void)
2488
/* See the comment in Field_long::store(long long) */
2489
assert(table->in_use == current_thd);
2490
#ifdef WORDS_BIGENDIAN
2491
if (table->s->db_low_byte_first)
2496
return unsigned_flag ? (int64_t) (uint32) j : (int64_t) j;
2499
String *Field_long::val_str(String *val_buffer,
2500
String *val_ptr __attribute__((unused)))
2502
CHARSET_INFO *cs= &my_charset_bin;
2504
uint mlength=max(field_length+1,12*cs->mbmaxlen);
2505
val_buffer->alloc(mlength);
2506
char *to=(char*) val_buffer->ptr();
2508
#ifdef WORDS_BIGENDIAN
2509
if (table->s->db_low_byte_first)
2516
length=cs->cset->long10_to_str(cs,to,mlength, 10,(long) (uint32)j);
2518
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
2519
val_buffer->length(length);
2521
prepend_zeros(val_buffer);
2526
bool Field_long::send_binary(Protocol *protocol)
2528
return protocol->store_long(Field_long::val_int());
2531
int Field_long::cmp(const uchar *a_ptr, const uchar *b_ptr)
2534
#ifdef WORDS_BIGENDIAN
2535
if (table->s->db_low_byte_first)
2547
return ((uint32) a < (uint32) b) ? -1 : ((uint32) a > (uint32) b) ? 1 : 0;
2548
return (a < b) ? -1 : (a > b) ? 1 : 0;
2551
void Field_long::sort_string(uchar *to,uint length __attribute__((unused)))
2553
#ifdef WORDS_BIGENDIAN
2554
if (!table->s->db_low_byte_first)
2559
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
2570
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */
2578
void Field_long::sql_type(String &res) const
2580
CHARSET_INFO *cs=res.charset();
2581
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
2582
"int(%d)",(int) field_length));
2583
add_zerofill_and_unsigned(res);
2586
/****************************************************************************
2587
Field type int64_t int (8 bytes)
2588
****************************************************************************/
2590
int Field_int64_t::store(const char *from,uint len,CHARSET_INFO *cs)
2596
tmp= cs->cset->strntoull10rnd(cs,from,len,unsigned_flag,&end,&error);
2597
if (error == MY_ERRNO_ERANGE)
2599
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2602
else if (table->in_use->count_cuted_fields &&
2603
check_int(cs, from, len, end, error))
2607
#ifdef WORDS_BIGENDIAN
2608
if (table->s->db_low_byte_first)
2614
int64_tstore(ptr,tmp);
2619
int Field_int64_t::store(double nr)
2632
else if (nr >= (double) UINT64_MAX)
2638
res=(int64_t) (uint64_t) nr;
2642
if (nr <= (double) INT64_MIN)
2645
error= (nr < (double) INT64_MIN);
2647
else if (nr >= (double) (uint64_t) INT64_MAX)
2650
error= (nr > (double) INT64_MAX);
2656
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2658
#ifdef WORDS_BIGENDIAN
2659
if (table->s->db_low_byte_first)
2665
int64_tstore(ptr,res);
2670
int Field_int64_t::store(int64_t nr, bool unsigned_val)
2674
if (nr < 0) // Only possible error
2677
if field is unsigned and value is signed (< 0) or
2678
if field is signed and value is unsigned we have an overflow
2680
if (unsigned_flag != unsigned_val)
2682
nr= unsigned_flag ? (uint64_t) 0 : (uint64_t) INT64_MAX;
2683
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2688
#ifdef WORDS_BIGENDIAN
2689
if (table->s->db_low_byte_first)
2695
int64_tstore(ptr,nr);
2700
double Field_int64_t::val_real(void)
2703
#ifdef WORDS_BIGENDIAN
2704
if (table->s->db_low_byte_first)
2711
/* The following is open coded to avoid a bug in gcc 3.3 */
2714
uint64_t tmp= (uint64_t) j;
2715
return uint64_t2double(tmp);
2721
int64_t Field_int64_t::val_int(void)
2724
#ifdef WORDS_BIGENDIAN
2725
if (table->s->db_low_byte_first)
2734
String *Field_int64_t::val_str(String *val_buffer,
2735
String *val_ptr __attribute__((unused)))
2737
CHARSET_INFO *cs= &my_charset_bin;
2739
uint mlength=max(field_length+1,22*cs->mbmaxlen);
2740
val_buffer->alloc(mlength);
2741
char *to=(char*) val_buffer->ptr();
2743
#ifdef WORDS_BIGENDIAN
2744
if (table->s->db_low_byte_first)
2750
length=(uint) (cs->cset->int64_t10_to_str)(cs,to,mlength,
2751
unsigned_flag ? 10 : -10, j);
2752
val_buffer->length(length);
2754
prepend_zeros(val_buffer);
2759
bool Field_int64_t::send_binary(Protocol *protocol)
2761
return protocol->store_int64_t(Field_int64_t::val_int(), unsigned_flag);
2765
int Field_int64_t::cmp(const uchar *a_ptr, const uchar *b_ptr)
2768
#ifdef WORDS_BIGENDIAN
2769
if (table->s->db_low_byte_first)
2777
int64_tget(a,a_ptr);
2778
int64_tget(b,b_ptr);
2781
return ((uint64_t) a < (uint64_t) b) ? -1 :
2782
((uint64_t) a > (uint64_t) b) ? 1 : 0;
2783
return (a < b) ? -1 : (a > b) ? 1 : 0;
2786
void Field_int64_t::sort_string(uchar *to,uint length __attribute__((unused)))
2788
#ifdef WORDS_BIGENDIAN
2789
if (!table->s->db_low_byte_first)
2794
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
2809
to[0] = (char) (ptr[7] ^ 128); /* Revers signbit */
2821
void Field_int64_t::sql_type(String &res) const
2823
CHARSET_INFO *cs=res.charset();
2824
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
2825
"bigint(%d)",(int) field_length));
2826
add_zerofill_and_unsigned(res);
2831
Floating-point numbers
2835
Field_real::pack(uchar *to, const uchar *from,
2836
uint max_length, bool low_byte_first)
2838
assert(max_length >= pack_length());
2839
#ifdef WORDS_BIGENDIAN
2840
if (low_byte_first != table->s->db_low_byte_first)
2842
const uchar *dptr= from + pack_length();
2843
while (dptr-- > from)
2849
return(Field::pack(to, from, max_length, low_byte_first));
2853
Field_real::unpack(uchar *to, const uchar *from,
2854
uint param_data, bool low_byte_first)
2856
#ifdef WORDS_BIGENDIAN
2857
if (low_byte_first != table->s->db_low_byte_first)
2859
const uchar *dptr= from + pack_length();
2860
while (dptr-- > from)
2862
return(from + pack_length());
2866
return(Field::unpack(to, from, param_data, low_byte_first));
2869
/****************************************************************************
2870
double precision floating point numbers
2871
****************************************************************************/
2873
int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
2877
double nr= my_strntod(cs,(char*) from, len, &end, &error);
2878
if (error || (!len || (((uint) (end-from) != len) && table->in_use->count_cuted_fields)))
2880
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
2881
(error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED), 1);
2882
error= error ? 1 : 2;
2884
Field_double::store(nr);
2889
int Field_double::store(double nr)
2891
int error= truncate(&nr, DBL_MAX);
2893
#ifdef WORDS_BIGENDIAN
2894
if (table->s->db_low_byte_first)
2896
float8store(ptr,nr);
2900
doublestore(ptr,nr);
2905
int Field_double::store(int64_t nr, bool unsigned_val)
2907
return Field_double::store(unsigned_val ? uint64_t2double((uint64_t) nr) :
2912
If a field has fixed length, truncate the double argument pointed to by 'nr'
2914
Also ensure that the argument is within [-max_value; max_value] range.
2917
int Field_real::truncate(double *nr, double max_value)
2926
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2929
else if (unsigned_flag && res < 0)
2932
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2938
uint order= field_length - dec;
2939
uint step= array_elements(log_10) - 1;
2941
for (; order > step; order-= step)
2942
max_value*= log_10[step];
2943
max_value*= log_10[order];
2944
max_value-= 1.0 / log_10[dec];
2946
/* Check for infinity so we don't get NaN in calculations */
2949
double tmp= rint((res - floor(res)) * log_10[dec]) / log_10[dec];
2950
res= floor(res) + tmp;
2954
if (res < -max_value)
2957
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2959
else if (res > max_value)
2962
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2973
int Field_real::store_decimal(const my_decimal *dm)
2976
my_decimal2double(E_DEC_FATAL_ERROR, dm, &dbl);
2980
double Field_double::val_real(void)
2983
#ifdef WORDS_BIGENDIAN
2984
if (table->s->db_low_byte_first)
2994
int64_t Field_double::val_int(void)
2998
#ifdef WORDS_BIGENDIAN
2999
if (table->s->db_low_byte_first)
3006
/* Check whether we fit into int64_t range */
3007
if (j <= (double) INT64_MIN)
3009
res= (int64_t) INT64_MIN;
3012
if (j >= (double) (uint64_t) INT64_MAX)
3014
res= (int64_t) INT64_MAX;
3017
return (int64_t) rint(j);
3021
char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
3022
String tmp(buf, sizeof(buf), &my_charset_latin1), *str;
3023
str= val_str(&tmp, 0);
3024
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3025
ER_TRUNCATED_WRONG_VALUE,
3026
ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
3033
my_decimal *Field_real::val_decimal(my_decimal *decimal_value)
3035
double2my_decimal(E_DEC_FATAL_ERROR, val_real(), decimal_value);
3036
return decimal_value;
3040
String *Field_double::val_str(String *val_buffer,
3041
String *val_ptr __attribute__((unused)))
3044
#ifdef WORDS_BIGENDIAN
3045
if (table->s->db_low_byte_first)
3053
uint to_length=max(field_length, DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
3054
val_buffer->alloc(to_length);
3055
char *to=(char*) val_buffer->ptr();
3058
if (dec >= NOT_FIXED_DEC)
3059
len= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
3061
len= my_fcvt(nr, dec, to, NULL);
3063
val_buffer->length((uint) len);
3065
prepend_zeros(val_buffer);
3069
bool Field_double::send_binary(Protocol *protocol)
3071
return protocol->store((double) Field_double::val_real(), dec, (String*) 0);
3075
int Field_double::cmp(const uchar *a_ptr, const uchar *b_ptr)
3078
#ifdef WORDS_BIGENDIAN
3079
if (table->s->db_low_byte_first)
3087
doubleget(a, a_ptr);
3088
doubleget(b, b_ptr);
3090
return (a < b) ? -1 : (a > b) ? 1 : 0;
3094
#define DBL_EXP_DIG (sizeof(double)*8-DBL_MANT_DIG)
3096
/* The following should work for IEEE */
3098
void Field_double::sort_string(uchar *to,uint length __attribute__((unused)))
3101
#ifdef WORDS_BIGENDIAN
3102
if (table->s->db_low_byte_first)
3109
change_double_for_sort(nr, to);
3114
Save the field metadata for double fields.
3116
Saves the pack length in the first byte of the field metadata array
3117
at index of *metadata_ptr.
3119
@param metadata_ptr First byte of field metadata
3121
@returns number of bytes written to metadata_ptr
3123
int Field_double::do_save_field_metadata(uchar *metadata_ptr)
3125
*metadata_ptr= pack_length();
3130
void Field_double::sql_type(String &res) const
3132
CHARSET_INFO *cs=res.charset();
3133
if (dec == NOT_FIXED_DEC)
3135
res.set_ascii(STRING_WITH_LEN("double"));
3139
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
3140
"double(%d,%d)",(int) field_length,dec));
3142
add_zerofill_and_unsigned(res);
3147
TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to
3148
2038-01-01 00:00:00 UTC stored as number of seconds since Unix
3151
Up to one of timestamps columns in the table can be automatically
3152
set on row update and/or have NOW() as default value.
3153
TABLE::timestamp_field points to Field object for such timestamp with
3154
auto-set-on-update. TABLE::time_stamp holds offset in record + 1 for this
3155
field, and is used by handler code which performs updates required.
3157
Actually SQL-99 says that we should allow niladic functions (like NOW())
3158
as defaults for any field. Current limitations (only NOW() and only
3159
for one TIMESTAMP field) are because of restricted binary .frm format
3160
and should go away in the future.
3162
Also because of this limitation of binary .frm format we use 5 different
3163
unireg_check values with TIMESTAMP field to distinguish various cases of
3164
DEFAULT or ON UPDATE values. These values are:
3166
TIMESTAMP_OLD_FIELD - old timestamp, if there was not any fields with
3167
auto-set-on-update (or now() as default) in this table before, then this
3168
field has NOW() as default and is updated when row changes, else it is
3169
field which has 0 as default value and is not automatically updated.
3170
TIMESTAMP_DN_FIELD - field with NOW() as default but not set on update
3171
automatically (TIMESTAMP DEFAULT NOW())
3172
TIMESTAMP_UN_FIELD - field which is set on update automatically but has not
3173
NOW() as default (but it may has 0 or some other const timestamp as
3174
default) (TIMESTAMP ON UPDATE NOW()).
3175
TIMESTAMP_DNUN_FIELD - field which has now() as default and is auto-set on
3176
update. (TIMESTAMP DEFAULT NOW() ON UPDATE NOW())
3177
NONE - field which is not auto-set on update with some other than NOW()
3178
default value (TIMESTAMP DEFAULT 0).
3180
Note that TIMESTAMP_OLD_FIELDs are never created explicitly now, they are
3181
left only for preserving ability to read old tables. Such fields replaced
3182
with their newer analogs in CREATE TABLE and in SHOW CREATE TABLE. This is
3183
because we want to prefer NONE unireg_check before TIMESTAMP_OLD_FIELD for
3184
"TIMESTAMP DEFAULT 'Const'" field. (Old timestamps allowed such
3185
specification too but ignored default value for first timestamp, which of
3186
course is non-standard.) In most cases user won't notice any change, only
3187
exception is different behavior of old/new timestamps during ALTER TABLE.
3190
Field_timestamp::Field_timestamp(uchar *ptr_arg,
3191
uint32 len_arg __attribute__((__unused__)),
3192
uchar *null_ptr_arg, uchar null_bit_arg,
3193
enum utype unireg_check_arg,
3194
const char *field_name_arg,
3197
:Field_str(ptr_arg, MAX_DATETIME_WIDTH, null_ptr_arg, null_bit_arg,
3198
unireg_check_arg, field_name_arg, cs)
3200
/* For 4.0 MYD and 4.0 InnoDB compatibility */
3201
flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
3202
if (!share->timestamp_field && unireg_check != NONE)
3204
/* This timestamp has auto-update */
3205
share->timestamp_field= this;
3206
flags|= TIMESTAMP_FLAG;
3207
if (unireg_check != TIMESTAMP_DN_FIELD)
3208
flags|= ON_UPDATE_NOW_FLAG;
3213
Field_timestamp::Field_timestamp(bool maybe_null_arg,
3214
const char *field_name_arg,
3216
:Field_str((uchar*) 0, MAX_DATETIME_WIDTH,
3217
maybe_null_arg ? (uchar*) "": 0, 0,
3218
NONE, field_name_arg, cs)
3220
/* For 4.0 MYD and 4.0 InnoDB compatibility */
3221
flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
3222
if (unireg_check != TIMESTAMP_DN_FIELD)
3223
flags|= ON_UPDATE_NOW_FLAG;
3228
Get auto-set type for TIMESTAMP field.
3230
Returns value indicating during which operations this TIMESTAMP field
3231
should be auto-set to current timestamp.
3233
timestamp_auto_set_type Field_timestamp::get_auto_set_type() const
3235
switch (unireg_check)
3237
case TIMESTAMP_DN_FIELD:
3238
return TIMESTAMP_AUTO_SET_ON_INSERT;
3239
case TIMESTAMP_UN_FIELD:
3240
return TIMESTAMP_AUTO_SET_ON_UPDATE;
3241
case TIMESTAMP_OLD_FIELD:
3243
Although we can have several such columns in legacy tables this
3244
function should be called only for first of them (i.e. the one
3245
having auto-set property).
3247
assert(table->timestamp_field == this);
3249
case TIMESTAMP_DNUN_FIELD:
3250
return TIMESTAMP_AUTO_SET_ON_BOTH;
3253
Normally this function should not be called for TIMESTAMPs without
3257
return TIMESTAMP_NO_AUTO_SET;
3262
int Field_timestamp::store(const char *from,
3264
CHARSET_INFO *cs __attribute__((__unused__)))
3269
bool have_smth_to_conv;
3270
bool in_dst_time_gap;
3271
THD *thd= table ? table->in_use : current_thd;
3273
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
3274
have_smth_to_conv= (str_to_datetime(from, len, &l_time, 1, &error) >
3275
MYSQL_TIMESTAMP_ERROR);
3277
if (error || !have_smth_to_conv)
3280
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
3281
from, len, MYSQL_TIMESTAMP_DATETIME, 1);
3284
/* Only convert a correct date (not a zero date) */
3285
if (have_smth_to_conv && l_time.month)
3287
if (!(tmp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap)))
3289
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3290
ER_WARN_DATA_OUT_OF_RANGE,
3291
from, len, MYSQL_TIMESTAMP_DATETIME, !error);
3294
else if (in_dst_time_gap)
3296
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3297
ER_WARN_INVALID_TIMESTAMP,
3298
from, len, MYSQL_TIMESTAMP_DATETIME, !error);
3302
store_timestamp(tmp);
3307
int Field_timestamp::store(double nr)
3310
if (nr < 0 || nr > 99991231235959.0)
3312
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3313
ER_WARN_DATA_OUT_OF_RANGE,
3314
nr, MYSQL_TIMESTAMP_DATETIME);
3315
nr= 0; // Avoid overflow on buff
3318
error|= Field_timestamp::store((int64_t) rint(nr), false);
3323
int Field_timestamp::store(int64_t nr,
3324
bool unsigned_val __attribute__((__unused__)))
3327
my_time_t timestamp= 0;
3329
bool in_dst_time_gap;
3330
THD *thd= table ? table->in_use : current_thd;
3332
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
3333
int64_t tmp= number_to_datetime(nr, &l_time, (thd->variables.sql_mode &
3334
MODE_NO_ZERO_DATE) |
3335
MODE_NO_ZERO_IN_DATE, &error);
3343
if (!(timestamp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap)))
3345
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3346
ER_WARN_DATA_OUT_OF_RANGE,
3347
nr, MYSQL_TIMESTAMP_DATETIME, 1);
3350
if (in_dst_time_gap)
3352
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3353
ER_WARN_INVALID_TIMESTAMP,
3354
nr, MYSQL_TIMESTAMP_DATETIME, 1);
3358
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3359
WARN_DATA_TRUNCATED,
3360
nr, MYSQL_TIMESTAMP_DATETIME, 1);
3362
store_timestamp(timestamp);
3366
double Field_timestamp::val_real(void)
3368
return (double) Field_timestamp::val_int();
3371
int64_t Field_timestamp::val_int(void)
3374
MYSQL_TIME time_tmp;
3375
THD *thd= table ? table->in_use : current_thd;
3377
thd->time_zone_used= 1;
3378
#ifdef WORDS_BIGENDIAN
3379
if (table && table->s->db_low_byte_first)
3380
temp=uint4korr(ptr);
3385
if (temp == 0L) // No time
3386
return(0); /* purecov: inspected */
3388
thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (my_time_t)temp);
3390
return time_tmp.year * 10000000000LL + time_tmp.month * 100000000LL +
3391
time_tmp.day * 1000000L + time_tmp.hour * 10000L +
3392
time_tmp.minute * 100 + time_tmp.second;
3396
String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
3399
MYSQL_TIME time_tmp;
3400
THD *thd= table ? table->in_use : current_thd;
3403
val_buffer->alloc(field_length+1);
3404
to= (char*) val_buffer->ptr();
3405
val_buffer->length(field_length);
3407
thd->time_zone_used= 1;
3408
#ifdef WORDS_BIGENDIAN
3409
if (table && table->s->db_low_byte_first)
3410
temp=uint4korr(ptr);
3416
{ /* Zero time is "000000" */
3417
val_ptr->set(STRING_WITH_LEN("0000-00-00 00:00:00"), &my_charset_bin);
3420
val_buffer->set_charset(&my_charset_bin); // Safety
3422
thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp,(my_time_t)temp);
3424
temp= time_tmp.year % 100;
3425
if (temp < YY_PART_YEAR - 1)
3435
temp2=temp/10; temp=temp-temp2*10;
3436
*to++= (char) ('0'+(char) (temp2));
3437
*to++= (char) ('0'+(char) (temp));
3439
temp=time_tmp.month;
3440
temp2=temp/10; temp=temp-temp2*10;
3441
*to++= (char) ('0'+(char) (temp2));
3442
*to++= (char) ('0'+(char) (temp));
3445
temp2=temp/10; temp=temp-temp2*10;
3446
*to++= (char) ('0'+(char) (temp2));
3447
*to++= (char) ('0'+(char) (temp));
3450
temp2=temp/10; temp=temp-temp2*10;
3451
*to++= (char) ('0'+(char) (temp2));
3452
*to++= (char) ('0'+(char) (temp));
3454
temp=time_tmp.minute;
3455
temp2=temp/10; temp=temp-temp2*10;
3456
*to++= (char) ('0'+(char) (temp2));
3457
*to++= (char) ('0'+(char) (temp));
3459
temp=time_tmp.second;
3460
temp2=temp/10; temp=temp-temp2*10;
3461
*to++= (char) ('0'+(char) (temp2));
3462
*to++= (char) ('0'+(char) (temp));
3468
bool Field_timestamp::get_date(MYSQL_TIME *ltime, uint fuzzydate)
3471
THD *thd= table ? table->in_use : current_thd;
3472
thd->time_zone_used= 1;
3473
#ifdef WORDS_BIGENDIAN
3474
if (table && table->s->db_low_byte_first)
3475
temp=uint4korr(ptr);
3480
{ /* Zero time is "000000" */
3481
if (fuzzydate & TIME_NO_ZERO_DATE)
3483
bzero((char*) ltime,sizeof(*ltime));
3487
thd->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)temp);
3492
bool Field_timestamp::get_time(MYSQL_TIME *ltime)
3494
return Field_timestamp::get_date(ltime,0);
3498
bool Field_timestamp::send_binary(Protocol *protocol)
3501
Field_timestamp::get_date(&tm, 0);
3502
return protocol->store(&tm);
3506
int Field_timestamp::cmp(const uchar *a_ptr, const uchar *b_ptr)
3509
#ifdef WORDS_BIGENDIAN
3510
if (table && table->s->db_low_byte_first)
3521
return ((uint32) a < (uint32) b) ? -1 : ((uint32) a > (uint32) b) ? 1 : 0;
3525
void Field_timestamp::sort_string(uchar *to,uint length __attribute__((unused)))
3527
#ifdef WORDS_BIGENDIAN
3528
if (!table || !table->s->db_low_byte_first)
3546
void Field_timestamp::sql_type(String &res) const
3548
res.set_ascii(STRING_WITH_LEN("timestamp"));
3552
void Field_timestamp::set_time()
3554
THD *thd= table ? table->in_use : current_thd;
3555
long tmp= (long) thd->query_start();
3557
store_timestamp(tmp);
3560
/****************************************************************************
3562
** In string context: HH:MM:SS
3563
** In number context: HHMMSS
3564
** Stored as a 3 byte unsigned int
3565
****************************************************************************/
3567
int Field_time::store(const char *from,
3569
CHARSET_INFO *cs __attribute__((__unused__)))
3576
if (str_to_time(from, len, <ime, &warning))
3580
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
3581
from, len, MYSQL_TIMESTAMP_TIME, 1);
3585
if (warning & MYSQL_TIME_WARN_TRUNCATED)
3587
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3588
WARN_DATA_TRUNCATED,
3589
from, len, MYSQL_TIMESTAMP_TIME, 1);
3592
if (warning & MYSQL_TIME_WARN_OUT_OF_RANGE)
3594
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3595
ER_WARN_DATA_OUT_OF_RANGE,
3596
from, len, MYSQL_TIMESTAMP_TIME, !error);
3601
tmp=(ltime.day*24L+ltime.hour)*10000L+(ltime.minute*100+ltime.second);
3611
int Field_time::store_time(MYSQL_TIME *ltime,
3612
timestamp_type time_type __attribute__((__unused__)))
3614
long tmp= ((ltime->month ? 0 : ltime->day * 24L) + ltime->hour) * 10000L +
3615
(ltime->minute * 100 + ltime->second);
3618
return Field_time::store((int64_t) tmp, false);
3622
int Field_time::store(double nr)
3626
if (nr > (double)TIME_MAX_VALUE)
3628
tmp= TIME_MAX_VALUE;
3629
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3630
ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME);
3633
else if (nr < (double)-TIME_MAX_VALUE)
3635
tmp= -TIME_MAX_VALUE;
3636
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3637
ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME);
3642
tmp=(long) floor(fabs(nr)); // Remove fractions
3645
if (tmp % 100 > 59 || tmp/100 % 100 > 59)
3648
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3649
ER_WARN_DATA_OUT_OF_RANGE, nr,
3650
MYSQL_TIMESTAMP_TIME);
3659
int Field_time::store(int64_t nr, bool unsigned_val)
3663
if (nr < (int64_t) -TIME_MAX_VALUE && !unsigned_val)
3665
tmp= -TIME_MAX_VALUE;
3666
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3667
ER_WARN_DATA_OUT_OF_RANGE, nr,
3668
MYSQL_TIMESTAMP_TIME, 1);
3671
else if (nr > (int64_t) TIME_MAX_VALUE || (nr < 0 && unsigned_val))
3673
tmp= TIME_MAX_VALUE;
3674
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3675
ER_WARN_DATA_OUT_OF_RANGE, nr,
3676
MYSQL_TIMESTAMP_TIME, 1);
3682
if (tmp % 100 > 59 || tmp/100 % 100 > 59)
3685
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3686
ER_WARN_DATA_OUT_OF_RANGE, nr,
3687
MYSQL_TIMESTAMP_TIME, 1);
3696
double Field_time::val_real(void)
3698
uint32 j= (uint32) uint3korr(ptr);
3702
int64_t Field_time::val_int(void)
3704
return (int64_t) sint3korr(ptr);
3710
This function is multi-byte safe as the result string is always of type
3714
String *Field_time::val_str(String *val_buffer,
3715
String *val_ptr __attribute__((unused)))
3718
val_buffer->alloc(MAX_DATE_STRING_REP_LENGTH);
3719
long tmp=(long) sint3korr(ptr);
3726
ltime.day= (uint) 0;
3727
ltime.hour= (uint) (tmp/10000);
3728
ltime.minute= (uint) (tmp/100 % 100);
3729
ltime.second= (uint) (tmp % 100);
3730
make_time((DATE_TIME_FORMAT*) 0, <ime, val_buffer);
3737
Normally we would not consider 'time' as a valid date, but we allow
3738
get_date() here to be able to do things like
3739
DATE_FORMAT(time, "%l.%i %p")
3742
bool Field_time::get_date(MYSQL_TIME *ltime, uint fuzzydate)
3745
THD *thd= table ? table->in_use : current_thd;
3746
if (!(fuzzydate & TIME_FUZZY_DATE))
3748
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3749
ER_WARN_DATA_OUT_OF_RANGE,
3750
ER(ER_WARN_DATA_OUT_OF_RANGE), field_name,
3754
tmp=(long) sint3korr(ptr);
3761
ltime->hour=tmp/10000;
3762
tmp-=ltime->hour*10000;
3763
ltime->minute= tmp/100;
3764
ltime->second= tmp % 100;
3765
ltime->year= ltime->month= ltime->day= ltime->second_part= 0;
3770
bool Field_time::get_time(MYSQL_TIME *ltime)
3772
long tmp=(long) sint3korr(ptr);
3780
ltime->hour= (int) (tmp/10000);
3781
tmp-=ltime->hour*10000;
3782
ltime->minute= (int) tmp/100;
3783
ltime->second= (int) tmp % 100;
3784
ltime->second_part=0;
3785
ltime->time_type= MYSQL_TIMESTAMP_TIME;
3790
bool Field_time::send_binary(Protocol *protocol)
3793
Field_time::get_time(&tm);
3794
tm.day= tm.hour/24; // Move hours to days
3795
tm.hour-= tm.day*24;
3796
return protocol->store_time(&tm);
3800
int Field_time::cmp(const uchar *a_ptr, const uchar *b_ptr)
3803
a=(int32) sint3korr(a_ptr);
3804
b=(int32) sint3korr(b_ptr);
3805
return (a < b) ? -1 : (a > b) ? 1 : 0;
3808
void Field_time::sort_string(uchar *to,uint length __attribute__((unused)))
3810
to[0] = (uchar) (ptr[2] ^ 128);
3815
void Field_time::sql_type(String &res) const
3817
res.set_ascii(STRING_WITH_LEN("time"));
3820
/****************************************************************************
3822
** Save in a byte the year 0, 1901->2155
3823
** Can handle 2 byte or 4 byte years!
3824
****************************************************************************/
3826
int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
3830
int64_t nr= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
3832
if (nr < 0 || (nr >= 100 && nr <= 1900) || nr > 2155 ||
3833
error == MY_ERRNO_ERANGE)
3836
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3839
if (table->in_use->count_cuted_fields &&
3840
(error= check_int(cs, from, len, end, error)))
3842
if (error == 1) /* empty or incorrect string */
3850
if (nr != 0 || len != 4)
3852
if (nr < YY_PART_YEAR)
3853
nr+=100; // 2000 - 2069
3857
*ptr= (char) (uchar) nr;
3862
int Field_year::store(double nr)
3864
if (nr < 0.0 || nr >= 2155.0)
3866
(void) Field_year::store((int64_t) -1, false);
3869
return Field_year::store((int64_t) nr, false);
3873
int Field_year::store(int64_t nr,
3874
bool unsigned_val __attribute__((__unused__)))
3876
if (nr < 0 || (nr >= 100 && nr <= 1900) || nr > 2155)
3879
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3882
if (nr != 0 || field_length != 4) // 0000 -> 0; 00 -> 2000
3884
if (nr < YY_PART_YEAR)
3885
nr+=100; // 2000 - 2069
3889
*ptr= (char) (uchar) nr;
3894
bool Field_year::send_binary(Protocol *protocol)
3896
uint64_t tmp= Field_year::val_int();
3897
return protocol->store_short(tmp);
3901
double Field_year::val_real(void)
3903
return (double) Field_year::val_int();
3907
int64_t Field_year::val_int(void)
3909
int tmp= (int) ptr[0];
3910
if (field_length != 4)
3911
tmp%=100; // Return last 2 char
3914
return (int64_t) tmp;
3918
String *Field_year::val_str(String *val_buffer,
3919
String *val_ptr __attribute__((unused)))
3921
val_buffer->alloc(5);
3922
val_buffer->length(field_length);
3923
char *to=(char*) val_buffer->ptr();
3924
sprintf(to,field_length == 2 ? "%02d" : "%04d",(int) Field_year::val_int());
3929
void Field_year::sql_type(String &res) const
3931
CHARSET_INFO *cs=res.charset();
3932
res.length(cs->cset->snprintf(cs,(char*)res.ptr(),res.alloced_length(),
3933
"year(%d)",(int) field_length));
3937
/****************************************************************************
3938
** The new date type
3939
** This is identical to the old date type, but stored on 3 bytes instead of 4
3940
** In number context: YYYYMMDD
3941
****************************************************************************/
3944
Store string into a date field
3947
Field_newdate::store()
3949
len Length of date field
3950
cs Character set (not used)
3954
1 Value was cut during conversion
3956
3 Datetime value that was cut (warning level NOTE)
3957
This is used by opt_range.cc:get_mm_leaf(). Note that there is a
3958
nearly-identical class Field_date doesn't ever return 3 from its
3962
int Field_newdate::store(const char *from,
3964
CHARSET_INFO *cs __attribute__((__unused__)))
3969
THD *thd= table ? table->in_use : current_thd;
3970
enum enum_mysql_timestamp_type ret;
3971
if ((ret= str_to_datetime(from, len, &l_time,
3973
(thd->variables.sql_mode &
3974
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
3975
MODE_INVALID_DATES))),
3976
&error)) <= MYSQL_TIMESTAMP_ERROR)
3983
tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
3984
if (!error && (ret != MYSQL_TIMESTAMP_DATE) &&
3985
(l_time.hour || l_time.minute || l_time.second || l_time.second_part))
3986
error= 3; // Datetime was cut (note)
3990
set_datetime_warning(error == 3 ? MYSQL_ERROR::WARN_LEVEL_NOTE :
3991
MYSQL_ERROR::WARN_LEVEL_WARN,
3992
WARN_DATA_TRUNCATED,
3993
from, len, MYSQL_TIMESTAMP_DATE, 1);
3995
int3store(ptr, tmp);
4000
int Field_newdate::store(double nr)
4002
if (nr < 0.0 || nr > 99991231235959.0)
4004
int3store(ptr,(int32) 0);
4005
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
4006
WARN_DATA_TRUNCATED, nr, MYSQL_TIMESTAMP_DATE);
4009
return Field_newdate::store((int64_t) rint(nr), false);
4013
int Field_newdate::store(int64_t nr,
4014
bool unsigned_val __attribute__((__unused__)))
4019
THD *thd= table ? table->in_use : current_thd;
4020
if (number_to_datetime(nr, &l_time,
4022
(thd->variables.sql_mode &
4023
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
4024
MODE_INVALID_DATES))),
4031
tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
4033
if (!error && l_time.time_type != MYSQL_TIMESTAMP_DATE &&
4034
(l_time.hour || l_time.minute || l_time.second || l_time.second_part))
4038
set_datetime_warning(error == 3 ? MYSQL_ERROR::WARN_LEVEL_NOTE :
4039
MYSQL_ERROR::WARN_LEVEL_WARN,
4041
ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED,
4042
nr,MYSQL_TIMESTAMP_DATE, 1);
4049
int Field_newdate::store_time(MYSQL_TIME *ltime,timestamp_type time_type)
4053
if (time_type == MYSQL_TIMESTAMP_DATE ||
4054
time_type == MYSQL_TIMESTAMP_DATETIME)
4056
tmp=ltime->year*16*32+ltime->month*32+ltime->day;
4057
if (check_date(ltime, tmp != 0,
4059
(current_thd->variables.sql_mode &
4060
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
4061
MODE_INVALID_DATES))), &error))
4063
char buff[MAX_DATE_STRING_REP_LENGTH];
4064
String str(buff, sizeof(buff), &my_charset_latin1);
4065
make_date((DATE_TIME_FORMAT *) 0, ltime, &str);
4066
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
4067
str.ptr(), str.length(), MYSQL_TIMESTAMP_DATE, 1);
4069
if (!error && ltime->time_type != MYSQL_TIMESTAMP_DATE &&
4070
(ltime->hour || ltime->minute || ltime->second || ltime->second_part))
4072
char buff[MAX_DATE_STRING_REP_LENGTH];
4073
String str(buff, sizeof(buff), &my_charset_latin1);
4074
make_datetime((DATE_TIME_FORMAT *) 0, ltime, &str);
4075
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_NOTE,
4076
WARN_DATA_TRUNCATED,
4077
str.ptr(), str.length(), MYSQL_TIMESTAMP_DATE, 1);
4085
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
4092
bool Field_newdate::send_binary(Protocol *protocol)
4095
Field_newdate::get_date(&tm,0);
4096
return protocol->store_date(&tm);
4100
double Field_newdate::val_real(void)
4102
return (double) Field_newdate::val_int();
4106
int64_t Field_newdate::val_int(void)
4108
ulong j= uint3korr(ptr);
4109
j= (j % 32L)+(j / 32L % 16L)*100L + (j/(16L*32L))*10000L;
4114
String *Field_newdate::val_str(String *val_buffer,
4115
String *val_ptr __attribute__((unused)))
4117
val_buffer->alloc(field_length);
4118
val_buffer->length(field_length);
4119
uint32 tmp=(uint32) uint3korr(ptr);
4121
char *pos=(char*) val_buffer->ptr()+10;
4123
/* Open coded to get more speed */
4124
*pos--=0; // End NULL
4125
part=(int) (tmp & 31);
4126
*pos--= (char) ('0'+part%10);
4127
*pos--= (char) ('0'+part/10);
4129
part=(int) (tmp >> 5 & 15);
4130
*pos--= (char) ('0'+part%10);
4131
*pos--= (char) ('0'+part/10);
4133
part=(int) (tmp >> 9);
4134
*pos--= (char) ('0'+part%10); part/=10;
4135
*pos--= (char) ('0'+part%10); part/=10;
4136
*pos--= (char) ('0'+part%10); part/=10;
4137
*pos= (char) ('0'+part);
4142
bool Field_newdate::get_date(MYSQL_TIME *ltime,uint fuzzydate)
4144
uint32 tmp=(uint32) uint3korr(ptr);
4145
ltime->day= tmp & 31;
4146
ltime->month= (tmp >> 5) & 15;
4147
ltime->year= (tmp >> 9);
4148
ltime->time_type= MYSQL_TIMESTAMP_DATE;
4149
ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
4150
return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ?
4155
bool Field_newdate::get_time(MYSQL_TIME *ltime)
4157
return Field_newdate::get_date(ltime,0);
4161
int Field_newdate::cmp(const uchar *a_ptr, const uchar *b_ptr)
4164
a=(uint32) uint3korr(a_ptr);
4165
b=(uint32) uint3korr(b_ptr);
4166
return (a < b) ? -1 : (a > b) ? 1 : 0;
4170
void Field_newdate::sort_string(uchar *to,uint length __attribute__((unused)))
4178
void Field_newdate::sql_type(String &res) const
4180
res.set_ascii(STRING_WITH_LEN("date"));
4184
/****************************************************************************
4186
** In string context: YYYY-MM-DD HH:MM:DD
4187
** In number context: YYYYMMDDHHMMDD
4188
** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int.
4189
****************************************************************************/
4191
int Field_datetime::store(const char *from,
4193
CHARSET_INFO *cs __attribute__((__unused__)))
4195
MYSQL_TIME time_tmp;
4198
enum enum_mysql_timestamp_type func_res;
4199
THD *thd= table ? table->in_use : current_thd;
4201
func_res= str_to_datetime(from, len, &time_tmp,
4203
(thd->variables.sql_mode &
4204
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
4205
MODE_INVALID_DATES))),
4207
if ((int) func_res > (int) MYSQL_TIMESTAMP_ERROR)
4208
tmp= TIME_to_uint64_t_datetime(&time_tmp);
4210
error= 1; // Fix if invalid zero date
4213
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
4214
ER_WARN_DATA_OUT_OF_RANGE,
4215
from, len, MYSQL_TIMESTAMP_DATETIME, 1);
4217
#ifdef WORDS_BIGENDIAN
4218
if (table && table->s->db_low_byte_first)
4224
int64_tstore(ptr,tmp);
4229
int Field_datetime::store(double nr)
4232
if (nr < 0.0 || nr > 99991231235959.0)
4234
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
4235
ER_WARN_DATA_OUT_OF_RANGE,
4236
nr, MYSQL_TIMESTAMP_DATETIME);
4240
error|= Field_datetime::store((int64_t) rint(nr), false);
4245
int Field_datetime::store(int64_t nr,
4246
bool unsigned_val __attribute__((__unused__)))
4248
MYSQL_TIME not_used;
4250
int64_t initial_nr= nr;
4251
THD *thd= table ? table->in_use : current_thd;
4253
nr= number_to_datetime(nr, ¬_used, (TIME_FUZZY_DATE |
4254
(thd->variables.sql_mode &
4255
(MODE_NO_ZERO_IN_DATE |
4257
MODE_INVALID_DATES))), &error);
4266
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
4267
error == 2 ? ER_WARN_DATA_OUT_OF_RANGE :
4268
WARN_DATA_TRUNCATED, initial_nr,
4269
MYSQL_TIMESTAMP_DATETIME, 1);
4271
#ifdef WORDS_BIGENDIAN
4272
if (table && table->s->db_low_byte_first)
4278
int64_tstore(ptr,nr);
4283
int Field_datetime::store_time(MYSQL_TIME *ltime,timestamp_type time_type)
4288
We don't perform range checking here since values stored in TIME
4289
structure always fit into DATETIME range.
4291
if (time_type == MYSQL_TIMESTAMP_DATE ||
4292
time_type == MYSQL_TIMESTAMP_DATETIME)
4294
tmp=((ltime->year*10000L+ltime->month*100+ltime->day)*1000000LL+
4295
(ltime->hour*10000L+ltime->minute*100+ltime->second));
4296
if (check_date(ltime, tmp != 0,
4298
(current_thd->variables.sql_mode &
4299
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
4300
MODE_INVALID_DATES))), &error))
4302
char buff[MAX_DATE_STRING_REP_LENGTH];
4303
String str(buff, sizeof(buff), &my_charset_latin1);
4304
make_datetime((DATE_TIME_FORMAT *) 0, ltime, &str);
4305
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
4306
str.ptr(), str.length(), MYSQL_TIMESTAMP_DATETIME,1);
4313
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
4315
#ifdef WORDS_BIGENDIAN
4316
if (table && table->s->db_low_byte_first)
4322
int64_tstore(ptr,tmp);
4326
bool Field_datetime::send_binary(Protocol *protocol)
4329
Field_datetime::get_date(&tm, TIME_FUZZY_DATE);
4330
return protocol->store(&tm);
4334
double Field_datetime::val_real(void)
4336
return (double) Field_datetime::val_int();
4339
int64_t Field_datetime::val_int(void)
4342
#ifdef WORDS_BIGENDIAN
4343
if (table && table->s->db_low_byte_first)
4352
String *Field_datetime::val_str(String *val_buffer,
4353
String *val_ptr __attribute__((unused)))
4355
val_buffer->alloc(field_length);
4356
val_buffer->length(field_length);
4362
#ifdef WORDS_BIGENDIAN
4363
if (table && table->s->db_low_byte_first)
4367
int64_tget(tmp,ptr);
4370
Avoid problem with slow int64_t arithmetic and sprintf
4373
part1=(long) (tmp/1000000LL);
4374
part2=(long) (tmp - (uint64_t) part1*1000000LL);
4376
pos=(char*) val_buffer->ptr() + MAX_DATETIME_WIDTH;
4378
*pos--= (char) ('0'+(char) (part2%10)); part2/=10;
4379
*pos--= (char) ('0'+(char) (part2%10)); part3= (int) (part2 / 10);
4381
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4382
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4384
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4385
*pos--= (char) ('0'+(char) part3);
4387
*pos--= (char) ('0'+(char) (part1%10)); part1/=10;
4388
*pos--= (char) ('0'+(char) (part1%10)); part1/=10;
4390
*pos--= (char) ('0'+(char) (part1%10)); part1/=10;
4391
*pos--= (char) ('0'+(char) (part1%10)); part3= (int) (part1/10);
4393
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4394
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4395
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4396
*pos=(char) ('0'+(char) part3);
4400
bool Field_datetime::get_date(MYSQL_TIME *ltime, uint fuzzydate)
4402
int64_t tmp=Field_datetime::val_int();
4404
part1=(uint32) (tmp/1000000LL);
4405
part2=(uint32) (tmp - (uint64_t) part1*1000000LL);
4407
ltime->time_type= MYSQL_TIMESTAMP_DATETIME;
4409
ltime->second_part= 0;
4410
ltime->second= (int) (part2%100);
4411
ltime->minute= (int) (part2/100%100);
4412
ltime->hour= (int) (part2/10000);
4413
ltime->day= (int) (part1%100);
4414
ltime->month= (int) (part1/100%100);
4415
ltime->year= (int) (part1/10000);
4416
return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ? 1 : 0;
4419
bool Field_datetime::get_time(MYSQL_TIME *ltime)
4421
return Field_datetime::get_date(ltime,0);
4424
int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr)
4427
#ifdef WORDS_BIGENDIAN
4428
if (table && table->s->db_low_byte_first)
4436
int64_tget(a,a_ptr);
4437
int64_tget(b,b_ptr);
4439
return ((uint64_t) a < (uint64_t) b) ? -1 :
4440
((uint64_t) a > (uint64_t) b) ? 1 : 0;
4443
void Field_datetime::sort_string(uchar *to,uint length __attribute__((unused)))
4445
#ifdef WORDS_BIGENDIAN
4446
if (!table || !table->s->db_low_byte_first)
4472
void Field_datetime::sql_type(String &res) const
4474
res.set_ascii(STRING_WITH_LEN("datetime"));
4477
/****************************************************************************
4479
** A string may be varchar or binary
4480
****************************************************************************/
4483
Report "not well formed" or "cannot convert" error
4484
after storing a character string info a field.
4487
check_string_copy_error()
4489
well_formed_error_pos - where not well formed data was first met
4490
cannot_convert_error_pos - where a not-convertable character was first met
4491
end - end of the string
4492
cs - character set of the string
4495
As of version 5.0 both cases return the same error:
4497
"Invalid string value: 'xxx' for column 't' at row 1"
4499
Future versions will possibly introduce a new error message:
4501
"Cannot convert character string: 'xxx' for column 't' at row 1"
4504
false - If errors didn't happen
4505
true - If an error happened
4509
check_string_copy_error(Field_str *field,
4510
const char *well_formed_error_pos,
4511
const char *cannot_convert_error_pos,
4515
const char *pos, *end_orig;
4518
if (!(pos= well_formed_error_pos) &&
4519
!(pos= cannot_convert_error_pos))
4523
set_if_smaller(end, pos + 6);
4525
for (t= tmp; pos < end; pos++)
4528
If the source string is ASCII compatible (mbminlen==1)
4529
and the source character is in ASCII printable range (0x20..0x7F),
4530
then display the character as is.
4532
Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
4533
or the source character is not in the printable range,
4534
then print the character using HEX notation.
4536
if (((unsigned char) *pos) >= 0x20 &&
4537
((unsigned char) *pos) <= 0x7F &&
4546
*t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
4547
*t++= _dig_vec_upper[((unsigned char) *pos) & 15];
4557
push_warning_printf(field->table->in_use,
4558
field->table->in_use->abort_on_warning ?
4559
MYSQL_ERROR::WARN_LEVEL_ERROR :
4560
MYSQL_ERROR::WARN_LEVEL_WARN,
4561
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
4562
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
4563
"string", tmp, field->field_name,
4564
(ulong) field->table->in_use->row_count);
4570
Check if we lost any important data and send a truncation error/warning
4573
Field_longstr::report_if_important_data()
4574
ptr - Truncated rest of string
4575
end - End of truncated string
4578
0 - None was truncated (or we don't count cut fields)
4579
2 - Some bytes was truncated
4582
Check if we lost any important data (anything in a binary string,
4583
or any non-space in others). If only trailing spaces was lost,
4584
send a truncation note, otherwise send a truncation error.
4588
Field_longstr::report_if_important_data(const char *ptr, const char *end)
4590
if ((ptr < end) && table->in_use->count_cuted_fields)
4592
if (test_if_important_data(field_charset, ptr, end))
4594
if (table->in_use->abort_on_warning)
4595
set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
4597
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
4599
else /* If we lost only spaces then produce a NOTE, not a WARNING */
4600
set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
4607
/* Copy a string and fill with space */
4609
int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
4612
const char *well_formed_error_pos;
4613
const char *cannot_convert_error_pos;
4614
const char *from_end_pos;
4616
/* See the comment for Field_long::store(long long) */
4617
assert(table->in_use == current_thd);
4619
copy_length= well_formed_copy_nchars(field_charset,
4620
(char*) ptr, field_length,
4622
field_length / field_charset->mbmaxlen,
4623
&well_formed_error_pos,
4624
&cannot_convert_error_pos,
4627
/* Append spaces if the string was shorter than the field. */
4628
if (copy_length < field_length)
4629
field_charset->cset->fill(field_charset,(char*) ptr+copy_length,
4630
field_length-copy_length,
4631
field_charset->pad_char);
4633
if (check_string_copy_error(this, well_formed_error_pos,
4634
cannot_convert_error_pos, from + length, cs))
4637
return report_if_important_data(from_end_pos, from + length);
4642
Store double value in Field_string or Field_varstring.
4644
Pretty prints double number into field_length characters buffer.
4649
int Field_str::store(double nr)
4651
char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
4652
uint local_char_length= field_length / charset()->mbmaxlen;
4656
length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error);
4659
if (table->in_use->abort_on_warning)
4660
set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
4662
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
4664
return store(buff, length, charset());
4668
uint Field::is_equal(Create_field *new_field)
4670
return (new_field->sql_type == real_type());
4674
/* If one of the fields is binary and the other one isn't return 1 else 0 */
4676
bool Field_str::compare_str_field_flags(Create_field *new_field, uint32 flag_arg)
4678
return (((new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
4679
!(flag_arg & (BINCMP_FLAG | BINARY_FLAG))) ||
4680
(!(new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
4681
(flag_arg & (BINCMP_FLAG | BINARY_FLAG))));
4685
uint Field_str::is_equal(Create_field *new_field)
4687
if (compare_str_field_flags(new_field, flags))
4690
return ((new_field->sql_type == real_type()) &&
4691
new_field->charset == field_charset &&
4692
new_field->length == max_display_length());
4696
int Field_string::store(int64_t nr, bool unsigned_val)
4700
CHARSET_INFO *cs=charset();
4701
l= (cs->cset->int64_t10_to_str)(cs,buff,sizeof(buff),
4702
unsigned_val ? 10 : -10, nr);
4703
return Field_string::store(buff,(uint)l,cs);
4707
int Field_longstr::store_decimal(const my_decimal *d)
4709
char buff[DECIMAL_MAX_STR_LENGTH+1];
4710
String str(buff, sizeof(buff), &my_charset_bin);
4711
my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
4712
return store(str.ptr(), str.length(), str.charset());
4715
uint32 Field_longstr::max_data_length() const
4717
return field_length + (field_length > 255 ? 2 : 1);
4721
double Field_string::val_real(void)
4725
CHARSET_INFO *cs= charset();
4728
result= my_strntod(cs,(char*) ptr,field_length,&end,&error);
4729
if (!table->in_use->no_errors &&
4730
(error || (field_length != (uint32)(end - (char*) ptr) &&
4731
!check_if_only_end_space(cs, end,
4732
(char*) ptr + field_length))))
4734
char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
4735
String tmp(buf, sizeof(buf), cs);
4736
tmp.copy((char*) ptr, field_length, cs);
4737
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
4738
ER_TRUNCATED_WRONG_VALUE,
4739
ER(ER_TRUNCATED_WRONG_VALUE),
4740
"DOUBLE", tmp.c_ptr());
4746
int64_t Field_string::val_int(void)
4750
CHARSET_INFO *cs= charset();
4753
result= my_strntoll(cs, (char*) ptr,field_length,10,&end,&error);
4754
if (!table->in_use->no_errors &&
4755
(error || (field_length != (uint32)(end - (char*) ptr) &&
4756
!check_if_only_end_space(cs, end,
4757
(char*) ptr + field_length))))
4759
char buf[LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE];
4760
String tmp(buf, sizeof(buf), cs);
4761
tmp.copy((char*) ptr, field_length, cs);
4762
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
4763
ER_TRUNCATED_WRONG_VALUE,
4764
ER(ER_TRUNCATED_WRONG_VALUE),
4765
"INTEGER", tmp.c_ptr());
4771
String *Field_string::val_str(String *val_buffer __attribute__((unused)),
4774
/* See the comment for Field_long::store(long long) */
4775
assert(table->in_use == current_thd);
4777
if (table->in_use->variables.sql_mode &
4778
MODE_PAD_CHAR_TO_FULL_LENGTH)
4779
length= my_charpos(field_charset, ptr, ptr + field_length, field_length);
4781
length= field_charset->cset->lengthsp(field_charset, (const char*) ptr,
4783
val_ptr->set((const char*) ptr, length, field_charset);
4788
my_decimal *Field_string::val_decimal(my_decimal *decimal_value)
4790
int err= str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr, field_length,
4791
charset(), decimal_value);
4792
if (!table->in_use->no_errors && err)
4794
char buf[DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE];
4795
CHARSET_INFO *cs= charset();
4796
String tmp(buf, sizeof(buf), cs);
4797
tmp.copy((char*) ptr, field_length, cs);
4798
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
4799
ER_TRUNCATED_WRONG_VALUE,
4800
ER(ER_TRUNCATED_WRONG_VALUE),
4801
"DECIMAL", tmp.c_ptr());
4804
return decimal_value;
4808
int Field_string::cmp(const uchar *a_ptr, const uchar *b_ptr)
4812
if (field_charset->mbmaxlen != 1)
4814
uint char_len= field_length/field_charset->mbmaxlen;
4815
a_len= my_charpos(field_charset, a_ptr, a_ptr + field_length, char_len);
4816
b_len= my_charpos(field_charset, b_ptr, b_ptr + field_length, char_len);
4819
a_len= b_len= field_length;
4821
We have to remove end space to be able to compare multi-byte-characters
4822
like in latin_de 'ae' and 0xe4
4824
return field_charset->coll->strnncollsp(field_charset,
4831
void Field_string::sort_string(uchar *to,uint length)
4833
uint tmp= my_strnxfrm(field_charset,
4836
assert(tmp == length);
4840
void Field_string::sql_type(String &res) const
4842
THD *thd= table->in_use;
4843
CHARSET_INFO *cs=res.charset();
4846
length= cs->cset->snprintf(cs,(char*) res.ptr(),
4847
res.alloced_length(), "%s(%d)",
4848
((type() == MYSQL_TYPE_VAR_STRING &&
4849
!thd->variables.new_mode) ?
4850
(has_charset() ? "varchar" : "varbinary") :
4851
(has_charset() ? "char" : "binary")),
4852
(int) field_length / charset()->mbmaxlen);
4854
if ((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) &&
4855
has_charset() && (charset()->state & MY_CS_BINSORT))
4856
res.append(STRING_WITH_LEN(" binary"));
4860
uchar *Field_string::pack(uchar *to, const uchar *from,
4862
bool low_byte_first __attribute__((unused)))
4864
uint length= min(field_length,max_length);
4865
uint local_char_length= max_length/field_charset->mbmaxlen;
4866
if (length > local_char_length)
4867
local_char_length= my_charpos(field_charset, from, from+length,
4869
set_if_smaller(length, local_char_length);
4870
while (length && from[length-1] == field_charset->pad_char)
4873
// Length always stored little-endian
4874
*to++= (uchar) length;
4875
if (field_length > 255)
4876
*to++= (uchar) (length >> 8);
4878
// Store the actual bytes of the string
4879
memcpy(to, from, length);
4885
Unpack a string field from row data.
4887
This method is used to unpack a string field from a master whose size
4888
of the field is less than that of the slave. Note that there can be a
4889
variety of field types represented with this class. Certain types like
4890
ENUM or SET are processed differently. Hence, the upper byte of the
4891
@c param_data argument contains the result of field->real_type() from
4894
@param to Destination of the data
4895
@param from Source of the data
4896
@param param_data Real type (upper) and length (lower) values
4898
@return New pointer into memory based on from + length of the data
4901
Field_string::unpack(uchar *to,
4904
bool low_byte_first __attribute__((unused)))
4907
param_data ? min(param_data & 0x00ff, field_length) : field_length;
4910
if (from_length > 255)
4912
length= uint2korr(from);
4916
length= (uint) *from++;
4918
memcpy(to, from, length);
4919
// Pad the string with the pad character of the fields charset
4920
bfill(to + length, field_length - length, field_charset->pad_char);
4926
Save the field metadata for string fields.
4928
Saves the real type in the first byte and the field length in the
4929
second byte of the field metadata array at index of *metadata_ptr and
4930
*(metadata_ptr + 1).
4932
@param metadata_ptr First byte of field metadata
4934
@returns number of bytes written to metadata_ptr
4936
int Field_string::do_save_field_metadata(uchar *metadata_ptr)
4938
*metadata_ptr= real_type();
4939
*(metadata_ptr + 1)= field_length;
4945
Compare two packed keys
4952
insert_or_update 1 if this is an insert or update
4960
int Field_string::pack_cmp(const uchar *a, const uchar *b, uint length,
4961
my_bool insert_or_update)
4963
uint a_length, b_length;
4966
a_length= uint2korr(a);
4967
b_length= uint2korr(b);
4973
a_length= (uint) *a++;
4974
b_length= (uint) *b++;
4976
return field_charset->coll->strnncollsp(field_charset,
4984
Compare a packed key against row.
4986
@param key Original key
4987
@param length Key length. (May be less than field length)
4988
@param insert_or_update 1 if this is an insert or update
4998
int Field_string::pack_cmp(const uchar *key, uint length,
4999
my_bool insert_or_update)
5001
uint row_length, local_key_length;
5005
local_key_length= uint2korr(key);
5009
local_key_length= (uint) *key++;
5011
/* Only use 'length' of key, not field_length */
5013
while (end > ptr && end[-1] == ' ')
5015
row_length= (uint) (end - ptr);
5017
return field_charset->coll->strnncollsp(field_charset,
5019
key, local_key_length,
5024
uint Field_string::packed_col_length(const uchar *data_ptr, uint length)
5027
return uint2korr(data_ptr)+2;
5028
return (uint) *data_ptr + 1;
5032
uint Field_string::max_packed_col_length(uint max_length)
5034
return (max_length > 255 ? 2 : 1)+max_length;
5038
uint Field_string::get_key_image(uchar *buff,
5040
imagetype type_arg __attribute__((__unused__)))
5042
uint bytes = my_charpos(field_charset, (char*) ptr,
5043
(char*) ptr + field_length,
5044
length / field_charset->mbmaxlen);
5045
memcpy(buff, ptr, bytes);
5047
field_charset->cset->fill(field_charset, (char*) buff + bytes,
5048
length - bytes, field_charset->pad_char);
5053
Field *Field_string::new_field(MEM_ROOT *root, struct st_table *new_table,
5057
if (type() != MYSQL_TYPE_VAR_STRING || keep_type)
5058
field= Field::new_field(root, new_table, keep_type);
5059
else if ((field= new Field_varstring(field_length, maybe_null(), field_name,
5060
new_table->s, charset())))
5063
Old VARCHAR field which should be modified to a VARCHAR on copy
5064
This is done to ensure that ALTER TABLE will convert old VARCHAR fields
5065
to now VARCHAR fields.
5067
field->init(new_table);
5069
Normally orig_table is different from table only if field was created
5070
via ::new_field. Here we alter the type of field, so ::new_field is
5071
not applicable. But we still need to preserve the original field
5072
metadata for the client-server protocol.
5074
field->orig_table= orig_table;
5080
/****************************************************************************
5082
Data in field->ptr is stored as:
5083
1 or 2 bytes length-prefix-header (from Field_varstring::length_bytes)
5087
When VARCHAR is stored in a key (for handler::index_read() etc) it's always
5088
stored with a 2 byte prefix. (Just like blob keys).
5090
Normally length_bytes is calculated as (field_length < 256 : 1 ? 2)
5091
The exception is if there is a prefix key field that is part of a long
5092
VARCHAR, in which case field_length for this may be 1 but the length_bytes
5094
****************************************************************************/
5096
const uint Field_varstring::MAX_SIZE= UINT16_MAX;
5099
Save the field metadata for varstring fields.
5101
Saves the field length in the first byte. Note: may consume
5102
2 bytes. Caller must ensure second byte is contiguous with
5103
first byte (e.g. array index 0,1).
5105
@param metadata_ptr First byte of field metadata
5107
@returns number of bytes written to metadata_ptr
5109
int Field_varstring::do_save_field_metadata(uchar *metadata_ptr)
5111
char *ptr= (char *)metadata_ptr;
5112
assert(field_length <= 65535);
5113
int2store(ptr, field_length);
5117
int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
5120
const char *well_formed_error_pos;
5121
const char *cannot_convert_error_pos;
5122
const char *from_end_pos;
5124
copy_length= well_formed_copy_nchars(field_charset,
5125
(char*) ptr + length_bytes,
5128
field_length / field_charset->mbmaxlen,
5129
&well_formed_error_pos,
5130
&cannot_convert_error_pos,
5133
if (length_bytes == 1)
5134
*ptr= (uchar) copy_length;
5136
int2store(ptr, copy_length);
5138
if (check_string_copy_error(this, well_formed_error_pos,
5139
cannot_convert_error_pos, from + length, cs))
5142
return report_if_important_data(from_end_pos, from + length);
5146
int Field_varstring::store(int64_t nr, bool unsigned_val)
5150
length= (uint) (field_charset->cset->int64_t10_to_str)(field_charset,
5156
return Field_varstring::store(buff, length, field_charset);
5160
double Field_varstring::val_real(void)
5164
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5165
return my_strntod(field_charset, (char*) ptr+length_bytes, length,
5166
&end_not_used, ¬_used);
5170
int64_t Field_varstring::val_int(void)
5174
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5175
return my_strntoll(field_charset, (char*) ptr+length_bytes, length, 10,
5176
&end_not_used, ¬_used);
5179
String *Field_varstring::val_str(String *val_buffer __attribute__((unused)),
5182
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5183
val_ptr->set((const char*) ptr+length_bytes, length, field_charset);
5188
my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value)
5190
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5191
str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr+length_bytes, length,
5192
charset(), decimal_value);
5193
return decimal_value;
5197
int Field_varstring::cmp_max(const uchar *a_ptr, const uchar *b_ptr,
5200
uint a_length, b_length;
5203
if (length_bytes == 1)
5205
a_length= (uint) *a_ptr;
5206
b_length= (uint) *b_ptr;
5210
a_length= uint2korr(a_ptr);
5211
b_length= uint2korr(b_ptr);
5213
set_if_smaller(a_length, max_len);
5214
set_if_smaller(b_length, max_len);
5215
diff= field_charset->coll->strnncollsp(field_charset,
5228
varstring and blob keys are ALWAYS stored with a 2 byte length prefix
5231
int Field_varstring::key_cmp(const uchar *key_ptr, uint max_key_length)
5233
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5234
uint local_char_length= max_key_length / field_charset->mbmaxlen;
5236
local_char_length= my_charpos(field_charset, ptr + length_bytes,
5237
ptr + length_bytes + length, local_char_length);
5238
set_if_smaller(length, local_char_length);
5239
return field_charset->coll->strnncollsp(field_charset,
5244
uint2korr(key_ptr), 0);
5249
Compare to key segments (always 2 byte length prefix).
5252
This is used only to compare key segments created for index_read().
5253
(keys are created and compared in key.cc)
5256
int Field_varstring::key_cmp(const uchar *a,const uchar *b)
5258
return field_charset->coll->strnncollsp(field_charset,
5259
a + HA_KEY_BLOB_LENGTH,
5261
b + HA_KEY_BLOB_LENGTH,
5267
void Field_varstring::sort_string(uchar *to,uint length)
5269
uint tot_length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5271
if (field_charset == &my_charset_bin)
5273
/* Store length last in high-byte order to sort longer strings first */
5274
if (length_bytes == 1)
5275
to[length-1]= tot_length;
5277
mi_int2store(to+length-2, tot_length);
5278
length-= length_bytes;
5281
tot_length= my_strnxfrm(field_charset,
5282
to, length, ptr + length_bytes,
5284
assert(tot_length == length);
5288
enum ha_base_keytype Field_varstring::key_type() const
5290
enum ha_base_keytype res;
5293
res= length_bytes == 1 ? HA_KEYTYPE_VARBINARY1 : HA_KEYTYPE_VARBINARY2;
5295
res= length_bytes == 1 ? HA_KEYTYPE_VARTEXT1 : HA_KEYTYPE_VARTEXT2;
5300
void Field_varstring::sql_type(String &res) const
5302
THD *thd= table->in_use;
5303
CHARSET_INFO *cs=res.charset();
5306
length= cs->cset->snprintf(cs,(char*) res.ptr(),
5307
res.alloced_length(), "%s(%d)",
5308
(has_charset() ? "varchar" : "varbinary"),
5309
(int) field_length / charset()->mbmaxlen);
5311
if ((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) &&
5312
has_charset() && (charset()->state & MY_CS_BINSORT))
5313
res.append(STRING_WITH_LEN(" binary"));
5317
uint32 Field_varstring::data_length()
5319
return length_bytes == 1 ? (uint32) *ptr : uint2korr(ptr);
5322
uint32 Field_varstring::used_length()
5324
return length_bytes == 1 ? 1 + (uint32) (uchar) *ptr : 2 + uint2korr(ptr);
5328
Functions to create a packed row.
5329
Here the number of length bytes are depending on the given max_length
5332
uchar *Field_varstring::pack(uchar *to, const uchar *from,
5334
bool low_byte_first __attribute__((unused)))
5336
uint length= length_bytes == 1 ? (uint) *from : uint2korr(from);
5337
set_if_smaller(max_length, field_length);
5338
if (length > max_length)
5341
/* Length always stored little-endian */
5342
*to++= length & 0xFF;
5343
if (max_length > 255)
5344
*to++= (length >> 8) & 0xFF;
5346
/* Store bytes of string */
5348
memcpy(to, from+length_bytes, length);
5354
Field_varstring::pack_key(uchar *to, const uchar *key, uint max_length,
5355
bool low_byte_first __attribute__((unused)))
5357
uint length= length_bytes == 1 ? (uint) *key : uint2korr(key);
5358
uint local_char_length= ((field_charset->mbmaxlen > 1) ?
5359
max_length/field_charset->mbmaxlen : max_length);
5361
if (length > local_char_length)
5363
local_char_length= my_charpos(field_charset, key, key+length,
5365
set_if_smaller(length, local_char_length);
5367
*to++= (char) (length & 255);
5368
if (max_length > 255)
5369
*to++= (char) (length >> 8);
5371
memcpy(to, key, length);
5377
Unpack a key into a record buffer.
5379
A VARCHAR key has a maximum size of 64K-1.
5380
In its packed form, the length field is one or two bytes long,
5381
depending on 'max_length'.
5383
@param to Pointer into the record buffer.
5384
@param key Pointer to the packed key.
5385
@param max_length Key length limit from key description.
5388
Pointer to end of 'key' (To the next key part if multi-segment key)
5392
Field_varstring::unpack_key(uchar *to __attribute__((__unused__)),
5393
const uchar *key, uint max_length,
5394
bool low_byte_first __attribute__((unused)))
5396
/* get length of the blob key */
5397
uint32 length= *key++;
5398
if (max_length > 255)
5399
length+= (*key++) << 8;
5401
/* put the length into the record buffer */
5402
if (length_bytes == 1)
5403
*ptr= (uchar) length;
5405
int2store(ptr, length);
5406
memcpy(ptr + length_bytes, key, length);
5407
return key + length;
5411
Create a packed key that will be used for storage in the index tree.
5413
@param to Store packed key segment here
5414
@param from Key segment (as given to index_read())
5415
@param max_length Max length of key
5422
Field_varstring::pack_key_from_key_image(uchar *to, const uchar *from, uint max_length,
5423
bool low_byte_first __attribute__((unused)))
5425
/* Key length is always stored as 2 bytes */
5426
uint length= uint2korr(from);
5427
if (length > max_length)
5429
*to++= (char) (length & 255);
5430
if (max_length > 255)
5431
*to++= (char) (length >> 8);
5433
memcpy(to, from+HA_KEY_BLOB_LENGTH, length);
5439
Unpack a varstring field from row data.
5441
This method is used to unpack a varstring field from a master
5442
whose size of the field is less than that of the slave.
5445
The string length is always packed little-endian.
5447
@param to Destination of the data
5448
@param from Source of the data
5449
@param param_data Length bytes from the master's field data
5451
@return New pointer into memory based on from + length of the data
5454
Field_varstring::unpack(uchar *to, const uchar *from,
5456
bool low_byte_first __attribute__((unused)))
5459
uint l_bytes= (param_data && (param_data < field_length)) ?
5460
(param_data <= 255) ? 1 : 2 : length_bytes;
5465
if (length_bytes == 2)
5468
else /* l_bytes == 2 */
5470
length= uint2korr(from);
5475
memcpy(to+ length_bytes, from, length);
5480
int Field_varstring::pack_cmp(const uchar *a, const uchar *b,
5481
uint key_length_arg,
5482
my_bool insert_or_update)
5484
uint a_length, b_length;
5485
if (key_length_arg > 255)
5487
a_length=uint2korr(a); a+= 2;
5488
b_length=uint2korr(b); b+= 2;
5492
a_length= (uint) *a++;
5493
b_length= (uint) *b++;
5495
return field_charset->coll->strnncollsp(field_charset,
5502
int Field_varstring::pack_cmp(const uchar *b, uint key_length_arg,
5503
my_bool insert_or_update)
5505
uchar *a= ptr+ length_bytes;
5506
uint a_length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5508
uint local_char_length= ((field_charset->mbmaxlen > 1) ?
5509
key_length_arg / field_charset->mbmaxlen :
5512
if (key_length_arg > 255)
5514
b_length=uint2korr(b); b+= HA_KEY_BLOB_LENGTH;
5517
b_length= (uint) *b++;
5519
if (a_length > local_char_length)
5521
local_char_length= my_charpos(field_charset, a, a+a_length,
5523
set_if_smaller(a_length, local_char_length);
5526
return field_charset->coll->strnncollsp(field_charset,
5533
uint Field_varstring::packed_col_length(const uchar *data_ptr, uint length)
5536
return uint2korr(data_ptr)+2;
5537
return (uint) *data_ptr + 1;
5541
uint Field_varstring::max_packed_col_length(uint max_length)
5543
return (max_length > 255 ? 2 : 1)+max_length;
5546
uint Field_varstring::get_key_image(uchar *buff,
5548
imagetype type __attribute__((__unused__)))
5550
uint f_length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5551
uint local_char_length= length / field_charset->mbmaxlen;
5552
uchar *pos= ptr+length_bytes;
5553
local_char_length= my_charpos(field_charset, pos, pos + f_length,
5555
set_if_smaller(f_length, local_char_length);
5556
/* Key is always stored with 2 bytes */
5557
int2store(buff,f_length);
5558
memcpy(buff+HA_KEY_BLOB_LENGTH, pos, f_length);
5559
if (f_length < length)
5562
Must clear this as we do a memcmp in opt_range.cc to detect
5565
bzero(buff+HA_KEY_BLOB_LENGTH+f_length, (length-f_length));
5567
return HA_KEY_BLOB_LENGTH+f_length;
5571
void Field_varstring::set_key_image(const uchar *buff,uint length)
5573
length= uint2korr(buff); // Real length is here
5574
(void) Field_varstring::store((const char*) buff+HA_KEY_BLOB_LENGTH, length,
5579
int Field_varstring::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
5582
uint32 a_length,b_length;
5584
if (length_bytes == 1)
5586
a_length= (uint) *a_ptr;
5587
b_length= (uint) *b_ptr;
5591
a_length= uint2korr(a_ptr);
5592
b_length= uint2korr(b_ptr);
5594
set_if_smaller(a_length, max_length);
5595
set_if_smaller(b_length, max_length);
5596
if (a_length != b_length)
5598
return memcmp(a_ptr+length_bytes, b_ptr+length_bytes, a_length);
5602
Field *Field_varstring::new_field(MEM_ROOT *root, struct st_table *new_table,
5605
Field_varstring *res= (Field_varstring*) Field::new_field(root, new_table,
5608
res->length_bytes= length_bytes;
5613
Field *Field_varstring::new_key_field(MEM_ROOT *root,
5614
struct st_table *new_table,
5615
uchar *new_ptr, uchar *new_null_ptr,
5618
Field_varstring *res;
5619
if ((res= (Field_varstring*) Field::new_key_field(root,
5625
/* Keys length prefixes are always packed with 2 bytes */
5626
res->length_bytes= 2;
5632
uint Field_varstring::is_equal(Create_field *new_field)
5634
if (new_field->sql_type == real_type() &&
5635
new_field->charset == field_charset)
5637
if (new_field->length == max_display_length())
5638
return IS_EQUAL_YES;
5639
if (new_field->length > max_display_length() &&
5640
((new_field->length <= 255 && max_display_length() <= 255) ||
5641
(new_field->length > 255 && max_display_length() > 255)))
5642
return IS_EQUAL_PACK_LENGTH; // VARCHAR, longer variable length
5648
void Field_varstring::hash(ulong *nr, ulong *nr2)
5652
*nr^= (*nr << 1) | 1;
5656
uint len= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5657
CHARSET_INFO *cs= charset();
5658
cs->coll->hash_sort(cs, ptr + length_bytes, len, nr, nr2);
5663
/****************************************************************************
5665
** A blob is saved as a length and a pointer. The length is stored in the
5666
** packlength slot and may be from 1-4.
5667
****************************************************************************/
5669
Field_blob::Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
5670
enum utype unireg_check_arg, const char *field_name_arg,
5671
TABLE_SHARE *share, uint blob_pack_length,
5673
:Field_longstr(ptr_arg, BLOB_PACK_LENGTH_TO_MAX_LENGH(blob_pack_length),
5674
null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg,
5676
packlength(blob_pack_length)
5679
share->blob_fields++;
5680
/* TODO: why do not fill table->s->blob_field array here? */
5684
void Field_blob::store_length(uchar *i_ptr,
5687
bool low_byte_first __attribute__((__unused__)))
5689
switch (i_packlength) {
5691
i_ptr[0]= (uchar) i_number;
5694
#ifdef WORDS_BIGENDIAN
5697
int2store(i_ptr,(unsigned short) i_number);
5701
shortstore(i_ptr,(unsigned short) i_number);
5704
int3store(i_ptr,i_number);
5707
#ifdef WORDS_BIGENDIAN
5710
int4store(i_ptr,i_number);
5714
longstore(i_ptr,i_number);
5719
uint32 Field_blob::get_length(const uchar *pos,
5720
uint packlength_arg,
5721
bool low_byte_first __attribute__((__unused__)))
5723
switch (packlength_arg) {
5725
return (uint32) pos[0];
5729
#ifdef WORDS_BIGENDIAN
5735
return (uint32) tmp;
5738
return (uint32) uint3korr(pos);
5742
#ifdef WORDS_BIGENDIAN
5748
return (uint32) tmp;
5751
return 0; // Impossible
5756
Put a blob length field into a record buffer.
5758
Depending on the maximum length of a blob, its length field is
5759
put into 1 to 4 bytes. This is a property of the blob object,
5760
described by 'packlength'.
5762
@param pos Pointer into the record buffer.
5763
@param length The length value to put.
5766
void Field_blob::put_length(uchar *pos, uint32 length)
5768
switch (packlength) {
5770
*pos= (char) length;
5773
int2store(pos, length);
5776
int3store(pos, length);
5779
int4store(pos, length);
5785
int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
5787
uint copy_length, new_length;
5788
const char *well_formed_error_pos;
5789
const char *cannot_convert_error_pos;
5790
const char *from_end_pos, *tmp;
5791
char buff[STRING_BUFFER_USUAL_SIZE];
5792
String tmpstr(buff,sizeof(buff), &my_charset_bin);
5796
bzero(ptr,Field_blob::pack_length());
5800
if (from == value.ptr())
5802
uint32 dummy_offset;
5803
if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
5805
Field_blob::store_length(length);
5806
bmove(ptr+packlength,(char*) &from,sizeof(char*));
5809
if (tmpstr.copy(from, length, cs))
5814
new_length= min(max_data_length(), field_charset->mbmaxlen * length);
5815
if (value.alloc(new_length))
5819
if (f_is_hex_escape(flags))
5821
copy_length= my_copy_with_hex_escaping(field_charset,
5822
(char*) value.ptr(), new_length,
5824
Field_blob::store_length(copy_length);
5826
bmove(ptr + packlength, (uchar*) &tmp, sizeof(char*));
5830
"length" is OK as "nchars" argument to well_formed_copy_nchars as this
5831
is never used to limit the length of the data. The cut of long data
5832
is done with the new_length value.
5834
copy_length= well_formed_copy_nchars(field_charset,
5835
(char*) value.ptr(), new_length,
5838
&well_formed_error_pos,
5839
&cannot_convert_error_pos,
5842
Field_blob::store_length(copy_length);
5844
bmove(ptr+packlength,(uchar*) &tmp,sizeof(char*));
5846
if (check_string_copy_error(this, well_formed_error_pos,
5847
cannot_convert_error_pos, from + length, cs))
5850
return report_if_important_data(from_end_pos, from + length);
5853
/* Fatal OOM error */
5854
bzero(ptr,Field_blob::pack_length());
5859
int Field_blob::store(double nr)
5861
CHARSET_INFO *cs=charset();
5862
value.set_real(nr, NOT_FIXED_DEC, cs);
5863
return Field_blob::store(value.ptr(),(uint) value.length(), cs);
5867
int Field_blob::store(int64_t nr, bool unsigned_val)
5869
CHARSET_INFO *cs=charset();
5870
value.set_int(nr, unsigned_val, cs);
5871
return Field_blob::store(value.ptr(), (uint) value.length(), cs);
5875
double Field_blob::val_real(void)
5878
char *end_not_used, *blob;
5882
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
5885
length= get_length(ptr);
5887
return my_strntod(cs, blob, length, &end_not_used, ¬_used);
5891
int64_t Field_blob::val_int(void)
5895
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
5898
uint32 length=get_length(ptr);
5899
return my_strntoll(charset(),blob,length,10,NULL,¬_used);
5902
String *Field_blob::val_str(String *val_buffer __attribute__((unused)),
5906
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
5908
val_ptr->set("",0,charset()); // A bit safer than ->length(0)
5910
val_ptr->set((const char*) blob,get_length(ptr),charset());
5915
my_decimal *Field_blob::val_decimal(my_decimal *decimal_value)
5919
memcpy_fixed(&blob, ptr+packlength, sizeof(const uchar*));
5926
length= get_length(ptr);
5928
str2my_decimal(E_DEC_FATAL_ERROR, blob, length, charset(),
5930
return decimal_value;
5934
int Field_blob::cmp(const uchar *a,uint32 a_length, const uchar *b,
5937
return field_charset->coll->strnncollsp(field_charset,
5938
a, a_length, b, b_length,
5943
int Field_blob::cmp_max(const uchar *a_ptr, const uchar *b_ptr,
5946
uchar *blob1,*blob2;
5947
memcpy_fixed(&blob1,a_ptr+packlength,sizeof(char*));
5948
memcpy_fixed(&blob2,b_ptr+packlength,sizeof(char*));
5949
uint a_len= get_length(a_ptr), b_len= get_length(b_ptr);
5950
set_if_smaller(a_len, max_length);
5951
set_if_smaller(b_len, max_length);
5952
return Field_blob::cmp(blob1,a_len,blob2,b_len);
5956
int Field_blob::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
5961
uint32 a_length,b_length;
5962
memcpy_fixed(&a,a_ptr+packlength,sizeof(char*));
5963
memcpy_fixed(&b,b_ptr+packlength,sizeof(char*));
5964
a_length=get_length(a_ptr);
5965
if (a_length > max_length)
5966
a_length=max_length;
5967
b_length=get_length(b_ptr);
5968
if (b_length > max_length)
5969
b_length=max_length;
5970
diff=memcmp(a,b,min(a_length,b_length));
5971
return diff ? diff : (int) (a_length - b_length);
5975
/* The following is used only when comparing a key */
5977
uint Field_blob::get_key_image(uchar *buff,
5979
imagetype type_arg __attribute__((__unused__)))
5981
uint32 blob_length= get_length(ptr);
5985
uint local_char_length= length / field_charset->mbmaxlen;
5986
local_char_length= my_charpos(field_charset, blob, blob + blob_length,
5988
set_if_smaller(blob_length, local_char_length);
5990
if ((uint32) length > blob_length)
5993
Must clear this as we do a memcmp in opt_range.cc to detect
5996
bzero(buff+HA_KEY_BLOB_LENGTH+blob_length, (length-blob_length));
5997
length=(uint) blob_length;
5999
int2store(buff,length);
6000
memcpy(buff+HA_KEY_BLOB_LENGTH, blob, length);
6001
return HA_KEY_BLOB_LENGTH+length;
6005
void Field_blob::set_key_image(const uchar *buff,uint length)
6007
length= uint2korr(buff);
6008
(void) Field_blob::store((const char*) buff+HA_KEY_BLOB_LENGTH, length,
6013
int Field_blob::key_cmp(const uchar *key_ptr, uint max_key_length)
6016
uint blob_length=get_length(ptr);
6017
memcpy_fixed(&blob1,ptr+packlength,sizeof(char*));
6018
CHARSET_INFO *cs= charset();
6019
uint local_char_length= max_key_length / cs->mbmaxlen;
6020
local_char_length= my_charpos(cs, blob1, blob1+blob_length,
6022
set_if_smaller(blob_length, local_char_length);
6023
return Field_blob::cmp(blob1, blob_length,
6024
key_ptr+HA_KEY_BLOB_LENGTH,
6025
uint2korr(key_ptr));
6028
int Field_blob::key_cmp(const uchar *a,const uchar *b)
6030
return Field_blob::cmp(a+HA_KEY_BLOB_LENGTH, uint2korr(a),
6031
b+HA_KEY_BLOB_LENGTH, uint2korr(b));
6036
Save the field metadata for blob fields.
6038
Saves the pack length in the first byte of the field metadata array
6039
at index of *metadata_ptr.
6041
@param metadata_ptr First byte of field metadata
6043
@returns number of bytes written to metadata_ptr
6045
int Field_blob::do_save_field_metadata(uchar *metadata_ptr)
6047
*metadata_ptr= pack_length_no_ptr();
6052
uint32 Field_blob::sort_length() const
6054
return (uint32) (current_thd->variables.max_sort_length +
6055
(field_charset == &my_charset_bin ? 0 : packlength));
6059
void Field_blob::sort_string(uchar *to,uint length)
6062
uint blob_length=get_length();
6068
if (field_charset == &my_charset_bin)
6073
Store length of blob last in blob to shorter blobs before longer blobs
6075
length-= packlength;
6078
switch (packlength) {
6080
*pos= (char) blob_length;
6083
mi_int2store(pos, blob_length);
6086
mi_int3store(pos, blob_length);
6089
mi_int4store(pos, blob_length);
6093
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
6095
blob_length=my_strnxfrm(field_charset,
6096
to, length, blob, blob_length);
6097
assert(blob_length == length);
6102
void Field_blob::sql_type(String &res) const
6106
switch (packlength) {
6107
default: str="tiny"; length=4; break;
6108
case 2: str=""; length=0; break;
6109
case 3: str="medium"; length= 6; break;
6110
case 4: str="long"; length=4; break;
6112
res.set_ascii(str,length);
6113
if (charset() == &my_charset_bin)
6114
res.append(STRING_WITH_LEN("blob"));
6117
res.append(STRING_WITH_LEN("text"));
6121
uchar *Field_blob::pack(uchar *to, const uchar *from,
6122
uint max_length, bool low_byte_first)
6126
uint32 length=get_length(); // Length of from string
6129
Store max length, which will occupy packlength bytes. If the max
6130
length given is smaller than the actual length of the blob, we
6131
just store the initial bytes of the blob.
6133
store_length(to, packlength, min(length, max_length), low_byte_first);
6136
Store the actual blob data, which will occupy 'length' bytes.
6140
get_ptr((uchar**) &from);
6141
memcpy(to+packlength, from,length);
6143
ptr=save; // Restore org row pointer
6144
return(to+packlength+length);
6149
Unpack a blob field from row data.
6151
This method is used to unpack a blob field from a master whose size of
6152
the field is less than that of the slave. Note: This method is included
6153
to satisfy inheritance rules, but is not needed for blob fields. It
6154
simply is used as a pass-through to the original unpack() method for
6157
@param to Destination of the data
6158
@param from Source of the data
6159
@param param_data @c true if base types should be stored in little-
6160
endian format, @c false if native format should
6163
@return New pointer into memory based on from + length of the data
6165
const uchar *Field_blob::unpack(uchar *to __attribute__((__unused__)),
6168
bool low_byte_first)
6170
uint const master_packlength=
6171
param_data > 0 ? param_data & 0xFF : packlength;
6172
uint32 const length= get_length(from, master_packlength, low_byte_first);
6173
bitmap_set_bit(table->write_set, field_index);
6174
store(reinterpret_cast<const char*>(from) + master_packlength,
6175
length, field_charset);
6176
return(from + master_packlength + length);
6179
/* Keys for blobs are like keys on varchars */
6181
int Field_blob::pack_cmp(const uchar *a, const uchar *b, uint key_length_arg,
6182
my_bool insert_or_update)
6184
uint a_length, b_length;
6185
if (key_length_arg > 255)
6187
a_length=uint2korr(a); a+=2;
6188
b_length=uint2korr(b); b+=2;
6192
a_length= (uint) *a++;
6193
b_length= (uint) *b++;
6195
return field_charset->coll->strnncollsp(field_charset,
6202
int Field_blob::pack_cmp(const uchar *b, uint key_length_arg,
6203
my_bool insert_or_update)
6206
uint a_length, b_length;
6207
memcpy_fixed(&a,ptr+packlength,sizeof(char*));
6209
return key_length_arg > 0 ? -1 : 0;
6211
a_length= get_length(ptr);
6212
if (key_length_arg > 255)
6214
b_length= uint2korr(b); b+=2;
6217
b_length= (uint) *b++;
6218
return field_charset->coll->strnncollsp(field_charset,
6224
/** Create a packed key that will be used for storage from a MySQL row. */
6227
Field_blob::pack_key(uchar *to, const uchar *from, uint max_length,
6228
bool low_byte_first __attribute__((unused)))
6232
uint32 length=get_length(); // Length of from string
6233
uint local_char_length= ((field_charset->mbmaxlen > 1) ?
6234
max_length/field_charset->mbmaxlen : max_length);
6236
get_ptr((uchar**) &from);
6237
if (length > local_char_length)
6238
local_char_length= my_charpos(field_charset, from, from+length,
6240
set_if_smaller(length, local_char_length);
6241
*to++= (uchar) length;
6242
if (max_length > 255) // 2 byte length
6243
*to++= (uchar) (length >> 8);
6244
memcpy(to, from, length);
6245
ptr=save; // Restore org row pointer
6251
Unpack a blob key into a record buffer.
6253
A blob key has a maximum size of 64K-1.
6254
In its packed form, the length field is one or two bytes long,
6255
depending on 'max_length'.
6256
Depending on the maximum length of a blob, its length field is
6257
put into 1 to 4 bytes. This is a property of the blob object,
6258
described by 'packlength'.
6259
Blobs are internally stored apart from the record buffer, which
6260
contains a pointer to the blob buffer.
6263
@param to Pointer into the record buffer.
6264
@param from Pointer to the packed key.
6265
@param max_length Key length limit from key description.
6268
Pointer into 'from' past the last byte copied from packed key.
6272
Field_blob::unpack_key(uchar *to, const uchar *from, uint max_length,
6273
bool low_byte_first __attribute__((unused)))
6275
/* get length of the blob key */
6276
uint32 length= *from++;
6277
if (max_length > 255)
6278
length+= *from++ << 8;
6280
/* put the length into the record buffer */
6281
put_length(to, length);
6283
/* put the address of the blob buffer or NULL */
6285
memcpy_fixed(to + packlength, &from, sizeof(from));
6287
bzero(to + packlength, sizeof(from));
6289
/* point to first byte of next field in 'from' */
6290
return from + length;
6294
/** Create a packed key that will be used for storage from a MySQL key. */
6297
Field_blob::pack_key_from_key_image(uchar *to, const uchar *from, uint max_length,
6298
bool low_byte_first __attribute__((unused)))
6300
uint length=uint2korr(from);
6301
if (length > max_length)
6303
*to++= (char) (length & 255);
6304
if (max_length > 255)
6305
*to++= (char) (length >> 8);
6307
memcpy(to, from+HA_KEY_BLOB_LENGTH, length);
6312
uint Field_blob::packed_col_length(const uchar *data_ptr, uint length)
6315
return uint2korr(data_ptr)+2;
6316
return (uint) *data_ptr + 1;
6320
uint Field_blob::max_packed_col_length(uint max_length)
6322
return (max_length > 255 ? 2 : 1)+max_length;
6326
uint Field_blob::is_equal(Create_field *new_field)
6328
if (compare_str_field_flags(new_field, flags))
6331
return ((new_field->sql_type == get_blob_type_from_length(max_data_length()))
6332
&& new_field->charset == field_charset &&
6333
((Field_blob *)new_field->field)->max_data_length() ==
6338
/****************************************************************************
6340
** This is a string which only can have a selection of different values.
6341
** If one uses this string in a number context one gets the type number.
6342
****************************************************************************/
6344
enum ha_base_keytype Field_enum::key_type() const
6346
switch (packlength) {
6347
default: return HA_KEYTYPE_BINARY;
6348
case 2: return HA_KEYTYPE_USHORT_INT;
6349
case 3: return HA_KEYTYPE_UINT24;
6350
case 4: return HA_KEYTYPE_ULONG_INT;
6351
case 8: return HA_KEYTYPE_ULONGLONG;
6355
void Field_enum::store_type(uint64_t value)
6357
switch (packlength) {
6358
case 1: ptr[0]= (uchar) value; break;
6360
#ifdef WORDS_BIGENDIAN
6361
if (table->s->db_low_byte_first)
6363
int2store(ptr,(unsigned short) value);
6367
shortstore(ptr,(unsigned short) value);
6369
case 3: int3store(ptr,(long) value); break;
6371
#ifdef WORDS_BIGENDIAN
6372
if (table->s->db_low_byte_first)
6374
int4store(ptr,value);
6378
longstore(ptr,(long) value);
6381
#ifdef WORDS_BIGENDIAN
6382
if (table->s->db_low_byte_first)
6384
int8store(ptr,value);
6388
int64_tstore(ptr,value); break;
6395
Storing a empty string in a enum field gives a warning
6396
(if there isn't a empty value in the enum)
6399
int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
6403
char buff[STRING_BUFFER_USUAL_SIZE];
6404
String tmpstr(buff,sizeof(buff), &my_charset_bin);
6406
/* Convert character set if necessary */
6407
if (String::needs_conversion(length, cs, field_charset, ¬_used))
6410
tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
6412
length= tmpstr.length();
6415
/* Remove end space */
6416
length= field_charset->cset->lengthsp(field_charset, from, length);
6417
uint tmp=find_type2(typelib, from, length, field_charset);
6420
if (length < 6) // Can't be more than 99999 enums
6422
/* This is for reading numbers with LOAD DATA INFILE */
6424
tmp=(uint) my_strntoul(cs,from,length,10,&end,&err);
6425
if (err || end != from+length || tmp > typelib->count)
6428
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
6430
if (!table->in_use->count_cuted_fields)
6434
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
6436
store_type((uint64_t) tmp);
6441
int Field_enum::store(double nr)
6443
return Field_enum::store((int64_t) nr, false);
6447
int Field_enum::store(int64_t nr,
6448
bool unsigned_val __attribute__((__unused__)))
6451
if ((uint64_t) nr > typelib->count || nr == 0)
6453
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
6454
if (nr != 0 || table->in_use->count_cuted_fields)
6460
store_type((uint64_t) (uint) nr);
6465
double Field_enum::val_real(void)
6467
return (double) Field_enum::val_int();
6471
int64_t Field_enum::val_int(void)
6473
switch (packlength) {
6475
return (int64_t) ptr[0];
6479
#ifdef WORDS_BIGENDIAN
6480
if (table->s->db_low_byte_first)
6485
return (int64_t) tmp;
6488
return (int64_t) uint3korr(ptr);
6492
#ifdef WORDS_BIGENDIAN
6493
if (table->s->db_low_byte_first)
6498
return (int64_t) tmp;
6503
#ifdef WORDS_BIGENDIAN
6504
if (table->s->db_low_byte_first)
6508
int64_tget(tmp,ptr);
6512
return 0; // impossible
6517
Save the field metadata for enum fields.
6519
Saves the real type in the first byte and the pack length in the
6520
second byte of the field metadata array at index of *metadata_ptr and
6521
*(metadata_ptr + 1).
6523
@param metadata_ptr First byte of field metadata
6525
@returns number of bytes written to metadata_ptr
6527
int Field_enum::do_save_field_metadata(uchar *metadata_ptr)
6529
*metadata_ptr= real_type();
6530
*(metadata_ptr + 1)= pack_length();
6535
String *Field_enum::val_str(String *val_buffer __attribute__((unused)),
6538
uint tmp=(uint) Field_enum::val_int();
6539
if (!tmp || tmp > typelib->count)
6540
val_ptr->set("", 0, field_charset);
6542
val_ptr->set((const char*) typelib->type_names[tmp-1],
6543
typelib->type_lengths[tmp-1],
6548
int Field_enum::cmp(const uchar *a_ptr, const uchar *b_ptr)
6551
ptr= (uchar*) a_ptr;
6552
uint64_t a=Field_enum::val_int();
6553
ptr= (uchar*) b_ptr;
6554
uint64_t b=Field_enum::val_int();
6556
return (a < b) ? -1 : (a > b) ? 1 : 0;
6559
void Field_enum::sort_string(uchar *to,uint length __attribute__((unused)))
6561
uint64_t value=Field_enum::val_int();
6563
for (uint i=0 ; i < packlength ; i++)
6565
*to-- = (uchar) (value & 255);
6571
void Field_enum::sql_type(String &res) const
6574
String enum_item(buffer, sizeof(buffer), res.charset());
6577
res.append(STRING_WITH_LEN("enum("));
6580
uint *len= typelib->type_lengths;
6581
for (const char **pos= typelib->type_names; *pos; pos++, len++)
6586
/* convert to res.charset() == utf8, then quote */
6587
enum_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
6588
append_unescaped(&res, enum_item.ptr(), enum_item.length());
6595
Field *Field_enum::new_field(MEM_ROOT *root, struct st_table *new_table,
6598
Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type);
6600
res->typelib= copy_typelib(root, typelib);
6607
This is a string which can have a collection of different values.
6608
Each string value is separated with a ','.
6609
For example "One,two,five"
6610
If one uses this string in a number context one gets the bits as a int64_t
6615
int Field_set::store(const char *from,uint length,CHARSET_INFO *cs)
6617
bool got_warning= 0;
6621
uint32 not_used_offset;
6622
char buff[STRING_BUFFER_USUAL_SIZE];
6623
String tmpstr(buff,sizeof(buff), &my_charset_bin);
6625
/* Convert character set if necessary */
6626
if (String::needs_conversion(length, cs, field_charset, ¬_used_offset))
6629
tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
6631
length= tmpstr.length();
6633
uint64_t tmp= find_set(typelib, from, length, field_charset,
6634
¬_used, ¬_used2, &got_warning);
6635
if (!tmp && length && length < 22)
6637
/* This is for reading numbers with LOAD DATA INFILE */
6639
tmp=my_strntoull(cs,from,length,10,&end,&err);
6640
if (err || end != from+length ||
6641
tmp > (uint64_t) (((int64_t) 1 << typelib->count) - (int64_t) 1))
6644
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
6647
else if (got_warning)
6648
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
6654
int Field_set::store(int64_t nr,
6655
bool unsigned_val __attribute__((__unused__)))
6658
uint64_t max_nr= set_bits(uint64_t, typelib->count);
6659
if ((uint64_t) nr > max_nr)
6662
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
6665
store_type((uint64_t) nr);
6670
String *Field_set::val_str(String *val_buffer,
6671
String *val_ptr __attribute__((unused)))
6673
uint64_t tmp=(uint64_t) Field_enum::val_int();
6676
val_buffer->length(0);
6677
val_buffer->set_charset(field_charset);
6678
while (tmp && bitnr < (uint) typelib->count)
6682
if (val_buffer->length())
6683
val_buffer->append(&field_separator, 1, &my_charset_latin1);
6684
String str(typelib->type_names[bitnr],
6685
typelib->type_lengths[bitnr],
6687
val_buffer->append(str);
6696
void Field_set::sql_type(String &res) const
6699
String set_item(buffer, sizeof(buffer), res.charset());
6702
res.append(STRING_WITH_LEN("set("));
6705
uint *len= typelib->type_lengths;
6706
for (const char **pos= typelib->type_names; *pos; pos++, len++)
6711
/* convert to res.charset() == utf8, then quote */
6712
set_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
6713
append_unescaped(&res, set_item.ptr(), set_item.length());
6721
1 if the fields are equally defined
6723
0 if the fields are unequally defined
1112
6726
bool Field::eq_def(Field *field)
6736
returns 1 if the fields are equally defined
1120
6738
bool Field_enum::eq_def(Field *field)
1122
6740
if (!Field::eq_def(field))
1125
6742
TYPELIB *from_lib=((Field_enum*) field)->typelib;
1127
6744
if (typelib->count < from_lib->count)
1130
for (uint32_t i=0 ; i < from_lib->count ; i++)
6746
for (uint i=0 ; i < from_lib->count ; i++)
1132
6747
if (my_strnncoll(field_charset,
1133
(const unsigned char*)typelib->type_names[i],
6748
(const uchar*)typelib->type_names[i],
1134
6749
strlen(typelib->type_names[i]),
1135
(const unsigned char*)from_lib->type_names[i],
6750
(const uchar*)from_lib->type_names[i],
1136
6751
strlen(from_lib->type_names[i])))
1143
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
1146
case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
1147
case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
1148
case DRIZZLE_TYPE_MICROTIME: return field::Microtime::max_string_length();
1149
case DRIZZLE_TYPE_TIMESTAMP: return field::Epoch::max_string_length();
1150
case DRIZZLE_TYPE_BOOLEAN: return field::Boolean::max_string_length();
1151
case DRIZZLE_TYPE_DATE:
1152
case DRIZZLE_TYPE_ENUM:
1153
case DRIZZLE_TYPE_LONG: return 4;
1154
case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1155
case DRIZZLE_TYPE_TIME:
1156
case DRIZZLE_TYPE_DATETIME:
1157
case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
1158
case DRIZZLE_TYPE_NULL: return 0;
1159
case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
1160
case DRIZZLE_TYPE_DECIMAL:
1168
uint32_t pack_length_to_packflag(uint32_t type)
1171
case 1: return 1 << FIELDFLAG_PACK_SHIFT;
6758
returns 1 if the fields are equally defined
6760
bool Field_num::eq_def(Field *field)
6762
if (!Field::eq_def(field))
6764
Field_num *from_num= (Field_num*) field;
6766
if (unsigned_flag != from_num->unsigned_flag ||
6767
(zerofill && !from_num->zerofill && !zero_pack()) ||
6768
dec != from_num->dec)
6774
uint Field_num::is_equal(Create_field *new_field)
6776
return ((new_field->sql_type == real_type()) &&
6777
((new_field->flags & UNSIGNED_FLAG) == (uint) (flags &
6779
((new_field->flags & AUTO_INCREMENT_FLAG) ==
6780
(uint) (flags & AUTO_INCREMENT_FLAG)) &&
6781
(new_field->length <= max_display_length()));
6785
/*****************************************************************************
6786
Handling of field and Create_field
6787
*****************************************************************************/
6790
Convert create_field::length from number of characters to number of bytes.
6793
void Create_field::create_length_to_internal_length(void)
6796
case MYSQL_TYPE_BLOB:
6797
case MYSQL_TYPE_VAR_STRING:
6798
case MYSQL_TYPE_STRING:
6799
case MYSQL_TYPE_VARCHAR:
6800
length*= charset->mbmaxlen;
6802
pack_length= calc_pack_length(sql_type, length);
6804
case MYSQL_TYPE_ENUM:
6805
case MYSQL_TYPE_SET:
6806
/* Pack_length already calculated in sql_parse.cc */
6807
length*= charset->mbmaxlen;
6808
key_length= pack_length;
6810
case MYSQL_TYPE_NEWDECIMAL:
6811
key_length= pack_length=
6812
my_decimal_get_binary_size(my_decimal_length_to_precision(length,
6819
key_length= pack_length= calc_pack_length(sql_type, length);
6826
Init for a tmp table field. To be extended if need be.
6828
void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
6829
uint32 length_arg, uint32 decimals_arg,
6830
bool maybe_null, bool is_unsigned)
6833
sql_type= sql_type_arg;
6834
char_length= length= length_arg;;
6835
unireg_check= Field::NONE;
6837
charset= &my_charset_bin;
6838
pack_flag= (FIELDFLAG_NUMBER |
6839
((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
6840
(maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
6841
(is_unsigned ? 0 : FIELDFLAG_DECIMAL));
6846
Initialize field definition for create.
6848
@param thd Thread handle
6849
@param fld_name Field name
6850
@param fld_type Field type
6851
@param fld_length Field length
6852
@param fld_decimals Decimal (if any)
6853
@param fld_type_modifier Additional type information
6854
@param fld_default_value Field default value (if any)
6855
@param fld_on_update_value The value of ON UPDATE clause
6856
@param fld_comment Field comment
6857
@param fld_change Field change
6858
@param fld_interval_list Interval list (if any)
6859
@param fld_charset Field charset
6867
bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type,
6868
char *fld_length, char *fld_decimals,
6869
uint fld_type_modifier, Item *fld_default_value,
6870
Item *fld_on_update_value, LEX_STRING *fld_comment,
6871
char *fld_change, List<String> *fld_interval_list,
6872
CHARSET_INFO *fld_charset,
6873
uint fld_geom_type __attribute__((__unused__)),
6874
enum column_format_type column_format)
6876
uint sign_len, allowed_type_modifier= 0;
6877
ulong max_field_charlength= MAX_FIELD_CHARLENGTH;
6880
field_name= fld_name;
6881
def= fld_default_value;
6882
flags= fld_type_modifier;
6883
flags|= (((uint)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
6884
unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
6885
Field::NEXT_NUMBER : Field::NONE);
6886
decimals= fld_decimals ? (uint)atoi(fld_decimals) : 0;
6887
if (decimals >= NOT_FIXED_DEC)
6889
my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
6898
pack_length= key_length= 0;
6899
charset= fld_charset;
6900
interval_list.empty();
6902
comment= *fld_comment;
6904
Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
6905
it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
6907
if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
6908
(fld_type_modifier & NOT_NULL_FLAG) && fld_type != MYSQL_TYPE_TIMESTAMP)
6909
flags|= NO_DEFAULT_VALUE_FLAG;
6911
if (fld_length && !(length= (uint) atoi(fld_length)))
6912
fld_length= 0; /* purecov: inspected */
6913
sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
6916
case MYSQL_TYPE_TINY:
6918
length= MAX_TINYINT_WIDTH+sign_len;
6919
allowed_type_modifier= AUTO_INCREMENT_FLAG;
6921
case MYSQL_TYPE_SHORT:
6923
length= MAX_SMALLINT_WIDTH+sign_len;
6924
allowed_type_modifier= AUTO_INCREMENT_FLAG;
6926
case MYSQL_TYPE_LONG:
6928
length= MAX_INT_WIDTH+sign_len;
6929
allowed_type_modifier= AUTO_INCREMENT_FLAG;
6931
case MYSQL_TYPE_LONGLONG:
6933
length= MAX_BIGINT_WIDTH;
6934
allowed_type_modifier= AUTO_INCREMENT_FLAG;
6936
case MYSQL_TYPE_NULL:
6938
case MYSQL_TYPE_NEWDECIMAL:
6939
my_decimal_trim(&length, &decimals);
6940
if (length > DECIMAL_MAX_PRECISION)
6942
my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
6943
DECIMAL_MAX_PRECISION);
6946
if (length < decimals)
6948
my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
6952
my_decimal_precision_to_length(length, decimals,
6953
fld_type_modifier & UNSIGNED_FLAG);
6955
my_decimal_get_binary_size(length, decimals);
6957
case MYSQL_TYPE_VARCHAR:
6959
Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table
6960
if they don't have a default value
6962
max_field_charlength= MAX_FIELD_VARCHARLENGTH;
6964
case MYSQL_TYPE_STRING:
6966
case MYSQL_TYPE_BLOB:
6967
if (fld_default_value)
6969
/* Allow empty as default value. */
6971
res= fld_default_value->val_str(&str);
6973
A default other than '' is always an error, and any non-NULL
6974
specified default is an error in strict mode.
6976
if (res->length() || (thd->variables.sql_mode &
6977
(MODE_STRICT_TRANS_TABLES |
6978
MODE_STRICT_ALL_TABLES)))
6980
my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
6981
fld_name); /* purecov: inspected */
6987
Otherwise a default of '' is just a warning.
6989
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
6990
ER_BLOB_CANT_HAVE_DEFAULT,
6991
ER(ER_BLOB_CANT_HAVE_DEFAULT),
6998
case MYSQL_TYPE_YEAR:
6999
if (!fld_length || length != 2)
7000
length= 4; /* Default length */
7001
flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
7003
case MYSQL_TYPE_DOUBLE:
7004
allowed_type_modifier= AUTO_INCREMENT_FLAG;
7005
if (!fld_length && !fld_decimals)
7008
decimals= NOT_FIXED_DEC;
7010
if (length < decimals &&
7011
decimals != NOT_FIXED_DEC)
7013
my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
7017
case MYSQL_TYPE_TIMESTAMP:
7020
/* Compressed date YYYYMMDDHHMMSS */
7021
length= MAX_DATETIME_COMPRESSED_WIDTH;
7023
else if (length != MAX_DATETIME_WIDTH)
7026
We support only even TIMESTAMP lengths less or equal than 14
7027
and 19 as length of 4.1 compatible representation.
7029
length= ((length+1)/2)*2; /* purecov: inspected */
7030
length= min(length, MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
7032
flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
7033
if (fld_default_value)
7035
/* Grammar allows only NOW() value for ON UPDATE clause */
7036
if (fld_default_value->type() == Item::FUNC_ITEM &&
7037
((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
7039
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
7040
Field::TIMESTAMP_DN_FIELD);
7042
We don't need default value any longer moreover it is dangerous.
7043
Everything handled by unireg_check further.
7048
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
7054
If we have default TIMESTAMP NOT NULL column without explicit DEFAULT
7055
or ON UPDATE values then for the sake of compatiblity we should treat
7056
this column as having DEFAULT NOW() ON UPDATE NOW() (when we don't
7057
have another TIMESTAMP column with auto-set option before this one)
7058
or DEFAULT 0 (in other cases).
7059
So here we are setting TIMESTAMP_OLD_FIELD only temporary, and will
7060
replace this value by TIMESTAMP_DNUN_FIELD or NONE later when
7061
information about all TIMESTAMP fields in table will be availiable.
7063
If we have TIMESTAMP NULL column without explicit DEFAULT value
7064
we treat it as having DEFAULT NULL attribute.
7066
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD :
7067
(flags & NOT_NULL_FLAG ? Field::TIMESTAMP_OLD_FIELD :
7071
case MYSQL_TYPE_DATE:
7072
/* Old date type. */
7073
sql_type= MYSQL_TYPE_NEWDATE;
7075
case MYSQL_TYPE_NEWDATE:
7078
case MYSQL_TYPE_TIME:
7081
case MYSQL_TYPE_DATETIME:
7082
length= MAX_DATETIME_WIDTH;
7084
case MYSQL_TYPE_SET:
7086
pack_length= get_set_pack_length(fld_interval_list->elements);
7088
List_iterator<String> it(*fld_interval_list);
7091
interval_list.push_back(tmp);
7093
Set fake length to 1 to pass the below conditions.
7094
Real length will be set in mysql_prepare_table()
7095
when we know the character set of the column
7100
case MYSQL_TYPE_ENUM:
7102
/* Should be safe. */
7103
pack_length= get_enum_pack_length(fld_interval_list->elements);
7105
List_iterator<String> it(*fld_interval_list);
7108
interval_list.push_back(tmp);
7109
length= 1; /* See comment for MYSQL_TYPE_SET above. */
7112
case MYSQL_TYPE_VAR_STRING:
7113
assert(0); /* Impossible, we killed it */
7116
/* Remember the value of length */
7117
char_length= length;
7119
if (!(flags & BLOB_FLAG) &&
7120
((length > max_field_charlength && fld_type != MYSQL_TYPE_SET &&
7121
fld_type != MYSQL_TYPE_ENUM &&
7122
(fld_type != MYSQL_TYPE_VARCHAR || fld_default_value)) ||
7124
fld_type != MYSQL_TYPE_STRING &&
7125
fld_type != MYSQL_TYPE_VARCHAR)))
7127
my_error((fld_type == MYSQL_TYPE_VAR_STRING ||
7128
fld_type == MYSQL_TYPE_VARCHAR ||
7129
fld_type == MYSQL_TYPE_STRING) ? ER_TOO_BIG_FIELDLENGTH :
7130
ER_TOO_BIG_DISPLAYWIDTH,
7132
fld_name, max_field_charlength); /* purecov: inspected */
7135
fld_type_modifier&= AUTO_INCREMENT_FLAG;
7136
if ((~allowed_type_modifier) & fld_type_modifier)
7138
my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
7142
return(false); /* success */
7146
enum_field_types get_blob_type_from_length(ulong length __attribute__((__unused__)))
7148
enum_field_types type;
7150
type= MYSQL_TYPE_BLOB;
7157
Make a field from the .frm file info
7160
uint32 calc_pack_length(enum_field_types type,uint32 length)
7163
case MYSQL_TYPE_VAR_STRING:
7164
case MYSQL_TYPE_STRING:
7165
case MYSQL_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
7166
case MYSQL_TYPE_YEAR:
7167
case MYSQL_TYPE_TINY : return 1;
7168
case MYSQL_TYPE_SHORT : return 2;
7169
case MYSQL_TYPE_DATE:
7170
case MYSQL_TYPE_NEWDATE:
7171
case MYSQL_TYPE_TIME: return 3;
7172
case MYSQL_TYPE_TIMESTAMP:
7173
case MYSQL_TYPE_LONG : return 4;
7174
case MYSQL_TYPE_DOUBLE: return sizeof(double);
7175
case MYSQL_TYPE_DATETIME:
7176
case MYSQL_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
7177
case MYSQL_TYPE_NULL : return 0;
7178
case MYSQL_TYPE_BLOB: return 4+portable_sizeof_char_ptr;
7179
case MYSQL_TYPE_SET:
7180
case MYSQL_TYPE_ENUM:
7181
case MYSQL_TYPE_NEWDECIMAL:
7182
abort(); return 0; // This shouldn't happen
7189
uint pack_length_to_packflag(uint type)
7192
case 1: return f_settype((uint) MYSQL_TYPE_TINY);
7193
case 2: return f_settype((uint) MYSQL_TYPE_SHORT);
1173
7194
case 3: assert(1);
1174
case 4: return f_settype(DRIZZLE_TYPE_LONG);
1175
case 8: return f_settype(DRIZZLE_TYPE_LONGLONG);
7195
case 4: return f_settype((uint) MYSQL_TYPE_LONG);
7196
case 8: return f_settype((uint) MYSQL_TYPE_LONGLONG);
1177
7198
return 0; // This shouldn't happen
7202
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length,
7203
uchar *null_pos, uchar null_bit,
7205
enum_field_types field_type,
7206
CHARSET_INFO *field_charset,
7207
Field::utype unireg_check,
7209
const char *field_name)
7211
if (!f_maybe_null(pack_flag))
7218
null_bit= ((uchar) 1) << null_bit;
7221
switch (field_type) {
7222
case MYSQL_TYPE_DATE:
7223
case MYSQL_TYPE_NEWDATE:
7224
case MYSQL_TYPE_TIME:
7225
case MYSQL_TYPE_DATETIME:
7226
case MYSQL_TYPE_TIMESTAMP:
7227
field_charset= &my_charset_bin;
7231
if (f_is_alpha(pack_flag))
7233
if (!f_is_packed(pack_flag))
7235
if (field_type == MYSQL_TYPE_STRING ||
7236
field_type == MYSQL_TYPE_VAR_STRING)
7237
return new Field_string(ptr,field_length,null_pos,null_bit,
7238
unireg_check, field_name,
7240
if (field_type == MYSQL_TYPE_VARCHAR)
7241
return new Field_varstring(ptr,field_length,
7242
HA_VARCHAR_PACKLENGTH(field_length),
7244
unireg_check, field_name,
7250
uint pack_length=calc_pack_length((enum_field_types)
7251
f_packtype(pack_flag),
7254
if (f_is_blob(pack_flag))
7255
return new Field_blob(ptr,null_pos,null_bit,
7256
unireg_check, field_name, share,
7257
pack_length, field_charset);
7260
if (f_is_enum(pack_flag))
7261
return new Field_enum(ptr,field_length,null_pos,null_bit,
7262
unireg_check, field_name,
7263
pack_length, interval, field_charset);
7265
return new Field_set(ptr,field_length,null_pos,null_bit,
7266
unireg_check, field_name,
7267
pack_length, interval, field_charset);
7271
switch (field_type) {
7272
case MYSQL_TYPE_NEWDECIMAL:
7273
return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
7274
unireg_check, field_name,
7275
f_decimals(pack_flag),
7276
f_is_zerofill(pack_flag) != 0,
7277
f_is_dec(pack_flag) == 0);
7278
case MYSQL_TYPE_DOUBLE:
7279
return new Field_double(ptr,field_length,null_pos,null_bit,
7280
unireg_check, field_name,
7281
f_decimals(pack_flag),
7282
f_is_zerofill(pack_flag) != 0,
7283
f_is_dec(pack_flag)== 0);
7284
case MYSQL_TYPE_TINY:
7285
return new Field_tiny(ptr,field_length,null_pos,null_bit,
7286
unireg_check, field_name,
7287
f_is_zerofill(pack_flag) != 0,
7288
f_is_dec(pack_flag) == 0);
7289
case MYSQL_TYPE_SHORT:
7290
return new Field_short(ptr,field_length,null_pos,null_bit,
7291
unireg_check, field_name,
7292
f_is_zerofill(pack_flag) != 0,
7293
f_is_dec(pack_flag) == 0);
7294
case MYSQL_TYPE_LONG:
7295
return new Field_long(ptr,field_length,null_pos,null_bit,
7296
unireg_check, field_name,
7297
f_is_zerofill(pack_flag) != 0,
7298
f_is_dec(pack_flag) == 0);
7299
case MYSQL_TYPE_LONGLONG:
7300
return new Field_int64_t(ptr,field_length,null_pos,null_bit,
7301
unireg_check, field_name,
7302
f_is_zerofill(pack_flag) != 0,
7303
f_is_dec(pack_flag) == 0);
7304
case MYSQL_TYPE_TIMESTAMP:
7305
return new Field_timestamp(ptr,field_length, null_pos, null_bit,
7306
unireg_check, field_name, share,
7308
case MYSQL_TYPE_YEAR:
7309
return new Field_year(ptr,field_length,null_pos,null_bit,
7310
unireg_check, field_name);
7311
case MYSQL_TYPE_DATE:
7312
case MYSQL_TYPE_NEWDATE:
7313
return new Field_newdate(ptr,null_pos,null_bit,
7314
unireg_check, field_name, field_charset);
7315
case MYSQL_TYPE_TIME:
7316
return new Field_time(ptr,null_pos,null_bit,
7317
unireg_check, field_name, field_charset);
7318
case MYSQL_TYPE_DATETIME:
7319
return new Field_datetime(ptr,null_pos,null_bit,
7320
unireg_check, field_name, field_charset);
7321
case MYSQL_TYPE_NULL:
7322
return new Field_null(ptr, field_length, unireg_check, field_name,
7324
default: // Impossible (Wrong version)
7331
/** Create a field suitable for create of table. */
7333
Create_field::Create_field(Field *old_field,Field *orig_field)
7336
field_name=change=old_field->field_name;
7337
length= old_field->field_length;
7338
flags= old_field->flags;
7339
unireg_check=old_field->unireg_check;
7340
pack_length=old_field->pack_length();
7341
key_length= old_field->key_length();
7342
sql_type= old_field->real_type();
7343
charset= old_field->charset(); // May be NULL ptr
7344
comment= old_field->comment;
7345
decimals= old_field->decimals();
7347
/* Fix if the original table had 4 byte pointer blobs */
7348
if (flags & BLOB_FLAG)
7349
pack_length= (pack_length- old_field->table->s->blob_ptr_size +
7350
portable_sizeof_char_ptr);
7353
case MYSQL_TYPE_BLOB:
7354
sql_type= MYSQL_TYPE_BLOB;
7355
length/= charset->mbmaxlen;
7356
key_length/= charset->mbmaxlen;
7358
case MYSQL_TYPE_STRING:
7359
/* Change CHAR -> VARCHAR if dynamic record length */
7360
if (old_field->type() == MYSQL_TYPE_VAR_STRING)
7361
sql_type= MYSQL_TYPE_VARCHAR;
7364
case MYSQL_TYPE_ENUM:
7365
case MYSQL_TYPE_SET:
7366
case MYSQL_TYPE_VARCHAR:
7367
case MYSQL_TYPE_VAR_STRING:
7368
/* This is corrected in create_length_to_internal_length */
7369
length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
7375
if (flags & (ENUM_FLAG | SET_FLAG))
7376
interval= ((Field_enum*) old_field)->typelib;
7380
char_length= length;
7382
if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
7383
old_field->ptr && orig_field &&
7384
(sql_type != MYSQL_TYPE_TIMESTAMP || /* set def only if */
7385
old_field->table->timestamp_field != old_field || /* timestamp field */
7386
unireg_check == Field::TIMESTAMP_UN_FIELD)) /* has default val */
7388
char buff[MAX_FIELD_WIDTH];
7389
String tmp(buff,sizeof(buff), charset);
7392
/* Get the value from default_values */
7393
diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
7394
orig_field->table->record[0]);
7395
orig_field->move_field_offset(diff); // Points now at default_values
7396
if (!orig_field->is_real_null())
7398
char buff[MAX_FIELD_WIDTH], *pos;
7399
String tmp(buff, sizeof(buff), charset), *res;
7400
res= orig_field->val_str(&tmp);
7401
pos= (char*) sql_strmake(res->ptr(), res->length());
7402
def= new Item_string(pos, res->length(), charset);
7404
orig_field->move_field_offset(-diff); // Back to record[0]
7410
maximum possible display length for blob.
7416
uint32 Field_blob::max_display_length()
7421
return 255 * field_charset->mbmaxlen;
7423
return 65535 * field_charset->mbmaxlen;
7425
return 16777215 * field_charset->mbmaxlen;
7427
return (uint32) 4294967295U;
7429
assert(0); // we should never go here
1180
7435
/*****************************************************************************
1181
7436
Warning handling
1182
7437
*****************************************************************************/
1184
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
1185
drizzled::error_t code,
1186
int cuted_increment)
7440
Produce warning or note about data saved into field.
7442
@param level - level of message (Note/Warning/Error)
7443
@param code - error code of message to be produced
7444
@param cuted_increment - whenever we should increase cut fields count or not
7447
This function won't produce warning and increase cut fields counter
7448
if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
7450
if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
7451
This allows us to avoid notes in optimisation, like convert_constant_item().
7454
1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
7460
Field::set_warning(MYSQL_ERROR::enum_warning_level level, uint code,
7461
int cuted_increment)
1189
7464
If this field was created only for type conversion purposes it
1190
7465
will have table == NULL.
1192
Session *session= table ? table->in_use : current_session;
1193
if (session->count_cuted_fields)
7467
THD *thd= table ? table->in_use : current_thd;
7468
if (thd->count_cuted_fields)
1195
session->cuted_fields+= cuted_increment;
1196
push_warning_printf(session, level, code, ER(code), field_name,
1197
session->row_count);
7470
thd->cuted_fields+= cuted_increment;
7471
push_warning_printf(thd, level, code, ER(code), field_name,
1200
return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
7475
return level >= MYSQL_ERROR::WARN_LEVEL_WARN;
1204
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1205
drizzled::error_t code,
1207
uint32_t str_length,
1208
type::timestamp_t ts_type,
1209
int cuted_increment)
7480
Produce warning or note about datetime string data saved into field.
7482
@param level level of message (Note/Warning/Error)
7483
@param code error code of message to be produced
7484
@param str string value which we tried to save
7485
@param str_length length of string which we tried to save
7486
@param ts_type type of datetime value (datetime/date/time)
7487
@param cuted_increment whenever we should increase cut fields count or not
7490
This function will always produce some warning but won't increase cut
7491
fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
7496
Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level, uint code,
7497
const char *str, uint str_length,
7498
timestamp_type ts_type, int cuted_increment)
1211
Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1213
if ((session->abortOnWarning() and
1214
level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
7500
THD *thd= table ? table->in_use : current_thd;
7501
if ((thd->really_abort_on_warning() &&
7502
level >= MYSQL_ERROR::WARN_LEVEL_WARN) ||
1215
7503
set_warning(level, code, cuted_increment))
1216
make_truncated_value_warning(session, level, str, str_length, ts_type,
7504
make_truncated_value_warning(thd, level, str, str_length, ts_type,
1220
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1221
drizzled::error_t code,
1223
type::timestamp_t ts_type,
1224
int cuted_increment)
7510
Produce warning or note about integer datetime value saved into field.
7512
@param level level of message (Note/Warning/Error)
7513
@param code error code of message to be produced
7514
@param nr numeric value which we tried to save
7515
@param ts_type type of datetime value (datetime/date/time)
7516
@param cuted_increment whenever we should increase cut fields count or not
7519
This function will always produce some warning but won't increase cut
7520
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
7525
Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level, uint code,
7526
int64_t nr, timestamp_type ts_type,
7527
int cuted_increment)
1226
Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1228
if (session->abortOnWarning() or
7529
THD *thd= table ? table->in_use : current_thd;
7530
if (thd->really_abort_on_warning() ||
1229
7531
set_warning(level, code, cuted_increment))
1231
char str_nr[DECIMAL_LONGLONG_DIGITS];
1232
char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
1233
make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
7534
char *str_end= int64_t10_to_str(nr, str_nr, -10);
7535
make_truncated_value_warning(thd, level, str_nr, (uint) (str_end - str_nr),
1234
7536
ts_type, field_name);
1238
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1239
const drizzled::error_t code,
1241
type::timestamp_t ts_type)
7542
Produce warning or note about double datetime data saved into field.
7544
@param level level of message (Note/Warning/Error)
7545
@param code error code of message to be produced
7546
@param nr double value which we tried to save
7547
@param ts_type type of datetime value (datetime/date/time)
7550
This function will always produce some warning but won't increase cut
7551
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
7556
Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level, uint code,
7557
double nr, timestamp_type ts_type)
1243
Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1245
if (session->abortOnWarning() or
7559
THD *thd= table ? table->in_use : current_thd;
7560
if (thd->really_abort_on_warning() ||
1246
7561
set_warning(level, code, 1))
1248
7563
/* DBL_DIG is enough to print '-[digits].E+###' */
1249
7564
char str_nr[DBL_DIG + 8];
1250
uint32_t str_len= snprintf(str_nr, sizeof(str_nr), "%g", nr);
1251
make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
7565
uint str_len= sprintf(str_nr, "%g", nr);
7566
make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
1256
bool Field::isReadSet() const
1258
return table->isReadSet(field_index);
1261
bool Field::isWriteSet()
1263
return table->isWriteSet(field_index);
1266
void Field::setReadSet(bool arg)
1269
table->setReadSet(field_index);
1271
table->clearReadSet(field_index);
1274
void Field::setWriteSet(bool arg)
1277
table->setWriteSet(field_index);
1279
table->clearWriteSet(field_index);
1282
void Field::pack_num(uint64_t arg, unsigned char *destination)
1284
if (not destination)
1287
int64_tstore(destination, arg);
1290
void Field::pack_num(uint32_t arg, unsigned char *destination)
1292
if (not destination)
1295
longstore(destination, arg);
1298
uint64_t Field::unpack_num(uint64_t &destination, const unsigned char *arg) const
1303
int64_tget(destination, arg);
1308
uint32_t Field::unpack_num(uint32_t &destination, const unsigned char *arg) const
1313
longget(destination, arg);
1318
std::ostream& operator<<(std::ostream& output, const Field &field)
1320
output << "Field:(";
1321
output << field.field_name;
1323
output << drizzled::display::type(field.real_type());
1326
if (field.flags & NOT_NULL_FLAG)
1327
output << " NOT_NULL";
1329
if (field.flags & PRI_KEY_FLAG)
1330
output << ", PRIMARY KEY";
1332
if (field.flags & UNIQUE_KEY_FLAG)
1333
output << ", UNIQUE KEY";
1335
if (field.flags & MULTIPLE_KEY_FLAG)
1336
output << ", MULTIPLE KEY";
1338
if (field.flags & BLOB_FLAG)
1341
if (field.flags & UNSIGNED_FLAG)
1342
output << ", UNSIGNED";
1344
if (field.flags & BINARY_FLAG)
1345
output << ", BINARY";
1349
return output; // for multiple << operators.
1352
} /* namespace drizzled */