~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/field.cc

Merge/fix in FAQ.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2010 Brian Aker
5
 
 *  Copyright (C) 2008 MySQL
6
 
 *
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.
11
 
 *
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.
16
 
 *
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
20
 
 */
 
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
 
21
16
 
22
17
/**
23
 
 * @file This file implements the Field class and API
24
 
 */
25
 
 
26
 
#include <config.h>
27
 
#include <cstdio>
 
18
  @file
 
19
 
 
20
  @brief
 
21
  This file implements classes defined in field.h
 
22
*/
 
23
 
 
24
#ifdef USE_PRAGMA_IMPLEMENTATION
 
25
#pragma implementation                          // gcc: Class implementation
 
26
#endif
 
27
 
 
28
#include "mysql_priv.h"
 
29
#include "sql_select.h"
 
30
#include <m_ctype.h>
28
31
#include <errno.h>
29
 
#include <float.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>
59
32
 
60
 
namespace drizzled
61
 
{
 
33
// Maximum allowed exponent value for converting string to decimal
 
34
#define MAX_EXPONENT 1024
62
35
 
63
36
/*****************************************************************************
64
37
  Instansiate templates and static variables
65
38
*****************************************************************************/
66
39
 
67
 
static enum_field_types
68
 
field_types_merge_rules [enum_field_types_size][enum_field_types_size]=
69
 
{
70
 
  /* DRIZZLE_TYPE_LONG -> */
71
 
  {
72
 
    //DRIZZLE_TYPE_LONG
73
 
    DRIZZLE_TYPE_LONG,
74
 
    //DRIZZLE_TYPE_DOUBLE
75
 
    DRIZZLE_TYPE_DOUBLE,
76
 
    //DRIZZLE_TYPE_NULL
77
 
    DRIZZLE_TYPE_LONG,
78
 
    //DRIZZLE_TYPE_TIMESTAMP
79
 
    DRIZZLE_TYPE_VARCHAR,
80
 
    //DRIZZLE_TYPE_LONGLONG
81
 
    DRIZZLE_TYPE_LONGLONG,
82
 
    //DRIZZLE_TYPE_DATETIME
83
 
    DRIZZLE_TYPE_VARCHAR,
84
 
    //DRIZZLE_TYPE_DATE
85
 
    DRIZZLE_TYPE_VARCHAR,
86
 
    //DRIZZLE_TYPE_VARCHAR
87
 
    DRIZZLE_TYPE_VARCHAR,
88
 
    //DRIZZLE_TYPE_DECIMAL
89
 
    DRIZZLE_TYPE_DECIMAL,
90
 
    //DRIZZLE_TYPE_ENUM
91
 
    DRIZZLE_TYPE_VARCHAR,
92
 
    //DRIZZLE_TYPE_BLOB
93
 
    DRIZZLE_TYPE_BLOB,
94
 
    //DRIZZLE_TYPE_TIME
95
 
    DRIZZLE_TYPE_TIME,
96
 
    //DRIZZLE_TYPE_BOOLEAN
97
 
    DRIZZLE_TYPE_VARCHAR,
98
 
    //DRIZZLE_TYPE_UUID
99
 
    DRIZZLE_TYPE_VARCHAR,
100
 
    //DRIZZLE_TYPE_MICROTIME
101
 
    DRIZZLE_TYPE_VARCHAR,
102
 
  },
103
 
  /* DRIZZLE_TYPE_DOUBLE -> */
104
 
  {
105
 
    //DRIZZLE_TYPE_LONG
106
 
    DRIZZLE_TYPE_DOUBLE,
107
 
    //DRIZZLE_TYPE_DOUBLE
108
 
    DRIZZLE_TYPE_DOUBLE,
109
 
    //DRIZZLE_TYPE_NULL
110
 
    DRIZZLE_TYPE_DOUBLE,
111
 
    //DRIZZLE_TYPE_TIMESTAMP
112
 
    DRIZZLE_TYPE_VARCHAR,
113
 
    //DRIZZLE_TYPE_LONGLONG
114
 
    DRIZZLE_TYPE_DOUBLE,
115
 
    //DRIZZLE_TYPE_DATETIME
116
 
    DRIZZLE_TYPE_VARCHAR,
117
 
    //DRIZZLE_TYPE_DATE
118
 
    DRIZZLE_TYPE_VARCHAR,
119
 
    //DRIZZLE_TYPE_VARCHAR
120
 
    DRIZZLE_TYPE_VARCHAR,
121
 
    //DRIZZLE_TYPE_DECIMAL
122
 
    DRIZZLE_TYPE_DOUBLE,
123
 
    //DRIZZLE_TYPE_ENUM
124
 
    DRIZZLE_TYPE_VARCHAR,
125
 
    //DRIZZLE_TYPE_BLOB
126
 
    DRIZZLE_TYPE_BLOB,
127
 
    //DRIZZLE_TYPE_TIME
128
 
    DRIZZLE_TYPE_TIME,
129
 
    //DRIZZLE_TYPE_BOOLEAN
130
 
    DRIZZLE_TYPE_VARCHAR,
131
 
    //DRIZZLE_TYPE_UUID
132
 
    DRIZZLE_TYPE_VARCHAR,
133
 
    //DRIZZLE_TYPE_MICROTIME
134
 
    DRIZZLE_TYPE_VARCHAR,
135
 
  },
136
 
  /* DRIZZLE_TYPE_NULL -> */
137
 
  {
138
 
    //DRIZZLE_TYPE_LONG
139
 
    DRIZZLE_TYPE_LONG,
140
 
    //DRIZZLE_TYPE_DOUBLE
141
 
    DRIZZLE_TYPE_DOUBLE,
142
 
    //DRIZZLE_TYPE_NULL
143
 
    DRIZZLE_TYPE_NULL,
144
 
    //DRIZZLE_TYPE_TIMESTAMP
145
 
    DRIZZLE_TYPE_TIMESTAMP,
146
 
    //DRIZZLE_TYPE_LONGLONG
147
 
    DRIZZLE_TYPE_LONGLONG,
148
 
    //DRIZZLE_TYPE_DATETIME
149
 
    DRIZZLE_TYPE_DATETIME,
150
 
    //DRIZZLE_TYPE_DATE
151
 
    DRIZZLE_TYPE_DATE,
152
 
    //DRIZZLE_TYPE_VARCHAR
153
 
    DRIZZLE_TYPE_VARCHAR,
154
 
    //DRIZZLE_TYPE_DECIMAL
155
 
    DRIZZLE_TYPE_DECIMAL,
156
 
    //DRIZZLE_TYPE_ENUM
157
 
    DRIZZLE_TYPE_ENUM,
158
 
    //DRIZZLE_TYPE_BLOB
159
 
    DRIZZLE_TYPE_BLOB,
160
 
    //DRIZZLE_TYPE_TIME
161
 
    DRIZZLE_TYPE_TIME,
162
 
    //DRIZZLE_TYPE_BOOLEAN
163
 
    DRIZZLE_TYPE_BOOLEAN,
164
 
    //DRIZZLE_TYPE_UUID
165
 
    DRIZZLE_TYPE_UUID,
166
 
    //DRIZZLE_TYPE_MICROTIME
167
 
    DRIZZLE_TYPE_MICROTIME,
168
 
  },
169
 
  /* DRIZZLE_TYPE_TIMESTAMP -> */
170
 
  {
171
 
    //DRIZZLE_TYPE_LONG
172
 
    DRIZZLE_TYPE_VARCHAR,
173
 
    //DRIZZLE_TYPE_DOUBLE
174
 
    DRIZZLE_TYPE_VARCHAR,
175
 
    //DRIZZLE_TYPE_NULL
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,
183
 
    //DRIZZLE_TYPE_DATE
184
 
    DRIZZLE_TYPE_DATE,
185
 
    //DRIZZLE_TYPE_VARCHAR
186
 
    DRIZZLE_TYPE_VARCHAR,
187
 
    //DRIZZLE_TYPE_DECIMAL
188
 
    DRIZZLE_TYPE_VARCHAR,
189
 
    //DRIZZLE_TYPE_ENUM
190
 
    DRIZZLE_TYPE_VARCHAR,
191
 
    //DRIZZLE_TYPE_BLOB
192
 
    DRIZZLE_TYPE_BLOB,
193
 
    //DRIZZLE_TYPE_TIME
194
 
    DRIZZLE_TYPE_TIME,
195
 
    //DRIZZLE_TYPE_BOOLEAN
196
 
    DRIZZLE_TYPE_VARCHAR,
197
 
    //DRIZZLE_TYPE_UUID
198
 
    DRIZZLE_TYPE_VARCHAR,
199
 
    //DRIZZLE_TYPE_MICROTIME
200
 
    DRIZZLE_TYPE_VARCHAR,
201
 
  },
202
 
  /* DRIZZLE_TYPE_LONGLONG -> */
203
 
  {
204
 
    //DRIZZLE_TYPE_LONG
205
 
    DRIZZLE_TYPE_LONGLONG,
206
 
    //DRIZZLE_TYPE_DOUBLE
207
 
    DRIZZLE_TYPE_DOUBLE,
208
 
    //DRIZZLE_TYPE_NULL
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,
216
 
    //DRIZZLE_TYPE_DATE
217
 
    DRIZZLE_TYPE_DATE,
218
 
    //DRIZZLE_TYPE_VARCHAR
219
 
    DRIZZLE_TYPE_VARCHAR,
220
 
    //DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_ENUM
221
 
    DRIZZLE_TYPE_DECIMAL,
222
 
    DRIZZLE_TYPE_VARCHAR,
223
 
    //DRIZZLE_TYPE_BLOB
224
 
    DRIZZLE_TYPE_BLOB,
225
 
    //DRIZZLE_TYPE_TIME
226
 
    DRIZZLE_TYPE_TIME,
227
 
    //DRIZZLE_TYPE_BOOLEAN
228
 
    DRIZZLE_TYPE_VARCHAR,
229
 
    //DRIZZLE_TYPE_UUID
230
 
    DRIZZLE_TYPE_VARCHAR,
231
 
    //DRIZZLE_TYPE_MICROTIME
232
 
    DRIZZLE_TYPE_VARCHAR,
233
 
  },
234
 
  /* DRIZZLE_TYPE_DATETIME -> */
235
 
  {
236
 
    //DRIZZLE_TYPE_LONG
237
 
    DRIZZLE_TYPE_VARCHAR,
238
 
    //DRIZZLE_TYPE_DOUBLE
239
 
    DRIZZLE_TYPE_VARCHAR,
240
 
    //DRIZZLE_TYPE_NULL
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,
248
 
    //DRIZZLE_TYPE_DATE
249
 
    DRIZZLE_TYPE_DATE,
250
 
    //DRIZZLE_TYPE_VARCHAR
251
 
    DRIZZLE_TYPE_VARCHAR,
252
 
    //DRIZZLE_TYPE_DECIMAL
253
 
    DRIZZLE_TYPE_VARCHAR,
254
 
    //DRIZZLE_TYPE_ENUM
255
 
    DRIZZLE_TYPE_VARCHAR,
256
 
    //DRIZZLE_TYPE_BLOB
257
 
    DRIZZLE_TYPE_BLOB,
258
 
    //DRIZZLE_TYPE_TIME
259
 
    DRIZZLE_TYPE_TIME,
260
 
    //DRIZZLE_TYPE_BOOLEAN
261
 
    DRIZZLE_TYPE_VARCHAR,
262
 
    //DRIZZLE_TYPE_UUID
263
 
    DRIZZLE_TYPE_VARCHAR,
264
 
    //DRIZZLE_TYPE_MICROTIME
265
 
    DRIZZLE_TYPE_VARCHAR,
266
 
  },
267
 
  /* DRIZZLE_TYPE_DATE -> */
268
 
  {
269
 
    //DRIZZLE_TYPE_LONG
270
 
    DRIZZLE_TYPE_VARCHAR,
271
 
    //DRIZZLE_TYPE_DOUBLE
272
 
    DRIZZLE_TYPE_VARCHAR,
273
 
    //DRIZZLE_TYPE_NULL
274
 
    DRIZZLE_TYPE_DATE,
275
 
    //DRIZZLE_TYPE_TIMESTAMP
276
 
    DRIZZLE_TYPE_DATETIME,
277
 
    //DRIZZLE_TYPE_LONGLONG
278
 
    DRIZZLE_TYPE_VARCHAR,
279
 
    //DRIZZLE_TYPE_DATETIME
280
 
    DRIZZLE_TYPE_DATETIME,
281
 
    //DRIZZLE_TYPE_DATE
282
 
    DRIZZLE_TYPE_DATE,
283
 
    //DRIZZLE_TYPE_VARCHAR
284
 
    DRIZZLE_TYPE_VARCHAR,
285
 
    //DRIZZLE_TYPE_DECIMAL
286
 
    DRIZZLE_TYPE_VARCHAR,
287
 
    //DRIZZLE_TYPE_ENUM
288
 
    DRIZZLE_TYPE_VARCHAR,
289
 
    //DRIZZLE_TYPE_BLOB
290
 
    DRIZZLE_TYPE_BLOB,
291
 
    //DRIZZLE_TYPE_TIME
292
 
    DRIZZLE_TYPE_TIME,
293
 
    //DRIZZLE_TYPE_BOOLEAN
294
 
    DRIZZLE_TYPE_VARCHAR,
295
 
    //DRIZZLE_TYPE_UUID
296
 
    DRIZZLE_TYPE_VARCHAR,
297
 
    //DRIZZLE_TYPE_MICROTIME
298
 
    DRIZZLE_TYPE_VARCHAR,
299
 
  },
300
 
  /* DRIZZLE_TYPE_VARCHAR -> */
301
 
  {
302
 
    //DRIZZLE_TYPE_LONG
303
 
    DRIZZLE_TYPE_VARCHAR,
304
 
    //DRIZZLE_TYPE_DOUBLE
305
 
    DRIZZLE_TYPE_VARCHAR,
306
 
    //DRIZZLE_TYPE_NULL
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,
314
 
    //DRIZZLE_TYPE_DATE
315
 
    DRIZZLE_TYPE_VARCHAR,
316
 
    //DRIZZLE_TYPE_VARCHAR
317
 
    DRIZZLE_TYPE_VARCHAR,
318
 
    //DRIZZLE_TYPE_DECIMAL
319
 
    DRIZZLE_TYPE_VARCHAR,
320
 
    //DRIZZLE_TYPE_ENUM
321
 
    DRIZZLE_TYPE_VARCHAR,
322
 
    //DRIZZLE_TYPE_BLOB
323
 
    DRIZZLE_TYPE_BLOB,
324
 
    //DRIZZLE_TYPE_TIME
325
 
    DRIZZLE_TYPE_TIME,
326
 
    //DRIZZLE_TYPE_BOOLEAN
327
 
    DRIZZLE_TYPE_VARCHAR,
328
 
    //DRIZZLE_TYPE_UUID
329
 
    DRIZZLE_TYPE_VARCHAR,
330
 
    //DRIZZLE_TYPE_MICROTIME
331
 
    DRIZZLE_TYPE_VARCHAR,
332
 
  },
333
 
  /* DRIZZLE_TYPE_DECIMAL -> */
334
 
  {
335
 
    //DRIZZLE_TYPE_LONG
336
 
    DRIZZLE_TYPE_DECIMAL,
337
 
    //DRIZZLE_TYPE_DOUBLE
338
 
    DRIZZLE_TYPE_DOUBLE,
339
 
    //DRIZZLE_TYPE_NULL
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,
347
 
    //DRIZZLE_TYPE_DATE
348
 
    DRIZZLE_TYPE_VARCHAR,
349
 
    //DRIZZLE_TYPE_VARCHAR
350
 
    DRIZZLE_TYPE_VARCHAR,
351
 
    //DRIZZLE_TYPE_DECIMAL
352
 
    DRIZZLE_TYPE_DECIMAL,
353
 
    //DRIZZLE_TYPE_ENUM
354
 
    DRIZZLE_TYPE_VARCHAR,
355
 
    //DRIZZLE_TYPE_BLOB
356
 
    DRIZZLE_TYPE_BLOB,
357
 
    //DRIZZLE_TYPE_TIME
358
 
    DRIZZLE_TYPE_TIME,
359
 
    //DRIZZLE_TYPE_BOOLEAN
360
 
    DRIZZLE_TYPE_VARCHAR,
361
 
    //DRIZZLE_TYPE_UUID
362
 
    DRIZZLE_TYPE_VARCHAR,
363
 
    //DRIZZLE_TYPE_MICROTIME
364
 
    DRIZZLE_TYPE_VARCHAR,
365
 
  },
366
 
  /* DRIZZLE_TYPE_ENUM -> */
367
 
  {
368
 
    //DRIZZLE_TYPE_LONG
369
 
    DRIZZLE_TYPE_VARCHAR,
370
 
    //DRIZZLE_TYPE_DOUBLE
371
 
    DRIZZLE_TYPE_VARCHAR,
372
 
    //DRIZZLE_TYPE_NULL
373
 
    DRIZZLE_TYPE_ENUM,
374
 
    //DRIZZLE_TYPE_TIMESTAMP
375
 
    DRIZZLE_TYPE_VARCHAR,
376
 
    //DRIZZLE_TYPE_LONGLONG
377
 
    DRIZZLE_TYPE_VARCHAR,
378
 
    //DRIZZLE_TYPE_DATETIME
379
 
    DRIZZLE_TYPE_VARCHAR,
380
 
    //DRIZZLE_TYPE_DATE
381
 
    DRIZZLE_TYPE_VARCHAR,
382
 
    //DRIZZLE_TYPE_VARCHAR
383
 
    DRIZZLE_TYPE_VARCHAR,
384
 
    //DRIZZLE_TYPE_DECIMAL
385
 
    DRIZZLE_TYPE_VARCHAR,
386
 
    //DRIZZLE_TYPE_ENUM
387
 
    DRIZZLE_TYPE_VARCHAR,
388
 
    //DRIZZLE_TYPE_BLOB
389
 
    DRIZZLE_TYPE_BLOB,
390
 
    //DRIZZLE_TYPE_TIME
391
 
    DRIZZLE_TYPE_TIME,
392
 
    //DRIZZLE_TYPE_BOOLEAN
393
 
    DRIZZLE_TYPE_VARCHAR,
394
 
    //DRIZZLE_TYPE_UUID
395
 
    DRIZZLE_TYPE_VARCHAR,
396
 
    //DRIZZLE_TYPE_MICROTIME
397
 
    DRIZZLE_TYPE_VARCHAR,
398
 
   },
399
 
  /* DRIZZLE_TYPE_BLOB -> */
400
 
  {
401
 
    //DRIZZLE_TYPE_LONG
402
 
    DRIZZLE_TYPE_BLOB,
403
 
    //DRIZZLE_TYPE_DOUBLE
404
 
    DRIZZLE_TYPE_BLOB,
405
 
    //DRIZZLE_TYPE_NULL
406
 
    DRIZZLE_TYPE_BLOB,
407
 
    //DRIZZLE_TYPE_TIMESTAMP
408
 
    DRIZZLE_TYPE_BLOB,
409
 
    //DRIZZLE_TYPE_LONGLONG
410
 
    DRIZZLE_TYPE_BLOB,
411
 
    //DRIZZLE_TYPE_DATETIME
412
 
    DRIZZLE_TYPE_BLOB,
413
 
    //DRIZZLE_TYPE_DATE
414
 
    DRIZZLE_TYPE_BLOB,
415
 
    //DRIZZLE_TYPE_VARCHAR
416
 
    DRIZZLE_TYPE_BLOB,
417
 
    //DRIZZLE_TYPE_DECIMAL
418
 
    DRIZZLE_TYPE_BLOB,
419
 
    //DRIZZLE_TYPE_ENUM
420
 
    DRIZZLE_TYPE_BLOB,
421
 
    //DRIZZLE_TYPE_BLOB
422
 
    DRIZZLE_TYPE_BLOB,
423
 
    //DRIZZLE_TYPE_TIME
424
 
    DRIZZLE_TYPE_TIME,
425
 
    //DRIZZLE_TYPE_BOOLEAN
426
 
    DRIZZLE_TYPE_VARCHAR,
427
 
    //DRIZZLE_TYPE_UUID
428
 
    DRIZZLE_TYPE_VARCHAR,
429
 
    //DRIZZLE_TYPE_MICROTIME
430
 
    DRIZZLE_TYPE_VARCHAR,
431
 
  },
432
 
  /* DRIZZLE_TYPE_TIME -> */
433
 
  {
434
 
    //DRIZZLE_TYPE_LONG
435
 
    DRIZZLE_TYPE_VARCHAR,
436
 
    //DRIZZLE_TYPE_DOUBLE
437
 
    DRIZZLE_TYPE_VARCHAR,
438
 
    //DRIZZLE_TYPE_NULL
439
 
    DRIZZLE_TYPE_TIME,
440
 
    //DRIZZLE_TYPE_TIMESTAMP
441
 
    DRIZZLE_TYPE_VARCHAR,
442
 
    //DRIZZLE_TYPE_LONGLONG
443
 
    DRIZZLE_TYPE_VARCHAR,
444
 
    //DRIZZLE_TYPE_DATETIME
445
 
    DRIZZLE_TYPE_VARCHAR,
446
 
    //DRIZZLE_TYPE_DATE
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,
454
 
    //DRIZZLE_TYPE_BLOB
455
 
    DRIZZLE_TYPE_BLOB,
456
 
    //DRIZZLE_TYPE_TIME
457
 
    DRIZZLE_TYPE_TIME,
458
 
    //DRIZZLE_TYPE_BOOLEAN
459
 
    DRIZZLE_TYPE_VARCHAR,
460
 
    //DRIZZLE_TYPE_UUID
461
 
    DRIZZLE_TYPE_UUID,
462
 
    //DRIZZLE_TYPE_MICROTIME
463
 
    DRIZZLE_TYPE_VARCHAR,
464
 
  },
465
 
  /* DRIZZLE_TYPE_BOOLEAN -> */
466
 
  {
467
 
    //DRIZZLE_TYPE_LONG
468
 
    DRIZZLE_TYPE_VARCHAR,
469
 
    //DRIZZLE_TYPE_DOUBLE
470
 
    DRIZZLE_TYPE_VARCHAR,
471
 
    //DRIZZLE_TYPE_NULL
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,
479
 
    //DRIZZLE_TYPE_DATE
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,
487
 
    //DRIZZLE_TYPE_BLOB
488
 
    DRIZZLE_TYPE_BLOB,
489
 
    //DRIZZLE_TYPE_TIME
490
 
    DRIZZLE_TYPE_TIME,
491
 
    //DRIZZLE_TYPE_BOOLEAN
492
 
    DRIZZLE_TYPE_BOOLEAN,
493
 
    //DRIZZLE_TYPE_UUID
494
 
    DRIZZLE_TYPE_VARCHAR,
495
 
    //DRIZZLE_TYPE_MICROTIME
496
 
    DRIZZLE_TYPE_VARCHAR,
497
 
  },
498
 
  /* DRIZZLE_TYPE_UUID -> */
499
 
  {
500
 
    //DRIZZLE_TYPE_LONG
501
 
    DRIZZLE_TYPE_VARCHAR,
502
 
    //DRIZZLE_TYPE_DOUBLE
503
 
    DRIZZLE_TYPE_VARCHAR,
504
 
    //DRIZZLE_TYPE_NULL
505
 
    DRIZZLE_TYPE_UUID,
506
 
    //DRIZZLE_TYPE_TIMESTAMP
507
 
    DRIZZLE_TYPE_VARCHAR,
508
 
    //DRIZZLE_TYPE_LONGLONG
509
 
    DRIZZLE_TYPE_VARCHAR,
510
 
    //DRIZZLE_TYPE_DATETIME
511
 
    DRIZZLE_TYPE_VARCHAR,
512
 
    //DRIZZLE_TYPE_DATE
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,
520
 
    //DRIZZLE_TYPE_BLOB
521
 
    DRIZZLE_TYPE_BLOB,
522
 
    //DRIZZLE_TYPE_TIME
523
 
    DRIZZLE_TYPE_TIME,
524
 
    //DRIZZLE_TYPE_BOOLEAN
525
 
    DRIZZLE_TYPE_VARCHAR,
526
 
    //DRIZZLE_TYPE_UUID
527
 
    DRIZZLE_TYPE_UUID,
528
 
    //DRIZZLE_TYPE_MICROTIME
529
 
    DRIZZLE_TYPE_VARCHAR,
530
 
  },
531
 
  /* DRIZZLE_TYPE_MICROTIME -> */
532
 
  {
533
 
    //DRIZZLE_TYPE_LONG
534
 
    DRIZZLE_TYPE_VARCHAR,
535
 
    //DRIZZLE_TYPE_DOUBLE
536
 
    DRIZZLE_TYPE_VARCHAR,
537
 
    //DRIZZLE_TYPE_NULL
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,
545
 
    //DRIZZLE_TYPE_DATE
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,
553
 
    //DRIZZLE_TYPE_BLOB
554
 
    DRIZZLE_TYPE_BLOB,
555
 
    //DRIZZLE_TYPE_TIME
556
 
    DRIZZLE_TYPE_TIME,
557
 
    //DRIZZLE_TYPE_BOOLEAN
558
 
    DRIZZLE_TYPE_VARCHAR,
559
 
    //DRIZZLE_TYPE_UUID
560
 
    DRIZZLE_TYPE_UUID,
561
 
    //DRIZZLE_TYPE_MICROTIME
562
 
    DRIZZLE_TYPE_MICROTIME,
563
 
  },
 
40
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
 
41
template class List<Create_field>;
 
42
template class List_iterator<Create_field>;
 
43
#endif
 
44
 
 
45
 
 
46
/*
 
47
  Rules for merging different types of fields in UNION
 
48
 
 
49
  NOTE: to avoid 256*256 table, gap in table types numeration is skiped
 
50
  following #defines describe that gap and how to canculate number of fields
 
51
  and index of field in thia array.
 
52
*/
 
53
#define FIELDTYPE_TEAR_FROM (MYSQL_TYPE_VARCHAR + 1)
 
54
#define FIELDTYPE_TEAR_TO   (MYSQL_TYPE_NEWDECIMAL - 1)
 
55
#define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO))
 
56
inline int field_type2index (enum_field_types field_type)
 
57
{
 
58
  return (field_type < FIELDTYPE_TEAR_FROM ?
 
59
          field_type :
 
60
          ((int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) - 1);
 
61
}
 
62
 
 
63
 
 
64
static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]=
 
65
{
 
66
  /* MYSQL_TYPE_DECIMAL -> */
 
67
  {
 
68
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
69
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_NEWDECIMAL,
 
70
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
71
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_NEWDECIMAL,
 
72
  //MYSQL_TYPE_DOUBLE
 
73
    MYSQL_TYPE_DOUBLE,
 
74
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
75
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_VARCHAR,
 
76
  //MYSQL_TYPE_LONGLONG
 
77
    MYSQL_TYPE_NEWDECIMAL,
 
78
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
79
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
80
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
81
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
82
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
83
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
84
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
85
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_VARCHAR,
 
86
  //MYSQL_TYPE_SET
 
87
    MYSQL_TYPE_VARCHAR,
 
88
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
89
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
90
  //MYSQL_TYPE_STRING       
 
91
    MYSQL_TYPE_STRING
 
92
  },
 
93
  /* MYSQL_TYPE_TINY -> */
 
94
  {
 
95
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
96
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_TINY,
 
97
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
98
    MYSQL_TYPE_SHORT,       MYSQL_TYPE_LONG,
 
99
  //MYSQL_TYPE_DOUBLE
 
100
    MYSQL_TYPE_DOUBLE,
 
101
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
102
    MYSQL_TYPE_TINY,        MYSQL_TYPE_VARCHAR,
 
103
  //MYSQL_TYPE_LONGLONG
 
104
    MYSQL_TYPE_LONGLONG,
 
105
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
106
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
107
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
108
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_TINY,
 
109
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
110
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
111
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
112
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_VARCHAR,
 
113
  //MYSQL_TYPE_SET
 
114
    MYSQL_TYPE_VARCHAR,
 
115
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
116
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
117
  //MYSQL_TYPE_STRING       
 
118
    MYSQL_TYPE_STRING     
 
119
  },
 
120
  /* MYSQL_TYPE_SHORT -> */
 
121
  {
 
122
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
123
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_SHORT,
 
124
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
125
    MYSQL_TYPE_SHORT,       MYSQL_TYPE_LONG,
 
126
  //MYSQL_TYPE_DOUBLE
 
127
    MYSQL_TYPE_DOUBLE,
 
128
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
129
    MYSQL_TYPE_SHORT,       MYSQL_TYPE_VARCHAR,
 
130
  //MYSQL_TYPE_LONGLONG
 
131
    MYSQL_TYPE_LONGLONG,
 
132
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
133
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
134
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
135
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_SHORT,
 
136
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
137
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
138
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
139
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_VARCHAR,
 
140
  //MYSQL_TYPE_SET
 
141
    MYSQL_TYPE_VARCHAR,
 
142
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
143
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
144
  //MYSQL_TYPE_STRING
 
145
    MYSQL_TYPE_STRING
 
146
  },
 
147
  /* MYSQL_TYPE_LONG -> */
 
148
  {
 
149
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
150
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_LONG,
 
151
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
152
    MYSQL_TYPE_LONG,        MYSQL_TYPE_LONG,
 
153
  //MYSQL_TYPE_DOUBLE
 
154
    MYSQL_TYPE_DOUBLE,
 
155
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
156
    MYSQL_TYPE_LONG,         MYSQL_TYPE_VARCHAR,
 
157
  //MYSQL_TYPE_LONGLONG
 
158
    MYSQL_TYPE_LONGLONG,
 
159
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
160
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
161
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
162
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_LONG,
 
163
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
164
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
165
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
166
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_VARCHAR,
 
167
  //MYSQL_TYPE_SET
 
168
    MYSQL_TYPE_VARCHAR,
 
169
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
170
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
171
  //MYSQL_TYPE_STRING
 
172
    MYSQL_TYPE_STRING
 
173
  },
 
174
  /* MYSQL_TYPE_DOUBLE -> */
 
175
  {
 
176
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
177
    MYSQL_TYPE_DOUBLE,      MYSQL_TYPE_DOUBLE,
 
178
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
179
    MYSQL_TYPE_DOUBLE,      MYSQL_TYPE_DOUBLE,
 
180
  //MYSQL_TYPE_DOUBLE
 
181
    MYSQL_TYPE_DOUBLE,
 
182
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
183
    MYSQL_TYPE_DOUBLE,      MYSQL_TYPE_VARCHAR,
 
184
  //MYSQL_TYPE_LONGLONG
 
185
    MYSQL_TYPE_DOUBLE,
 
186
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
187
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
188
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
189
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_DOUBLE,
 
190
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
191
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
192
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
193
    MYSQL_TYPE_DOUBLE,      MYSQL_TYPE_VARCHAR,
 
194
  //MYSQL_TYPE_SET
 
195
    MYSQL_TYPE_VARCHAR,
 
196
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
197
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
198
  //MYSQL_TYPE_STRING
 
199
    MYSQL_TYPE_STRING
 
200
  },
 
201
  /* MYSQL_TYPE_NULL -> */
 
202
  {
 
203
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
204
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_TINY,
 
205
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
206
    MYSQL_TYPE_SHORT,       MYSQL_TYPE_LONG,
 
207
  //MYSQL_TYPE_DOUBLE
 
208
    MYSQL_TYPE_DOUBLE,
 
209
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
210
    MYSQL_TYPE_NULL,        MYSQL_TYPE_TIMESTAMP,
 
211
  //MYSQL_TYPE_LONGLONG
 
212
    MYSQL_TYPE_LONGLONG,
 
213
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
214
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_TIME,
 
215
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
216
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_YEAR,
 
217
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
218
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_VARCHAR,
 
219
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
220
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_ENUM,
 
221
  //MYSQL_TYPE_SET
 
222
    MYSQL_TYPE_SET,
 
223
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
224
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
225
  //MYSQL_TYPE_STRING
 
226
    MYSQL_TYPE_STRING
 
227
  },
 
228
  /* MYSQL_TYPE_TIMESTAMP -> */
 
229
  {
 
230
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
231
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
232
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
233
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
234
  //MYSQL_TYPE_DOUBLE
 
235
    MYSQL_TYPE_VARCHAR,
 
236
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
237
    MYSQL_TYPE_TIMESTAMP,   MYSQL_TYPE_TIMESTAMP,
 
238
  //MYSQL_TYPE_LONGLONG
 
239
    MYSQL_TYPE_VARCHAR,
 
240
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
241
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_DATETIME,
 
242
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
243
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_VARCHAR,
 
244
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
245
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_VARCHAR,
 
246
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
247
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
248
  //MYSQL_TYPE_SET
 
249
    MYSQL_TYPE_VARCHAR,
 
250
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
251
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
252
  //MYSQL_TYPE_STRING
 
253
    MYSQL_TYPE_STRING
 
254
  },
 
255
  /* MYSQL_TYPE_LONGLONG -> */
 
256
  {
 
257
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
258
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_LONGLONG,
 
259
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
260
    MYSQL_TYPE_LONGLONG,    MYSQL_TYPE_LONGLONG,
 
261
  //MYSQL_TYPE_DOUBLE
 
262
    MYSQL_TYPE_DOUBLE,
 
263
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
264
    MYSQL_TYPE_LONGLONG,    MYSQL_TYPE_VARCHAR,
 
265
  //MYSQL_TYPE_LONGLONG
 
266
    MYSQL_TYPE_LONGLONG,
 
267
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
268
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
269
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
270
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_LONGLONG,
 
271
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
272
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_VARCHAR,
 
273
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
274
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_VARCHAR,
 
275
  //MYSQL_TYPE_SET
 
276
    MYSQL_TYPE_VARCHAR,
 
277
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
278
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
279
  //MYSQL_TYPE_STRING
 
280
    MYSQL_TYPE_STRING
 
281
  },
 
282
  /* MYSQL_TYPE_DATE -> */
 
283
  {
 
284
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
285
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
286
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
287
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
288
  //MYSQL_TYPE_DOUBLE
 
289
    MYSQL_TYPE_VARCHAR,
 
290
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
291
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_DATETIME,
 
292
  //MYSQL_TYPE_LONGLONG
 
293
    MYSQL_TYPE_VARCHAR,
 
294
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
295
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_DATETIME,
 
296
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
297
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_VARCHAR,
 
298
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
299
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_VARCHAR,
 
300
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
301
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
302
  //MYSQL_TYPE_SET
 
303
    MYSQL_TYPE_VARCHAR,
 
304
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
305
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
306
  //MYSQL_TYPE_STRING
 
307
    MYSQL_TYPE_STRING
 
308
  },
 
309
  /* MYSQL_TYPE_TIME -> */
 
310
  {
 
311
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
312
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
313
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
314
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
315
  //MYSQL_TYPE_DOUBLE
 
316
    MYSQL_TYPE_VARCHAR,
 
317
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
318
    MYSQL_TYPE_TIME,        MYSQL_TYPE_DATETIME,
 
319
  //MYSQL_TYPE_LONGLONG
 
320
    MYSQL_TYPE_VARCHAR,
 
321
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
322
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_TIME,
 
323
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
324
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_VARCHAR,
 
325
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
326
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_VARCHAR,
 
327
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
328
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
329
  //MYSQL_TYPE_SET
 
330
    MYSQL_TYPE_VARCHAR,
 
331
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
332
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
333
  //MYSQL_TYPE_STRING
 
334
    MYSQL_TYPE_STRING
 
335
  },
 
336
  /* MYSQL_TYPE_DATETIME -> */
 
337
  {
 
338
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
339
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
340
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
341
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
342
  //MYSQL_TYPE_DOUBLE
 
343
    MYSQL_TYPE_VARCHAR,
 
344
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
345
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_DATETIME,
 
346
  //MYSQL_TYPE_LONGLONG
 
347
    MYSQL_TYPE_VARCHAR,
 
348
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
349
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_DATETIME,
 
350
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
351
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_VARCHAR,
 
352
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
353
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_VARCHAR,
 
354
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
355
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
356
  //MYSQL_TYPE_SET
 
357
    MYSQL_TYPE_VARCHAR,
 
358
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
359
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
360
  //MYSQL_TYPE_STRING
 
361
    MYSQL_TYPE_STRING
 
362
  },
 
363
  /* MYSQL_TYPE_YEAR -> */
 
364
  {
 
365
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
366
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_TINY,
 
367
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
368
    MYSQL_TYPE_SHORT,       MYSQL_TYPE_LONG,
 
369
  //MYSQL_TYPE_DOUBLE
 
370
    MYSQL_TYPE_DOUBLE,
 
371
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
372
    MYSQL_TYPE_YEAR,        MYSQL_TYPE_VARCHAR,
 
373
  //MYSQL_TYPE_LONGLONG
 
374
    MYSQL_TYPE_LONGLONG,
 
375
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
376
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
377
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
378
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_YEAR,
 
379
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
380
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
381
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
382
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_VARCHAR,
 
383
  //MYSQL_TYPE_SET
 
384
    MYSQL_TYPE_VARCHAR,
 
385
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
386
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
387
  //MYSQL_TYPE_STRING
 
388
    MYSQL_TYPE_STRING
 
389
  },
 
390
  /* MYSQL_TYPE_NEWDATE -> */
 
391
  {
 
392
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
393
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
394
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
395
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
396
  //MYSQL_TYPE_DOUBLE
 
397
    MYSQL_TYPE_VARCHAR,
 
398
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
399
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_DATETIME,
 
400
  //MYSQL_TYPE_LONGLONG
 
401
    MYSQL_TYPE_VARCHAR,
 
402
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
403
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_DATETIME,
 
404
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
405
    MYSQL_TYPE_DATETIME,    MYSQL_TYPE_VARCHAR,
 
406
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
407
    MYSQL_TYPE_NEWDATE,     MYSQL_TYPE_VARCHAR,
 
408
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
409
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
410
  //MYSQL_TYPE_SET
 
411
    MYSQL_TYPE_VARCHAR,
 
412
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
413
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
414
  //MYSQL_TYPE_STRING
 
415
    MYSQL_TYPE_STRING
 
416
  },
 
417
  /* MYSQL_TYPE_VARCHAR -> */
 
418
  {
 
419
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
420
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
421
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
422
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
423
  //MYSQL_TYPE_DOUBLE
 
424
    MYSQL_TYPE_VARCHAR,
 
425
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
426
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
427
  //MYSQL_TYPE_LONGLONG
 
428
    MYSQL_TYPE_VARCHAR,
 
429
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
430
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
431
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
432
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
433
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
434
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
435
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
436
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
437
  //MYSQL_TYPE_SET
 
438
    MYSQL_TYPE_VARCHAR,
 
439
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
440
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
441
  //MYSQL_TYPE_STRING
 
442
    MYSQL_TYPE_VARCHAR
 
443
  },
 
444
  /* MYSQL_TYPE_NEWDECIMAL -> */
 
445
  {
 
446
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
447
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_NEWDECIMAL,
 
448
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
449
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_NEWDECIMAL,
 
450
  //MYSQL_TYPE_DOUBLE
 
451
    MYSQL_TYPE_DOUBLE,
 
452
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
453
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_VARCHAR,
 
454
  //MYSQL_TYPE_LONGLONG
 
455
    MYSQL_TYPE_NEWDECIMAL,
 
456
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
457
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
458
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
459
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_NEWDECIMAL,
 
460
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
461
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
462
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
463
    MYSQL_TYPE_NEWDECIMAL,  MYSQL_TYPE_VARCHAR,
 
464
  //MYSQL_TYPE_SET
 
465
    MYSQL_TYPE_VARCHAR,
 
466
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
467
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
468
  //MYSQL_TYPE_STRING
 
469
    MYSQL_TYPE_STRING
 
470
  },
 
471
  /* MYSQL_TYPE_ENUM -> */
 
472
  {
 
473
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
474
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
475
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
476
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
477
  //MYSQL_TYPE_DOUBLE
 
478
    MYSQL_TYPE_VARCHAR,
 
479
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
480
    MYSQL_TYPE_ENUM,        MYSQL_TYPE_VARCHAR,
 
481
  //MYSQL_TYPE_LONGLONG
 
482
    MYSQL_TYPE_VARCHAR,
 
483
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
484
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
485
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
486
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
487
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
488
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
489
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
490
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
491
  //MYSQL_TYPE_SET
 
492
    MYSQL_TYPE_VARCHAR,
 
493
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
494
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
495
  //MYSQL_TYPE_STRING
 
496
    MYSQL_TYPE_STRING
 
497
  },
 
498
  /* MYSQL_TYPE_SET -> */
 
499
  {
 
500
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
501
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
502
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
503
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
504
  //MYSQL_TYPE_DOUBLE
 
505
    MYSQL_TYPE_VARCHAR,
 
506
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
507
    MYSQL_TYPE_SET,         MYSQL_TYPE_VARCHAR,
 
508
  //MYSQL_TYPE_LONGLONG
 
509
    MYSQL_TYPE_VARCHAR,
 
510
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
511
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
512
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
513
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
514
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
515
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
516
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
517
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
518
  //MYSQL_TYPE_SET
 
519
    MYSQL_TYPE_VARCHAR,
 
520
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
521
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
522
  //MYSQL_TYPE_STRING
 
523
    MYSQL_TYPE_STRING
 
524
  },
 
525
  /* MYSQL_TYPE_BLOB -> */
 
526
  {
 
527
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
528
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_BLOB,
 
529
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
530
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_BLOB,
 
531
  //MYSQL_TYPE_DOUBLE
 
532
    MYSQL_TYPE_BLOB,
 
533
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
534
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_BLOB,
 
535
  //MYSQL_TYPE_LONGLONG
 
536
    MYSQL_TYPE_BLOB,
 
537
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
538
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_BLOB,
 
539
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
540
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_BLOB,
 
541
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
542
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_BLOB,
 
543
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
544
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_BLOB,
 
545
  //MYSQL_TYPE_SET
 
546
    MYSQL_TYPE_BLOB,
 
547
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
548
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_BLOB,
 
549
  //MYSQL_TYPE_STRING
 
550
    MYSQL_TYPE_BLOB
 
551
  },
 
552
  /* MYSQL_TYPE_VAR_STRING -> */
 
553
  {
 
554
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
555
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
556
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
557
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
558
  //MYSQL_TYPE_DOUBLE
 
559
    MYSQL_TYPE_VARCHAR,
 
560
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
561
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
562
  //MYSQL_TYPE_LONGLONG
 
563
    MYSQL_TYPE_VARCHAR,
 
564
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
565
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
566
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
567
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
568
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
569
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
570
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
571
    MYSQL_TYPE_VARCHAR,     MYSQL_TYPE_VARCHAR,
 
572
  //MYSQL_TYPE_SET
 
573
    MYSQL_TYPE_VARCHAR,
 
574
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
575
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
576
  //MYSQL_TYPE_STRING
 
577
    MYSQL_TYPE_VARCHAR
 
578
  },
 
579
  /* MYSQL_TYPE_STRING -> */
 
580
  {
 
581
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
582
    MYSQL_TYPE_STRING,      MYSQL_TYPE_STRING,
 
583
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
584
    MYSQL_TYPE_STRING,      MYSQL_TYPE_STRING,
 
585
  //MYSQL_TYPE_DOUBLE
 
586
    MYSQL_TYPE_STRING,
 
587
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
588
    MYSQL_TYPE_STRING,      MYSQL_TYPE_STRING,
 
589
  //MYSQL_TYPE_LONGLONG
 
590
    MYSQL_TYPE_STRING,
 
591
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
592
    MYSQL_TYPE_STRING,      MYSQL_TYPE_STRING,
 
593
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
594
    MYSQL_TYPE_STRING,      MYSQL_TYPE_STRING,
 
595
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
596
    MYSQL_TYPE_STRING,      MYSQL_TYPE_VARCHAR,
 
597
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
598
    MYSQL_TYPE_STRING,      MYSQL_TYPE_STRING,
 
599
  //MYSQL_TYPE_SET
 
600
    MYSQL_TYPE_STRING,
 
601
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
602
    MYSQL_TYPE_BLOB,        MYSQL_TYPE_VARCHAR,
 
603
  //MYSQL_TYPE_STRING
 
604
    MYSQL_TYPE_STRING
 
605
  }
564
606
};
565
607
 
566
 
static Item_result field_types_result_type [enum_field_types_size]=
567
 
{
568
 
  //DRIZZLE_TYPE_LONG
569
 
  INT_RESULT,
570
 
  //DRIZZLE_TYPE_DOUBLE
 
608
/**
 
609
  Return type of which can carry value of both given types in UNION result.
 
610
 
 
611
  @param a  type for merging
 
612
  @param b  type for merging
 
613
 
 
614
  @return
 
615
    type of field
 
616
*/
 
617
 
 
618
enum_field_types Field::field_type_merge(enum_field_types a,
 
619
                                         enum_field_types b)
 
620
{
 
621
  assert(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
 
622
  assert(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
 
623
  return field_types_merge_rules[field_type2index(a)]
 
624
                                [field_type2index(b)];
 
625
}
 
626
 
 
627
 
 
628
static Item_result field_types_result_type [FIELDTYPE_NUM]=
 
629
{
 
630
  //MYSQL_TYPE_DECIMAL      MYSQL_TYPE_TINY
 
631
  DECIMAL_RESULT,           INT_RESULT,
 
632
  //MYSQL_TYPE_SHORT        MYSQL_TYPE_LONG
 
633
  INT_RESULT,               INT_RESULT,
 
634
  //MYSQL_TYPE_DOUBLE
571
635
  REAL_RESULT,
572
 
  //DRIZZLE_TYPE_NULL
573
 
  STRING_RESULT,
574
 
  //DRIZZLE_TYPE_TIMESTAMP
575
 
  STRING_RESULT,
576
 
  //DRIZZLE_TYPE_LONGLONG
 
636
  //MYSQL_TYPE_NULL         MYSQL_TYPE_TIMESTAMP
 
637
  STRING_RESULT,            STRING_RESULT,
 
638
  //MYSQL_TYPE_LONGLONG
577
639
  INT_RESULT,
578
 
  //DRIZZLE_TYPE_DATETIME
579
 
  STRING_RESULT,
580
 
  //DRIZZLE_TYPE_DATE
581
 
  STRING_RESULT,
582
 
  //DRIZZLE_TYPE_VARCHAR
583
 
  STRING_RESULT,
584
 
  //DRIZZLE_TYPE_DECIMAL   
585
 
  DECIMAL_RESULT,           
586
 
  //DRIZZLE_TYPE_ENUM
587
 
  STRING_RESULT,
588
 
  //DRIZZLE_TYPE_BLOB
589
 
  STRING_RESULT,
590
 
  //DRIZZLE_TYPE_TIME
591
 
  STRING_RESULT,
592
 
  //DRIZZLE_TYPE_BOOLEAN
593
 
  STRING_RESULT,
594
 
  //DRIZZLE_TYPE_UUID
595
 
  STRING_RESULT,
596
 
  //DRIZZLE_TYPE_MICROTIME
597
 
  STRING_RESULT,
 
640
  //MYSQL_TYPE_DATE         MYSQL_TYPE_TIME
 
641
  STRING_RESULT,            STRING_RESULT,
 
642
  //MYSQL_TYPE_DATETIME     MYSQL_TYPE_YEAR
 
643
  STRING_RESULT,            INT_RESULT,
 
644
  //MYSQL_TYPE_NEWDATE      MYSQL_TYPE_VARCHAR
 
645
  STRING_RESULT,            STRING_RESULT,
 
646
  //MYSQL_TYPE_NEWDECIMAL   MYSQL_TYPE_ENUM
 
647
  DECIMAL_RESULT,           STRING_RESULT,
 
648
  //MYSQL_TYPE_SET
 
649
  STRING_RESULT,
 
650
  //MYSQL_TYPE_BLOB         MYSQL_TYPE_VAR_STRING
 
651
  STRING_RESULT,            STRING_RESULT,
 
652
  //MYSQL_TYPE_STRING
 
653
  STRING_RESULT
598
654
};
599
655
 
600
 
bool test_if_important_data(const CHARSET_INFO * const cs, 
601
 
                            const char *str,
602
 
                            const char *strend)
 
656
 
 
657
/*
 
658
  Test if the given string contains important data:
 
659
  not spaces for character string,
 
660
  or any data for binary string.
 
661
 
 
662
  SYNOPSIS
 
663
    test_if_important_data()
 
664
    cs          Character set
 
665
    str         String to test
 
666
    strend      String end
 
667
 
 
668
  RETURN
 
669
    false - If string does not have important data
 
670
    true  - If string has some important data
 
671
*/
 
672
 
 
673
static bool
 
674
test_if_important_data(CHARSET_INFO *cs, const char *str, const char *strend)
603
675
{
604
676
  if (cs != &my_charset_bin)
605
677
    str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
606
678
  return (str < strend);
607
679
}
608
680
 
609
 
void *Field::operator new(size_t size)
610
 
{
611
 
  return memory::sql_alloc(size);
612
 
}
613
 
 
614
 
void *Field::operator new(size_t size, memory::Root *mem_root)
615
 
{
616
 
  return mem_root->alloc_root(static_cast<uint32_t>(size));
617
 
}
618
 
 
619
 
enum_field_types Field::field_type_merge(enum_field_types a,
620
 
                                         enum_field_types b)
621
 
{
622
 
  assert(a < enum_field_types_size);
623
 
  assert(b < enum_field_types_size);
624
 
  return field_types_merge_rules[a][b];
625
 
}
 
681
 
 
682
/**
 
683
  Detect Item_result by given field type of UNION merge result.
 
684
 
 
685
  @param field_type  given field type
 
686
 
 
687
  @return
 
688
    Item_result (type of internal MySQL expression result)
 
689
*/
626
690
 
627
691
Item_result Field::result_merge_type(enum_field_types field_type)
628
692
{
629
 
  assert(field_type < enum_field_types_size);
630
 
  return field_types_result_type[field_type];
631
 
}
632
 
 
633
 
bool Field::eq(Field *field)
634
 
{
635
 
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
636
 
          null_bit == field->null_bit);
637
 
}
638
 
 
639
 
uint32_t Field::pack_length() const
640
 
{
641
 
  return field_length;
642
 
}
643
 
 
644
 
uint32_t Field::pack_length_in_rec() const
645
 
{
646
 
  return pack_length();
647
 
}
648
 
 
649
 
uint32_t Field::data_length()
650
 
{
651
 
  return pack_length();
652
 
}
653
 
 
654
 
uint32_t Field::used_length()
655
 
{
656
 
  return pack_length();
657
 
}
658
 
 
659
 
uint32_t Field::sort_length() const
660
 
{
661
 
  return pack_length();
662
 
}
663
 
 
664
 
uint32_t Field::max_data_length() const
665
 
{
666
 
  return pack_length();
667
 
}
668
 
 
669
 
int Field::reset(void)
670
 
{
671
 
  memset(ptr, 0, pack_length());
672
 
  return 0;
673
 
}
674
 
 
675
 
void Field::reset_fields()
676
 
{}
677
 
 
678
 
void Field::set_default()
679
 
{
680
 
  ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->getInsertRecord());
681
 
  memcpy(ptr, ptr + l_offset, pack_length());
682
 
  if (null_ptr)
683
 
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
684
 
 
685
 
  if (this == table->next_number_field)
686
 
    table->auto_increment_field_not_null= false;
687
 
}
688
 
 
689
 
bool Field::binary() const
690
 
{
691
 
  return true;
692
 
}
693
 
 
694
 
bool Field::zero_pack() const
695
 
{
696
 
  return true;
697
 
}
698
 
 
699
 
enum ha_base_keytype Field::key_type() const
700
 
{
701
 
  return HA_KEYTYPE_BINARY;
702
 
}
703
 
 
704
 
uint32_t Field::key_length() const
705
 
{
706
 
  return pack_length();
707
 
}
708
 
 
709
 
enum_field_types Field::real_type() const
710
 
{
711
 
  return type();
712
 
}
713
 
 
714
 
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
715
 
{
716
 
  return cmp(a, b);
717
 
}
718
 
 
719
 
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
720
 
{
721
 
  return memcmp(a,b,pack_length());
722
 
}
723
 
 
724
 
int Field::cmp_offset(uint32_t row_offset)
725
 
{
726
 
  return cmp(ptr,ptr+row_offset);
727
 
}
728
 
 
729
 
int Field::cmp_binary_offset(uint32_t row_offset)
730
 
{
731
 
  return cmp_binary(ptr, ptr+row_offset);
732
 
}
733
 
 
734
 
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
735
 
{
736
 
  return cmp(a, b);
737
 
}
738
 
 
739
 
int Field::key_cmp(const unsigned char *str, uint32_t)
740
 
{
741
 
  return cmp(ptr,str);
742
 
}
743
 
 
744
 
uint32_t Field::decimals() const
745
 
{
746
 
  return 0;
747
 
}
748
 
 
749
 
bool Field::is_null(ptrdiff_t row_offset) const
750
 
{
751
 
  return null_ptr ?
752
 
    (null_ptr[row_offset] & null_bit ? true : false) :
753
 
    table->null_row;
754
 
}
755
 
 
756
 
bool Field::is_real_null(ptrdiff_t row_offset) const
757
 
{
758
 
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
759
 
}
760
 
 
761
 
bool Field::is_null_in_record(const unsigned char *record) const
762
 
{
763
 
  if (! null_ptr)
764
 
    return false;
765
 
  return test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
766
 
}
767
 
 
768
 
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset) const
769
 
{
770
 
  if (! null_ptr)
771
 
    return false;
772
 
  return test(null_ptr[with_offset] & null_bit);
773
 
}
774
 
 
775
 
void Field::set_null(ptrdiff_t row_offset)
776
 
{
777
 
  if (null_ptr)
778
 
    null_ptr[row_offset]|= null_bit;
779
 
}
780
 
 
781
 
void Field::set_notnull(ptrdiff_t row_offset)
782
 
{
783
 
  if (null_ptr)
784
 
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
785
 
}
786
 
 
787
 
bool Field::maybe_null(void) const
788
 
{
789
 
  return null_ptr != 0 || table->maybe_null;
790
 
}
791
 
 
792
 
bool Field::real_maybe_null(void) const
793
 
{
794
 
  return null_ptr != 0;
795
 
}
 
693
  assert(field_type < FIELDTYPE_TEAR_FROM || field_type
 
694
              > FIELDTYPE_TEAR_TO);
 
695
  return field_types_result_type[field_type2index(field_type)];
 
696
}
 
697
 
 
698
/*****************************************************************************
 
699
  Static help functions
 
700
*****************************************************************************/
 
701
 
 
702
 
 
703
/**
 
704
  Check whether a field type can be partially indexed by a key.
 
705
 
 
706
  This is a static method, rather than a virtual function, because we need
 
707
  to check the type of a non-Field in mysql_alter_table().
 
708
 
 
709
  @param type  field type
 
710
 
 
711
  @retval
 
712
    true  Type can have a prefixed key
 
713
  @retval
 
714
    false Type can not have a prefixed key
 
715
*/
796
716
 
797
717
bool Field::type_can_have_key_part(enum enum_field_types type)
798
718
{
799
719
  switch (type) {
800
 
  case DRIZZLE_TYPE_VARCHAR:
801
 
  case DRIZZLE_TYPE_BLOB:
 
720
  case MYSQL_TYPE_VARCHAR:
 
721
  case MYSQL_TYPE_BLOB:
 
722
  case MYSQL_TYPE_VAR_STRING:
 
723
  case MYSQL_TYPE_STRING:
802
724
    return true;
803
725
  default:
804
726
    return false;
805
727
  }
806
728
}
807
729
 
 
730
 
 
731
/**
 
732
  Numeric fields base class constructor.
 
733
*/
 
734
Field_num::Field_num(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
 
735
                     uchar null_bit_arg, utype unireg_check_arg,
 
736
                     const char *field_name_arg,
 
737
                     uint8 dec_arg, bool zero_arg, bool unsigned_arg)
 
738
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
739
         unireg_check_arg, field_name_arg),
 
