~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Monty Taylor
  • Date: 2008-07-28 02:47:38 UTC
  • mto: (212.5.1 codestyle)
  • mto: This revision was merged to the branch mainline in revision 219.
  • Revision ID: monty@inaugust.com-20080728024738-366ikqnoqv7d8g6l
Fixed the includes in places to make the myisam header file move work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB
2
 
 
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.
6
 
 
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.
11
 
 
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 */
15
 
 
16
 
 
17
 
/**
18
 
  @file
19
 
 
20
 
  @brief
21
 
  This file implements classes defined in field.h
22
 
*/
23
 
#include <drizzled/server_includes.h>
24
 
#include "sql_select.h"
25
 
#include <errno.h>
26
 
#include <drizzled/drizzled_error_messages.h>
27
 
 
28
 
// Maximum allowed exponent value for converting string to decimal
29
 
#define MAX_EXPONENT 1024
30
 
 
31
 
/*****************************************************************************
32
 
  Instansiate templates and static variables
33
 
*****************************************************************************/
34
 
 
35
 
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
36
 
template class List<Create_field>;
37
 
template class List_iterator<Create_field>;
38
 
#endif
39
 
 
40
 
 
41
 
/*
42
 
  Rules for merging different types of fields in UNION
43
 
 
44
 
  NOTE: to avoid 256*256 table, gap in table types numeration is skiped
45
 
  following #defines describe that gap and how to canculate number of fields
46
 
  and index of field in thia array.
47
 
*/
48
 
#define FIELDTYPE_TEAR_FROM (DRIZZLE_TYPE_VARCHAR + 1)
49
 
#define FIELDTYPE_TEAR_TO   (DRIZZLE_TYPE_VIRTUAL - 1)
50
 
#define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO))
51
 
inline int field_type2index (enum_field_types field_type)
52
 
{
53
 
  return (field_type < FIELDTYPE_TEAR_FROM ?
54
 
          field_type :
55
 
          ((int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) - 1);
56
 
}
57
 
 
58
 
 
59
 
static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]=
60
 
