~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Lee
  • Date: 2009-01-01 17:36:53 UTC
  • mto: (758.1.3 devel)
  • mto: This revision was merged to the branch mainline in revision 759.
  • Revision ID: lbieber@lbieber-desktop-20090101173653-qo5945pnje5j3vuu
more header file cleanup

Show diffs side-by-side

added added

removed removed

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