740
  dec(dec_arg),zerofill(zero_arg),unsigned_flag(unsigned_arg)
 
741
{
 
742
  if (zerofill)
 
743
    flags|=ZEROFILL_FLAG;
 
744
  if (unsigned_flag)
 
745
    flags|=UNSIGNED_FLAG;
 
746
}
 
747
 
 
748
 
 
749
void Field_num::prepend_zeros(String *value)
 
750
{
 
751
  int diff;
 
752
  if ((diff= (int) (field_length - value->length())) > 0)
 
753
  {
 
754
    bmove_upp((uchar*) value->ptr()+field_length,
 
755
              (uchar*) value->ptr()+value->length(),
 
756
              value->length());
 
757
    bfill((uchar*) value->ptr(),diff,'0');
 
758
    value->length(field_length);
 
759
    (void) value->c_ptr_quick();                // Avoid warnings in purify
 
760
  }
 
761
}
 
762
 
 
763
/**
 
764
  Test if given number is a int.
 
765
 
 
766
  @todo
 
767
    Make this multi-byte-character safe
 
768
 
 
769
  @param str            String to test
 
770
  @param length        Length of 'str'
 
771
  @param int_end        Pointer to char after last used digit
 
772
  @param cs             Character set
 
773
 
 
774
  @note
 
775
    This is called after one has called strntoull10rnd() function.
 
776
 
 
777
  @retval
 
778
    0   OK
 
779
  @retval
 
780
    1   error: empty string or wrong integer.
 
781
  @retval
 
782
    2   error: garbage at the end of string.
 
783
*/
 