{
61
 
  /* DRIZZLE_TYPE_DECIMAL -> */
62
 
  {
63
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
64
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_NEWDECIMAL,
65
 
  //DRIZZLE_TYPE_LONG
66
 
    DRIZZLE_TYPE_NEWDECIMAL,
67
 
  //DRIZZLE_TYPE_DOUBLE
68
 
    DRIZZLE_TYPE_DOUBLE,
69
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
70
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
71
 
  //DRIZZLE_TYPE_LONGLONG
72
 
    DRIZZLE_TYPE_NEWDECIMAL,
73
 
  //DRIZZLE_TYPE_TIME
74
 
    DRIZZLE_TYPE_VARCHAR,
75
 
  //DRIZZLE_TYPE_DATETIME
76
 
    DRIZZLE_TYPE_VARCHAR,
77
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
78
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
79
 
  // DRIZZLE_TYPE_VIRTUAL
80
 
    DRIZZLE_TYPE_VIRTUAL,
81
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
82
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
83
 
  //DRIZZLE_TYPE_BLOB
84
 
    DRIZZLE_TYPE_BLOB,
85
 
  },
86
 
  /* DRIZZLE_TYPE_TINY -> */
87
 
  {
88
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
89
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
90
 
  //DRIZZLE_TYPE_LONG
91
 
    DRIZZLE_TYPE_LONG,
92
 
  //DRIZZLE_TYPE_DOUBLE
93
 
    DRIZZLE_TYPE_DOUBLE,
94
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
95
 
    DRIZZLE_TYPE_TINY,        DRIZZLE_TYPE_VARCHAR,
96
 
  //DRIZZLE_TYPE_LONGLONG
97
 
    DRIZZLE_TYPE_LONGLONG,
98
 
  //DRIZZLE_TYPE_TIME
99
 
    DRIZZLE_TYPE_VARCHAR,
100
 
  //DRIZZLE_TYPE_DATETIME
101
 
    DRIZZLE_TYPE_VARCHAR,
102
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
103
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
104
 
  // DRIZZLE_TYPE_VIRTUAL
105
 
    DRIZZLE_TYPE_VIRTUAL,
106
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
107
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
108
 
  //DRIZZLE_TYPE_BLOB
109
 
    DRIZZLE_TYPE_BLOB,
110
 
  },
111
 
  /* DRIZZLE_TYPE_LONG -> */
112
 
  {
113
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
114
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONG,
115
 
  //DRIZZLE_TYPE_LONG
116
 
    DRIZZLE_TYPE_LONG,
117
 
  //DRIZZLE_TYPE_DOUBLE
118
 
    DRIZZLE_TYPE_DOUBLE,
119
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
120
 
    DRIZZLE_TYPE_LONG,         DRIZZLE_TYPE_VARCHAR,
121
 
  //DRIZZLE_TYPE_LONGLONG
122
 
    DRIZZLE_TYPE_LONGLONG,
123
 
  //DRIZZLE_TYPE_TIME
124
 
    DRIZZLE_TYPE_VARCHAR,
125
 
  //DRIZZLE_TYPE_DATETIME
126
 
    DRIZZLE_TYPE_VARCHAR,
127
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
128
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
129
 
  // DRIZZLE_TYPE_VIRTUAL
130
 
    DRIZZLE_TYPE_VIRTUAL,
131
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
132
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
133
 
  //DRIZZLE_TYPE_BLOB
134
 
    DRIZZLE_TYPE_BLOB,
135
 
  },
136
 
  /* DRIZZLE_TYPE_DOUBLE -> */
137
 
  {
138
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
139
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_DOUBLE,
140
 
  //DRIZZLE_TYPE_LONG
141
 
    DRIZZLE_TYPE_DOUBLE,
142
 
  //DRIZZLE_TYPE_DOUBLE
143
 
    DRIZZLE_TYPE_DOUBLE,
144
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
145
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
146
 
  //DRIZZLE_TYPE_LONGLONG
147
 
    DRIZZLE_TYPE_DOUBLE,
148
 
  //DRIZZLE_TYPE_TIME
149
 
    DRIZZLE_TYPE_VARCHAR,
150
 
  //DRIZZLE_TYPE_DATETIME
151
 
    DRIZZLE_TYPE_VARCHAR,
152
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
153
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
154
 
  // DRIZZLE_TYPE_VIRTUAL
155
 
    DRIZZLE_TYPE_VIRTUAL,
156
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
157
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
158
 
  //DRIZZLE_TYPE_BLOB
159
 
    DRIZZLE_TYPE_BLOB,
160
 
  },
161
 
  /* DRIZZLE_TYPE_NULL -> */
162
 
  {
163
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
164
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
165
 
  //DRIZZLE_TYPE_LONG
166
 
    DRIZZLE_TYPE_LONG,
167
 
  //DRIZZLE_TYPE_DOUBLE
168
 
    DRIZZLE_TYPE_DOUBLE,
169
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
170
 
    DRIZZLE_TYPE_NULL,        DRIZZLE_TYPE_TIMESTAMP,
171
 
  //DRIZZLE_TYPE_LONGLONG
172
 
    DRIZZLE_TYPE_LONGLONG,
173
 
  //DRIZZLE_TYPE_TIME
174
 
    DRIZZLE_TYPE_TIME,
175
 
  //DRIZZLE_TYPE_DATETIME
176
 
    DRIZZLE_TYPE_DATETIME,
177
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
178
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
179
 
  // DRIZZLE_TYPE_VIRTUAL
180
 
    DRIZZLE_TYPE_VIRTUAL,
181
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
182
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_ENUM,
183
 
  //DRIZZLE_TYPE_BLOB
184
 
    DRIZZLE_TYPE_BLOB,
185
 
  },
186
 
  /* DRIZZLE_TYPE_TIMESTAMP -> */
187
 
  {
188
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
189
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
190
 
  //DRIZZLE_TYPE_LONG
191
 
    DRIZZLE_TYPE_VARCHAR,
192
 
  //DRIZZLE_TYPE_DOUBLE
193
 
    DRIZZLE_TYPE_VARCHAR,
194
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
195
 
    DRIZZLE_TYPE_TIMESTAMP,   DRIZZLE_TYPE_TIMESTAMP,
196
 
  //DRIZZLE_TYPE_LONGLONG
197
 
    DRIZZLE_TYPE_VARCHAR,
198
 
  //DRIZZLE_TYPE_TIME
199
 
    DRIZZLE_TYPE_DATETIME,
200
 
  //DRIZZLE_TYPE_DATETIME
201
 
    DRIZZLE_TYPE_DATETIME,
202
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
203
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
204
 
  // DRIZZLE_TYPE_VIRTUAL
205
 
    DRIZZLE_TYPE_VIRTUAL,
206
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
207
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
208
 
  //DRIZZLE_TYPE_BLOB
209
 
    DRIZZLE_TYPE_BLOB,
210
 
  },
211
 
  /* DRIZZLE_TYPE_LONGLONG -> */
212
 
  {
213
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
214
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONGLONG,
215
 
  //DRIZZLE_TYPE_LONG
216
 
    DRIZZLE_TYPE_LONGLONG,
217
 
  //DRIZZLE_TYPE_DOUBLE
218
 
    DRIZZLE_TYPE_DOUBLE,
219
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
220
 
    DRIZZLE_TYPE_LONGLONG,    DRIZZLE_TYPE_VARCHAR,
221
 
  //DRIZZLE_TYPE_LONGLONG
222
 
    DRIZZLE_TYPE_LONGLONG,
223
 
  //DRIZZLE_TYPE_TIME
224
 
    DRIZZLE_TYPE_VARCHAR,
225
 
  //DRIZZLE_TYPE_DATETIME
226
 
    DRIZZLE_TYPE_VARCHAR,
227
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
228
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
229
 
  // DRIZZLE_TYPE_VIRTUAL
230
 
    DRIZZLE_TYPE_VIRTUAL,
231
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
232
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
233
 
  //DRIZZLE_TYPE_BLOB
234
 
    DRIZZLE_TYPE_BLOB,
235
 
  },
236
 
  /* DRIZZLE_TYPE_TIME -> */
237
 
  {
238
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
239
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
240
 
  //DRIZZLE_TYPE_LONG
241
 
    DRIZZLE_TYPE_VARCHAR,
242
 
  //DRIZZLE_TYPE_DOUBLE
243
 
    DRIZZLE_TYPE_VARCHAR,
244
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
245
 
    DRIZZLE_TYPE_TIME,        DRIZZLE_TYPE_DATETIME,
246
 
  //DRIZZLE_TYPE_LONGLONG
247
 
    DRIZZLE_TYPE_VARCHAR,
248
 
  //DRIZZLE_TYPE_TIME
249
 
    DRIZZLE_TYPE_TIME,
250
 
  //DRIZZLE_TYPE_DATETIME
251
 
    DRIZZLE_TYPE_DATETIME,
252
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
253
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
254
 
  // DRIZZLE_TYPE_VIRTUAL
255
 
    DRIZZLE_TYPE_VIRTUAL,
256
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
257
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
258
 
  //DRIZZLE_TYPE_BLOB
259
 
    DRIZZLE_TYPE_BLOB,
260
 
  },
261
 
  /* DRIZZLE_TYPE_DATETIME -> */
262
 
  {
263
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
264
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
265
 
  //DRIZZLE_TYPE_LONG
266
 
    DRIZZLE_TYPE_VARCHAR,
267
 
  //DRIZZLE_TYPE_DOUBLE
268
 
    DRIZZLE_TYPE_VARCHAR,
269
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
270
 
    DRIZZLE_TYPE_DATETIME,    DRIZZLE_TYPE_DATETIME,
271
 
  //DRIZZLE_TYPE_LONGLONG
272
 
    DRIZZLE_TYPE_VARCHAR,
273
 
  //DRIZZLE_TYPE_TIME
274
 
    DRIZZLE_TYPE_DATETIME,
275
 
  //DRIZZLE_TYPE_DATETIME
276
 
    DRIZZLE_TYPE_DATETIME,
277
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
278
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
279
 
  // DRIZZLE_TYPE_VIRTUAL
280
 
    DRIZZLE_TYPE_VIRTUAL,
281
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
282
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
283
 
  //DRIZZLE_TYPE_BLOB
284
 
    DRIZZLE_TYPE_BLOB,
285
 
  },
286
 
  /* DRIZZLE_TYPE_NEWDATE -> */
287
 
  {
288
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
289
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
290
 
  //DRIZZLE_TYPE_LONG
291
 
    DRIZZLE_TYPE_VARCHAR,
292
 
  //DRIZZLE_TYPE_DOUBLE
293
 
    DRIZZLE_TYPE_VARCHAR,
294
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
295
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_DATETIME,
296
 
  //DRIZZLE_TYPE_LONGLONG
297
 
    DRIZZLE_TYPE_VARCHAR,
298
 
  //DRIZZLE_TYPE_TIME
299
 
    DRIZZLE_TYPE_DATETIME,
300
 
  //DRIZZLE_TYPE_DATETIME
301
 
    DRIZZLE_TYPE_DATETIME,
302
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
303
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
304
 
  // DRIZZLE_TYPE_VIRTUAL
305
 
    DRIZZLE_TYPE_VIRTUAL,
306
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
307
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
308
 
  //DRIZZLE_TYPE_BLOB
309
 
    DRIZZLE_TYPE_BLOB,
310
 
  },
311
 
  /* DRIZZLE_TYPE_VARCHAR -> */
312
 
  {
313
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
314
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
315
 
  //DRIZZLE_TYPE_LONG
316
 
    DRIZZLE_TYPE_VARCHAR,
317
 
  //DRIZZLE_TYPE_DOUBLE
318
 
    DRIZZLE_TYPE_VARCHAR,
319
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
320
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
321
 
  //DRIZZLE_TYPE_LONGLONG
322
 
    DRIZZLE_TYPE_VARCHAR,
323
 
  //DRIZZLE_TYPE_TIME
324
 
    DRIZZLE_TYPE_VARCHAR,
325
 
  //DRIZZLE_TYPE_DATETIME
326
 
    DRIZZLE_TYPE_VARCHAR,
327
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
328
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
329
 
  // DRIZZLE_TYPE_VIRTUAL
330
 
    DRIZZLE_TYPE_VIRTUAL,
331
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
332
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
333
 
  //DRIZZLE_TYPE_BLOB
334
 
    DRIZZLE_TYPE_BLOB,
335
 
  },
336
 
  /* DRIZZLE_TYPE_VIRTUAL -> */
337
 
  {
338
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
339
 
    DRIZZLE_TYPE_VIRTUAL,  DRIZZLE_TYPE_VIRTUAL,
340
 
  //DRIZZLE_TYPE_LONG
341
 
    DRIZZLE_TYPE_VIRTUAL,
342
 
  //DRIZZLE_TYPE_DOUBLE
343
 
    DRIZZLE_TYPE_VIRTUAL,
344
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
345
 
    DRIZZLE_TYPE_VIRTUAL,  DRIZZLE_TYPE_VIRTUAL,
346
 
  //DRIZZLE_TYPE_LONGLONG
347
 
    DRIZZLE_TYPE_VIRTUAL,
348
 
  //DRIZZLE_TYPE_TIME
349
 
    DRIZZLE_TYPE_VIRTUAL,
350
 
  //DRIZZLE_TYPE_DATETIME
351
 
    DRIZZLE_TYPE_VIRTUAL,
352
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
353
 
    DRIZZLE_TYPE_VIRTUAL,     DRIZZLE_TYPE_VIRTUAL,
354
 
  // DRIZZLE_TYPE_VIRTUAL
355
 
    DRIZZLE_TYPE_VIRTUAL,
356
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
357
 
    DRIZZLE_TYPE_VIRTUAL,  DRIZZLE_TYPE_VIRTUAL,
358
 
  //DRIZZLE_TYPE_BLOB
359
 
    DRIZZLE_TYPE_VIRTUAL,
360
 
  },
361
 
  /* DRIZZLE_TYPE_NEWDECIMAL -> */
362
 
  {
363
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
364
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_NEWDECIMAL,
365
 
  //DRIZZLE_TYPE_LONG
366
 
    DRIZZLE_TYPE_NEWDECIMAL,
367
 
  //DRIZZLE_TYPE_DOUBLE
368
 
    DRIZZLE_TYPE_DOUBLE,
369
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
370
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
371
 
  //DRIZZLE_TYPE_LONGLONG
372
 
    DRIZZLE_TYPE_NEWDECIMAL,
373
 
  //DRIZZLE_TYPE_TIME
374
 
    DRIZZLE_TYPE_VARCHAR,
375
 
  //DRIZZLE_TYPE_DATETIME
376
 
    DRIZZLE_TYPE_VARCHAR,
377
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
378
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
379
 
  // DRIZZLE_TYPE_VIRTUAL
380
 
    DRIZZLE_TYPE_VIRTUAL,
381
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
382
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
383
 
  //DRIZZLE_TYPE_BLOB
384
 
    DRIZZLE_TYPE_BLOB,
385
 
  },
386
 
  /* DRIZZLE_TYPE_ENUM -> */
387
 
  {
388
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
389
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
390
 
  //DRIZZLE_TYPE_LONG
391
 
    DRIZZLE_TYPE_VARCHAR,
392
 
  //DRIZZLE_TYPE_DOUBLE
393
 
    DRIZZLE_TYPE_VARCHAR,
394
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
395
 
    DRIZZLE_TYPE_ENUM,        DRIZZLE_TYPE_VARCHAR,
396
 
  //DRIZZLE_TYPE_LONGLONG
397
 
    DRIZZLE_TYPE_VARCHAR,
398
 
  //DRIZZLE_TYPE_TIME
399
 
    DRIZZLE_TYPE_VARCHAR,
400
 
  //DRIZZLE_TYPE_DATETIME
401
 
    DRIZZLE_TYPE_VARCHAR,
402
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
403
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
404
 
  // DRIZZLE_TYPE_VIRTUAL
405
 
    DRIZZLE_TYPE_VIRTUAL,
406
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
407
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
408
 
  //DRIZZLE_TYPE_BLOB
409
 
    DRIZZLE_TYPE_BLOB,
410
 
  },
411
 
  /* DRIZZLE_TYPE_BLOB -> */
412
 
  {
413
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
414
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
415
 
  //DRIZZLE_TYPE_LONG
416
 
    DRIZZLE_TYPE_BLOB,
417
 
  //DRIZZLE_TYPE_DOUBLE
418
 
    DRIZZLE_TYPE_BLOB,
419
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
420
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
421
 
  //DRIZZLE_TYPE_LONGLONG
422
 
    DRIZZLE_TYPE_BLOB,
423
 
  //DRIZZLE_TYPE_TIME
424
 
    DRIZZLE_TYPE_BLOB,
425
 
  //DRIZZLE_TYPE_DATETIME
426
 
    DRIZZLE_TYPE_BLOB,
427
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
428
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
429
 
  // DRIZZLE_TYPE_VIRTUAL
430
 
    DRIZZLE_TYPE_VIRTUAL,
431
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
432
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
433
 
  //DRIZZLE_TYPE_BLOB
434
 
    DRIZZLE_TYPE_BLOB,
435
 
  },
436
 
};
437
 
 
438
 
/**
439
 
  Return type of which can carry value of both given types in UNION result.
440
 
 
441
 
  @param a  type for merging
442
 
  @param b  type for merging
443
 
 
444
 
  @return
445
 
    type of field
446
 
*/
447
 
 
448
 
enum_field_types Field::field_type_merge(enum_field_types a,
449
 
                                         enum_field_types b)
450
 