784
 
 
785
int Field_num::check_int(CHARSET_INFO *cs, const char *str, int length, 
 
786
                         const char *int_end, int error)
 
787
{
 
788
  /* Test if we get an empty string or wrong integer */
 
789
  if (str == int_end || error == MY_ERRNO_EDOM)
 
790
  {
 
791
    char buff[128];
 
792
    String tmp(buff, (uint32) sizeof(buff), system_charset_info);
 
793
    tmp.copy(str, length, system_charset_info);
 
794
    push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
 
795
                        ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, 
 
796
                        ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
 
797
                        "integer", tmp.c_ptr(), field_name,
 
798
                        (ulong) table->in_use->row_count);
 
799
    return 1;
 
800
  }
 
801
  /* Test if we have garbage at the end of the given string. */
 
802
  if (test_if_important_data(cs, int_end, str + length))
 
803
  {
 
804
    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
 
805
    return 2;
 
806
  }
 
807
  return 0;
 
808
}
 
809
 
 
810
 
 
811
/*
 
812
  Conver a string to an integer then check bounds.
 
813
  
 
814
  SYNOPSIS
 
815
    Field_num::get_int
 
816
    cs            Character set
 
817
    from          String to convert
 
818
    len           Length of the string
 
819
    rnd           OUT int64_t value
 
820
    unsigned_max  max unsigned value
 
821
    signed_min    min signed value
 
822
    signed_max    max signed value
 
823
 
 
824
  DESCRIPTION
 
825
    The function calls strntoull10rnd() to get an integer value then
 
826
    check bounds and errors returned. In case of any error a warning
 
827
    is raised.
 
828
 
 
829
  RETURN
 
830
    0   ok
 
831
    1   error
 
832
*/
 
833
 
 
834
bool Field_num::get_int(CHARSET_INFO *cs, const char *from, uint len,
 
835
                        int64_t *rnd, uint64_t unsigned_max, 
 
836
                        int64_t signed_min, int64_t signed_max)
 
837
{
 
838
  char *end;
 
839
  int error;
 
840
  
 
841
  *rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len,
 
842
                                            unsigned_flag, &end,
 
843
                                            &error);
 
844
  if (unsigned_flag)
 
845
  {
 
846
 
 
847
    if ((((uint64_t) *rnd > unsigned_max) && (*rnd= (int64_t) unsigned_max)) ||
 
848
        error == MY_ERRNO_ERANGE)
 
849
    {
 
850
      goto out_of_range;
 
851
    }
 
852
  }
 
853
  else
 
854
  {
 
855
    if (*rnd < signed_min)
 
856
    {
 
857
      *rnd= signed_min;
 
858
      goto out_of_range;
 
859
    }
 
860
    else if (*rnd > signed_max)
 
861
    {
 
862
      *rnd= signed_max;
 
863
      goto out_of_range;
 
864
    }
 
865
  }
 
866
  if (table->in_use->count_cuted_fields &&
 
867
      check_int(cs, from, len, end, error))
 
868
    return 1;
 
869
  return 0;
 
870
 
 
871
out_of_range:
 
872
  set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
873
  return 1;
 
874
}
 
875
 
 
876
/**
 
877
  Process decimal library return codes and issue warnings for overflow and
 
878
  truncation.
 
879
 
 
880
  @param op_result  decimal library return code (E_DEC_* see include/decimal.h)
 
881
 
 
882
  @retval
 
883
    1  there was overflow
 
884
  @retval
 
885
    0  no error or some other errors except overflow
 
886
*/
 
887
 
808
888
int Field::warn_if_overflow(int op_result)
809
889
{
810
890
  if (op_result == E_DEC_OVERFLOW)
811
891
  {
812
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
813
 
    return E_DEC_OVERFLOW;
 
892
    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
893
    return 1;
814
894
  }
815
895
  if (op_result == E_DEC_TRUNCATED)
816
896
  {
817
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
818
 
    return E_DEC_TRUNCATED;
 
897
    set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
 
898
    /* We return 0 here as this is not a critical issue */
819
899
  }
820
900
  return 0;
821
901
}
822
902
 
823
 
void Field::init(Table *table_arg)
824
 
{
825
 
  orig_table= table= table_arg;
826
 
}
 
903
 
 
904
#ifdef NOT_USED
 
905
static bool test_if_real(const char *str,int length, CHARSET_INFO *cs)
 
906
{
 
907
  cs= system_charset_info; // QQ move test_if_real into CHARSET_INFO struct
 
908
 
 
909
  while (length && my_isspace(cs,*str))
 
910
  {                                             // Allow start space
 
911
    length--; str++;
 
912
  }
 
913
  if (!length)
 
914
    return 0;
 
915
  if (*str == '+' || *str == '-')
 
916
  {
 
917
    length--; str++;
 
918
    if (!length || !(my_isdigit(cs,*str) || *str == '.'))
 
919
      return 0;
 
920
  }
 
921
  while (length && my_isdigit(cs,*str))
 
922
  {
 
923
    length--; str++;
 
924
  }
 
925
  if (!length)
 
926
    return 1;
 
927
  if (*str == '.')
 
928
  {
 
929
    length--; str++;
 
930
    while (length && my_isdigit(cs,*str))
 
931
    {
 
932
      length--; str++;
 
933
    }
 
934
  }
 
935
  if (!length)
 
936
    return 1;
 
937
  if (*str == 'E' || *str == 'e')
 
938
  {
 
939
    if (length < 3 || (str[1] != '+' && str[1] != '-') || 
 
940
        !my_isdigit(cs,str[2]))
 
941
      return 0;
 
942
    length-=3;
 
943
    str+=3;
 
944
    while (length && my_isdigit(cs,*str))
 
945
    {
 
946
      length--; str++;
 
947
    }
 
948
  }
 
949
  for (; length ; length--, str++)
 
950
  {                                             // Allow end space
 
951
    if (!my_isspace(cs,*str))
 
952
      return 0;
 
953
  }
 
954
  return 1;
 
955
}
 
956
#endif
 
957
 
 
958
 
 
959
/**
 
960
  Interpret field value as an integer but return the result as a string.
 
961
 
 
962
  This is used for printing bit_fields as numbers while debugging.
 
963
*/
 
964
 
 
965
String *Field::val_int_as_str(String *val_buffer, my_bool unsigned_val)
 
966
{
 
967
  CHARSET_INFO *cs= &my_charset_bin;
 
968
  uint length;
 
969
  int64_t value= val_int();
 
970
 
 
971
  if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
 
972
    return 0;
 
973
  length= (uint) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
 
974
                                                MY_INT64_NUM_DECIMAL_DIGITS,
 
975
                                                unsigned_val ? 10 : -10,
 
976
                                                value);
 
977
  val_buffer->length(length);
 
978
  return val_buffer;
 
979
}
 
980
 
827
981
 
828
982
/// This is used as a table name when the table structure is not set up
829
 
Field::Field(unsigned char *ptr_arg,
830
 
             uint32_t length_arg,
831
 
             unsigned char *null_ptr_arg,
832
 
             unsigned char null_bit_arg,
833
 
             utype unireg_check_arg, 
834
 
             const char *field_name_arg) :
835
 
    ptr(ptr_arg),
836
 
    null_ptr(null_ptr_arg),
837
 
    table(NULL),
838
 
    orig_table(NULL),
839
 
    field_name(field_name_arg),
840
 
    comment(NULL_LEX_STRING),
841
 
    key_start(0),
842
 
    part_of_key(0),
843
 
    part_of_key_not_clustered(0),
844
 
    part_of_sortkey(0),
845
 
    unireg_check(unireg_check_arg),
846
 
    field_length(length_arg),
847
 
    flags(null_ptr ? 0: NOT_NULL_FLAG),
848
 
    field_index(0),
849
 
    null_bit(null_bit_arg),
850
 
    is_created_from_null_item(false)
 
983
Field::Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
 
984
             uchar null_bit_arg,
 
985
             utype unireg_check_arg, const char *field_name_arg)
 
986
  :ptr(ptr_arg), null_ptr(null_ptr_arg),
 
987
   table(0), orig_table(0), table_name(0),
 
988
   field_name(field_name_arg),
 
989
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
 
990
   part_of_sortkey(0), unireg_check(unireg_check_arg),
 
991
   field_length(length_arg), null_bit(null_bit_arg), 
 
992
   is_created_from_null_item(false)
851
993
{
 
994
  flags=null_ptr ? 0: NOT_NULL_FLAG;
 
995
  comment.str= (char*) "";
 
996
  comment.length=0;
 
997
  field_index= 0;
852
998
}
853
999
 
854
 
void Field::hash(uint32_t *nr, uint32_t *nr2) const
 
1000
 
 
1001
void Field::hash(ulong *nr, ulong *nr2)
855
1002
{
856
1003
  if (is_null())
857
1004
  {
859
1006
  }
860
1007
  else
861
1008
  {
862
 
    uint32_t len= pack_length();
863
 
    const CHARSET_INFO * const cs= charset();
 
1009
    uint len= pack_length();
 
1010
    CHARSET_INFO *cs= charset();
864
1011
    cs->coll->hash_sort(cs, ptr, len, nr, nr2);
865
1012
  }
866
1013
}
867
1014
 
 
1015
size_t
 
1016
Field::do_last_null_byte() const
 
1017
{
 
1018
  assert(null_ptr == NULL || null_ptr >= table->record[0]);
 
1019
  if (null_ptr)
 
1020
    return (size_t) (null_ptr - table->record[0]) + 1;
 
1021
  return LAST_NULL_BYTE_UNDEF;
 
1022
}
 
1023
 
 
1024
 
868
1025
void Field::copy_from_tmp(int row_offset)
869
1026
{
870
1027
  memcpy(ptr,ptr+row_offset,pack_length());
871
1028
  if (null_ptr)
872
1029
  {
873
 
    *null_ptr= (unsigned char) ((null_ptr[0] &
874
 
                                 (unsigned char) ~(uint32_t) null_bit) |
875
 
                                (null_ptr[row_offset] &
876
 
                                 (unsigned char) null_bit));
 
1030
    *null_ptr= (uchar) ((null_ptr[0] & (uchar) ~(uint) null_bit) | (null_ptr[row_offset] & (uchar) null_bit));
877
1031
  }
878
1032
}
879
1033
 
880
 
int Field::store_and_check(enum_check_fields check_level,
881
 
                           const char *to, 
882
 
                           uint32_t length,
883
 
                           const CHARSET_INFO * const cs)
884
 
 
 
1034
 
 
1035
bool Field::send_binary(Protocol *protocol)
 
1036
{
 
1037
  char buff[MAX_FIELD_WIDTH];
 
1038
  String tmp(buff,sizeof(buff),charset());
 
1039
  val_str(&tmp);
 
1040
  return protocol->store(tmp.ptr(), tmp.length(), tmp.charset());
 
1041
}
 
1042
 
 
1043
 
 
1044
/**
 
1045
   Check to see if field size is compatible with destination.
 
1046
 
 
1047
   This method is used in row-based replication to verify that the slave's
 
1048
   field size is less than or equal to the master's field size. The 
 
1049
   encoded field metadata (from the master or source) is decoded and compared
 
1050
   to the size of this field (the slave or destination). 
 
1051
 
 
1052
   @param   field_metadata   Encoded size in field metadata
 
1053
 
 
1054
   @retval 0 if this field's size is < the source field's size
 
1055
   @retval 1 if this field's size is >= the source field's size
 
1056
*/
 
1057
int Field::compatible_field_size(uint field_metadata)
 
1058
{
 
1059
  uint const source_size= pack_length_from_metadata(field_metadata);
 
1060
  uint const destination_size= row_pack_length();
 
1061
  return (source_size <= destination_size);
 
1062
}
 
1063
 
 
1064
 
 
1065
int Field::store(const char *to, uint length, CHARSET_INFO *cs,
 
1066
                 enum_check_fields check_level)
885
1067
{
886
1068
  int res;
887
1069
  enum_check_fields old_check_level= table->in_use->count_cuted_fields;
891
1073
  return res;
892
1074
}
893
1075
 
894
 
unsigned char *Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool)
 
1076
 
 
1077
/**
 
1078
   Pack the field into a format suitable for storage and transfer.
 
1079
 
 
1080
   To implement packing functionality, only the virtual function
 
1081
   should be overridden. The other functions are just convenience
 
1082
   functions and hence should not be overridden.
 
1083
 
 
1084
   The value of <code>low_byte_first</code> is dependent on how the
 
1085
   packed data is going to be used: for local use, e.g., temporary
 
1086
   store on disk or in memory, use the native format since that is
 
1087
   faster. For data that is going to be transfered to other machines
 
1088
   (e.g., when writing data to the binary log), data should always be
 
1089
   stored in little-endian format.
 
1090
 
 
1091
   @note The default method for packing fields just copy the raw bytes
 
1092
   of the record into the destination, but never more than
 
1093
   <code>max_length</code> characters.
 
1094
 
 
1095
   @param to
 
1096
   Pointer to memory area where representation of field should be put.
 
1097
 
 
1098
   @param from
 
1099
   Pointer to memory area where record representation of field is
 
1100
   stored.
 
1101
 
 
1102
   @param max_length
 
1103
   Maximum length of the field, as given in the column definition. For
 
1104
   example, for <code>CHAR(1000)</code>, the <code>max_length</code>
 
1105
   is 1000. This information is sometimes needed to decide how to pack
 
1106
   the data.
 
1107
 
 
1108
   @param low_byte_first
 
1109
   @c true if integers should be stored little-endian, @c false if
 
1110
   native format should be used. Note that for little-endian machines,
 
1111
   the value of this flag is a moot point since the native format is
 
1112
   little-endian.
 
1113
*/
 
1114
uchar *
 
1115
Field::pack(uchar *to, const uchar *from, uint max_length,
 
1116
            bool low_byte_first __attribute__((unused)))
895
1117
{
896
 
  uint32_t length= pack_length();
 
1118
  uint32 length= pack_length();
897
1119
  set_if_smaller(length, max_length);
898
1120
  memcpy(to, from, length);
899
1121
  return to+length;
900
1122
}
901
1123
 
902
 
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
903
 
{
904
 
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->getShare()->db_low_byte_first);
905
 
  return(result);
906
 
}
907
 
 
908
 
const unsigned char *Field::unpack(unsigned char* to,
909
 
                                   const unsigned char *from, 
910
 
                                   uint32_t param_data,
911
 
                                   bool)
912
 
{
913
 
  uint32_t length=pack_length();
 
1124
/**
 
1125
   Unpack a field from row data.
 
1126
 
 
1127
   This method is used to unpack a field from a master whose size of
 
1128
   the field is less than that of the slave.
 
1129
 
 
1130
   The <code>param_data</code> parameter is a two-byte integer (stored
 
1131
   in the least significant 16 bits of the unsigned integer) usually
 
1132
   consisting of two parts: the real type in the most significant byte
 
1133
   and a original pack length in the least significant byte.
 
1134
 
 
1135
   The exact layout of the <code>param_data</code> field is given by
 
1136
   the <code>Table_map_log_event::save_field_metadata()</code>.
 
1137
 
 
1138
   This is the default method for unpacking a field. It just copies
 
1139
   the memory block in byte order (of original pack length bytes or
 
1140
   length of field, whichever is smaller).
 
1141
 
 
1142
   @param   to         Destination of the data
 
1143
   @param   from       Source of the data
 
1144
   @param   param_data Real type and original pack length of the field
 
1145
                       data
 
1146
 
 
1147
   @param low_byte_first
 
1148
   If this flag is @c true, all composite entities (e.g., lengths)
 
1149
   should be unpacked in little-endian format; otherwise, the entities
 
1150
   are unpacked in native order.
 
1151
 
 
1152
   @return  New pointer into memory based on from + length of the data
 
1153
*/
 
1154
const uchar *
 
1155
Field::unpack(uchar* to, const uchar *from, uint param_data,
 
1156
              bool low_byte_first __attribute__((unused)))
 
1157
{
 
1158
  uint length=pack_length();
914
1159
  int from_type= 0;
915
1160
  /*
916
1161
    If from length is > 255, it has encoded data in the upper bits. Need
930
1175
    return from+length;
931
1176
  }
932
1177
 
933
 
  uint32_t len= (param_data && (param_data < length)) ?
 
1178
  uint len= (param_data && (param_data < length)) ?
934
1179
            param_data : length;
935
1180
 
936
1181
  memcpy(to, from, param_data > length ? length : len);
937
 
  return (from + len);
938
 
}
939
 
 
940
 
const unsigned char *Field::unpack(unsigned char* to, const unsigned char *from)
941
 
{
942
 
  const unsigned char *result= unpack(to, from, 0U, table->getShare()->db_low_byte_first);
943
 
  return(result);
944
 
}
945
 
 
946
 
type::Decimal *Field::val_decimal(type::Decimal *) const
 
1182
  return from+len;
 
1183
}
 
1184
 
 
1185
 
 
1186
my_decimal *Field::val_decimal(my_decimal *decimal __attribute__((__unused__)))
947
1187
{
948
1188
  /* This never have to be called */
949
1189
  assert(0);
951
1191
}
952
1192
 
953
1193
 
954
 
void Field::make_field(SendField *field)
955
 
{
956
 
  if (orig_table && orig_table->getShare()->getSchemaName() && *orig_table->getShare()->getSchemaName())
 
1194
void Field_num::add_zerofill_and_unsigned(String &res) const
 
1195
{
 
1196
  if (unsigned_flag)
 
1197
    res.append(STRING_WITH_LEN(" unsigned"));
 
1198
  if (zerofill)
 
1199
    res.append(STRING_WITH_LEN(" zerofill"));
 
1200
}
 
1201
 
 
1202
 
 
1203
void Field::make_field(Send_field *field)
 
1204
{
 
1205
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
957
1206
  {
958
 
    field->db_name= orig_table->getShare()->getSchemaName();
959
 
    field->org_table_name= orig_table->getShare()->getTableName();
 
1207
    field->db_name= orig_table->s->db.str;
 
1208
    field->org_table_name= orig_table->s->table_name.str;
960
1209
  }
961
1210
  else
962
1211
    field->org_table_name= field->db_name= "";
963
1212
  if (orig_table)
964
1213
  {
965
 
    field->table_name= orig_table->getAlias();
 
1214
    field->table_name= orig_table->alias;
966
1215
    field->org_col_name= field_name;
967
1216
  }
968
1217
  else
972
1221
  }
973
1222
  field->col_name= field_name;
974
1223
  field->charsetnr= charset()->number;
975
 
  field->length= field_length;
976
 
  field->type= type();
977
 
  field->flags= table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
 
1224
  field->length=field_length;
 
1225
  field->type=type();
 
1226
  field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
978
1227
  field->decimals= 0;
979
1228
}
980
1229
 
981
 
int64_t Field::convert_decimal2int64_t(const type::Decimal *val, bool, int *err)
 
1230
 
 
1231
/**
 
1232
  Conversion from decimal to int64_t with checking overflow and
 
1233
  setting correct value (min/max) in case of overflow.
 
1234
 
 
1235
  @param val             value which have to be converted
 
1236
  @param unsigned_flag   type of integer in which we convert val
 
1237
  @param err             variable to pass error code
 
1238
 
 
1239
  @return
 
1240
    value converted from val
 
1241
*/
 
1242
int64_t Field::convert_decimal2int64_t(const my_decimal *val,
 
1243
                                         bool unsigned_flag, int *err)
982
1244
{
983
1245
  int64_t i;
984
 
  if (warn_if_overflow(val->val_int32(E_DEC_ERROR &
985
 
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
986
 
                                      false, &i)))
 
1246
  if (unsigned_flag)
 
1247
  {
 
1248
    if (val->sign())
 
1249
    {
 
1250
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1251
      i= 0;
 
1252
      *err= 1;
 
1253
    }
 
1254
    else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
1255
                                           ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
 
1256
                                           val, true, &i)))
 