{
451
 
  assert(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
452
 
  assert(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
453
 
  return field_types_merge_rules[field_type2index(a)]
454
 
                                [field_type2index(b)];
455
 
}
456
 
 
457
 
 
458
 
static Item_result field_types_result_type [FIELDTYPE_NUM]=
459
 
{
460
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
461
 
  DECIMAL_RESULT,           INT_RESULT,
462
 
  //DRIZZLE_TYPE_LONG
463
 
  INT_RESULT,
464
 
  //DRIZZLE_TYPE_DOUBLE
465
 
  REAL_RESULT,
466
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
467
 
  STRING_RESULT,            STRING_RESULT,
468
 
  //DRIZZLE_TYPE_LONGLONG
469
 
  INT_RESULT,
470
 
  //DRIZZLE_TYPE_TIME
471
 
  STRING_RESULT,
472
 
  //DRIZZLE_TYPE_DATETIME
473
 
  STRING_RESULT,
474
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
475
 
  STRING_RESULT,            STRING_RESULT,
476
 
  //DRIZZLE_TYPE_VIRTUAL
477
 
  STRING_RESULT,
478
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
479
 
  DECIMAL_RESULT,           STRING_RESULT,
480
 
  //DRIZZLE_TYPE_BLOB
481
 
  STRING_RESULT,
482
 
};
483
 
 
484
 
 
485
 
/*
486
 
  Test if the given string contains important data:
487
 
  not spaces for character string,
488
 
  or any data for binary string.
489
 
 
490
 
  SYNOPSIS
491
 
    test_if_important_data()
492
 
    cs          Character set
493
 
    str         String to test
494
 
    strend      String end
495
 
 
496
 
  RETURN
497
 
    false - If string does not have important data
498
 
    true  - If string has some important data
499
 
*/
500
 
 
501
 
bool
502
 
test_if_important_data(const CHARSET_INFO * const cs, const char *str,
503
 
                       const char *strend)
504
 
{
505
 
  if (cs != &my_charset_bin)
506
 
    str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
507
 
  return (str < strend);
508
 
}
509
 
 
510
 
 
511
 
/**
512
 
  Detect Item_result by given field type of UNION merge result.
513
 
 
514
 
  @param field_type  given field type
515
 
 
516
 
  @return
517
 
    Item_result (type of internal MySQL expression result)
518
 
*/
519
 
 
520
 
Item_result Field::result_merge_type(enum_field_types field_type)
521
 
{
522
 
  assert(field_type < FIELDTYPE_TEAR_FROM || field_type
523
 
              > FIELDTYPE_TEAR_TO);
524
 
  return field_types_result_type[field_type2index(field_type)];
525
 
}
526
 
 
527
 
/*****************************************************************************
528
 
  Static help functions
529
 
*****************************************************************************/
530
 
 
531
 
 
532
 
/**
533
 
  Check whether a field type can be partially indexed by a key.
534
 
 
535
 
  This is a static method, rather than a virtual function, because we need
536
 
  to check the type of a non-Field in mysql_alter_table().
537
 
 
538
 
  @param type  field type
539
 
 
540
 
  @retval
541
 
    true  Type can have a prefixed key
542
 
  @retval
543
 
    false Type can not have a prefixed key
544
 
*/
545
 
 
546
 
bool Field::type_can_have_key_part(enum enum_field_types type)
547
 
{
548
 
  switch (type) {
549
 
  case DRIZZLE_TYPE_VARCHAR:
550
 
  case DRIZZLE_TYPE_BLOB:
551
 
    return true;
552
 
  default:
553
 
    return false;
554
 
  }
555
 
}
556
 
 
557
 
 
558
 
/**
559
 
  Process decimal library return codes and issue warnings for overflow and
560
 
  truncation.
561
 
 
562
 
  @param op_result  decimal library return code (E_DEC_* see include/decimal.h)
563
 
 
564
 
  @retval
565
 
    1  there was overflow
566
 
  @retval
567
 
    0  no error or some other errors except overflow
568
 
*/
569
 
 
570
 
int Field::warn_if_overflow(int op_result)
571
 
{
572
 
  if (op_result == E_DEC_OVERFLOW)
573
 
  {
574
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
575
 
    return 1;
576
 
  }
577
 
  if (op_result == E_DEC_TRUNCATED)
578
 
  {
579
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
580
 
    /* We return 0 here as this is not a critical issue */
581
 
  }
582
 
  return 0;
583
 
}
584
 
 
585
 
 
586
 
#ifdef NOT_USED
587
 
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
588
 
{
589
 
  cs= system_charset_info; // QQ move test_if_real into CHARSET_INFO struct
590
 
 
591
 
  while (length && my_isspace(cs,*str))
592
 
  {                                             // Allow start space
593
 
    length--; str++;
594
 
  }
595
 
  if (!length)
596
 
    return 0;
597
 
  if (*str == '+' || *str == '-')
598
 
  {
599
 
    length--; str++;
600
 
    if (!length || !(my_isdigit(cs,*str) || *str == '.'))
601
 
      return 0;
602
 
  }
603
 
  while (length && my_isdigit(cs,*str))
604
 
  {
605
 
    length--; str++;
606
 
  }
607
 
  if (!length)
608
 
    return 1;
609
 
  if (*str == '.')
610
 
  {
611
 
    length--; str++;
612
 
    while (length && my_isdigit(cs,*str))
613
 
    {
614
 
      length--; str++;
615
 
    }
616
 
  }
617
 
  if (!length)
618
 
    return 1;
619
 
  if (*str == 'E' || *str == 'e')
620
 
  {
621
 
    if (length < 3 || (str[1] != '+' && str[1] != '-') || 
622
 
        !my_isdigit(cs,str[2]))
623
 
      return 0;
624
 
    length-=3;
625
 
    str+=3;
626
 
    while (length && my_isdigit(cs,*str))
627
 
    {
628
 
      length--; str++;
629
 
    }
630
 
  }
631
 
  for (; length ; length--, str++)
632
 
  {                                             // Allow end space
633
 
    if (!my_isspace(cs,*str))
634
 
      return 0;
635
 
  }
636
 
  return 1;
637
 
}
638
 
#endif
639
 
 
640
 
 
641
 
/**
642
 
  Interpret field value as an integer but return the result as a string.
643
 
 
644
 
  This is used for printing bit_fields as numbers while debugging.
645
 
*/
646
 
 
647
 
String *Field::val_int_as_str(String *val_buffer, bool unsigned_val)
648
 
{
649
 
  const CHARSET_INFO * const cs= &my_charset_bin;
650
 
  uint32_t length;
651
 
  int64_t value= val_int();
652
 
 
653
 
  if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
654
 
    return 0;
655
 
  length= (uint32_t) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
656
 
                                                MY_INT64_NUM_DECIMAL_DIGITS,
657
 
                                                unsigned_val ? 10 : -10,
658
 
                                                value);
659
 
  val_buffer->length(length);
660
 
  return val_buffer;
661
 
}
662
 
 
663
 
 
664
 
/// This is used as a table name when the table structure is not set up
665
 
Field::Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
666
 
             unsigned char null_bit_arg,
667
 
             utype unireg_check_arg, const char *field_name_arg)
668
 
  :ptr(ptr_arg), null_ptr(null_ptr_arg),
669
 
   table(0), orig_table(0), table_name(0),
670
 
   field_name(field_name_arg),
671
 
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
672
 
   part_of_sortkey(0), unireg_check(unireg_check_arg),
673
 
   field_length(length_arg), null_bit(null_bit_arg), 
674
 
   is_created_from_null_item(false),
675
 
   vcol_info(NULL), is_stored(true)
676
 
{
677
 
  flags=null_ptr ? 0: NOT_NULL_FLAG;
678
 
  comment.str= (char*) "";
679
 
  comment.length=0;
680
 
  field_index= 0;
681
 
}
682
 
 
683
 
 
684
 
void Field::hash(uint32_t *nr, uint32_t *nr2)
685
 
{
686
 
  if (is_null())
687
 
  {
688
 
    *nr^= (*nr << 1) | 1;
689
 
  }
690
 
  else
691
 
  {
692
 
    uint32_t len= pack_length();
693
 
    const CHARSET_INFO * const cs= charset();
694
 
    cs->coll->hash_sort(cs, ptr, len, nr, nr2);
695
 
  }
696
 
}
697
 
 
698
 
size_t
699
 
Field::do_last_null_byte() const
700
 
{
701
 
  assert(null_ptr == NULL || null_ptr >= table->record[0]);
702
 
  if (null_ptr)
703
 
    return (size_t) (null_ptr - table->record[0]) + 1;
704
 
  return LAST_NULL_BYTE_UNDEF;
705
 
}
706
 
 
707
 
 
708
 
void Field::copy_from_tmp(int row_offset)
709
 
{
710
 
  memcpy(ptr,ptr+row_offset,pack_length());
711
 
  if (null_ptr)
712
 
  {
713
 
    *null_ptr= (unsigned char) ((null_ptr[0] & (unsigned char) ~(uint32_t) null_bit) | (null_ptr[row_offset] & (unsigned char) null_bit));
714
 
  }
715
 
}
716
 
 
717
 
 
718
 
bool Field::send_binary(Protocol *protocol)
719
 
{
720
 
  char buff[MAX_FIELD_WIDTH];
721
 
  String tmp(buff,sizeof(buff),charset());
722
 
  val_str(&tmp);
723
 
  return protocol->store(tmp.ptr(), tmp.length(), tmp.charset());
724
 
}
725
 
 
726
 
 
727
 
/**
728
 
   Check to see if field size is compatible with destination.
729
 
 
730
 
   This method is used in row-based replication to verify that the slave's
731
 
   field size is less than or equal to the master's field size. The 
732
 
   encoded field metadata (from the master or source) is decoded and compared
733
 
   to the size of this field (the slave or destination). 
734
 
 
735
 
   @param   field_metadata   Encoded size in field metadata
736
 
 
737
 
   @retval 0 if this field's size is < the source field's size
738
 
   @retval 1 if this field's size is >= the source field's size
739
 
*/
740
 
int Field::compatible_field_size(uint32_t field_metadata)
741
 
{
742
 
  uint32_t const source_size= pack_length_from_metadata(field_metadata);
743
 
  uint32_t const destination_size= row_pack_length();
744
 
  return (source_size <= destination_size);
745
 
}
746
 
 
747
 
 
748
 