1257
    {
 
1258
      i= ~(int64_t) 0;
 
1259
      *err= 1;
 
1260
    }
 
1261
  }
 
1262
  else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
1263
                                         ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
 
1264
                                         val, false, &i)))
987
1265
  {
988
1266
    i= (val->sign() ? INT64_MIN : INT64_MAX);
989
1267
    *err= 1;
991
1269
  return i;
992
1270
}
993
1271
 
994
 
uint32_t Field::fill_cache_field(CacheField *copy)
995
 
{
996
 
  uint32_t store_length;
 
1272
 
 
1273
/**
 
1274
  Storing decimal in integer fields.
 
1275
 
 
1276
  @param val       value for storing
 
1277
 
 
1278
  @note
 
1279
    This method is used by all integer fields, real/decimal redefine it
 
1280
 
 
1281
  @retval
 
1282
    0     OK
 
1283
  @retval
 
1284
    !=0  error
 
1285
*/
 
1286
 
 
1287
int Field_num::store_decimal(const my_decimal *val)
 
1288
{
 
1289
  int err= 0;
 
1290
  int64_t i= convert_decimal2int64_t(val, unsigned_flag, &err);
 
1291
  return test(err | store(i, unsigned_flag));
 
1292
}
 
1293
 
 
1294
 
 
1295
/**
 
1296
  Return decimal value of integer field.
 
1297
 
 
1298
  @param decimal_value     buffer for storing decimal value
 
1299
 
 
1300
  @note
 
1301
    This method is used by all integer fields, real/decimal redefine it.
 
1302
    All int64_t values fit in our decimal buffer which cal store 8*9=72
 
1303
    digits of integer number
 
1304
 
 
1305
  @return
 
1306
    pointer to decimal buffer with value of field
 
1307
*/
 
1308
 
 
1309
my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
 
1310
{
 
1311
  assert(result_type() == INT_RESULT);
 
1312
  int64_t nr= val_int();
 
1313
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
 
1314
  return decimal_value;
 
1315
}
 
1316
 
 
1317
 
 
1318
Field_str::Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
 
1319
                     uchar null_bit_arg, utype unireg_check_arg,
 
1320
                     const char *field_name_arg, CHARSET_INFO *charset_arg)
 
1321
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 
1322
         unireg_check_arg, field_name_arg)
 
1323
{
 
1324
  field_charset= charset_arg;
 
1325
  if (charset_arg->state & MY_CS_BINSORT)
 
1326
    flags|=BINARY_FLAG;
 
1327
  field_derivation= DERIVATION_IMPLICIT;
 
1328
}
 
1329
 
 
1330
 
 
1331
void Field_num::make_field(Send_field *field)
 
1332
{
 
1333
  Field::make_field(field);
 
1334
  field->decimals= dec;
 
1335
}
 
1336
 
 
1337
/**
 
1338
  Decimal representation of Field_str.
 
1339
 
 
1340
  @param d         value for storing
 
1341
 
 
1342
  @note
 
1343
    Field_str is the base class for fields like Field_enum,
 
1344
    Field_date and some similar. Some dates use fraction and also
 
1345
    string value should be converted to floating point value according
 
1346
    our rules, so we use double to store value of decimal in string.
 
1347
 
 
1348
  @todo
 
1349
    use decimal2string?
 
1350
 
 
1351
  @retval
 
1352
    0     OK
 
1353
  @retval
 
1354
    !=0  error
 
1355
*/
 
1356
 
 
1357
int Field_str::store_decimal(const my_decimal *d)
 
1358
{
 
1359
  double val;
 
1360
  /* TODO: use decimal2string? */
 
1361
  int err= warn_if_overflow(my_decimal2double(E_DEC_FATAL_ERROR &
 
1362
                                            ~E_DEC_OVERFLOW, d, &val));
 
1363
  return err | store(val);
 
1364
}
 
1365
 
 
1366
 
 
1367
my_decimal *Field_str::val_decimal(my_decimal *decimal_value)
 
1368
{
 
1369
  int64_t nr= val_int();
 
1370
  int2my_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value);
 
1371
  return decimal_value;
 
1372
}
 
1373
 
 
1374
 
 
1375
uint Field::fill_cache_field(CACHE_FIELD *copy)
 
1376
{
 
1377
  uint store_length;
997
1378
  copy->str=ptr;
998
1379
  copy->length=pack_length();
999
1380
  copy->blob_field=0;
1001
1382
  {
1002
1383
    copy->blob_field=(Field_blob*) this;
1003
1384
    copy->strip=0;
1004
 
    copy->length-= table->getShare()->sizeBlobPtr();
 
1385
    copy->length-= table->s->blob_ptr_size;
1005
1386
    return copy->length;
1006
1387
  }
 
1388
  else if (!zero_pack() &&
 
1389
           (type() == MYSQL_TYPE_STRING && copy->length >= 4 &&
 
1390
            copy->length < 256))
 
1391
  {
 
1392
    copy->strip=1;                              /* Remove end space */
 
1393
    store_length= 2;
 
1394
  }
1007
1395
  else
1008
1396
  {
1009
1397
    copy->strip=0;
1012
1400
  return copy->length+ store_length;
1013
1401
}
1014
1402
 
1015
 
bool Field::get_date(type::Time &ltime, uint32_t fuzzydate) const
1016
 
{
1017
 
  char buff[type::Time::MAX_STRING_LENGTH];
1018
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1019
 
 
1020
 
  assert(getTable() and getTable()->getSession());
1021
 
 
1022
 
  if (not (res= val_str_internal(&tmp)) or
1023
 
      str_to_datetime_with_warn(getTable()->getSession(),
1024
 
                                res->ptr(), res->length(),
1025
 
                                &ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
1026
 
  {
1027
 
    return true;
1028
 
  }
1029
 
 
1030
 
  return false;
1031
 
}
1032
 
 
1033
 
bool Field::get_time(type::Time &ltime) const
1034
 
{
1035
 
  char buff[type::Time::MAX_STRING_LENGTH];
1036
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1037
 
 
1038
 
  if (not (res= val_str_internal(&tmp)) or
1039
 
      str_to_time_with_warn(getTable()->getSession(), res->ptr(), res->length(), &ltime))
1040
 
  {
1041
 
    return true;
1042
 
  }
1043
 
 
1044
 
  return false;
1045
 
}
1046
 
 
1047
 
int Field::store_time(type::Time &ltime, type::timestamp_t)
1048
 
{
1049
 
  String tmp;
1050
 
 
1051
 
  ltime.convert(tmp);
1052
 
 
1053
 
  return store(tmp.ptr(), tmp.length(), &my_charset_bin);
1054
 
}
1055
 
 
1056
 
bool Field::optimize_range(uint32_t idx, uint32_t)
1057
 
{
1058
 
  return test(table->index_flags(idx) & HA_READ_RANGE);
1059
 
}
1060
 
 
1061
 
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
 
1403
 
 
1404
bool Field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
 
1405
{
 
1406
  char buff[40];
 
1407
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
 
1408
  if (!(res=val_str(&tmp)) ||
 
1409
      str_to_datetime_with_warn(res->ptr(), res->length(),
 
1410
                                ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
 
1411
    return 1;
 
1412
  return 0;
 
1413
}
 
1414
 
 
1415
bool Field::get_time(MYSQL_TIME *ltime)
 
1416
{
 
1417
  char buff[40];
 
1418
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
 
1419
  if (!(res=val_str(&tmp)) ||
 
1420
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
 
1421
    return 1;
 
1422
  return 0;
 
1423
}
 
1424
 
 
1425
/**
 
1426
  This is called when storing a date in a string.
 
1427
 
 
1428
  @note
 
1429
    Needs to be changed if/when we want to support different time formats.
 
1430
*/
 
1431
 
 
1432
int Field::store_time(MYSQL_TIME *ltime,
 
1433
                      timestamp_type type_arg __attribute__((__unused__)))
 
1434
{
 
1435
  char buff[MAX_DATE_STRING_REP_LENGTH];
 
1436
  uint length= (uint) my_TIME_to_str(ltime, buff);
 
1437
  return store(buff, length, &my_charset_bin);
 
1438
}
 
1439
 
 
1440
 
 
1441
bool Field::optimize_range(uint idx, uint part)
 
1442
{
 
1443
  return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
 
1444
}
 
1445
 
 
1446
 
 
1447
Field *Field::new_field(MEM_ROOT *root, struct st_table *new_table,
 
1448
                        bool keep_type __attribute__((unused)))
1062
1449
{
1063
1450
  Field *tmp;
1064
 
  if (!(tmp= (Field*) root->memdup_root((char*) this,size_of())))
 
1451
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1065
1452
    return 0;
1066
1453
 
1067
1454
  if (tmp->table->maybe_null)
1068
1455
    tmp->flags&= ~NOT_NULL_FLAG;
1069
1456
  tmp->table= new_table;
1070
 
  tmp->key_start.reset();
1071
 
  tmp->part_of_key.reset();
1072
 
  tmp->part_of_sortkey.reset();
 
1457
  tmp->key_start.init(0);
 
1458
  tmp->part_of_key.init(0);
 
1459
  tmp->part_of_sortkey.init(0);
1073
1460
  tmp->unireg_check= Field::NONE;
1074
 
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
 
1461
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG |
 
1462
                ZEROFILL_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
1075
1463
  tmp->reset_fields();
1076
1464
  return tmp;
1077
1465
}
1078
1466
 
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)
 
1467
 
 
1468
Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table,
 
1469
                            uchar *new_ptr, uchar *new_null_ptr,
 
1470
                            uint new_null_bit)
1083
1471
{
1084
1472
  Field *tmp;
1085
1473
  if ((tmp= new_field(root, new_table, table == new_table)))
1086
1474
  {
1087
 
    tmp->ptr= new_ptr;
 
1475
    tmp->ptr=      new_ptr;
1088
1476
    tmp->null_ptr= new_null_ptr;
1089
1477
    tmp->null_bit= new_null_bit;
1090
1478
  }
1091
1479
  return tmp;
1092
1480
}
1093
1481
 
1094
 
Field *Field::clone(memory::Root *root, Table *new_table)
 
1482
 
 
1483
/* This is used to generate a field in TABLE from TABLE_SHARE */
 
1484
 
 
1485
Field *Field::clone(MEM_ROOT *root, struct st_table *new_table)
1095
1486
{
1096
1487
  Field *tmp;
1097
 
  if ((tmp= (Field*) root->memdup_root((char*) this,size_of())))
 
1488
  if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1098
1489
  {
1099
1490
    tmp->init(new_table);
1100
 
    tmp->move_field_offset((ptrdiff_t) (new_table->getInsertRecord() -
1101
 
                                           new_table->getDefaultValues()));
 
1491
    tmp->move_field_offset((my_ptrdiff_t) (new_table->record[0] -
 
1492
                                           new_table->s->default_values));
1102
1493
  }
1103
1494
  return tmp;
1104
1495
}
1105
1496
 
1106
1497
 
1107
 
uint32_t Field::is_equal(CreateField *new_field_ptr)
1108
 
{
1109
 
  return (new_field_ptr->sql_type == real_type());
1110
 
}
 
1498
/****************************************************************************
 
1499
** tiny int
 
1500
****************************************************************************/
 
1501
 
 
1502
int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
 
1503
{
 
1504
  int error;
 
1505
  int64_t rnd;
 
1506
  
 
1507
  error= get_int(cs, from, len, &rnd, 255, -128, 127);
 
1508
  ptr[0]= unsigned_flag ? (char) (uint64_t) rnd : (char) rnd;
 
1509
  return error;
 
1510
}
 
1511
 
 
1512
 
 
1513
int Field_tiny::store(double nr)
 
1514
{
 
1515
  int error= 0;
 
1516
  nr=rint(nr);
 
1517
  if (unsigned_flag)
 
1518
  {
 
1519
    if (nr < 0.0)
 
1520
    {
 
1521
      *ptr=0;
 
1522
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1523
      error= 1;
 
1524
    }
 
1525
    else if (nr > 255.0)
 
1526
    {
 
1527
      *ptr=(char) 255;
 
1528
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1529
      error= 1;
 
1530
    }
 
1531
    else
 
1532
      *ptr=(char) nr;
 
1533
  }
 
1534
  else
 
1535
  {
 
1536
    if (nr < -128.0)
 
1537
    {
 
1538
      *ptr= (char) -128;
 
1539
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1540
      error= 1;
 
1541
    }
 
1542
    else if (nr > 127.0)
 
1543
    {
 
1544
      *ptr=127;
 
1545
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1546
      error= 1;
 
1547
    }
 
1548
    else
 
1549
      *ptr=(char) (int) nr;
 
1550
  }
 
1551
  return error;
 
1552
}
 
1553
 
 
1554
 
 
1555
int Field_tiny::store(int64_t nr, bool unsigned_val)
 
1556
{
 
1557
  int error= 0;
 
1558
 
 
1559
  if (unsigned_flag)
 
1560
  {
 
1561
    if (nr < 0 && !unsigned_val)
 
1562
    {
 
1563
      *ptr= 0;
 
1564
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1565
      error= 1;
 
1566
    }
 
1567
    else if ((uint64_t) nr > (uint64_t) 255)
 
1568
    {
 
1569
      *ptr= (char) 255;
 
1570
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1571
      error= 1;
 
1572
    }
 
1573
    else
 
1574
      *ptr=(char) nr;
 
1575
  }
 
1576
  else
 
1577
  {
 
1578
    if (nr < 0 && unsigned_val)
 
1579
      nr= 256;                                    // Generate overflow
 
1580
    if (nr < -128)
 
1581
    {
 
1582
      *ptr= (char) -128;
 
1583
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1584
      error= 1;
 
1585
    }
 
1586
    else if (nr > 127)
 
1587
    {
 
1588
      *ptr=127;
 
1589
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1590
      error= 1;
 
1591
    }
 
1592
    else
 
1593
      *ptr=(char) nr;
 
1594
  }
 
1595
  return error;
 
1596
}
 
1597
 
 
1598
 
 
1599
double Field_tiny::val_real(void)
 
1600
{
 
1601
  int tmp= unsigned_flag ? (int) ptr[0] :
 
1602
    (int) ((signed char*) ptr)[0];
 
1603
  return (double) tmp;
 
1604
}
 
1605
 
 
1606
 
 
1607
int64_t Field_tiny::val_int(void)
 
1608
{
 
1609
  int tmp= unsigned_flag ? (int) ptr[0] :
 
1610
    (int) ((signed char*) ptr)[0];
 
1611
  return (int64_t) tmp;
 
1612
}
 
1613
 
 
1614
 
 
1615
String *Field_tiny::val_str(String *val_buffer,
 
1616
                            String *val_ptr __attribute__((unused)))
 
1617
{
 
1618
  CHARSET_INFO *cs= &my_charset_bin;
 
1619
  uint length;
 
1620
  uint mlength=max(field_length+1,5*cs->mbmaxlen);
 
1621
  val_buffer->alloc(mlength);
 
1622
  char *to=(char*) val_buffer->ptr();
 
1623
 
 
1624
  if (unsigned_flag)
 
1625
    length= (uint) cs->cset->long10_to_str(cs,to,mlength, 10,
 
1626
                                           (long) *ptr);
 
1627
  else
 
1628
    length= (uint) cs->cset->long10_to_str(cs,to,mlength,-10,
 
1629
                                           (long) *((signed char*) ptr));
 
1630
  
 
1631
  val_buffer->length(length);
 
1632
  if (zerofill)
 
1633
    prepend_zeros(val_buffer);
 
1634
  return val_buffer;
 
1635
}
 
1636
 
 
1637
bool Field_tiny::send_binary(Protocol *protocol)
 
1638
{
 
1639
  return protocol->store_tiny((int64_t) (int8) ptr[0]);
 
1640
}
 
1641
 
 
1642
int Field_tiny::cmp(const uchar *a_ptr, const uchar *b_ptr)
 
1643
{
 
1644
  signed char a,b;
 
1645
  a=(signed char) a_ptr[0]; b= (signed char) b_ptr[0];
 
1646
  if (unsigned_flag)
 
1647
    return ((uchar) a < (uchar) b) ? -1 : ((uchar) a > (uchar) b) ? 1 : 0;
 
1648
  return (a < b) ? -1 : (a > b) ? 1 : 0;
 
1649
}
 
1650
 
 
1651
void Field_tiny::sort_string(uchar *to,uint length __attribute__((unused)))
 
1652
{
 
1653
  if (unsigned_flag)
 
1654
    *to= *ptr;
 
1655
  else
 
1656
    to[0] = (char) (ptr[0] ^ (uchar) 128);      /* Revers signbit */
 
1657
}
 
1658
 
 
1659
void Field_tiny::sql_type(String &res) const
 
1660
{
 
1661
  CHARSET_INFO *cs=res.charset();
 
1662
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
 
1663
                          "tinyint(%d)",(int) field_length));
 
1664
  add_zerofill_and_unsigned(res);
 
1665
}
 
1666
 
 
1667
 
 
1668
/*
 
1669
  Report "not well formed" or "cannot convert" error
 
1670
  after storing a character string info a field.
 
1671
 
 
1672
  SYNOPSIS
 
1673
    check_string_copy_error()
 
1674
    field                    - Field
 
1675
    well_formed_error_pos    - where not well formed data was first met
 
1676
    cannot_convert_error_pos - where a not-convertable character was first met
 
1677
    end                      - end of the string
 
1678
    cs                       - character set of the string
 
1679
 
 
1680
  NOTES
 
1681
    As of version 5.0 both cases return the same error:
 
1682
  
 
1683
      "Invalid string value: 'xxx' for column 't' at row 1"
 
1684
  
 
1685
  Future versions will possibly introduce a new error message:
 
1686
 
 
1687
      "Cannot convert character string: 'xxx' for column 't' at row 1"
 
1688
 
 
1689
  RETURN
 
1690
    false - If errors didn't happen
 
1691
    true  - If an error happened
 
1692
*/
 
1693
 
 
1694
bool
 
1695
check_string_copy_error(Field_str *field,
 
1696
                        const char *well_formed_error_pos,
 
1697
                        const char *cannot_convert_error_pos,
 
1698
                        const char *end,
 
1699
                        CHARSET_INFO *cs)
 
1700
{
 
1701
  const char *pos, *end_orig;
 
1702
  char tmp[64], *t;
 
1703
  
 
1704
  if (!(pos= well_formed_error_pos) &&
 
1705
      !(pos= cannot_convert_error_pos))
 
1706
    return false;
 
1707
 
 
1708
  end_orig= end;
 
1709
  set_if_smaller(end, pos + 6);
 
1710
 
 
1711
  for (t= tmp; pos < end; pos++)
 
1712
  {
 
1713
    /*
 
1714
      If the source string is ASCII compatible (mbminlen==1)
 
1715
      and the source character is in ASCII printable range (0x20..0x7F),
 
1716
      then display the character as is.
 
1717
      
 
1718
      Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
 
1719
      or the source character is not in the printable range,
 
1720
      then print the character using HEX notation.
 
1721
    */
 
1722
    if (((unsigned char) *pos) >= 0x20 &&
 
1723
        ((unsigned char) *pos) <= 0x7F &&
 
1724
        cs->mbminlen == 1)
 
1725
    {
 
1726
      *t++= *pos;
 
1727
    }
 
1728
    else
 
1729
    {
 
1730
      *t++= '\\';
 
1731
      *t++= 'x';
 
1732
      *t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
 
1733
      *t++= _dig_vec_upper[((unsigned char) *pos) & 15];
 
1734
    }
 
1735
  }
 
1736
  if (end_orig > end)
 
1737
  {
 
1738
    *t++= '.';
 
1739
    *t++= '.';
 
1740
    *t++= '.';
 
1741
  }
 
1742
  *t= '\0';
 
1743
  push_warning_printf(field->table->in_use, 
 
1744
                      field->table->in_use->abort_on_warning ?
 
1745
                      MYSQL_ERROR::WARN_LEVEL_ERROR :
 
1746
                      MYSQL_ERROR::WARN_LEVEL_WARN,
 
1747
                      ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, 
 
1748
                      ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
 
1749
                      "string", tmp, field->field_name,
 
1750
                      (ulong) field->table->in_use->row_count);
 
1751
  return true;
 
1752
}
 
1753
 
 
1754
 
 
1755
/*
 
1756
  Check if we lost any important data and send a truncation error/warning
 
1757
 
 
1758
  SYNOPSIS
 
1759
    Field_longstr::report_if_important_data()
 
1760
    ptr                      - Truncated rest of string
 
1761
    end                      - End of truncated string
 
1762
 
 
1763
  RETURN VALUES
 
1764
    0   - None was truncated (or we don't count cut fields)
 
1765
    2   - Some bytes was truncated
 
1766
 
 
1767
  NOTE
 
1768
    Check if we lost any important data (anything in a binary string,
 
1769
    or any non-space in others). If only trailing spaces was lost,
 
1770
    send a truncation note, otherwise send a truncation error.
 
1771
*/
 
1772
 
 
1773
int
 
1774
Field_longstr::report_if_important_data(const char *ptr, const char *end)
 
1775
{
 
1776
  if ((ptr < end) && table->in_use->count_cuted_fields)
 
1777
  {
 
1778
    if (test_if_important_data(field_charset, ptr, end))
 
1779
    {
 
1780
      if (table->in_use->abort_on_warning)
 
1781
        set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
 
1782
      else
 
1783
        set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
 
1784
    }
 
1785
    else /* If we lost only spaces then produce a NOTE, not a WARNING */
 
1786
      set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
 
1787
    return 2;
 
1788
  }
 
1789
  return 0;
 
1790
}
 
1791
 
 
1792
 
 
1793
/**
 
1794
  Store double value in Field_string or Field_varstring.
 
1795
 
 
1796
  Pretty prints double number into field_length characters buffer.
 
1797
 
 
1798
  @param nr            number
 
1799
*/
 
1800
 
 
1801
int Field_str::store(double nr)
 
1802
{
 
1803
  char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
 
1804
  uint local_char_length= field_length / charset()->mbmaxlen;
 
1805
  size_t length;
 
1806
  my_bool error;
 
1807
 
 
1808
  length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error);
 
1809
  if (error)
 
1810
  {
 
1811
    if (table->in_use->abort_on_warning)
 
1812
      set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
 
1813
    else
 
1814
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
 
1815
  }
 
1816
  return store(buff, length, charset());
 
1817
}
 
1818
 
 
1819
 
 
1820
uint Field::is_equal(Create_field *new_field)
 
1821
{
 
1822
  return (new_field->sql_type == real_type());
 
1823
}
 
1824
 
 
1825
 
 
1826
/* If one of the fields is binary and the other one isn't return 1 else 0 */
 
1827
 
 
1828
bool Field_str::compare_str_field_flags(Create_field *new_field, uint32 flag_arg)
 
1829
{
 
1830
  return (((new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
 
1831
          !(flag_arg & (BINCMP_FLAG | BINARY_FLAG))) ||
 
1832
         (!(new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
 
1833
          (flag_arg & (BINCMP_FLAG | BINARY_FLAG))));
 
1834
}
 
1835
 
 
1836
 
 
1837
uint Field_str::is_equal(Create_field *new_field)
 
1838
{
 
1839
  if (compare_str_field_flags(new_field, flags))
 
1840
    return 0;
 
1841
 
 
1842
  return ((new_field->sql_type == real_type()) &&
 
1843
          new_field->charset == field_charset &&
 
1844
          new_field->length == max_display_length());
 
1845
}
 
1846
 
 
1847
 
 
1848
int Field_longstr::store_decimal(const my_decimal *d)
 
1849
{
 
1850
  char buff[DECIMAL_MAX_STR_LENGTH+1];
 
1851
  String str(buff, sizeof(buff), &my_charset_bin);
 
1852
  my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
 
1853
  return store(str.ptr(), str.length(), str.charset());
 
1854
}
 
1855
 
 
1856
uint32 Field_longstr::max_data_length() const
 
1857
{
 
1858
  return field_length + (field_length > 255 ? 2 : 1);
 
1859
}
 
1860
 
 
1861
 
 
1862
/****************************************************************************
 
1863
** enum type.
 
1864
** This is a string which only can have a selection of different values.
 
1865
** If one uses this string in a number context one gets the type number.
 
1866
****************************************************************************/
 
1867
 
 
1868
enum ha_base_keytype Field_enum::key_type() const
 
1869
{
 
1870
  switch (packlength) {
 
1871
  default: return HA_KEYTYPE_BINARY;
 
1872
  case 2: return HA_KEYTYPE_USHORT_INT;
 
1873
  case 3: return HA_KEYTYPE_UINT24;
 
1874
  case 4: return HA_KEYTYPE_ULONG_INT;
 
1875
  case 8: return HA_KEYTYPE_ULONGLONG;
 
1876
  }
 
1877
}
 
1878
 
 
1879
void Field_enum::store_type(uint64_t value)
 
1880
{
 
1881
  switch (packlength) {
 
1882
  case 1: ptr[0]= (uchar) value;  break;
 
1883
  case 2:
 
1884
#ifdef WORDS_BIGENDIAN
 
1885
  if (table->s->db_low_byte_first)
 
1886
  {
 
1887
    int2store(ptr,(unsigned short) value);
 
1888
  }
 
1889
  else
 
1890
#endif
 
1891
    shortstore(ptr,(unsigned short) value);
 
1892
  break;
 
1893
  case 3: int3store(ptr,(long) value); break;
 
1894
  case 4:
 
1895
#ifdef WORDS_BIGENDIAN
 
1896
  if (table->s->db_low_byte_first)
 
1897
  {
 
1898
    int4store(ptr,value);
 
1899
  }
 
1900
  else
 
1901
#endif
 
1902
    longstore(ptr,(long) value);
 
1903
  break;
 
1904
  case 8:
 
1905
#ifdef WORDS_BIGENDIAN
 
1906
  if (table->s->db_low_byte_first)
 
1907
  {
 
1908
    int8store(ptr,value);
 
1909
  }
 
1910
  else
 
1911
#endif
 
1912
    int64_tstore(ptr,value); break;
 
1913
  }
 
1914
}
 
1915
 
 
1916
 
 
1917
/**
 
1918
  @note
 
1919
    Storing a empty string in a enum field gives a warning
 
1920
    (if there isn't a empty value in the enum)
 
1921
*/
 
1922
 
 
1923
int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
 
1924
{
 
1925
  int err= 0;
 
1926
  uint32 not_used;
 
1927
  char buff[STRING_BUFFER_USUAL_SIZE];
 
1928
  String tmpstr(buff,sizeof(buff), &my_charset_bin);
 
1929
 
 
1930
  /* Convert character set if necessary */
 
1931
  if (String::needs_conversion(length, cs, field_charset, &not_used))
 
1932
  { 
 
1933
    uint dummy_errors;
 
1934
    tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
 
1935
    from= tmpstr.ptr();
 
1936
    length=  tmpstr.length();
 
1937
  }
 
1938
 
 
1939
  /* Remove end space */
 
1940
  length= field_charset->cset->lengthsp(field_charset, from, length);
 
1941
  uint tmp=find_type2(typelib, from, length, field_charset);
 
1942
  if (!tmp)
 
1943
  {
 
1944
    if (length < 6) // Can't be more than 99999 enums
 
1945
    {
 
1946
      /* This is for reading numbers with LOAD DATA INFILE */
 
1947
      char *end;
 
1948
      tmp=(uint) my_strntoul(cs,from,length,10,&end,&err);
 
1949
      if (err || end != from+length || tmp > typelib->count)
 
1950
      {
 
1951
        tmp=0;
 
1952
        set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
 
1953
      }
 
1954
      if (!table->in_use->count_cuted_fields)
 
1955
        err= 0;
 
1956
    }
 
1957
    else
 
1958
      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
 
1959
  }
 
1960
  store_type((uint64_t) tmp);
 
1961
  return err;
 
1962
}
 
1963
 
 
1964
 
 
1965
int Field_enum::store(double nr)
 
1966
{
 
1967
  return Field_enum::store((int64_t) nr, false);
 
1968
}
 
1969
 
 
1970
 
 
1971
int Field_enum::store(int64_t nr,
 
1972
                      bool unsigned_val __attribute__((__unused__)))
 
1973
{
 
1974
  int error= 0;
 
1975
  if ((uint64_t) nr > typelib->count || nr == 0)
 
1976
  {
 
1977
    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
 
1978
    if (nr != 0 || table->in_use->count_cuted_fields)
 
1979
    {
 
1980
      nr= 0;
 
1981
      error= 1;
 
1982
    }
 
1983
  }
 
1984
  store_type((uint64_t) (uint) nr);
 
1985
  return error;
 
1986
}
 
1987
 
 
1988
 
 
1989
double Field_enum::val_real(void)
 
1990
{
 
1991
  return (double) Field_enum::val_int();
 
1992
}
 
1993
 
 
1994
 
 
1995
int64_t Field_enum::val_int(void)
 
1996
{
 
1997
  switch (packlength) {
 
1998
  case 1:
 
1999
    return (int64_t) ptr[0];
 
2000
  case 2:
 
2001
  {
 
2002
    uint16 tmp;
 
2003
#ifdef WORDS_BIGENDIAN
 
2004
    if (table->s->db_low_byte_first)
 
2005
      tmp=sint2korr(ptr);
 
2006
    else
 
2007
#endif
 
2008
      shortget(tmp,ptr);
 
2009
    return (int64_t) tmp;
 
2010
  }
 
2011
  case 3:
 
2012
    return (int64_t) uint3korr(ptr);
 
2013
  case 4:
 
2014
  {
 
2015
    uint32 tmp;
 
2016
#ifdef WORDS_BIGENDIAN
 
2017
    if (table->s->db_low_byte_first)
 
2018
      tmp=uint4korr(ptr);
 
2019
    else
 
2020
#endif
 
2021
      longget(tmp,ptr);
 
2022
    return (int64_t) tmp;
 
2023
  }
 
2024
  case 8:
 
2025
  {
 
2026
    int64_t tmp;
 
2027
#ifdef WORDS_BIGENDIAN
 
2028
    if (table->s->db_low_byte_first)
 
2029
      tmp=sint8korr(ptr);
 
2030
    else
 
2031
#endif
 
2032
      int64_tget(tmp,ptr);
 
2033
    return tmp;
 
2034
  }
 
2035
  }
 
2036
  return 0;                                     // impossible
 
2037
}
 
2038
 
 
2039
 
 
2040
/**
 
2041
   Save the field metadata for enum fields.
 
2042
 
 
2043
   Saves the real type in the first byte and the pack length in the 
 
2044
   second byte of the field metadata array at index of *metadata_ptr and
 
2045
   *(metadata_ptr + 1).
 
2046
 
 
2047
   @param   metadata_ptr   First byte of field metadata
 
2048
 
 
2049
   @returns number of bytes written to metadata_ptr
 
2050
*/
 
2051
int Field_enum::do_save_field_metadata(uchar *metadata_ptr)
 
2052
{
 
2053
  *metadata_ptr= real_type();
 
2054
  *(metadata_ptr + 1)= pack_length();
 
2055
  return 2;
 
2056
}
 
2057
 
 
2058
 
 
2059
String *Field_enum::val_str(String *val_buffer __attribute__((unused)),
 
2060
                            String *val_ptr)
 
2061
{
 
2062
  uint tmp=(uint) Field_enum::val_int();
 
2063
  if (!tmp || tmp > typelib->count)
 
2064
    val_ptr->set("", 0, field_charset);
 
2065
  else
 
2066
    val_ptr->set((const char*) typelib->type_names[tmp-1],
 
2067
                 typelib->type_lengths[tmp-1],
 
2068
                 field_charset);
 
2069
  return val_ptr;
 
2070
}
 
2071
 
 
2072
int Field_enum::cmp(const uchar *a_ptr, const uchar *b_ptr)
 
2073
{
 
2074
  uchar *old= ptr;
 
2075
  ptr= (uchar*) a_ptr;
 
2076
  uint64_t a=Field_enum::val_int();
 
2077
  ptr= (uchar*) b_ptr;
 
2078
  uint64_t b=Field_enum::val_int();
 
2079
  ptr= old;
 
2080
  return (a < b) ? -1 : (a > b) ? 1 : 0;
 
2081
}
 
2082
 
 
2083
void Field_enum::sort_string(uchar *to,uint length __attribute__((unused)))
 
2084
{
 
2085
  uint64_t value=Field_enum::val_int();
 
2086
  to+=packlength-1;
 
2087
  for (uint i=0 ; i < packlength ; i++)
 
2088
  {
 
2089
    *to-- = (uchar) (value & 255);
 
2090
    value>>=8;
 
2091
  }
 
2092
}
 
2093
 
 
2094
 
 
2095
void Field_enum::sql_type(String &res) const
 
2096
{
 
2097
  char buffer[255];
 
2098
  String enum_item(buffer, sizeof(buffer), res.charset());
 
2099
 
 
2100
  res.length(0);
 
2101
  res.append(STRING_WITH_LEN("enum("));
 
2102
 
 
2103
  bool flag=0;
 
2104
  uint *len= typelib->type_lengths;
 
2105
  for (const char **pos= typelib->type_names; *pos; pos++, len++)
 
2106
  {
 
2107
    uint dummy_errors;
 
2108
    if (flag)
 
2109
      res.append(',');
 
2110
    /* convert to res.charset() == utf8, then quote */
 
2111
    enum_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
 
2112
    append_unescaped(&res, enum_item.ptr(), enum_item.length());
 
2113
    flag= 1;
 
2114
  }
 
2115
  res.append(')');
 
2116
}
 
2117
 
 
2118
 
 
2119
Field *Field_enum::new_field(MEM_ROOT *root, struct st_table *new_table,
 
2120
                             bool keep_type)
 
2121
{
 
2122
  Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type);
 
2123
  if (res)
 
2124
    res->typelib= copy_typelib(root, typelib);
 
2125
  return res;
 
2126
}
 
2127
 
 
2128
 
 
2129
/**
 
2130
  @retval
 
2131
    1  if the fields are equally defined
 
2132
  @retval
 
2133
    0  if the fields are unequally defined
 
2134
*/
1111
2135
 
1112
2136
bool Field::eq_def(Field *field)
1113
2137
{
1117
2141
  return 1;
1118
2142
}
1119
2143
 
 
2144
/**
 
2145
  @return
 
2146
  returns 1 if the fields are equally defined
 
2147
*/
1120
2148
bool Field_enum::eq_def(Field *field)
1121
2149
{
1122
2150
  if (!Field::eq_def(field))
1123
2151
    return 0;
1124
 
 
1125
2152
  TYPELIB *from_lib=((Field_enum*) field)->typelib;
1126
2153
 
1127
2154
  if (typelib->count < from_lib->count)
1128
2155
    return 0;
1129
 
 
1130
 
  for (uint32_t i=0 ; i < from_lib->count ; i++)
1131
 
  {
 
2156
  for (uint i=0 ; i < from_lib->count ; i++)
1132
2157
    if (my_strnncoll(field_charset,
1133
 
                     (const unsigned char*)typelib->type_names[i],
 
2158
                     (const uchar*)typelib->type_names[i],
1134
2159
                     strlen(typelib->type_names[i]),
1135
 
                     (const unsigned char*)from_lib->type_names[i],
 
2160
                     (const uchar*)from_lib->type_names[i],
1136
2161
                     strlen(from_lib->type_names[i])))
1137
2162
      return 0;
1138
 
  }
1139
 
 
1140
 
  return 1;
1141
 
}
1142
 
 
1143
 
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
1144
 
{
1145
 
  switch (type) {
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:
1161
 
                          break;
1162
 
  }
1163
 
 
1164
 
  assert(0);
1165
 
  abort();
1166
 
}
1167
 
 
1168
 
uint32_t pack_length_to_packflag(uint32_t type)
1169
 
{
1170
 
  switch (type) {
1171
 
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
1172
 
    case 2: assert(1);
 
2163
  return 1;
 
2164
}
 
2165
 
 
2166
/**
 
2167
  @return
 
2168
  returns 1 if the fields are equally defined
 
2169
*/
 
2170
bool Field_num::eq_def(Field *field)
 
2171
{
 
2172
  if (!Field::eq_def(field))
 
2173
    return 0;
 
2174
  Field_num *from_num= (Field_num*) field;
 
2175
 
 
2176
  if (unsigned_flag != from_num->unsigned_flag ||
 
2177
      (zerofill && !from_num->zerofill && !zero_pack()) ||
 
2178
      dec != from_num->dec)
 
2179
    return 0;
 
2180
  return 1;
 
2181
}
 
2182
 
 
2183
 
 
2184
uint Field_num::is_equal(Create_field *new_field)
 
2185
{
 
2186
  return ((new_field->sql_type == real_type()) &&
 
2187
          ((new_field->flags & UNSIGNED_FLAG) == (uint) (flags &
 
2188
                                                         UNSIGNED_FLAG)) &&
 
2189
          ((new_field->flags & AUTO_INCREMENT_FLAG) ==
 
2190
           (uint) (flags & AUTO_INCREMENT_FLAG)) &&
 
2191
          (new_field->length <= max_display_length()));
 
2192
}
 
2193
 
 
2194
 
 
2195
/*****************************************************************************
 
2196
  Handling of field and Create_field
 
2197
*****************************************************************************/
 
2198
 
 
2199
/**
 
2200
  Convert create_field::length from number of characters to number of bytes.
 
2201
*/
 
2202
 
 
2203
void Create_field::create_length_to_internal_length(void)
 
2204
{
 
2205
  switch (sql_type) {
 
2206
  case MYSQL_TYPE_BLOB:
 
2207
  case MYSQL_TYPE_VAR_STRING:
 
2208
  case MYSQL_TYPE_STRING:
 
2209
  case MYSQL_TYPE_VARCHAR:
 
2210
    length*= charset->mbmaxlen;
 
2211
    key_length= length;
 
2212
    pack_length= calc_pack_length(sql_type, length);
 
2213
    break;
 
2214
  case MYSQL_TYPE_ENUM:
 
2215
  case MYSQL_TYPE_SET:
 
2216
    /* Pack_length already calculated in sql_parse.cc */
 
2217
    length*= charset->mbmaxlen;
 
2218
    key_length= pack_length;
 
2219
    break;
 
2220
  case MYSQL_TYPE_NEWDECIMAL:
 
2221
    key_length= pack_length=
 
2222
      my_decimal_get_binary_size(my_decimal_length_to_precision(length,
 
2223
                                                                decimals,
 
2224
                                                                flags &
 
2225
                                                                UNSIGNED_FLAG),
 
2226
                                 decimals);
 
2227
    break;
 
2228
  default:
 
2229
    key_length= pack_length= calc_pack_length(sql_type, length);
 
2230
    break;
 
2231
  }
 
2232
}
 
2233
 
 
2234
 
 
2235
/**
 
2236
  Init for a tmp table field. To be extended if need be.
 
2237
*/
 
2238
void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
 
2239
                                      uint32 length_arg, uint32 decimals_arg,
 
2240
                                      bool maybe_null, bool is_unsigned)
 
2241
{
 
2242
  field_name= "";
 
2243
  sql_type= sql_type_arg;
 
2244
  char_length= length= length_arg;;
 
2245
  unireg_check= Field::NONE;
 
2246
  interval= 0;
 
2247
  charset= &my_charset_bin;
 
2248
  pack_flag= (FIELDFLAG_NUMBER |
 
2249
              ((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
 
2250
              (maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
 
2251
              (is_unsigned ? 0 : FIELDFLAG_DECIMAL));
 
2252
}
 
2253
 
 
2254
 
 
2255
/**
 
2256
  Initialize field definition for create.
 
2257
 
 
2258
  @param thd                   Thread handle
 
2259
  @param fld_name              Field name
 
2260
  @param fld_type              Field type
 
2261
  @param fld_length            Field length
 
2262
  @param fld_decimals          Decimal (if any)
 
2263
  @param fld_type_modifier     Additional type information
 
2264
  @param fld_default_value     Field default value (if any)
 
2265
  @param fld_on_update_value   The value of ON UPDATE clause
 
2266
  @param fld_comment           Field comment
 
2267
  @param fld_change            Field change
 
2268
  @param fld_interval_list     Interval list (if any)
 
2269
  @param fld_charset           Field charset
 
2270
 
 
2271
  @retval
 
2272
    false on success
 
2273
  @retval
 
2274
    true  on error
 
2275
*/
 
2276
 
 
2277
bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type,
 
2278
                        char *fld_length, char *fld_decimals,
 
2279
                        uint fld_type_modifier, Item *fld_default_value,
 
2280
                        Item *fld_on_update_value, LEX_STRING *fld_comment,
 
2281
                        char *fld_change, List<String> *fld_interval_list,
 
2282
                        CHARSET_INFO *fld_charset,
 
2283
                        uint fld_geom_type __attribute__((__unused__)),
 
2284
                        enum column_format_type column_format)
 
2285
{
 
2286
  uint sign_len, allowed_type_modifier= 0;
 
2287
  ulong max_field_charlength= MAX_FIELD_CHARLENGTH;
 
2288
 
 
2289
  field= 0;
 
2290
  field_name= fld_name;
 
2291
  def= fld_default_value;
 
2292
  flags= fld_type_modifier;
 
2293
  flags|= (((uint)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
 
2294
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
 
2295
                 Field::NEXT_NUMBER : Field::NONE);
 
2296
  decimals= fld_decimals ? (uint)atoi(fld_decimals) : 0;
 
2297
  if (decimals >= NOT_FIXED_DEC)
 
2298
  {
 
2299
    my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
 
2300
             NOT_FIXED_DEC-1);
 
2301
    return(true);
 
2302
  }
 
2303
 
 
2304
  sql_type= fld_type;
 
2305
  length= 0;
 
2306
  change= fld_change;
 
2307
  interval= 0;
 
2308
  pack_length= key_length= 0;
 
2309
  charset= fld_charset;
 
2310
  interval_list.empty();
 
2311
 
 
2312
  comment= *fld_comment;
 
2313
  /*
 
2314
    Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
 
2315
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
 
2316
  */
 
2317
  if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
 
2318
      (fld_type_modifier & NOT_NULL_FLAG) && fld_type != MYSQL_TYPE_TIMESTAMP)
 
2319
    flags|= NO_DEFAULT_VALUE_FLAG;
 
2320
 
 
2321
  if (fld_length && !(length= (uint) atoi(fld_length)))
 
2322
    fld_length= 0; /* purecov: inspected */
 
2323
  sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
 
2324
 
 
2325
  switch (fld_type) {
 
2326
  case MYSQL_TYPE_TINY:
 
2327
    if (!fld_length)
 
2328
      length= MAX_TINYINT_WIDTH+sign_len;
 
2329
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
 
2330
    break;
 
2331
  case MYSQL_TYPE_SHORT:
 
2332
    if (!fld_length)
 
2333
      length= MAX_SMALLINT_WIDTH+sign_len;
 
2334
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
 
2335
    break;
 
2336
  case MYSQL_TYPE_LONG:
 
2337
    if (!fld_length)
 
2338
      length= MAX_INT_WIDTH+sign_len;
 
2339
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
 
2340
    break;
 
2341
  case MYSQL_TYPE_LONGLONG:
 
2342
    if (!fld_length)
 
2343
      length= MAX_BIGINT_WIDTH;
 
2344
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
 
2345
    break;
 
2346
  case MYSQL_TYPE_NULL:
 
2347
    break;
 
2348
  case MYSQL_TYPE_NEWDECIMAL:
 
2349
    my_decimal_trim(&length, &decimals);
 
2350
    if (length > DECIMAL_MAX_PRECISION)
 
2351
    {
 
2352
      my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
 
2353
               DECIMAL_MAX_PRECISION);
 
2354
      return(true);
 
2355
    }
 
2356
    if (length < decimals)
 
2357
    {
 
2358
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
 
2359
      return(true);
 
2360
    }
 
2361
    length=
 
2362
      my_decimal_precision_to_length(length, decimals,
 
2363
                                     fld_type_modifier & UNSIGNED_FLAG);
 
2364
    pack_length=
 
2365
      my_decimal_get_binary_size(length, decimals);
 
2366
    break;
 
2367
  case MYSQL_TYPE_VARCHAR:
 
2368
    /*
 
2369
      Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table
 
2370
      if they don't have a default value
 
2371
    */
 
2372
    max_field_charlength= MAX_FIELD_VARCHARLENGTH;
 
2373
    break;
 
2374
  case MYSQL_TYPE_STRING:
 
2375
    break;
 
2376
  case MYSQL_TYPE_BLOB:
 
2377
    if (fld_default_value)
 
2378
    {
 
2379
      /* Allow empty as default value. */
 
2380
      String str,*res;
 
2381
      res= fld_default_value->val_str(&str);
 
2382
      /*
 
2383
        A default other than '' is always an error, and any non-NULL
 
2384
        specified default is an error in strict mode.
 
2385
      */
 
2386
      if (res->length() || (thd->variables.sql_mode &
 
2387
                            (MODE_STRICT_TRANS_TABLES |
 
2388
                             MODE_STRICT_ALL_TABLES)))
 
2389
      {
 
2390
        my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
 
2391
                 fld_name); /* purecov: inspected */
 
2392
        return(true);
 
2393
      }
 
2394
      else
 
2395
      {
 
2396
        /*
 
2397
          Otherwise a default of '' is just a warning.
 
2398
        */
 
2399
        push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
2400
                            ER_BLOB_CANT_HAVE_DEFAULT,
 
2401
                            ER(ER_BLOB_CANT_HAVE_DEFAULT),
 
2402
                            fld_name);
 
2403
      }
 
2404
      def= 0;
 
2405
    }
 
2406
    flags|= BLOB_FLAG;
 
2407
    break;
 
2408
  case MYSQL_TYPE_YEAR:
 
2409
    if (!fld_length || length != 2)
 
2410
      length= 4; /* Default length */
 
2411
    flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
 
2412
    break;
 
2413
  case MYSQL_TYPE_DOUBLE:
 
2414
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
 
2415
    if (!fld_length && !fld_decimals)
 
2416
    {
 
2417
      length= DBL_DIG+7;
 
2418
      decimals= NOT_FIXED_DEC;
 
2419
    }
 
2420
    if (length < decimals &&
 
2421
        decimals != NOT_FIXED_DEC)
 
2422
    {
 
2423
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
 
2424
      return(true);
 
2425
    }
 
2426
    break;
 
2427
  case MYSQL_TYPE_TIMESTAMP:
 
2428
    if (!fld_length)
 
2429
    {
 
2430
      /* Compressed date YYYYMMDDHHMMSS */
 
2431
      length= MAX_DATETIME_COMPRESSED_WIDTH;
 
2432
    }
 
2433
    else if (length != MAX_DATETIME_WIDTH)
 
2434
    {
 
2435
      /*
 
2436
        We support only even TIMESTAMP lengths less or equal than 14
 
2437
        and 19 as length of 4.1 compatible representation.
 
2438
      */
 
2439
      length= ((length+1)/2)*2; /* purecov: inspected */
 
2440
      length= min(length, MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
 
2441
    }
 
2442
    flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
 
2443
    if (fld_default_value)
 
2444
    {
 
2445
      /* Grammar allows only NOW() value for ON UPDATE clause */
 
2446
      if (fld_default_value->type() == Item::FUNC_ITEM && 
 
2447
          ((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
 
2448
      {
 
2449
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
 
2450
                                             Field::TIMESTAMP_DN_FIELD);
 
2451
        /*
 
2452
          We don't need default value any longer moreover it is dangerous.
 
2453
          Everything handled by unireg_check further.
 
2454
        */
 
2455
        def= 0;
 
2456
      }
 
2457
      else
 
2458
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
 
2459
                                             Field::NONE);
 
2460
    }
 
2461
    else
 
2462
    {
 
2463
      /*
 
2464
        If we have default TIMESTAMP NOT NULL column without explicit DEFAULT
 
2465
        or ON UPDATE values then for the sake of compatiblity we should treat
 
2466
        this column as having DEFAULT NOW() ON UPDATE NOW() (when we don't
 
2467
        have another TIMESTAMP column with auto-set option before this one)
 
2468
        or DEFAULT 0 (in other cases).
 
2469
        So here we are setting TIMESTAMP_OLD_FIELD only temporary, and will
 
2470
        replace this value by TIMESTAMP_DNUN_FIELD or NONE later when
 
2471
        information about all TIMESTAMP fields in table will be availiable.
 
2472
 
 
2473
        If we have TIMESTAMP NULL column without explicit DEFAULT value
 
2474
        we treat it as having DEFAULT NULL attribute.
 
2475
      */
 
2476
      unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD :
 
2477
                     (flags & NOT_NULL_FLAG ? Field::TIMESTAMP_OLD_FIELD :
 
2478
                                              Field::NONE));
 
2479
    }
 
2480
    break;
 
2481
  case MYSQL_TYPE_DATE:
 
2482
    /* Old date type. */
 
2483
    sql_type= MYSQL_TYPE_NEWDATE;
 
2484
    /* fall trough */
 
2485
  case MYSQL_TYPE_NEWDATE:
 
2486
    length= 10;
 
2487
    break;
 
2488
  case MYSQL_TYPE_TIME:
 
2489
    length= 10;
 
2490
    break;
 
2491
  case MYSQL_TYPE_DATETIME:
 
2492
    length= MAX_DATETIME_WIDTH;
 
2493
    break;
 
2494
  case MYSQL_TYPE_SET:
 
2495
    {
 
2496
      pack_length= get_set_pack_length(fld_interval_list->elements);
 
2497
 
 
2498
      List_iterator<String> it(*fld_interval_list);
 
2499
      String *tmp;
 
2500
      while ((tmp= it++))
 
2501
        interval_list.push_back(tmp);
 
2502
      /*
 
2503
        Set fake length to 1 to pass the below conditions.
 
2504
        Real length will be set in mysql_prepare_table()
 
2505
        when we know the character set of the column
 
2506
      */
 
2507
      length= 1;
 
2508
      break;
 
2509
    }
 
2510
  case MYSQL_TYPE_ENUM:
 
2511
    {
 
2512
      /* Should be safe. */
 
2513
      pack_length= get_enum_pack_length(fld_interval_list->elements);
 
2514
 
 
2515
      List_iterator<String> it(*fld_interval_list);
 
2516
      String *tmp;
 
2517
      while ((tmp= it++))
 
2518
        interval_list.push_back(tmp);
 
2519
      length= 1; /* See comment for MYSQL_TYPE_SET above. */
 
2520
      break;
 
2521
   }
 
2522
  case MYSQL_TYPE_VAR_STRING:
 
2523
    assert(0);  /* Impossible, we killed it */
 
2524
    break;
 
2525
  }
 
2526
  /* Remember the value of length */
 
2527
  char_length= length;
 
2528
 
 
2529
  if (!(flags & BLOB_FLAG) &&
 
2530
      ((length > max_field_charlength && fld_type != MYSQL_TYPE_SET &&
 
2531
        fld_type != MYSQL_TYPE_ENUM &&
 
2532
        (fld_type != MYSQL_TYPE_VARCHAR || fld_default_value)) ||
 
2533
       (!length &&
 
2534
        fld_type != MYSQL_TYPE_STRING &&
 
2535
        fld_type != MYSQL_TYPE_VARCHAR)))
 
2536
  {
 
2537
    my_error((fld_type == MYSQL_TYPE_VAR_STRING ||
 
2538
              fld_type == MYSQL_TYPE_VARCHAR ||
 
2539
              fld_type == MYSQL_TYPE_STRING) ?  ER_TOO_BIG_FIELDLENGTH :
 
2540
                                                ER_TOO_BIG_DISPLAYWIDTH,
 
2541
              MYF(0),
 
2542
              fld_name, max_field_charlength); /* purecov: inspected */
 
2543
    return(true);
 
2544
  }
 
2545
  fld_type_modifier&= AUTO_INCREMENT_FLAG;
 
2546
  if ((~allowed_type_modifier) & fld_type_modifier)
 
2547
  {
 
2548
    my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
 
2549
    return(true);
 
2550
  }
 
2551
 
 
2552
  return(false); /* success */
 
2553
}
 
2554
 
 
2555
 
 
2556
enum_field_types get_blob_type_from_length(ulong length __attribute__((__unused__)))
 
2557
{
 
2558
  enum_field_types type;
 
2559
 
 
2560
  type= MYSQL_TYPE_BLOB;
 
2561
 
 
2562
  return type;
 
2563
}
 
2564
 
 
2565
 
 
2566
/*
 
2567
  Make a field from the .frm file info
 
2568
*/
 
2569
 
 
2570
uint32 calc_pack_length(enum_field_types type,uint32 length)
 
2571
{
 
2572
  switch (type) {
 
2573
  case MYSQL_TYPE_VAR_STRING:
 
2574
  case MYSQL_TYPE_STRING:
 
2575
  case MYSQL_TYPE_VARCHAR:     return (length + (length < 256 ? 1: 2));
 
2576
  case MYSQL_TYPE_YEAR:
 
2577
  case MYSQL_TYPE_TINY  : return 1;
 
2578
  case MYSQL_TYPE_SHORT : return 2;
 
2579
  case MYSQL_TYPE_DATE:
 
2580
  case MYSQL_TYPE_NEWDATE:
 
2581
  case MYSQL_TYPE_TIME:   return 3;
 
2582
  case MYSQL_TYPE_TIMESTAMP:
 
2583
  case MYSQL_TYPE_LONG  : return 4;
 
2584
  case MYSQL_TYPE_DOUBLE: return sizeof(double);
 
2585
  case MYSQL_TYPE_DATETIME:
 
2586
  case MYSQL_TYPE_LONGLONG: return 8;   /* Don't crash if no int64_t */
 
2587
  case MYSQL_TYPE_NULL  : return 0;
 
2588
  case MYSQL_TYPE_BLOB:         return 4+portable_sizeof_char_ptr;
 
2589
  case MYSQL_TYPE_SET:
 
2590
  case MYSQL_TYPE_ENUM:
 
2591
  case MYSQL_TYPE_NEWDECIMAL:
 
2592
    abort(); return 0;                          // This shouldn't happen
 
2593
  default:
 
2594
    return 0;
 
2595
  }
 
2596
}
 
2597
 
 
2598
 
 
2599
uint pack_length_to_packflag(uint type)
 
2600
{
 
2601
  switch (type) {
 
2602
    case 1: return f_settype((uint) MYSQL_TYPE_TINY);
 
2603
    case 2: return f_settype((uint) MYSQL_TYPE_SHORT);
1173
2604
    case 3: assert(1);
1174
 
    case 4: return f_settype(DRIZZLE_TYPE_LONG);
1175
 
    case 8: return f_settype(DRIZZLE_TYPE_LONGLONG);
 
2605
    case 4: return f_settype((uint) MYSQL_TYPE_LONG);
 
2606
    case 8: return f_settype((uint) MYSQL_TYPE_LONGLONG);
1176
2607
  }
1177
2608
  return 0;                                     // This shouldn't happen
1178
2609
}
1179
2610
 
 
2611
 
 
2612
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length,
 
2613
                  uchar *null_pos, uchar null_bit,
 
2614
                  uint pack_flag,
 
2615
                  enum_field_types field_type,
 
2616
                  CHARSET_INFO *field_charset,
 
2617
                  Field::utype unireg_check,
 
2618
                  TYPELIB *interval,
 
2619
                  const char *field_name)
 