int Field::store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
749
 
                 enum_check_fields check_level)
750
 
{
751
 
  int res;
752
 
  enum_check_fields old_check_level= table->in_use->count_cuted_fields;
753
 
  table->in_use->count_cuted_fields= check_level;
754
 
  res= store(to, length, cs);
755
 
  table->in_use->count_cuted_fields= old_check_level;
756
 
  return res;
757
 
}
758
 
 
759
 
 
760
 
/**
761
 
   Pack the field into a format suitable for storage and transfer.
762
 
 
763
 
   To implement packing functionality, only the virtual function
764
 
   should be overridden. The other functions are just convenience
765
 
   functions and hence should not be overridden.
766
 
 
767
 
   The value of <code>low_byte_first</code> is dependent on how the
768
 
   packed data is going to be used: for local use, e.g., temporary
769
 
   store on disk or in memory, use the native format since that is
770
 
   faster. For data that is going to be transfered to other machines
771
 
   (e.g., when writing data to the binary log), data should always be
772
 
   stored in little-endian format.
773
 
 
774
 
   @note The default method for packing fields just copy the raw bytes
775
 
   of the record into the destination, but never more than
776
 
   <code>max_length</code> characters.
777
 
 
778
 
   @param to
779
 
   Pointer to memory area where representation of field should be put.
780
 
 
781
 
   @param from
782
 
   Pointer to memory area where record representation of field is
783
 
   stored.
784
 
 
785
 
   @param max_length
786
 
   Maximum length of the field, as given in the column definition. For
787
 
   example, for <code>CHAR(1000)</code>, the <code>max_length</code>
788
 
   is 1000. This information is sometimes needed to decide how to pack
789
 
   the data.
790
 
 
791
 
   @param low_byte_first
792
 
   @c true if integers should be stored little-endian, @c false if
793
 
   native format should be used. Note that for little-endian machines,
794
 
   the value of this flag is a moot point since the native format is
795
 
   little-endian.
796
 
*/
797
 
unsigned char *
798
 
Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length,
799
 
            bool low_byte_first __attribute__((unused)))
800
 
{
801
 
  uint32_t length= pack_length();
802
 
  set_if_smaller(length, max_length);
803
 
  memcpy(to, from, length);
804
 
  return to+length;
805
 
}
806
 
 
807
 
/**
808
 
   Unpack a field from row data.
809
 
 
810
 
   This method is used to unpack a field from a master whose size of
811
 
   the field is less than that of the slave.
812
 
 
813
 
   The <code>param_data</code> parameter is a two-byte integer (stored
814
 
   in the least significant 16 bits of the unsigned integer) usually
815
 
   consisting of two parts: the real type in the most significant byte
816
 
   and a original pack length in the least significant byte.
817
 
 
818
 
   The exact layout of the <code>param_data</code> field is given by
819
 
   the <code>Table_map_log_event::save_field_metadata()</code>.
820
 
 
821
 
   This is the default method for unpacking a field. It just copies
822
 
   the memory block in byte order (of original pack length bytes or
823
 
   length of field, whichever is smaller).
824
 
 
825
 
   @param   to         Destination of the data
826
 
   @param   from       Source of the data
827
 
   @param   param_data Real type and original pack length of the field
828
 
                       data
829
 
 
830
 
   @param low_byte_first
831
 
   If this flag is @c true, all composite entities (e.g., lengths)
832
 
   should be unpacked in little-endian format; otherwise, the entities
833
 
   are unpacked in native order.
834
 
 
835
 
   @return  New pointer into memory based on from + length of the data
836
 
*/
837
 
const unsigned char *
838
 
Field::unpack(unsigned char* to, const unsigned char *from, uint32_t param_data,
839
 
              bool low_byte_first __attribute__((unused)))
840
 
{
841
 
  uint32_t length=pack_length();
842
 
  int from_type= 0;
843
 
  /*
844
 
    If from length is > 255, it has encoded data in the upper bits. Need
845
 
    to mask it out.
846
 
  */
847
 
  if (param_data > 255)
848
 
  {
849
 
    from_type= (param_data & 0xff00) >> 8U;  // real_type.
850
 
    param_data= param_data & 0x00ff;        // length.
851
 
  }
852
 
 
853
 
  if ((param_data == 0) ||
854
 
      (length == param_data) ||
855
 
      (from_type != real_type()))
856
 
  {
857
 
    memcpy(to, from, length);
858
 
    return from+length;
859
 
  }
860
 
 
861
 
  uint32_t len= (param_data && (param_data < length)) ?
862
 
            param_data : length;
863
 
 
864
 
  memcpy(to, from, param_data > length ? length : len);
865
 
  return from+len;
866
 
}
867
 
 
868
 
 
869
 
my_decimal *Field::val_decimal(my_decimal *decimal __attribute__((unused)))
870
 
{
871
 
  /* This never have to be called */
872
 
  assert(0);
873
 
  return 0;
874
 
}
875
 
 
876
 
 
877
 
void Field::make_field(Send_field *field)
878
 
{
879
 
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
880
 
  {
881
 
    field->db_name= orig_table->s->db.str;
882
 
    field->org_table_name= orig_table->s->table_name.str;
883
 
  }
884
 
  else
885
 
    field->org_table_name= field->db_name= "";
886
 
  if (orig_table)
887
 
  {
888
 
    field->table_name= orig_table->alias;
889
 
    field->org_col_name= field_name;
890
 
  }
891
 
  else
892
 
  {
893
 
    field->table_name= "";
894
 
    field->org_col_name= "";
895
 
  }
896
 
  field->col_name= field_name;
897
 
  field->charsetnr= charset()->number;
898
 
  field->length=field_length;
899
 
  field->type=type();
900
 
  field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
901
 
  field->decimals= 0;
902
 
}
903
 
 
904
 
 
905
 
/**
906
 
  Conversion from decimal to int64_t with checking overflow and
907
 
  setting correct value (min/max) in case of overflow.
908
 
 
909
 
  @param val             value which have to be converted
910
 
  @param unsigned_flag   type of integer in which we convert val
911
 
  @param err             variable to pass error code
912
 
 
913
 
  @return
914
 
    value converted from val
915
 
*/
916
 
int64_t Field::convert_decimal2int64_t(const my_decimal *val,
917
 
                                         bool unsigned_flag __attribute__((unused)), int *err)
918
 
{
919
 
  int64_t i;
920
 
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
921
 
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
922
 
                                      val, false, &i)))
923
 
  {
924
 
    i= (val->sign() ? INT64_MIN : INT64_MAX);
925
 
    *err= 1;
926
 
  }
927
 
  return i;
928
 
}
929
 
 
930
 
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
931
 
{
932
 
  uint32_t store_length;
933
 
  copy->str=ptr;
934
 
  copy->length=pack_length();
935
 
  copy->blob_field=0;
936
 
  if (flags & BLOB_FLAG)
937
 
  {
938
 
    copy->blob_field=(Field_blob*) this;
939
 
    copy->strip=0;
940
 
    copy->length-= table->s->blob_ptr_size;
941
 
    return copy->length;
942
 
  }
943
 
  else
944
 
  {
945
 
    copy->strip=0;
946
 
    store_length= 0;
947
 
  }
948
 
  return copy->length+ store_length;
949
 
}
950
 
 
951
 
 
952
 
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
953
 