2620
{
 
2621
  if (!f_maybe_null(pack_flag))
 
2622
  {
 
2623
    null_pos=0;
 
2624
    null_bit=0;
 
2625
  }
 
2626
  else
 
2627
  {
 
2628
    null_bit= ((uchar) 1) << null_bit;
 
2629
  }
 
2630
 
 
2631
  switch (field_type) {
 
2632
  case MYSQL_TYPE_DATE:
 
2633
  case MYSQL_TYPE_NEWDATE:
 
2634
  case MYSQL_TYPE_TIME:
 
2635
  case MYSQL_TYPE_DATETIME:
 
2636
  case MYSQL_TYPE_TIMESTAMP:
 
2637
    field_charset= &my_charset_bin;
 
2638
  default: break;
 
2639
  }
 
2640
 
 
2641
  if (f_is_alpha(pack_flag))
 
2642
  {
 
2643
    if (!f_is_packed(pack_flag))
 
2644
    {
 
2645
      if (field_type == MYSQL_TYPE_STRING ||
 
2646
          field_type == MYSQL_TYPE_VAR_STRING)
 
2647
        return new Field_string(ptr,field_length,null_pos,null_bit,
 
2648
                                unireg_check, field_name,
 
2649
                                field_charset);
 
2650
      if (field_type == MYSQL_TYPE_VARCHAR)
 
2651
        return new Field_varstring(ptr,field_length,
 
2652
                                   HA_VARCHAR_PACKLENGTH(field_length),
 
2653
                                   null_pos,null_bit,
 
2654
                                   unireg_check, field_name,
 
2655
                                   share,
 
2656
                                   field_charset);
 
2657
      return 0;                                 // Error
 
2658
    }
 
2659
 
 
2660
    uint pack_length=calc_pack_length((enum_field_types)
 
2661
                                      f_packtype(pack_flag),
 
2662
                                      field_length);
 
2663
 
 
2664
    if (f_is_blob(pack_flag))
 
2665
      return new Field_blob(ptr,null_pos,null_bit,
 
2666
                            unireg_check, field_name, share,
 
2667
                            pack_length, field_charset);
 
2668
    if (interval)
 
2669
    {
 
2670
      if (f_is_enum(pack_flag))
 
2671
        return new Field_enum(ptr,field_length,null_pos,null_bit,
 
2672
                                  unireg_check, field_name,
 
2673
                                  pack_length, interval, field_charset);
 
2674
      else
 
2675
        return new Field_set(ptr,field_length,null_pos,null_bit,
 
2676
                             unireg_check, field_name,
 
2677
                             pack_length, interval, field_charset);
 
2678
    }
 
2679
  }
 
2680
 
 
2681
  switch (field_type) {
 
2682
  case MYSQL_TYPE_NEWDECIMAL:
 
2683
    return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
 
2684
                                 unireg_check, field_name,
 
2685
                                 f_decimals(pack_flag),
 
2686
                                 f_is_zerofill(pack_flag) != 0,
 
2687
                                 f_is_dec(pack_flag) == 0);
 
2688
  case MYSQL_TYPE_DOUBLE:
 
2689
    return new Field_double(ptr,field_length,null_pos,null_bit,
 
2690
                            unireg_check, field_name,
 
2691
                            f_decimals(pack_flag),
 
2692
                            f_is_zerofill(pack_flag) != 0,
 
2693
                            f_is_dec(pack_flag)== 0);
 
2694
  case MYSQL_TYPE_TINY:
 
2695
    return new Field_tiny(ptr,field_length,null_pos,null_bit,
 
2696
                          unireg_check, field_name,
 
2697
                          f_is_zerofill(pack_flag) != 0,
 
2698
                          f_is_dec(pack_flag) == 0);
 
2699
  case MYSQL_TYPE_SHORT:
 
2700
    return new Field_short(ptr,field_length,null_pos,null_bit,
 
2701
                           unireg_check, field_name,
 
2702
                           f_is_zerofill(pack_flag) != 0,
 
2703
                           f_is_dec(pack_flag) == 0);
 
2704
  case MYSQL_TYPE_LONG:
 
2705
    return new Field_long(ptr,field_length,null_pos,null_bit,
 
2706
                           unireg_check, field_name,
 
2707
                           f_is_zerofill(pack_flag) != 0,
 
2708
                           f_is_dec(pack_flag) == 0);
 
2709
  case MYSQL_TYPE_LONGLONG:
 
2710
    return new Field_int64_t(ptr,field_length,null_pos,null_bit,
 
2711
                              unireg_check, field_name,
 
2712
                              f_is_zerofill(pack_flag) != 0,
 
2713
                              f_is_dec(pack_flag) == 0);
 
2714
  case MYSQL_TYPE_TIMESTAMP:
 
2715
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,
 
2716
                               unireg_check, field_name, share,
 
2717
                               field_charset);
 