{
954
 
  char buff[40];
955
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
956
 
  if (!(res=val_str(&tmp)) ||
957
 
      str_to_datetime_with_warn(res->ptr(), res->length(),
958
 
                                ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
959
 
    return 1;
960
 
  return 0;
961
 
}
962
 
 
963
 
bool Field::get_time(DRIZZLE_TIME *ltime)
964
 
{
965
 
  char buff[40];
966
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
967
 
  if (!(res=val_str(&tmp)) ||
968
 
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
969
 
    return 1;
970
 
  return 0;
971
 
}
972
 
 
973
 
/**
974
 
  This is called when storing a date in a string.
975
 
 
976
 
  @note
977
 
    Needs to be changed if/when we want to support different time formats.
978
 
*/
979
 
 
980
 
int Field::store_time(DRIZZLE_TIME *ltime,
981
 
                      enum enum_drizzle_timestamp_type type_arg __attribute__((unused)))
982
 
{
983
 
  char buff[MAX_DATE_STRING_REP_LENGTH];
984
 
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
985
 
  return store(buff, length, &my_charset_bin);
986
 
}
987
 
 
988
 
 
989
 
bool Field::optimize_range(uint32_t idx, uint32_t part)
990
 
{
991
 
  return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
992
 
}
993
 
 
994
 
 
995
 
Field *Field::new_field(MEM_ROOT *root, Table *new_table,
996
 
                        bool keep_type __attribute__((unused)))
997
 
{
998
 
  Field *tmp;
999
 
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1000
 
    return 0;
1001
 
 
1002
 
  if (tmp->table->maybe_null)
1003
 
    tmp->flags&= ~NOT_NULL_FLAG;
1004
 
  tmp->table= new_table;
1005
 
  tmp->key_start.init(0);
1006
 
  tmp->part_of_key.init(0);
1007
 
  tmp->part_of_sortkey.init(0);
1008
 
  tmp->unireg_check= Field::NONE;
1009
 
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
1010
 
  tmp->reset_fields();
1011
 
  return tmp;
1012
 
}
1013
 
 
1014
 
 
1015
 
Field *Field::new_key_field(MEM_ROOT *root, Table *new_table,
1016
 
                            unsigned char *new_ptr, unsigned char *new_null_ptr,
1017
 
                            uint32_t new_null_bit)
1018
 
{
1019
 
  Field *tmp;
1020
 
  if ((tmp= new_field(root, new_table, table == new_table)))
1021
 
  {
1022
 
    tmp->ptr=      new_ptr;
1023
 
    tmp->null_ptr= new_null_ptr;
1024
 
    tmp->null_bit= new_null_bit;
1025
 
  }
1026
 
  return tmp;
1027
 
}
1028
 
 
1029
 
 
1030
 
/* This is used to generate a field in Table from TABLE_SHARE */
1031
 
 
1032
 
Field *Field::clone(MEM_ROOT *root, Table *new_table)
1033
 
{
1034
 
  Field *tmp;
1035
 
  if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1036
 
  {
1037
 
    tmp->init(new_table);
1038
 
    tmp->move_field_offset((my_ptrdiff_t) (new_table->record[0] -
1039
 
                                           new_table->s->default_values));
1040
 
  }
1041
 
  return tmp;
1042
 
}
1043
 
 
1044
 
 
1045
 
/****************************************************************************
1046
 
** tiny int
1047
 
****************************************************************************/
1048
 
 
1049
 
int Field_tiny::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
1050
 
{
1051
 
  int error;
1052
 
  int64_t rnd;
1053
 
  
1054
 
  error= get_int(cs, from, len, &rnd, 255, -128, 127);
1055
 
  ptr[0]= (char) rnd;
1056
 
  return error;
1057
 
}
1058
 
 
1059
 
 
1060
 
int Field_tiny::store(double nr)
1061
 
{
1062
 
  int error= 0;
1063
 
  nr=rint(nr);
1064
 
 
1065
 
  {
1066
 
    if (nr < -128.0)
1067
 
    {
1068
 
      *ptr= (char) -128;
1069
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1070
 
      error= 1;
1071
 
    }
1072
 
    else if (nr > 127.0)
1073
 
    {
1074
 
      *ptr=127;
1075
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1076
 
      error= 1;
1077
 
    }
1078
 
    else
1079
 
      *ptr=(char) (int) nr;
1080
 
  }
1081
 
  return error;
1082
 
}
1083
 
 
1084
 
 
1085
 
int Field_tiny::store(int64_t nr, bool unsigned_val)
1086
 
{
1087
 
  int error= 0;
1088
 
 
1089
 
  {
1090
 
    if (nr < 0 && unsigned_val)
1091
 
      nr= 256;                                    // Generate overflow
1092
 
    if (nr < -128)
1093
 
    {
1094
 
      *ptr= (char) -128;
1095
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1096
 
      error= 1;
1097
 
    }
1098
 
    else if (nr > 127)
1099
 
    {
1100
 
      *ptr=127;
1101
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1102
 
      error= 1;
1103
 
    }
1104
 
    else
1105
 
      *ptr=(char) nr;
1106
 
  }
1107
 
  return error;
1108
 
}
1109
 
 
1110
 
 
1111
 
double Field_tiny::val_real(void)
1112
 
{
1113
 
  int tmp= (int) ((signed char*) ptr)[0];
1114
 
  return (double) tmp;
1115
 
}
1116
 
 
1117
 
 
1118
 
int64_t Field_tiny::val_int(void)
1119
 
{
1120
 
  int tmp= (int) ((signed char*) ptr)[0];
1121
 
  return (int64_t) tmp;
1122
 
}
1123
 
 
1124
 
 
1125
 
String *Field_tiny::val_str(String *val_buffer,
1126
 
                            String *val_ptr __attribute__((unused)))
1127
 
{
1128
 
  const CHARSET_INFO * const cs= &my_charset_bin;
1129
 
  uint32_t length;
1130
 
  uint32_t mlength=cmax(field_length+1,5*cs->mbmaxlen);
1131
 
  val_buffer->alloc(mlength);
1132
 
  char *to=(char*) val_buffer->ptr();
1133
 
 
1134
 
  length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength,-10,
1135
 
                                             (long) *((signed char*) ptr));
1136
 
 
1137
 
  val_buffer->length(length);
1138
 
 
1139
 
  return val_buffer;
1140
 
}
1141
 
 
1142
 
bool Field_tiny::send_binary(Protocol *protocol)
1143
 
{
1144
 
  return protocol->store_tiny((int64_t) (int8_t) ptr[0]);
1145
 
}
1146
 
 
1147
 
int Field_tiny::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
1148
 
{
1149
 
  signed char a,b;
1150
 
  a=(signed char) a_ptr[0]; b= (signed char) b_ptr[0];
1151
 
 
1152
 
  return (a < b) ? -1 : (a > b) ? 1 : 0;
1153
 
}
1154
 
 
1155
 
void Field_tiny::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
1156
 
{
1157
 
  to[0] = (char) (ptr[0] ^ (unsigned char) 128);        /* Revers signbit */
1158
 
}
1159
 
 
1160
 
void Field_tiny::sql_type(String &res) const
1161
 
{
1162
 
  const CHARSET_INFO * const cs=res.charset();
1163
 
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
1164
 
                          "tinyint(%d)",(int) field_length));
1165
 
}
1166
 
 
1167
 
/*
1168
 
  Report "not well formed" or "cannot convert" error
1169
 
  after storing a character string info a field.
1170
 
 
1171
 
  SYNOPSIS
1172
 
    check_string_copy_error()
1173
 
    field                    - Field
1174
 
    well_formed_error_pos    - where not well formed data was first met
1175
 
    cannot_convert_error_pos - where a not-convertable character was first met
1176
 
    end                      - end of the string
1177
 
    cs                       - character set of the string
1178
 
 
1179
 
  NOTES
1180
 
    As of version 5.0 both cases return the same error:
1181
 
 
1182
 
      "Invalid string value: 'xxx' for column 't' at row 1"
1183
 
 
1184
 
  Future versions will possibly introduce a new error message:
1185
 
 
1186
 
      "Cannot convert character string: 'xxx' for column 't' at row 1"
1187
 
 
1188
 
  RETURN
1189
 
    false - If errors didn't happen
1190
 
    true  - If an error happened
1191
 
*/
1192
 
 
1193
 
bool
1194
 
check_string_copy_error(Field_str *field,
1195
 
                        const char *well_formed_error_pos,
1196
 
                        const char *cannot_convert_error_pos,
1197
 
                        const char *end,
1198
 
                        const CHARSET_INFO * const cs)
1199
 
{
1200
 
  const char *pos, *end_orig;
1201
 
  char tmp[64], *t;
1202
 
  
1203
 
  if (!(pos= well_formed_error_pos) &&
1204
 
      !(pos= cannot_convert_error_pos))
1205
 
    return false;
1206
 
 
1207
 
  end_orig= end;
1208
 
  set_if_smaller(end, pos + 6);
1209
 
 
1210
 
  for (t= tmp; pos < end; pos++)
1211
 
  {
1212
 
    /*
1213
 
      If the source string is ASCII compatible (mbminlen==1)
1214
 
      and the source character is in ASCII printable range (0x20..0x7F),
1215
 
      then display the character as is.
1216
 
      
1217
 
      Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
1218
 
      or the source character is not in the printable range,
1219
 
      then print the character using HEX notation.
1220
 
    */
1221
 
    if (((unsigned char) *pos) >= 0x20 &&
1222
 
        ((unsigned char) *pos) <= 0x7F &&
1223
 
        cs->mbminlen == 1)
1224
 
    {
1225
 
      *t++= *pos;
1226
 
    }
1227
 
    else
1228
 
    {
1229
 
      *t++= '\\';
1230
 
      *t++= 'x';
1231
 
      *t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
1232
 
      *t++= _dig_vec_upper[((unsigned char) *pos) & 15];
1233
 
    }
1234
 
  }
1235
 
  if (end_orig > end)
1236
 
  {
1237
 
    *t++= '.';
1238
 
    *t++= '.';
1239
 
    *t++= '.';
1240
 
  }
1241
 
  *t= '\0';
1242
 
  push_warning_printf(field->table->in_use, 
1243
 
                      field->table->in_use->abort_on_warning ?
1244
 
                      DRIZZLE_ERROR::WARN_LEVEL_ERROR :
1245
 
                      DRIZZLE_ERROR::WARN_LEVEL_WARN,
1246
 
                      ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, 
1247
 
                      ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1248
 
                      "string", tmp, field->field_name,
1249
 
                      (uint32_t) field->table->in_use->row_count);
1250
 
  return true;
1251
 
}
1252
 
 
1253
 
uint32_t Field::is_equal(Create_field *new_field)
1254
 
{
1255
 
  return (new_field->sql_type == real_type());
1256
 
}
1257
 
 
1258
 
/**
1259
 
  @retval
1260
 
    1  if the fields are equally defined
1261
 
  @retval
1262
 
    0  if the fields are unequally defined
1263
 
*/
1264
 
 
1265
 
bool Field::eq_def(Field *field)
1266
 
{
1267
 
  if (real_type() != field->real_type() || charset() != field->charset() ||
1268
 
      pack_length() != field->pack_length())
1269
 
    return 0;
1270
 
  return 1;
1271
 
}
1272
 
 
1273
 
/**
1274
 
  @return
1275
 
  returns 1 if the fields are equally defined
1276
 
*/
1277
 
bool Field_enum::eq_def(Field *field)
1278
 
{
1279
 
  if (!Field::eq_def(field))
1280
 
    return 0;
1281
 
  TYPELIB *from_lib=((Field_enum*) field)->typelib;
1282
 
 
1283
 
  if (typelib->count < from_lib->count)
1284
 
    return 0;
1285
 
  for (uint32_t i=0 ; i < from_lib->count ; i++)
1286
 
    if (my_strnncoll(field_charset,
1287
 
                     (const unsigned char*)typelib->type_names[i],
1288
 
                     strlen(typelib->type_names[i]),
1289
 
                     (const unsigned char*)from_lib->type_names[i],
1290
 
                     strlen(from_lib->type_names[i])))
1291
 
      return 0;
1292
 
  return 1;
1293
 
}
1294
 
 
1295
 
/*****************************************************************************
1296
 
  Handling of field and Create_field
1297
 
*****************************************************************************/
1298
 
 
1299
 
/**
1300
 
  Convert create_field::length from number of characters to number of bytes.
1301
 
*/
1302
 
 
1303
 
void Create_field::create_length_to_internal_length(void)
1304
 
{
1305
 
  switch (sql_type) {
1306
 
  case DRIZZLE_TYPE_BLOB:
1307
 
  case DRIZZLE_TYPE_VARCHAR:
1308
 
    length*= charset->mbmaxlen;
1309
 
    key_length= length;
1310
 
    pack_length= calc_pack_length(sql_type, length);
1311
 
    break;
1312
 
  case DRIZZLE_TYPE_ENUM:
1313
 
    /* Pack_length already calculated in sql_parse.cc */
1314
 
    length*= charset->mbmaxlen;
1315
 
    key_length= pack_length;
1316
 
    break;
1317
 
  case DRIZZLE_TYPE_NEWDECIMAL:
1318
 
    key_length= pack_length=
1319
 
      my_decimal_get_binary_size(my_decimal_length_to_precision(length,
1320
 
                                                                decimals,
1321
 
                                                                flags &
1322
 
                                                                UNSIGNED_FLAG),
1323
 
                                 decimals);
1324
 
    break;
1325
 
  default:
1326
 
    key_length= pack_length= calc_pack_length(sql_type, length);
1327
 
    break;
1328
 
  }
1329
 
}
1330
 
 
1331
 
 
1332
 
/**
1333
 
  Init for a tmp table field. To be extended if need be.
1334
 
*/
1335
 
void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
1336
 
                                      uint32_t length_arg, uint32_t decimals_arg,
1337
 
                                      bool maybe_null, bool is_unsigned)
1338
 
{
1339
 
  field_name= "";
1340
 
  sql_type= sql_type_arg;
1341
 
  char_length= length= length_arg;;
1342
 
  unireg_check= Field::NONE;
1343
 
  interval= 0;
1344
 
  charset= &my_charset_bin;
1345
 
  pack_flag= (FIELDFLAG_NUMBER |
1346
 
              ((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
1347
 
              (maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
1348
 
              (is_unsigned ? 0 : FIELDFLAG_DECIMAL));
1349
 
  vcol_info= NULL;
1350
 
  is_stored= true;
1351
 
}
1352
 
 
1353
 
 
1354
 
/**
1355
 
  Initialize field definition for create.
1356
 
 
1357
 
  @param thd                   Thread handle
1358
 
  @param fld_name              Field name
1359
 
  @param fld_type              Field type
1360
 
  @param fld_length            Field length
1361
 
  @param fld_decimals          Decimal (if any)
1362
 
  @param fld_type_modifier     Additional type information
1363
 
  @param fld_default_value     Field default value (if any)
1364
 
  @param fld_on_update_value   The value of ON UPDATE clause
1365
 
  @param fld_comment           Field comment
1366
 
  @param fld_change            Field change
1367
 
  @param fld_interval_list     Interval list (if any)
1368
 
  @param fld_charset           Field charset
1369
 
  @param fld_vcol_info         Virtual column data
1370
 
 
1371
 
  @retval
1372
 
    false on success
1373
 
  @retval
1374
 
    true  on error
1375
 
*/
1376
 
 
1377
 
bool Create_field::init(THD *thd __attribute__((unused)), char *fld_name, enum_field_types fld_type,
1378
 
                        char *fld_length, char *fld_decimals,
1379
 
                        uint32_t fld_type_modifier, Item *fld_default_value,
1380
 
                        Item *fld_on_update_value, LEX_STRING *fld_comment,
1381
 
                        char *fld_change, List<String> *fld_interval_list,
1382
 
                        const CHARSET_INFO * const fld_charset,
1383
 
                        uint32_t fld_geom_type __attribute__((unused)),
1384
 
                        enum column_format_type column_format,
1385
 
                        virtual_column_info *fld_vcol_info)
1386
 
{
1387
 
  uint32_t sign_len, allowed_type_modifier= 0;
1388
 
  uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
1389
 
 
1390
 
  field= 0;
1391
 
  field_name= fld_name;
1392
 
  def= fld_default_value;
1393
 
  flags= fld_type_modifier;
1394
 
  flags|= (((uint32_t)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
1395
 
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
1396
 
                 Field::NEXT_NUMBER : Field::NONE);
1397
 
  decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
1398
 
  if (decimals >= NOT_FIXED_DEC)
1399
 
  {
1400
 
    my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
1401
 
             NOT_FIXED_DEC-1);
1402
 
    return(true);
1403
 
  }
1404
 
 
1405
 
  sql_type= fld_type;
1406
 
  length= 0;
1407
 
  change= fld_change;
1408
 
  interval= 0;
1409
 
  pack_length= key_length= 0;
1410
 
  charset= fld_charset;
1411
 
  interval_list.empty();
1412
 
 
1413
 
  comment= *fld_comment;
1414
 
  vcol_info= fld_vcol_info;
1415
 
  is_stored= true;
1416
 
 
1417
 
  /* Initialize data for a virtual field */
1418
 
  if (fld_type == DRIZZLE_TYPE_VIRTUAL)
1419
 
  {
1420
 
    assert(vcol_info && vcol_info->expr_item);
1421
 
    is_stored= vcol_info->get_field_stored();
1422
 
    /*
1423
 
      Perform per item-type checks to determine if the expression is 
1424
 
      allowed for a virtual column.
1425
 
      Note that validation of the specific function is done later in
1426
 
      procedures open_table_from_share and fix_fields_vcol_func
1427
 
    */
1428
 
    switch (vcol_info->expr_item->type()) {
1429
 
    case Item::FUNC_ITEM:
1430
 
         if (((Item_func *)vcol_info->expr_item)->functype() == Item_func::FUNC_SP)
1431
 
         {
1432
 
           my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), field_name);
1433
 
           return(true);
1434
 
         }
1435
 
         break;
1436
 
    case Item::COPY_STR_ITEM:
1437
 
    case Item::FIELD_AVG_ITEM:
1438
 
    case Item::PROC_ITEM:
1439
 
    case Item::REF_ITEM:
1440
 
    case Item::FIELD_STD_ITEM:
1441
 
    case Item::FIELD_VARIANCE_ITEM:
1442
 
    case Item::INSERT_VALUE_ITEM:
1443
 
    case Item::SUBSELECT_ITEM:
1444
 
    case Item::CACHE_ITEM:
1445
 
    case Item::TYPE_HOLDER:
1446
 
    case Item::PARAM_ITEM:
1447
 
    case Item::VIEW_FIXER_ITEM: 
1448
 
         my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), field_name);
1449
 
         return true;
1450
 
         break;
1451
 
    default: 
1452
 
      // Continue with the field creation
1453
 
      break;
1454
 
    }
1455
 
    /*
1456
 
      Make a field created for the real type.
1457
 
      Note that "real" and virtual fields differ from each other
1458
 
      only by Field::vcol_info, which is always 0 for normal columns.
1459
 
      vcol_info is updated for fields later in procedure open_binary_frm.
1460
 
    */
1461
 
    sql_type= fld_type= vcol_info->get_real_type();
1462
 
  }
1463
 
 
1464
 
  /*
1465
 
    Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
1466
 
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
1467
 
  */
1468
 
  if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