2718
  case MYSQL_TYPE_YEAR:
 
2719
    return new Field_year(ptr,field_length,null_pos,null_bit,
 
2720
                          unireg_check, field_name);
 
2721
  case MYSQL_TYPE_DATE:
 
2722
  case MYSQL_TYPE_NEWDATE:
 
2723
    return new Field_newdate(ptr,null_pos,null_bit,
 
2724
                             unireg_check, field_name, field_charset);
 
2725
  case MYSQL_TYPE_TIME:
 
2726
    return new Field_time(ptr,null_pos,null_bit,
 
2727
                          unireg_check, field_name, field_charset);
 
2728
  case MYSQL_TYPE_DATETIME:
 
2729
    return new Field_datetime(ptr,null_pos,null_bit,
 
2730
                              unireg_check, field_name, field_charset);
 
2731
  case MYSQL_TYPE_NULL:
 
2732
    return new Field_null(ptr, field_length, unireg_check, field_name,
 
2733
                          field_charset);
 
2734
  default:                                      // Impossible (Wrong version)
 
2735
    break;
 
2736
  }
 
2737
  return 0;
 
2738
}
 
2739
 
 
2740
 
 
2741
/** Create a field suitable for create of table. */
 
2742
 
 
2743
Create_field::Create_field(Field *old_field,Field *orig_field)
 
2744
{
 
2745
  field=      old_field;
 
2746
  field_name=change=old_field->field_name;
 
2747
  length=     old_field->field_length;
 
2748
  flags=      old_field->flags;
 
2749
  unireg_check=old_field->unireg_check;
 
2750
  pack_length=old_field->pack_length();
 
2751
  key_length= old_field->key_length();
 
2752
  sql_type=   old_field->real_type();
 
2753
  charset=    old_field->charset();             // May be NULL ptr
 
2754
  comment=    old_field->comment;
 
2755
  decimals=   old_field->decimals();
 
2756
 
 
2757
  /* Fix if the original table had 4 byte pointer blobs */
 
2758
  if (flags & BLOB_FLAG)
 
2759
    pack_length= (pack_length- old_field->table->s->blob_ptr_size +
 
2760
                  portable_sizeof_char_ptr);
 
2761
 
 
2762
  switch (sql_type) {
 
2763
  case MYSQL_TYPE_BLOB:
 
2764
    sql_type= MYSQL_TYPE_BLOB;
 
2765
    length/= charset->mbmaxlen;
 
2766
    key_length/= charset->mbmaxlen;
 
2767
    break;
 
2768
  case MYSQL_TYPE_STRING:
 
2769
    /* Change CHAR -> VARCHAR if dynamic record length */
 
2770
    if (old_field->type() == MYSQL_TYPE_VAR_STRING)
 
2771
      sql_type= MYSQL_TYPE_VARCHAR;
 
2772
    /* fall through */
 
2773
 
 
2774
  case MYSQL_TYPE_ENUM:
 
2775
  case MYSQL_TYPE_SET:
 
2776
  case MYSQL_TYPE_VARCHAR:
 
2777
  case MYSQL_TYPE_VAR_STRING:
 
2778
    /* This is corrected in create_length_to_internal_length */
 
2779
    length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
 
2780
    break;
 
2781
  default:
 
2782
    break;
 
2783
  }
 
2784
 
 
2785
  if (flags & (ENUM_FLAG | SET_FLAG))
 
2786
    interval= ((Field_enum*) old_field)->typelib;
 
2787
  else
 
2788
    interval=0;
 
2789
  def=0;
 
2790
  char_length= length;
 
2791
 
 
2792
  if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
 
2793
      old_field->ptr && orig_field &&
 
2794
      (sql_type != MYSQL_TYPE_TIMESTAMP ||                /* set def only if */
 
2795
       old_field->table->timestamp_field != old_field ||  /* timestamp field */ 
 
2796
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
 
2797
  {
 
2798
    char buff[MAX_FIELD_WIDTH];
 
2799
    String tmp(buff,sizeof(buff), charset);
 
2800
    my_ptrdiff_t diff;
 
2801
 
 
2802
    /* Get the value from default_values */
 
2803
    diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
 
2804
                          orig_field->table->record[0]);
 
2805
    orig_field->move_field_offset(diff);        // Points now at default_values
 
2806
    if (!orig_field->is_real_null())
 
2807
    {
 
2808
      char buff[MAX_FIELD_WIDTH], *pos;
 
2809
      String tmp(buff, sizeof(buff), charset), *res;
 
2810
      res= orig_field->val_str(&tmp);
 
2811
      pos= (char*) sql_strmake(res->ptr(), res->length());
 
2812
      def= new Item_string(pos, res->length(), charset);
 
2813
    }
 
2814
    orig_field->move_field_offset(-diff);       // Back to record[0]
 
2815
  }
 
2816
}
 
2817
 
 
2818
 
1180
2819
/*****************************************************************************
1181
2820
 Warning handling
1182
2821
*****************************************************************************/
1183
2822
 
1184
 
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
1185
 
                        drizzled::error_t code,
1186
 
                        int cuted_increment)
 
2823
/**
 
2824
  Produce warning or note about data saved into field.
 
2825
 
 
2826
  @param level            - level of message (Note/Warning/Error)
 
2827
  @param code             - error code of message to be produced
 
2828
  @param cuted_increment  - whenever we should increase cut fields count or not
 
2829
 
 
2830
  @note
 
2831
    This function won't produce warning and increase cut fields counter
 
2832
    if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
 
2833
 
 
2834
    if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
 
2835
    This allows us to avoid notes in optimisation, like convert_constant_item().
 
2836
 
 
2837
  @retval
 
2838
    1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
 
2839
  @retval
 
2840
    0 otherwise
 
2841
*/
 
2842
 
 
2843
bool 
 
2844
Field::set_warning(MYSQL_ERROR::enum_warning_level level, uint code,
 
2845
                   int cuted_increment)
1187
2846
{
1188
2847
  /*
1189
2848
    If this field was created only for type conversion purposes it
1190
2849
    will have table == NULL.
1191
2850
  */
1192
 
  Session *session= table ? table->in_use : current_session;
1193
 
  if (session->count_cuted_fields)
 
2851
  THD *thd= table ? table->in_use : current_thd;
 
2852
  if (thd->count_cuted_fields)
1194
2853
  {
1195
 
    session->cuted_fields+= cuted_increment;
1196
 
    push_warning_printf(session, level, code, ER(code), field_name,
1197
 
                        session->row_count);
 
2854
    thd->cuted_fields+= cuted_increment;
 
2855
    push_warning_printf(thd, level, code, ER(code), field_name,
 
2856
                        thd->row_count);
1198
2857
    return 0;
1199
2858
  }
1200
 
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
 
2859
  return level >= MYSQL_ERROR::WARN_LEVEL_WARN;
1201
2860
}
1202
2861
 
1203
2862
 
1204
 
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1205
 
                                 drizzled::error_t code,
1206
 
                                 const char *str, 
1207
 
                                 uint32_t str_length,
1208
 
                                 type::timestamp_t ts_type, 
1209
 
                                 int cuted_increment)
 
2863
/**
 
2864
  Produce warning or note about datetime string data saved into field.
 
2865
 
 
2866
  @param level            level of message (Note/Warning/Error)
 
2867
  @param code             error code of message to be produced
 
2868
  @param str              string value which we tried to save
 
2869
  @param str_length       length of string which we tried to save
 
2870
  @param ts_type          type of datetime value (datetime/date/time)
 
2871
  @param cuted_increment  whenever we should increase cut fields count or not
 
2872
 
 
2873
  @note
 
2874
    This function will always produce some warning but won't increase cut
 
2875
    fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
 
2876
    thread.
 
2877
*/
 
2878
 
 
2879
void 
 
2880
Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level, uint code, 
 
2881
                            const char *str, uint str_length, 
 
2882
                            timestamp_type ts_type, int cuted_increment)
1210
2883
{
1211
 
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1212
 
 
1213
 
  if ((session->abortOnWarning() and
1214
 
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
 
2884
  THD *thd= table ? table->in_use : current_thd;
 
2885
  if ((thd->really_abort_on_warning() &&
 
2886
       level >= MYSQL_ERROR::WARN_LEVEL_WARN) ||
1215
2887
      set_warning(level, code, cuted_increment))
1216
 
    make_truncated_value_warning(session, level, str, str_length, ts_type,
 
2888
    make_truncated_value_warning(thd, level, str, str_length, ts_type,
1217
2889
                                 field_name);
1218
2890
}
1219
2891
 
1220
 
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
1221
 
                                 drizzled::error_t code,
1222
 
                                 int64_t nr, 
1223
 
                                 type::timestamp_t ts_type,
1224
 
                                 int cuted_increment)
 
2892
 
 
2893
/**
 
2894
  Produce warning or note about integer datetime value saved into field.
 
2895
 
 
2896
  @param level            level of message (Note/Warning/Error)
 
2897
  @param code             error code of message to be produced
 
2898
  @param nr               numeric value which we tried to save
 
2899
  @param ts_type          type of datetime value (datetime/date/time)
 
2900
  @param cuted_increment  whenever we should increase cut fields count or not
 
2901
 
 
2902
  @note
 
2903
    This function will always produce some warning but won't increase cut
 
2904
    fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
 
2905
    thread.
 
2906
*/
 
2907
 
 
2908
void 
 
2909
Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level, uint code, 
 
2910
                            int64_t nr, timestamp_type ts_type,
 
2911
                            int cuted_increment)
1225
2912
{
1226
 
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1227
 
 
1228
 
  if (session->abortOnWarning() or
 
2913
  THD *thd= table ? table->in_use : current_thd;
 
2914
  if (thd->really_abort_on_warning() ||
1229
2915
      set_warning(level, code, cuted_increment))
1230
2916
  {
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),
 
2917
    char str_nr[22];
 
2918
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
 
2919
    make_truncated_value_warning(thd, level, str_nr, (uint) (str_end - str_nr), 
1234
2920
                                 ts_type, field_name);
1235
2921
  }
1236
2922
}
1237
2923
 
1238
 
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1239
 
                                 const drizzled::error_t code,
1240
 
                                 double nr, 
1241
 
                                 type::timestamp_t ts_type)
 
2924
 
 
2925
/**
 
2926
  Produce warning or note about double datetime data saved into field.
 
2927
 
 
2928
  @param level            level of message (Note/Warning/Error)
 
2929
  @param code             error code of message to be produced
 
2930
  @param nr               double value which we tried to save
 
2931
  @param ts_type          type of datetime value (datetime/date/time)
 
2932
 
 
2933
  @note
 
2934
    This function will always produce some warning but won't increase cut
 
2935
    fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
 
2936
    thread.
 
2937
*/
 
2938
 
 
2939
void 
 
2940
Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level, uint code, 
 
2941
                            double nr, timestamp_type ts_type)
1242
2942
{
1243
 
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1244
 
 
1245
 
  if (session->abortOnWarning() or
 
2943
  THD *thd= table ? table->in_use : current_thd;
 
2944
  if (thd->really_abort_on_warning() ||
1246
2945
      set_warning(level, code, 1))
1247
2946
  {
1248
2947
    /* DBL_DIG is enough to print '-[digits].E+###' */
1249
2948
    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,
 
2949
    uint str_len= sprintf(str_nr, "%g", nr);
 
2950
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
1252
2951
                                 field_name);
1253
2952
  }
1254
2953
}
1255
 
 
1256
 
bool Field::isReadSet() const 
1257
 
1258
 
  return table->isReadSet(field_index); 
1259
 
}
1260
 
 
1261
 
bool Field::isWriteSet()
1262
 
1263
 
  return table->isWriteSet(field_index); 
1264
 
}
1265
 
 
1266
 
void Field::setReadSet(bool arg)
1267
 
{
1268
 
  if (arg)
1269
 
    table->setReadSet(field_index);
1270
 
  else
1271
 
    table->clearReadSet(field_index);
1272
 
}
1273
 
 
1274
 
void Field::setWriteSet(bool arg)
1275
 
{
1276
 
  if (arg)
1277
 
    table->setWriteSet(field_index);
1278
 
  else
1279
 
    table->clearWriteSet(field_index);
1280
 
}
1281
 
 
1282
 
void Field::pack_num(uint64_t arg, unsigned char *destination)
1283
 
{
1284
 
  if (not destination)
1285
 
    destination= ptr;
1286
 
 
1287
 
  int64_tstore(destination, arg);
1288
 
}
1289
 
 
1290
 
void Field::pack_num(uint32_t arg, unsigned char *destination)
1291
 
{
1292
 
  if (not destination)
1293
 
    destination= ptr;
1294
 
 
1295
 
  longstore(destination, arg);
1296
 
}
1297
 
 
1298
 
uint64_t Field::unpack_num(uint64_t &destination, const unsigned char *arg) const
1299
 
{
1300
 
  if (not arg)
1301
 
    arg= ptr;
1302
 
 
1303
 
  int64_tget(destination, arg);
1304
 
 
1305
 
  return destination;
1306
 
}
1307
 
 
1308
 
uint32_t Field::unpack_num(uint32_t &destination, const unsigned char *arg) const
1309
 
{
1310
 
  if (not arg)
1311
 
    arg= ptr;
1312
 
 
1313
 
  longget(destination, arg);
1314
 
 
1315
 
  return destination;
1316
 
}
1317
 
 
1318
 
std::ostream& operator<<(std::ostream& output, const Field &field)
1319
 
{
1320
 
  output << "Field:(";
1321
 
  output <<  field.field_name;
1322
 
  output << ", ";
1323
 
  output << drizzled::display::type(field.real_type());
1324
 
  output << ", { ";
1325
 
 
1326
 
  if (field.flags & NOT_NULL_FLAG)
1327
 
    output << " NOT_NULL";
1328
 
 
1329
 
  if (field.flags & PRI_KEY_FLAG)
1330
 
    output << ", PRIMARY KEY";
1331
 
 
1332
 
  if (field.flags & UNIQUE_KEY_FLAG)
1333
 
    output << ", UNIQUE KEY";
1334
 
 
1335
 
  if (field.flags & MULTIPLE_KEY_FLAG)
1336
 
    output << ", MULTIPLE KEY";
1337
 
 
1338
 
  if (field.flags & BLOB_FLAG)
1339
 
    output << ", BLOB";
1340
 
 
1341
 
  if (field.flags & UNSIGNED_FLAG)
1342
 
    output << ", UNSIGNED";
1343
 
 
1344
 
  if (field.flags & BINARY_FLAG)
1345
 
    output << ", BINARY";
1346
 
  output << "}, ";
1347
 
  output << ")";
1348
 
 
1349
 
  return output;  // for multiple << operators.
1350
 
}
1351
 
 
1352
 
} /* namespace drizzled */