1469
 
      (fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
1470
 
    flags|= NO_DEFAULT_VALUE_FLAG;
1471
 
 
1472
 
  if (fld_length && !(length= (uint32_t) atoi(fld_length)))
1473
 
    fld_length= 0; /* purecov: inspected */
1474
 
  sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
1475
 
 
1476
 
  switch (fld_type) {
1477
 
  case DRIZZLE_TYPE_TINY:
1478
 
    if (!fld_length)
1479
 
      length= MAX_TINYINT_WIDTH+sign_len;
1480
 
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
1481
 
    break;
1482
 
  case DRIZZLE_TYPE_LONG:
1483
 
    if (!fld_length)
1484
 
      length= MAX_INT_WIDTH+sign_len;
1485
 
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
1486
 
    break;
1487
 
  case DRIZZLE_TYPE_LONGLONG:
1488
 
    if (!fld_length)
1489
 
      length= MAX_BIGINT_WIDTH;
1490
 
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
1491
 
    break;
1492
 
  case DRIZZLE_TYPE_NULL:
1493
 
    break;
1494
 
  case DRIZZLE_TYPE_NEWDECIMAL:
1495
 
    my_decimal_trim(&length, &decimals);
1496
 
    if (length > DECIMAL_MAX_PRECISION)
1497
 
    {
1498
 
      my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
1499
 
               DECIMAL_MAX_PRECISION);
1500
 
      return(true);
1501
 
    }
1502
 
    if (length < decimals)
1503
 
    {
1504
 
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
1505
 
      return(true);
1506
 
    }
1507
 
    length=
1508
 
      my_decimal_precision_to_length(length, decimals,
1509
 
                                     fld_type_modifier & UNSIGNED_FLAG);
1510
 
    pack_length=
1511
 
      my_decimal_get_binary_size(length, decimals);
1512
 
    break;
1513
 
  case DRIZZLE_TYPE_VARCHAR:
1514
 
    /*
1515
 
      Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table
1516
 
      if they don't have a default value
1517
 
    */
1518
 
    max_field_charlength= MAX_FIELD_VARCHARLENGTH;
1519
 
    break;
1520
 
  case DRIZZLE_TYPE_BLOB:
1521
 
    if (fld_default_value)
1522
 
    {
1523
 
      /* Allow empty as default value. */
1524
 
      String str,*res;
1525
 
      res= fld_default_value->val_str(&str);
1526
 
    }
1527
 
    flags|= BLOB_FLAG;
1528
 
    break;
1529
 
  case DRIZZLE_TYPE_DOUBLE:
1530
 
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
1531
 
    if (!fld_length && !fld_decimals)
1532
 
    {
1533
 
      length= DBL_DIG+7;
1534
 
      decimals= NOT_FIXED_DEC;
1535
 
    }
1536
 
    if (length < decimals &&
1537
 
        decimals != NOT_FIXED_DEC)
1538
 
    {
1539
 
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
1540
 
      return(true);
1541
 
    }
1542
 
    break;
1543
 
  case DRIZZLE_TYPE_TIMESTAMP:
1544
 
    if (!fld_length)
1545
 
    {
1546
 
      /* Compressed date YYYYMMDDHHMMSS */
1547
 
      length= MAX_DATETIME_COMPRESSED_WIDTH;
1548
 
    }
1549
 
    else if (length != MAX_DATETIME_WIDTH)
1550
 
    {
1551
 
      /*
1552
 
        We support only even TIMESTAMP lengths less or equal than 14
1553
 
        and 19 as length of 4.1 compatible representation.
1554
 
      */
1555
 
      length= ((length+1)/2)*2; /* purecov: inspected */
1556
 
      length= cmin(length, (uint32_t)MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
1557
 
    }
1558
 
    flags|= UNSIGNED_FLAG;
1559
 
    if (fld_default_value)
1560
 
    {
1561
 
      /* Grammar allows only NOW() value for ON UPDATE clause */
1562
 
      if (fld_default_value->type() == Item::FUNC_ITEM && 
1563
 
          ((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
1564
 
      {
1565
 
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
1566
 
                                             Field::TIMESTAMP_DN_FIELD);
1567
 
        /*
1568
 
          We don't need default value any longer moreover it is dangerous.
1569
 
          Everything handled by unireg_check further.
1570
 
        */
1571
 
        def= 0;
1572
 
      }
1573
 
      else
1574
 
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
1575
 
                                             Field::NONE);
1576
 
    }
1577
 
    else
1578
 
    {
1579
 
      /*
1580
 
        If we have default TIMESTAMP NOT NULL column without explicit DEFAULT
1581
 
        or ON UPDATE values then for the sake of compatiblity we should treat
1582
 
        this column as having DEFAULT NOW() ON UPDATE NOW() (when we don't
1583
 
        have another TIMESTAMP column with auto-set option before this one)
1584
 
        or DEFAULT 0 (in other cases).
1585
 
        So here we are setting TIMESTAMP_OLD_FIELD only temporary, and will
1586
 
        replace this value by TIMESTAMP_DNUN_FIELD or NONE later when
1587
 
        information about all TIMESTAMP fields in table will be availiable.
1588
 
 
1589
 
        If we have TIMESTAMP NULL column without explicit DEFAULT value
1590
 
        we treat it as having DEFAULT NULL attribute.
1591
 
      */
1592
 
      unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD :
1593
 
                     (flags & NOT_NULL_FLAG ? Field::TIMESTAMP_OLD_FIELD :
1594
 
                                              Field::NONE));
1595
 
    }
1596
 
    break;
1597
 
  case DRIZZLE_TYPE_NEWDATE:
1598
 
    length= 10;
1599
 
    break;
1600
 
  case DRIZZLE_TYPE_TIME:
1601
 
    length= 10;
1602
 
    break;
1603
 
  case DRIZZLE_TYPE_DATETIME:
1604
 
    length= MAX_DATETIME_WIDTH;
1605
 
    break;
1606
 
  case DRIZZLE_TYPE_ENUM:
1607
 
    {
1608
 
      /* Should be safe. */
1609
 
      pack_length= get_enum_pack_length(fld_interval_list->elements);
1610
 
 
1611
 
      List_iterator<String> it(*fld_interval_list);
1612
 
      String *tmp;
1613
 
      while ((tmp= it++))
1614
 
        interval_list.push_back(tmp);
1615
 
      length= 1; /* See comment for DRIZZLE_TYPE_SET above. */
1616
 
      break;
1617
 
   }
1618
 
  case DRIZZLE_TYPE_VIRTUAL: // Must not happen
1619
 
    assert(0);
1620
 
  }
1621
 
  /* Remember the value of length */
1622
 
  char_length= length;
1623
 
 
1624
 
  if (!(flags & BLOB_FLAG) &&
1625
 
      ((length > max_field_charlength &&
1626
 
        fld_type != DRIZZLE_TYPE_ENUM &&
1627
 
        (fld_type != DRIZZLE_TYPE_VARCHAR || fld_default_value)) ||
1628
 
       (!length && fld_type != DRIZZLE_TYPE_VARCHAR)))
1629
 
  {
1630
 
    my_error((fld_type == DRIZZLE_TYPE_VARCHAR) ?  ER_TOO_BIG_FIELDLENGTH : ER_TOO_BIG_DISPLAYWIDTH,
1631
 
              MYF(0),
1632
 
              fld_name, max_field_charlength); /* purecov: inspected */
1633
 
    return(true);
1634
 
  }
1635
 
  fld_type_modifier&= AUTO_INCREMENT_FLAG;
1636
 
  if ((~allowed_type_modifier) & fld_type_modifier)
1637
 
  {
1638
 
    my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
1639
 
    return(true);
1640
 
  }
1641
 
 
1642
 
  return(false); /* success */
1643
 
}
1644
 
 
1645
 
 
1646
 
enum_field_types get_blob_type_from_length(uint32_t length __attribute__((unused)))
1647
 
{
1648
 
  enum_field_types type;
1649
 
 
1650
 
  type= DRIZZLE_TYPE_BLOB;
1651
 
 
1652
 
  return type;
1653
 
}
1654
 
 
1655
 
 
1656
 
/*
1657
 
  Make a field from the .frm file info
1658
 
*/
1659
 
 
1660
 
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
1661
 
{
1662
 
  switch (type) {
1663
 
  case DRIZZLE_TYPE_VARCHAR:     return (length + (length < 256 ? 1: 2));
1664
 
  case DRIZZLE_TYPE_TINY        : return 1;
1665
 
  case DRIZZLE_TYPE_NEWDATE:
1666
 
  case DRIZZLE_TYPE_TIME:   return 3;
1667
 
  case DRIZZLE_TYPE_TIMESTAMP:
1668
 
  case DRIZZLE_TYPE_LONG        : return 4;
1669
 
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1670
 
  case DRIZZLE_TYPE_DATETIME:
1671
 
  case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
1672
 
  case DRIZZLE_TYPE_NULL        : return 0;
1673
 
  case DRIZZLE_TYPE_BLOB:               return 4+portable_sizeof_char_ptr;
1674
 
  case DRIZZLE_TYPE_ENUM:
1675
 
  case DRIZZLE_TYPE_NEWDECIMAL:
1676
 
    abort(); return 0;                          // This shouldn't happen
1677
 
  default:
1678
 
    return 0;
1679
 
  }
1680
 
}
1681
 
 
1682
 
 
1683
 
uint32_t pack_length_to_packflag(uint32_t type)
1684
 
{
1685
 
  switch (type) {
1686
 
    case 1: return f_settype((uint32_t) DRIZZLE_TYPE_TINY);
1687
 
    case 2: assert(1);
1688
 
    case 3: assert(1);
1689
 
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
1690
 
    case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
1691
 
  }
1692
 
  return 0;                                     // This shouldn't happen
1693
 
}
1694
 
 
1695
 
 
1696
 
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
1697
 
                  unsigned char *null_pos, unsigned char null_bit,
1698
 
                  uint32_t pack_flag,
1699
 
                  enum_field_types field_type,
1700
 
                  const CHARSET_INFO * field_charset,
1701
 
                  Field::utype unireg_check,
1702
 
                  TYPELIB *interval,
1703
 
                  const char *field_name)
1704
 
{
1705
 
  if (!f_maybe_null(pack_flag))
1706
 
  {
1707
 
    null_pos=0;
1708
 
    null_bit=0;
1709
 
  }
1710
 
  else
1711
 
  {
1712
 
    null_bit= ((unsigned char) 1) << null_bit;
1713
 
  }
1714
 
 
1715
 
  switch (field_type) {
1716
 
  case DRIZZLE_TYPE_NEWDATE:
1717
 
  case DRIZZLE_TYPE_TIME:
1718
 
  case DRIZZLE_TYPE_DATETIME:
1719
 
  case DRIZZLE_TYPE_TIMESTAMP:
1720
 
    field_charset= &my_charset_bin;
1721
 
  default: break;
1722
 
  }
1723
 
 
1724
 
  if (f_is_alpha(pack_flag))
1725
 
  {
1726
 
    if (!f_is_packed(pack_flag))
1727
 
    {
1728
 
      if (field_type == DRIZZLE_TYPE_VARCHAR)
1729
 
        return new Field_varstring(ptr,field_length,
1730
 
                                   HA_VARCHAR_PACKLENGTH(field_length),
1731
 
                                   null_pos,null_bit,
1732
 
                                   unireg_check, field_name,
1733
 
                                   share,
1734
 
                                   field_charset);
1735
 
      return 0;                                 // Error
1736
 
    }
1737
 
 
1738
 
    uint32_t pack_length=calc_pack_length((enum_field_types)
1739
 
                                      f_packtype(pack_flag),
1740
 
                                      field_length);
1741
 
 
1742
 
    if (f_is_blob(pack_flag))
1743
 
      return new Field_blob(ptr,null_pos,null_bit,
1744
 
                            unireg_check, field_name, share,
1745
 
                            pack_length, field_charset);
1746
 
    if (interval)
1747
 
    {
1748
 
      if (f_is_enum(pack_flag))
1749
 
        return new Field_enum(ptr,field_length,null_pos,null_bit,
1750
 
                                  unireg_check, field_name,
1751
 
                                  pack_length, interval, field_charset);
1752
 
    }
1753
 
  }
1754
 
 
1755
 
  switch (field_type) {
1756
 
  case DRIZZLE_TYPE_NEWDECIMAL:
1757
 
    return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
1758
 
                                 unireg_check, field_name,
1759
 
                                 f_decimals(pack_flag),
1760
 
                                 f_is_decimal_precision(pack_flag) != 0,
1761
 
                                 f_is_dec(pack_flag) == 0);
1762
 
  case DRIZZLE_TYPE_DOUBLE:
1763
 
    return new Field_double(ptr,field_length,null_pos,null_bit,
1764
 
                            unireg_check, field_name,
1765
 
                            f_decimals(pack_flag),
1766
 
                            false,
1767
 
                            f_is_dec(pack_flag)== 0);
1768
 
  case DRIZZLE_TYPE_TINY:
1769
 
    return new Field_tiny(ptr,field_length,null_pos,null_bit,
1770
 
                          unireg_check, field_name,
1771
 
                          false,
1772
 
                          f_is_dec(pack_flag) == 0);
1773
 
  case DRIZZLE_TYPE_LONG:
1774
 
    return new Field_long(ptr,field_length,null_pos,null_bit,
1775
 
                           unireg_check, field_name,
1776
 
                           false,
1777
 
                           f_is_dec(pack_flag) == 0);
1778
 
  case DRIZZLE_TYPE_LONGLONG:
1779
 
    return new Field_int64_t(ptr,field_length,null_pos,null_bit,
1780
 
                              unireg_check, field_name,
1781
 
                              false,
1782
 
                              f_is_dec(pack_flag) == 0);
1783
 
  case DRIZZLE_TYPE_TIMESTAMP:
1784
 
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,
1785
 
                               unireg_check, field_name, share,
1786
 
                               field_charset);
1787
 
  case DRIZZLE_TYPE_NEWDATE:
1788
 
    return new Field_newdate(ptr,null_pos,null_bit,
1789
 
                             unireg_check, field_name, field_charset);
1790
 
  case DRIZZLE_TYPE_TIME:
1791
 
    return new Field_time(ptr,null_pos,null_bit,
1792
 
                          unireg_check, field_name, field_charset);
1793
 
  case DRIZZLE_TYPE_DATETIME:
1794
 
    return new Field_datetime(ptr,null_pos,null_bit,
1795
 
                              unireg_check, field_name, field_charset);
1796
 
  case DRIZZLE_TYPE_NULL:
1797
 
    return new Field_null(ptr, field_length, unireg_check, field_name,
1798
 
                          field_charset);
1799
 
  case DRIZZLE_TYPE_VIRTUAL:                    // Must not happen
1800
 
    assert(0);
1801
 
  default:                                      // Impossible (Wrong version)
1802
 
    break;
1803
 
  }
1804
 
  return 0;
1805
 
}
1806
 
 
1807
 
 
1808
 
/** Create a field suitable for create of table. */
1809
 
 
1810
 
Create_field::Create_field(Field *old_field,Field *orig_field)
1811
 
{
1812
 
  field=      old_field;
1813
 
  field_name=change=old_field->field_name;
1814
 
  length=     old_field->field_length;
1815
 
  flags=      old_field->flags;
1816
 
  unireg_check=old_field->unireg_check;
1817
 
  pack_length=old_field->pack_length();
1818
 
  key_length= old_field->key_length();
1819
 
  sql_type=   old_field->real_type();
1820
 
  charset=    old_field->charset();             // May be NULL ptr
1821
 
  comment=    old_field->comment;
1822
 
  decimals=   old_field->decimals();
1823
 
  vcol_info=  old_field->vcol_info;
1824
 
  is_stored= old_field->is_stored;
1825
 
 
1826
 
  /* Fix if the original table had 4 byte pointer blobs */
1827
 
  if (flags & BLOB_FLAG)
1828
 
    pack_length= (pack_length- old_field->table->s->blob_ptr_size +
1829
 
                  portable_sizeof_char_ptr);
1830
 
 
1831
 
  switch (sql_type) {
1832
 
  case DRIZZLE_TYPE_BLOB:
1833
 
    sql_type= DRIZZLE_TYPE_BLOB;
1834
 
    length/= charset->mbmaxlen;
1835
 
    key_length/= charset->mbmaxlen;
1836
 
    break;
1837
 
    /* Change CHAR -> VARCHAR if dynamic record length */
1838
 
  case DRIZZLE_TYPE_ENUM:
1839
 
  case DRIZZLE_TYPE_VARCHAR:
1840
 
    /* This is corrected in create_length_to_internal_length */
1841
 
    length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
1842
 
    break;
1843
 
  default:
1844
 
    break;
1845
 
  }
1846
 
 
1847
 
  if (flags & (ENUM_FLAG | SET_FLAG))
1848
 
    interval= ((Field_enum*) old_field)->typelib;
1849
 
  else
1850
 
    interval=0;
1851
 
  def=0;
1852
 
  char_length= length;
1853
 
 
1854
 
  if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
1855
 
      old_field->ptr && orig_field &&
1856
 
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
1857
 
       old_field->table->timestamp_field != old_field ||  /* timestamp field */ 
1858
 
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
1859
 
  {
1860
 
    char buff[MAX_FIELD_WIDTH];
1861
 
    String tmp(buff,sizeof(buff), charset);
1862
 
    my_ptrdiff_t diff;
1863
 
 
1864
 
    /* Get the value from default_values */
1865
 
    diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
1866
 
                          orig_field->table->record[0]);
1867
 
    orig_field->move_field_offset(diff);        // Points now at default_values
1868
 
    if (!orig_field->is_real_null())
1869
 
    {
1870
 
      char buff[MAX_FIELD_WIDTH], *pos;
1871
 
      String tmp(buff, sizeof(buff), charset), *res;
1872
 
      res= orig_field->val_str(&tmp);
1873
 
      pos= (char*) sql_strmake(res->ptr(), res->length());
1874
 
      def= new Item_string(pos, res->length(), charset);
1875
 
    }
1876
 
    orig_field->move_field_offset(-diff);       // Back to record[0]
1877
 
  }
1878
 
}
1879
 
 
1880
 
 
1881
 
/*****************************************************************************
1882
 
 Warning handling
1883
 
*****************************************************************************/
1884
 
 
1885
 
/**
1886
 
  Produce warning or note about data saved into field.
1887
 
 
1888
 
  @param level            - level of message (Note/Warning/Error)
1889
 
  @param code             - error code of message to be produced
1890
 
  @param cuted_increment  - whenever we should increase cut fields count or not
1891
 
 
1892
 
  @note
1893
 
    This function won't produce warning and increase cut fields counter
1894
 
    if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
1895
 
 
1896
 
    if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
1897
 
    This allows us to avoid notes in optimisation, like convert_constant_item().
1898
 
 
1899
 
  @retval
1900
 
    1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
1901
 
  @retval
1902
 
    0 otherwise
1903
 
*/
1904
 
 
1905
 
bool 
1906
 
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
1907
 
                   int cuted_increment)
1908
 
{
1909
 
  /*
1910
 
    If this field was created only for type conversion purposes it
1911
 
    will have table == NULL.
1912
 
  */
1913
 
  THD *thd= table ? table->in_use : current_thd;
1914
 
  if (thd->count_cuted_fields)
1915
 
  {
1916
 
    thd->cuted_fields+= cuted_increment;
1917
 
    push_warning_printf(thd, level, code, ER(code), field_name,
1918
 
                        thd->row_count);
1919
 
    return 0;
1920
 
  }
1921
 
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
1922
 
}
1923
 
 
1924
 
 
1925
 
/**
1926
 
  Produce warning or note about datetime string data saved into field.
1927
 
 
1928
 
  @param level            level of message (Note/Warning/Error)
1929
 
  @param code             error code of message to be produced
1930
 
  @param str              string value which we tried to save
1931
 
  @param str_length       length of string which we tried to save
1932
 
  @param ts_type          type of datetime value (datetime/date/time)
1933
 
  @param cuted_increment  whenever we should increase cut fields count or not
1934
 
 
1935
 
  @note
1936
 
    This function will always produce some warning but won't increase cut
1937
 
    fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
1938
 
    thread.
1939
 
*/
1940
 
 
1941
 
void 
1942
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
1943
 
                            unsigned int code, 
1944
 
                            const char *str, uint32_t str_length, 
1945
 
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
1946
 
{
1947
 
  THD *thd= table ? table->in_use : current_thd;
1948
 
  if ((thd->really_abort_on_warning() &&
1949
 
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
1950
 
      set_warning(level, code, cuted_increment))
1951
 
    make_truncated_value_warning(thd, level, str, str_length, ts_type,
1952
 
                                 field_name);
1953
 
}
1954
 
 
1955
 
 
1956
 
/**
1957
 
  Produce warning or note about integer datetime value saved into field.
1958
 
 
1959
 
  @param level            level of message (Note/Warning/Error)
1960
 
  @param code             error code of message to be produced
1961
 
  @param nr               numeric value which we tried to save
1962
 
  @param ts_type          type of datetime value (datetime/date/time)
1963
 
  @param cuted_increment  whenever we should increase cut fields count or not
1964
 
 
1965
 
  @note
1966
 
    This function will always produce some warning but won't increase cut
1967
 
    fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
1968
 
    thread.
1969
 
*/
1970
 
 
1971
 
void 
1972
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
1973
 
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
1974
 
                            int cuted_increment)
1975
 
{
1976
 
  THD *thd= table ? table->in_use : current_thd;
1977
 
  if (thd->really_abort_on_warning() ||
1978
 
      set_warning(level, code, cuted_increment))
1979
 
  {
1980
 
    char str_nr[22];
1981
 
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
1982
 
    make_truncated_value_warning(thd, level, str_nr, (uint32_t) (str_end - str_nr), 
1983
 
                                 ts_type, field_name);
1984
 
  }
1985
 
}
1986
 
 
1987
 
 
1988
 
/**
1989
 
  Produce warning or note about double datetime data saved into field.
1990
 
 
1991
 
  @param level            level of message (Note/Warning/Error)
1992
 
  @param code             error code of message to be produced
1993
 
  @param nr               double value which we tried to save
1994
 
  @param ts_type          type of datetime value (datetime/date/time)
1995
 
 
1996
 
  @note
1997
 
    This function will always produce some warning but won't increase cut
1998
 
    fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
1999
 
    thread.
2000
 
*/
2001
 
 
2002
 
void 
2003
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
2004
 
                            double nr, enum enum_drizzle_timestamp_type ts_type)
2005
 
{
2006
 
  THD *thd= table ? table->in_use : current_thd;
2007
 
  if (thd->really_abort_on_warning() ||
2008
 
      set_warning(level, code, 1))
2009
 
  {
2010
 
    /* DBL_DIG is enough to print '-[digits].E+###' */
2011
 
    char str_nr[DBL_DIG + 8];
2012
 
    uint32_t str_len= sprintf(str_nr, "%g", nr);
2013
 
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
2014
 
                                 field_name);
2015
 
  }
2016
 
}