~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

Fix merge issues with 1.0 CC fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
 
4
 *  Copyright (C) 2010 Brian Aker
4
5
 *  Copyright (C) 2008 MySQL
5
6
 *
6
7
 *  This program is free software; you can redistribute it and/or modify
19
20
 */
20
21
 
21
22
/**
22
 
  @file
 
23
 * @file This file implements the Field class and API
 
24
 */
23
25
 
24
 
  @brief
25
 
  This file implements classes defined in field.h
26
 
*/
27
 
#include <drizzled/server_includes.h>
28
 
#include "sql_select.h"
 
26
#include <config.h>
 
27
#include <cstdio>
29
28
#include <errno.h>
 
29
#include <float.h>
 
30
#include <drizzled/sql_select.h>
30
31
#include <drizzled/error.h>
31
 
#include <drizzled/virtual_column_info.h>
32
32
#include <drizzled/field/str.h>
33
 
#include <drizzled/field/longstr.h>
34
33
#include <drizzled/field/num.h>
35
34
#include <drizzled/field/blob.h>
 
35
#include <drizzled/field/boolean.h>
36
36
#include <drizzled/field/enum.h>
37
37
#include <drizzled/field/null.h>
38
38
#include <drizzled/field/date.h>
39
 
#include <drizzled/field/fdecimal.h>
 
39
#include <drizzled/field/decimal.h>
40
40
#include <drizzled/field/real.h>
41
41
#include <drizzled/field/double.h>
42
 
#include <drizzled/field/long.h>
43
 
#include <drizzled/field/int64_t.h>
 
42
#include <drizzled/field/int32.h>
 
43
#include <drizzled/field/int64.h>
44
44
#include <drizzled/field/num.h>
45
 
#include <drizzled/field/timetype.h>
46
 
#include <drizzled/field/timestamp.h>
 
45
#include <drizzled/field/time.h>
 
46
#include <drizzled/field/epoch.h>
47
47
#include <drizzled/field/datetime.h>
 
48
#include <drizzled/field/microtime.h>
48
49
#include <drizzled/field/varstring.h>
 
50
#include <drizzled/field/uuid.h>
 
51
#include <drizzled/field/ipv6.h>
 
52
#include <drizzled/time_functions.h>
 
53
#include <drizzled/internal/m_string.h>
 
54
#include <drizzled/table.h>
 
55
#include <drizzled/util/test.h>
 
56
#include <drizzled/session.h>
 
57
#include <drizzled/current_session.h>
 
58
#include <drizzled/display.h>
 
59
#include <drizzled/typelib.h>
 
60
#include <drizzled/create_field.h>
49
61
 
 
62
namespace drizzled {
50
63
 
51
64
/*****************************************************************************
52
65
  Instansiate templates and static variables
53
66
*****************************************************************************/
54
67
 
55
 
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
56
 
template class List<Create_field>;
57
 
template class List_iterator<Create_field>;
58
 
#endif
59
 
 
60
 
 
61
68
static enum_field_types
62
 
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
 
69
field_types_merge_rules [enum_field_types_size][enum_field_types_size]=
63
70
{
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
 
  },
95
71
  /* DRIZZLE_TYPE_LONG -> */
96
72
  {
97
 
    //DRIZZLE_TYPE_TINY
98
 
    DRIZZLE_TYPE_LONG,
99
73
    //DRIZZLE_TYPE_LONG
100
74
    DRIZZLE_TYPE_LONG,
101
75
    //DRIZZLE_TYPE_DOUBLE
106
80
    DRIZZLE_TYPE_VARCHAR,
107
81
    //DRIZZLE_TYPE_LONGLONG
108
82
    DRIZZLE_TYPE_LONGLONG,
109
 
    //DRIZZLE_TYPE_TIME
110
 
    DRIZZLE_TYPE_VARCHAR,
111
83
    //DRIZZLE_TYPE_DATETIME
112
84
    DRIZZLE_TYPE_VARCHAR,
113
85
    //DRIZZLE_TYPE_DATE
114
86
    DRIZZLE_TYPE_VARCHAR,
115
87
    //DRIZZLE_TYPE_VARCHAR
116
88
    DRIZZLE_TYPE_VARCHAR,
117
 
    //DRIZZLE_TYPE_VIRTUAL
118
 
    DRIZZLE_TYPE_VIRTUAL,
119
 
    //DRIZZLE_TYPE_NEWDECIMAL
120
 
    DRIZZLE_TYPE_NEWDECIMAL,
 
89
    //DRIZZLE_TYPE_DECIMAL
 
90
    DRIZZLE_TYPE_DECIMAL,
121
91
    //DRIZZLE_TYPE_ENUM
122
92
    DRIZZLE_TYPE_VARCHAR,
123
93
    //DRIZZLE_TYPE_BLOB
124
94
    DRIZZLE_TYPE_BLOB,
 
95
    //DRIZZLE_TYPE_TIME
 
96
    DRIZZLE_TYPE_TIME,
 
97
    //DRIZZLE_TYPE_BOOLEAN
 
98
    DRIZZLE_TYPE_VARCHAR,
 
99
    //DRIZZLE_TYPE_UUID
 
100
    DRIZZLE_TYPE_VARCHAR,
 
101
    //DRIZZLE_TYPE_MICROTIME
 
102
    DRIZZLE_TYPE_VARCHAR,
 
103
    //DRIZZLE_TYPE_IPV6
 
104
    DRIZZLE_TYPE_VARCHAR,
125
105
  },
126
106
  /* DRIZZLE_TYPE_DOUBLE -> */
127
107
  {
128
 
    //DRIZZLE_TYPE_TINY
129
 
    DRIZZLE_TYPE_DOUBLE,
130
108
    //DRIZZLE_TYPE_LONG
131
109
    DRIZZLE_TYPE_DOUBLE,
132
110
    //DRIZZLE_TYPE_DOUBLE
137
115
    DRIZZLE_TYPE_VARCHAR,
138
116
    //DRIZZLE_TYPE_LONGLONG
139
117
    DRIZZLE_TYPE_DOUBLE,
140
 
    //DRIZZLE_TYPE_TIME
141
 
    DRIZZLE_TYPE_VARCHAR,
142
118
    //DRIZZLE_TYPE_DATETIME
143
119
    DRIZZLE_TYPE_VARCHAR,
144
120
    //DRIZZLE_TYPE_DATE
145
121
    DRIZZLE_TYPE_VARCHAR,
146
122
    //DRIZZLE_TYPE_VARCHAR
147
123
    DRIZZLE_TYPE_VARCHAR,
148
 
    //DRIZZLE_TYPE_VIRTUAL
149
 
    DRIZZLE_TYPE_VIRTUAL,
150
 
    //DRIZZLE_TYPE_NEWDECIMAL
 
124
    //DRIZZLE_TYPE_DECIMAL
151
125
    DRIZZLE_TYPE_DOUBLE,
152
126
    //DRIZZLE_TYPE_ENUM
153
127
    DRIZZLE_TYPE_VARCHAR,
154
128
    //DRIZZLE_TYPE_BLOB
155
129
    DRIZZLE_TYPE_BLOB,
 
130
    //DRIZZLE_TYPE_TIME
 
131
    DRIZZLE_TYPE_TIME,
 
132
    //DRIZZLE_TYPE_BOOLEAN
 
133
    DRIZZLE_TYPE_VARCHAR,
 
134
    //DRIZZLE_TYPE_UUID
 
135
    DRIZZLE_TYPE_VARCHAR,
 
136
    //DRIZZLE_TYPE_MICROTIME
 
137
    DRIZZLE_TYPE_VARCHAR,
 
138
    //DRIZZLE_TYPE_IPV6
 
139
    DRIZZLE_TYPE_VARCHAR,
156
140
  },
157
141
  /* DRIZZLE_TYPE_NULL -> */
158
142
  {
159
 
    //DRIZZLE_TYPE_TINY
160
 
    DRIZZLE_TYPE_TINY,
161
143
    //DRIZZLE_TYPE_LONG
162
144
    DRIZZLE_TYPE_LONG,
163
145
    //DRIZZLE_TYPE_DOUBLE
168
150
    DRIZZLE_TYPE_TIMESTAMP,
169
151
    //DRIZZLE_TYPE_LONGLONG
170
152
    DRIZZLE_TYPE_LONGLONG,
171
 
    //DRIZZLE_TYPE_TIME
172
 
    DRIZZLE_TYPE_TIME,
173
153
    //DRIZZLE_TYPE_DATETIME
174
154
    DRIZZLE_TYPE_DATETIME,
175
155
    //DRIZZLE_TYPE_DATE
176
156
    DRIZZLE_TYPE_DATE,
177
157
    //DRIZZLE_TYPE_VARCHAR
178
158
    DRIZZLE_TYPE_VARCHAR,
179
 
    //DRIZZLE_TYPE_VIRTUAL
180
 
    DRIZZLE_TYPE_VIRTUAL,
181
 
    //DRIZZLE_TYPE_NEWDECIMAL
182
 
    DRIZZLE_TYPE_NEWDECIMAL,
 
159
    //DRIZZLE_TYPE_DECIMAL
 
160
    DRIZZLE_TYPE_DECIMAL,
183
161
    //DRIZZLE_TYPE_ENUM
184
162
    DRIZZLE_TYPE_ENUM,
185
163
    //DRIZZLE_TYPE_BLOB
186
164
    DRIZZLE_TYPE_BLOB,
 
165
    //DRIZZLE_TYPE_TIME
 
166
    DRIZZLE_TYPE_TIME,
 
167
    //DRIZZLE_TYPE_BOOLEAN
 
168
    DRIZZLE_TYPE_BOOLEAN,
 
169
    //DRIZZLE_TYPE_UUID
 
170
    DRIZZLE_TYPE_UUID,
 
171
    //DRIZZLE_TYPE_MICROTIME
 
172
    DRIZZLE_TYPE_MICROTIME,
 
173
    //DRIZZLE_TYPE_IPV6
 
174
    DRIZZLE_TYPE_VARCHAR,
187
175
  },
188
176
  /* DRIZZLE_TYPE_TIMESTAMP -> */
189
177
  {
190
 
    //DRIZZLE_TYPE_TINY
191
 
    DRIZZLE_TYPE_VARCHAR,
192
178
    //DRIZZLE_TYPE_LONG
193
179
    DRIZZLE_TYPE_VARCHAR,
194
180
    //DRIZZLE_TYPE_DOUBLE
199
185
    DRIZZLE_TYPE_TIMESTAMP,
200
186
    //DRIZZLE_TYPE_LONGLONG
201
187
    DRIZZLE_TYPE_VARCHAR,
202
 
    //DRIZZLE_TYPE_TIME
203
 
    DRIZZLE_TYPE_DATETIME,
204
188
    //DRIZZLE_TYPE_DATETIME
205
189
    DRIZZLE_TYPE_DATETIME,
206
190
    //DRIZZLE_TYPE_DATE
207
191
    DRIZZLE_TYPE_DATE,
208
192
    //DRIZZLE_TYPE_VARCHAR
209
193
    DRIZZLE_TYPE_VARCHAR,
210
 
    //DRIZZLE_TYPE_VIRTUAL
211
 
    DRIZZLE_TYPE_VIRTUAL,
212
 
    //DRIZZLE_TYPE_NEWDECIMAL
 
194
    //DRIZZLE_TYPE_DECIMAL
213
195
    DRIZZLE_TYPE_VARCHAR,
214
196
    //DRIZZLE_TYPE_ENUM
215
197
    DRIZZLE_TYPE_VARCHAR,
216
198
    //DRIZZLE_TYPE_BLOB
217
199
    DRIZZLE_TYPE_BLOB,
 
200
    //DRIZZLE_TYPE_TIME
 
201
    DRIZZLE_TYPE_TIME,
 
202
    //DRIZZLE_TYPE_BOOLEAN
 
203
    DRIZZLE_TYPE_VARCHAR,
 
204
    //DRIZZLE_TYPE_UUID
 
205
    DRIZZLE_TYPE_VARCHAR,
 
206
    //DRIZZLE_TYPE_MICROTIME
 
207
    DRIZZLE_TYPE_VARCHAR,
 
208
    //DRIZZLE_TYPE_IPV6
 
209
    DRIZZLE_TYPE_VARCHAR,
218
210
  },
219
211
  /* DRIZZLE_TYPE_LONGLONG -> */
220
212
  {
221
 
    //DRIZZLE_TYPE_TINY
222
 
    DRIZZLE_TYPE_LONGLONG,
223
213
    //DRIZZLE_TYPE_LONG
224
214
    DRIZZLE_TYPE_LONGLONG,
225
215
    //DRIZZLE_TYPE_DOUBLE
230
220
    DRIZZLE_TYPE_VARCHAR,
231
221
    //DRIZZLE_TYPE_LONGLONG
232
222
    DRIZZLE_TYPE_LONGLONG,
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,
 
223
    //DRIZZLE_TYPE_DATETIME
 
224
    DRIZZLE_TYPE_VARCHAR,
 
225
    //DRIZZLE_TYPE_DATE
 
226
    DRIZZLE_TYPE_DATE,
 
227
    //DRIZZLE_TYPE_VARCHAR
 
228
    DRIZZLE_TYPE_VARCHAR,
 
229
    //DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_ENUM
 
230
    DRIZZLE_TYPE_DECIMAL,
 
231
    DRIZZLE_TYPE_VARCHAR,
 
232
    //DRIZZLE_TYPE_BLOB
 
233
    DRIZZLE_TYPE_BLOB,
 
234
    //DRIZZLE_TYPE_TIME
 
235
    DRIZZLE_TYPE_TIME,
 
236
    //DRIZZLE_TYPE_BOOLEAN
 
237
    DRIZZLE_TYPE_VARCHAR,
 
238
    //DRIZZLE_TYPE_UUID
 
239
    DRIZZLE_TYPE_VARCHAR,
 
240
    //DRIZZLE_TYPE_MICROTIME
 
241
    DRIZZLE_TYPE_VARCHAR,
 
242
    //DRIZZLE_TYPE_IPV6
 
243
    DRIZZLE_TYPE_VARCHAR,
280
244
  },
281
245
  /* DRIZZLE_TYPE_DATETIME -> */
282
246
  {
283
 
    //DRIZZLE_TYPE_TINY
284
 
    DRIZZLE_TYPE_VARCHAR,
285
247
    //DRIZZLE_TYPE_LONG
286
248
    DRIZZLE_TYPE_VARCHAR,
287
249
    //DRIZZLE_TYPE_DOUBLE
292
254
    DRIZZLE_TYPE_DATETIME,
293
255
    //DRIZZLE_TYPE_LONGLONG
294
256
    DRIZZLE_TYPE_VARCHAR,
295
 
    //DRIZZLE_TYPE_TIME
296
 
    DRIZZLE_TYPE_DATETIME,
297
257
    //DRIZZLE_TYPE_DATETIME
298
258
    DRIZZLE_TYPE_DATETIME,
299
259
    //DRIZZLE_TYPE_DATE
300
260
    DRIZZLE_TYPE_DATE,
301
261
    //DRIZZLE_TYPE_VARCHAR
302
262
    DRIZZLE_TYPE_VARCHAR,
303
 
    //DRIZZLE_TYPE_VIRTUAL
304
 
    DRIZZLE_TYPE_VIRTUAL,
305
 
    //DRIZZLE_TYPE_NEWDECIMAL
 
263
    //DRIZZLE_TYPE_DECIMAL
306
264
    DRIZZLE_TYPE_VARCHAR,
307
265
    //DRIZZLE_TYPE_ENUM
308
266
    DRIZZLE_TYPE_VARCHAR,
309
267
    //DRIZZLE_TYPE_BLOB
310
268
    DRIZZLE_TYPE_BLOB,
 
269
    //DRIZZLE_TYPE_TIME
 
270
    DRIZZLE_TYPE_TIME,
 
271
    //DRIZZLE_TYPE_BOOLEAN
 
272
    DRIZZLE_TYPE_VARCHAR,
 
273
    //DRIZZLE_TYPE_UUID
 
274
    DRIZZLE_TYPE_VARCHAR,
 
275
    //DRIZZLE_TYPE_MICROTIME
 
276
    DRIZZLE_TYPE_VARCHAR,
 
277
    //DRIZZLE_TYPE_IPV6
 
278
    DRIZZLE_TYPE_VARCHAR,
311
279
  },
312
280
  /* DRIZZLE_TYPE_DATE -> */
313
281
  {
314
 
    //DRIZZLE_TYPE_TINY
315
 
    DRIZZLE_TYPE_VARCHAR,
316
282
    //DRIZZLE_TYPE_LONG
317
283
    DRIZZLE_TYPE_VARCHAR,
318
284
    //DRIZZLE_TYPE_DOUBLE
323
289
    DRIZZLE_TYPE_DATETIME,
324
290
    //DRIZZLE_TYPE_LONGLONG
325
291
    DRIZZLE_TYPE_VARCHAR,
326
 
    //DRIZZLE_TYPE_TIME
327
 
    DRIZZLE_TYPE_DATETIME,
328
292
    //DRIZZLE_TYPE_DATETIME
329
293
    DRIZZLE_TYPE_DATETIME,
330
294
    //DRIZZLE_TYPE_DATE
331
295
    DRIZZLE_TYPE_DATE,
332
296
    //DRIZZLE_TYPE_VARCHAR
333
297
    DRIZZLE_TYPE_VARCHAR,
334
 
    //DRIZZLE_TYPE_VIRTUAL
335
 
    DRIZZLE_TYPE_VIRTUAL,
336
 
    //DRIZZLE_TYPE_NEWDECIMAL
 
298
    //DRIZZLE_TYPE_DECIMAL
337
299
    DRIZZLE_TYPE_VARCHAR,
338
300
    //DRIZZLE_TYPE_ENUM
339
301
    DRIZZLE_TYPE_VARCHAR,
340
302
    //DRIZZLE_TYPE_BLOB
341
303
    DRIZZLE_TYPE_BLOB,
 
304
    //DRIZZLE_TYPE_TIME
 
305
    DRIZZLE_TYPE_TIME,
 
306
    //DRIZZLE_TYPE_BOOLEAN
 
307
    DRIZZLE_TYPE_VARCHAR,
 
308
    //DRIZZLE_TYPE_UUID
 
309
    DRIZZLE_TYPE_VARCHAR,
 
310
    //DRIZZLE_TYPE_MICROTIME
 
311
    DRIZZLE_TYPE_VARCHAR,
 
312
    //DRIZZLE_TYPE_IPV6
 
313
    DRIZZLE_TYPE_VARCHAR,
342
314
  },
343
315
  /* DRIZZLE_TYPE_VARCHAR -> */
344
316
  {
345
 
    //DRIZZLE_TYPE_TINY
346
 
    DRIZZLE_TYPE_VARCHAR,
347
317
    //DRIZZLE_TYPE_LONG
348
318
    DRIZZLE_TYPE_VARCHAR,
349
319
    //DRIZZLE_TYPE_DOUBLE
354
324
    DRIZZLE_TYPE_VARCHAR,
355
325
    //DRIZZLE_TYPE_LONGLONG
356
326
    DRIZZLE_TYPE_VARCHAR,
357
 
    //DRIZZLE_TYPE_TIME
358
 
    DRIZZLE_TYPE_VARCHAR,
359
327
    //DRIZZLE_TYPE_DATETIME
360
328
    DRIZZLE_TYPE_VARCHAR,
361
329
    //DRIZZLE_TYPE_DATE
362
330
    DRIZZLE_TYPE_VARCHAR,
363
331
    //DRIZZLE_TYPE_VARCHAR
364
332
    DRIZZLE_TYPE_VARCHAR,
365
 
    //DRIZZLE_TYPE_VIRTUAL
366
 
    DRIZZLE_TYPE_VIRTUAL,
367
 
    //DRIZZLE_TYPE_NEWDECIMAL
 
333
    //DRIZZLE_TYPE_DECIMAL
368
334
    DRIZZLE_TYPE_VARCHAR,
369
335
    //DRIZZLE_TYPE_ENUM
370
336
    DRIZZLE_TYPE_VARCHAR,
371
337
    //DRIZZLE_TYPE_BLOB
372
338
    DRIZZLE_TYPE_BLOB,
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
339
    //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,
 
340
    DRIZZLE_TYPE_TIME,
 
341
    //DRIZZLE_TYPE_BOOLEAN
 
342
    DRIZZLE_TYPE_VARCHAR,
 
343
    //DRIZZLE_TYPE_UUID
 
344
    DRIZZLE_TYPE_VARCHAR,
 
345
    //DRIZZLE_TYPE_MICROTIME
 
346
    DRIZZLE_TYPE_VARCHAR,
 
347
    //DRIZZLE_TYPE_IPV6
 
348
    DRIZZLE_TYPE_VARCHAR,
404
349
  },
405
 
  /* DRIZZLE_TYPE_NEWDECIMAL -> */
 
350
  /* DRIZZLE_TYPE_DECIMAL -> */
406
351
  {
407
 
    //DRIZZLE_TYPE_TINY
408
 
    DRIZZLE_TYPE_NEWDECIMAL,
409
352
    //DRIZZLE_TYPE_LONG
410
 
    DRIZZLE_TYPE_NEWDECIMAL,
 
353
    DRIZZLE_TYPE_DECIMAL,
411
354
    //DRIZZLE_TYPE_DOUBLE
412
355
    DRIZZLE_TYPE_DOUBLE,
413
356
    //DRIZZLE_TYPE_NULL
414
 
    DRIZZLE_TYPE_NEWDECIMAL,
 
357
    DRIZZLE_TYPE_DECIMAL,
415
358
    //DRIZZLE_TYPE_TIMESTAMP
416
359
    DRIZZLE_TYPE_VARCHAR,
417
360
    //DRIZZLE_TYPE_LONGLONG
418
 
    DRIZZLE_TYPE_NEWDECIMAL,
419
 
    //DRIZZLE_TYPE_TIME
420
 
    DRIZZLE_TYPE_VARCHAR,
 
361
    DRIZZLE_TYPE_DECIMAL,
421
362
    //DRIZZLE_TYPE_DATETIME
422
363
    DRIZZLE_TYPE_VARCHAR,
423
364
    //DRIZZLE_TYPE_DATE
424
365
    DRIZZLE_TYPE_VARCHAR,
425
366
    //DRIZZLE_TYPE_VARCHAR
426
367
    DRIZZLE_TYPE_VARCHAR,
427
 
    //DRIZZLE_TYPE_VIRTUAL
428
 
    DRIZZLE_TYPE_VIRTUAL,
429
 
    //DRIZZLE_TYPE_NEWDECIMAL
430
 
    DRIZZLE_TYPE_NEWDECIMAL,
 
368
    //DRIZZLE_TYPE_DECIMAL
 
369
    DRIZZLE_TYPE_DECIMAL,
431
370
    //DRIZZLE_TYPE_ENUM
432
371
    DRIZZLE_TYPE_VARCHAR,
433
372
    //DRIZZLE_TYPE_BLOB
434
373
    DRIZZLE_TYPE_BLOB,
 
374
    //DRIZZLE_TYPE_TIME
 
375
    DRIZZLE_TYPE_TIME,
 
376
    //DRIZZLE_TYPE_BOOLEAN
 
377
    DRIZZLE_TYPE_VARCHAR,
 
378
    //DRIZZLE_TYPE_UUID
 
379
    DRIZZLE_TYPE_VARCHAR,
 
380
    //DRIZZLE_TYPE_MICROTIME
 
381
    DRIZZLE_TYPE_VARCHAR,
 
382
    //DRIZZLE_TYPE_IPV6
 
383
    DRIZZLE_TYPE_VARCHAR,
435
384
  },
436
385
  /* DRIZZLE_TYPE_ENUM -> */
437
386
  {
438
 
    //DRIZZLE_TYPE_TINY
439
 
    DRIZZLE_TYPE_VARCHAR,
440
387
    //DRIZZLE_TYPE_LONG
441
388
    DRIZZLE_TYPE_VARCHAR,
442
389
    //DRIZZLE_TYPE_DOUBLE
447
394
    DRIZZLE_TYPE_VARCHAR,
448
395
    //DRIZZLE_TYPE_LONGLONG
449
396
    DRIZZLE_TYPE_VARCHAR,
450
 
    //DRIZZLE_TYPE_TIME
451
 
    DRIZZLE_TYPE_VARCHAR,
452
397
    //DRIZZLE_TYPE_DATETIME
453
398
    DRIZZLE_TYPE_VARCHAR,
454
399
    //DRIZZLE_TYPE_DATE
455
400
    DRIZZLE_TYPE_VARCHAR,
456
401
    //DRIZZLE_TYPE_VARCHAR
457
402
    DRIZZLE_TYPE_VARCHAR,
458
 
    //DRIZZLE_TYPE_VIRTUAL
459
 
    DRIZZLE_TYPE_VIRTUAL,
460
 
    //DRIZZLE_TYPE_NEWDECIMAL
 
403
    //DRIZZLE_TYPE_DECIMAL
461
404
    DRIZZLE_TYPE_VARCHAR,
462
405
    //DRIZZLE_TYPE_ENUM
463
406
    DRIZZLE_TYPE_VARCHAR,
464
407
    //DRIZZLE_TYPE_BLOB
465
408
    DRIZZLE_TYPE_BLOB,
466
 
  },
 
409
    //DRIZZLE_TYPE_TIME
 
410
    DRIZZLE_TYPE_TIME,
 
411
    //DRIZZLE_TYPE_BOOLEAN
 
412
    DRIZZLE_TYPE_VARCHAR,
 
413
    //DRIZZLE_TYPE_UUID
 
414
    DRIZZLE_TYPE_VARCHAR,
 
415
    //DRIZZLE_TYPE_MICROTIME
 
416
    DRIZZLE_TYPE_VARCHAR,
 
417
    //DRIZZLE_TYPE_IPV6
 
418
    DRIZZLE_TYPE_VARCHAR,
 
419
   },
467
420
  /* DRIZZLE_TYPE_BLOB -> */
468
421
  {
469
 
    //DRIZZLE_TYPE_TINY
470
 
    DRIZZLE_TYPE_BLOB,
471
422
    //DRIZZLE_TYPE_LONG
472
423
    DRIZZLE_TYPE_BLOB,
473
424
    //DRIZZLE_TYPE_DOUBLE
478
429
    DRIZZLE_TYPE_BLOB,
479
430
    //DRIZZLE_TYPE_LONGLONG
480
431
    DRIZZLE_TYPE_BLOB,
481
 
    //DRIZZLE_TYPE_TIME
482
 
    DRIZZLE_TYPE_BLOB,
483
432
    //DRIZZLE_TYPE_DATETIME
484
433
    DRIZZLE_TYPE_BLOB,
485
434
    //DRIZZLE_TYPE_DATE
486
435
    DRIZZLE_TYPE_BLOB,
487
436
    //DRIZZLE_TYPE_VARCHAR
488
437
    DRIZZLE_TYPE_BLOB,
489
 
    //DRIZZLE_TYPE_VIRTUAL
490
 
    DRIZZLE_TYPE_VIRTUAL,
491
 
    //DRIZZLE_TYPE_NEWDECIMAL
 
438
    //DRIZZLE_TYPE_DECIMAL
492
439
    DRIZZLE_TYPE_BLOB,
493
440
    //DRIZZLE_TYPE_ENUM
494
441
    DRIZZLE_TYPE_BLOB,
495
442
    //DRIZZLE_TYPE_BLOB
496
443
    DRIZZLE_TYPE_BLOB,
 
444
    //DRIZZLE_TYPE_TIME
 
445
    DRIZZLE_TYPE_TIME,
 
446
    //DRIZZLE_TYPE_BOOLEAN
 
447
    DRIZZLE_TYPE_VARCHAR,
 
448
    //DRIZZLE_TYPE_UUID
 
449
    DRIZZLE_TYPE_VARCHAR,
 
450
    //DRIZZLE_TYPE_MICROTIME
 
451
    DRIZZLE_TYPE_VARCHAR,
 
452
    //DRIZZLE_TYPE_IPV6
 
453
    DRIZZLE_TYPE_VARCHAR,
 
454
  },
 
455
  /* DRIZZLE_TYPE_TIME -> */
 
456
  {
 
457
    //DRIZZLE_TYPE_LONG
 
458
    DRIZZLE_TYPE_VARCHAR,
 
459
    //DRIZZLE_TYPE_DOUBLE
 
460
    DRIZZLE_TYPE_VARCHAR,
 
461
    //DRIZZLE_TYPE_NULL
 
462
    DRIZZLE_TYPE_TIME,
 
463
    //DRIZZLE_TYPE_TIMESTAMP
 
464
    DRIZZLE_TYPE_VARCHAR,
 
465
    //DRIZZLE_TYPE_LONGLONG
 
466
    DRIZZLE_TYPE_VARCHAR,
 
467
    //DRIZZLE_TYPE_DATETIME
 
468
    DRIZZLE_TYPE_VARCHAR,
 
469
    //DRIZZLE_TYPE_DATE
 
470
    DRIZZLE_TYPE_VARCHAR,
 
471
    //DRIZZLE_TYPE_VARCHAR
 
472
    DRIZZLE_TYPE_VARCHAR,
 
473
    //DRIZZLE_TYPE_DECIMAL
 
474
    DRIZZLE_TYPE_VARCHAR,
 
475
    //DRIZZLE_TYPE_VARCHAR,
 
476
    DRIZZLE_TYPE_VARCHAR,
 
477
    //DRIZZLE_TYPE_BLOB
 
478
    DRIZZLE_TYPE_BLOB,
 
479
    //DRIZZLE_TYPE_TIME
 
480
    DRIZZLE_TYPE_TIME,
 
481
    //DRIZZLE_TYPE_BOOLEAN
 
482
    DRIZZLE_TYPE_VARCHAR,
 
483
    //DRIZZLE_TYPE_UUID
 
484
    DRIZZLE_TYPE_UUID,
 
485
    //DRIZZLE_TYPE_MICROTIME
 
486
    DRIZZLE_TYPE_VARCHAR,
 
487
    //DRIZZLE_TYPE_IPV6
 
488
    DRIZZLE_TYPE_VARCHAR,
 
489
  },
 
490
  /* DRIZZLE_TYPE_BOOLEAN -> */
 
491
  {
 
492
    //DRIZZLE_TYPE_LONG
 
493
    DRIZZLE_TYPE_VARCHAR,
 
494
    //DRIZZLE_TYPE_DOUBLE
 
495
    DRIZZLE_TYPE_VARCHAR,
 
496
    //DRIZZLE_TYPE_NULL
 
497
    DRIZZLE_TYPE_BOOLEAN,
 
498
    //DRIZZLE_TYPE_TIMESTAMP
 
499
    DRIZZLE_TYPE_VARCHAR,
 
500
    //DRIZZLE_TYPE_LONGLONG
 
501
    DRIZZLE_TYPE_VARCHAR,
 
502
    //DRIZZLE_TYPE_DATETIME
 
503
    DRIZZLE_TYPE_VARCHAR,
 
504
    //DRIZZLE_TYPE_DATE
 
505
    DRIZZLE_TYPE_VARCHAR,
 
506
    //DRIZZLE_TYPE_VARCHAR
 
507
    DRIZZLE_TYPE_VARCHAR,
 
508
    //DRIZZLE_TYPE_DECIMAL
 
509
    DRIZZLE_TYPE_VARCHAR,
 
510
    //DRIZZLE_TYPE_VARCHAR,
 
511
    DRIZZLE_TYPE_VARCHAR,
 
512
    //DRIZZLE_TYPE_BLOB
 
513
    DRIZZLE_TYPE_BLOB,
 
514
    //DRIZZLE_TYPE_TIME
 
515
    DRIZZLE_TYPE_TIME,
 
516
    //DRIZZLE_TYPE_BOOLEAN
 
517
    DRIZZLE_TYPE_BOOLEAN,
 
518
    //DRIZZLE_TYPE_UUID
 
519
    DRIZZLE_TYPE_VARCHAR,
 
520
    //DRIZZLE_TYPE_MICROTIME
 
521
    DRIZZLE_TYPE_VARCHAR,
 
522
    //DRIZZLE_TYPE_IPV6
 
523
    DRIZZLE_TYPE_VARCHAR,
 
524
  },
 
525
  /* DRIZZLE_TYPE_UUID -> */
 
526
  {
 
527
    //DRIZZLE_TYPE_LONG
 
528
    DRIZZLE_TYPE_VARCHAR,
 
529
    //DRIZZLE_TYPE_DOUBLE
 
530
    DRIZZLE_TYPE_VARCHAR,
 
531
    //DRIZZLE_TYPE_NULL
 
532
    DRIZZLE_TYPE_UUID,
 
533
    //DRIZZLE_TYPE_TIMESTAMP
 
534
    DRIZZLE_TYPE_VARCHAR,
 
535
    //DRIZZLE_TYPE_LONGLONG
 
536
    DRIZZLE_TYPE_VARCHAR,
 
537
    //DRIZZLE_TYPE_DATETIME
 
538
    DRIZZLE_TYPE_VARCHAR,
 
539
    //DRIZZLE_TYPE_DATE
 
540
    DRIZZLE_TYPE_VARCHAR,
 
541
    //DRIZZLE_TYPE_VARCHAR
 
542
    DRIZZLE_TYPE_VARCHAR,
 
543
    //DRIZZLE_TYPE_DECIMAL
 
544
    DRIZZLE_TYPE_VARCHAR,
 
545
    //DRIZZLE_TYPE_VARCHAR,
 
546
    DRIZZLE_TYPE_VARCHAR,
 
547
    //DRIZZLE_TYPE_BLOB
 
548
    DRIZZLE_TYPE_BLOB,
 
549
    //DRIZZLE_TYPE_TIME
 
550
    DRIZZLE_TYPE_TIME,
 
551
    //DRIZZLE_TYPE_BOOLEAN
 
552
    DRIZZLE_TYPE_VARCHAR,
 
553
    //DRIZZLE_TYPE_UUID
 
554
    DRIZZLE_TYPE_UUID,
 
555
    //DRIZZLE_TYPE_MICROTIME
 
556
    DRIZZLE_TYPE_VARCHAR,
 
557
    //DRIZZLE_TYPE_IPV6
 
558
    DRIZZLE_TYPE_VARCHAR,
 
559
  },
 
560
  /* DRIZZLE_TYPE_MICROTIME -> */
 
561
  {
 
562
    //DRIZZLE_TYPE_LONG
 
563
    DRIZZLE_TYPE_VARCHAR,
 
564
    //DRIZZLE_TYPE_DOUBLE
 
565
    DRIZZLE_TYPE_VARCHAR,
 
566
    //DRIZZLE_TYPE_NULL
 
567
    DRIZZLE_TYPE_MICROTIME,
 
568
    //DRIZZLE_TYPE_TIMESTAMP
 
569
    DRIZZLE_TYPE_VARCHAR,
 
570
    //DRIZZLE_TYPE_LONGLONG
 
571
    DRIZZLE_TYPE_VARCHAR,
 
572
    //DRIZZLE_TYPE_DATETIME
 
573
    DRIZZLE_TYPE_VARCHAR,
 
574
    //DRIZZLE_TYPE_DATE
 
575
    DRIZZLE_TYPE_VARCHAR,
 
576
    //DRIZZLE_TYPE_VARCHAR
 
577
    DRIZZLE_TYPE_VARCHAR,
 
578
    //DRIZZLE_TYPE_DECIMAL
 
579
    DRIZZLE_TYPE_VARCHAR,
 
580
    //DRIZZLE_TYPE_VARCHAR,
 
581
    DRIZZLE_TYPE_VARCHAR,
 
582
    //DRIZZLE_TYPE_BLOB
 
583
    DRIZZLE_TYPE_BLOB,
 
584
    //DRIZZLE_TYPE_TIME
 
585
    DRIZZLE_TYPE_TIME,
 
586
    //DRIZZLE_TYPE_BOOLEAN
 
587
    DRIZZLE_TYPE_VARCHAR,
 
588
    //DRIZZLE_TYPE_UUID
 
589
    DRIZZLE_TYPE_UUID,
 
590
    //DRIZZLE_TYPE_MICROTIME
 
591
    DRIZZLE_TYPE_MICROTIME,
 
592
    //DRIZZLE_TYPE_IPV6
 
593
    DRIZZLE_TYPE_VARCHAR,
 
594
  },
 
595
  /* DRIZZLE_TYPE_IPV6 -> */
 
596
  {
 
597
    //DRIZZLE_TYPE_LONG
 
598
    DRIZZLE_TYPE_VARCHAR,
 
599
    //DRIZZLE_TYPE_DOUBLE
 
600
    DRIZZLE_TYPE_VARCHAR,
 
601
    //DRIZZLE_TYPE_NULL
 
602
    DRIZZLE_TYPE_IPV6,
 
603
    //DRIZZLE_TYPE_TIMESTAMP
 
604
    DRIZZLE_TYPE_VARCHAR,
 
605
    //DRIZZLE_TYPE_LONGLONG
 
606
    DRIZZLE_TYPE_VARCHAR,
 
607
    //DRIZZLE_TYPE_DATETIME
 
608
    DRIZZLE_TYPE_VARCHAR,
 
609
    //DRIZZLE_TYPE_DATE
 
610
    DRIZZLE_TYPE_VARCHAR,
 
611
    //DRIZZLE_TYPE_VARCHAR
 
612
    DRIZZLE_TYPE_VARCHAR,
 
613
    //DRIZZLE_TYPE_DECIMAL
 
614
    DRIZZLE_TYPE_VARCHAR,
 
615
    //DRIZZLE_TYPE_VARCHAR,
 
616
    DRIZZLE_TYPE_VARCHAR,
 
617
    //DRIZZLE_TYPE_BLOB
 
618
    DRIZZLE_TYPE_BLOB,
 
619
    //DRIZZLE_TYPE_TIME
 
620
    DRIZZLE_TYPE_TIME,
 
621
    //DRIZZLE_TYPE_BOOLEAN
 
622
    DRIZZLE_TYPE_VARCHAR,
 
623
    //DRIZZLE_TYPE_UUID
 
624
    DRIZZLE_TYPE_UUID,
 
625
    //DRIZZLE_TYPE_MICROTIME
 
626
    DRIZZLE_TYPE_MICROTIME,
 
627
    //DRIZZLE_TYPE_IPV6
 
628
    DRIZZLE_TYPE_VARCHAR,
497
629
  },
498
630
};
499
631
 
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,
 
632
static Item_result field_types_result_type [enum_field_types_size]=
 
633
{
523
634
  //DRIZZLE_TYPE_LONG
524
635
  INT_RESULT,
525
636
  //DRIZZLE_TYPE_DOUBLE
530
641
  STRING_RESULT,
531
642
  //DRIZZLE_TYPE_LONGLONG
532
643
  INT_RESULT,
533
 
  //DRIZZLE_TYPE_TIME
534
 
  STRING_RESULT,
535
644
  //DRIZZLE_TYPE_DATETIME
536
645
  STRING_RESULT,
537
646
  //DRIZZLE_TYPE_DATE
538
647
  STRING_RESULT,
539
648
  //DRIZZLE_TYPE_VARCHAR
540
649
  STRING_RESULT,
541
 
  //DRIZZLE_TYPE_VIRTUAL
 
650
  //DRIZZLE_TYPE_DECIMAL   
 
651
  DECIMAL_RESULT,           
 
652
  //DRIZZLE_TYPE_ENUM
542
653
  STRING_RESULT,
543
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
544
 
  DECIMAL_RESULT,           STRING_RESULT,
545
654
  //DRIZZLE_TYPE_BLOB
546
655
  STRING_RESULT,
 
656
  //DRIZZLE_TYPE_TIME
 
657
  STRING_RESULT,
 
658
  //DRIZZLE_TYPE_BOOLEAN
 
659
  STRING_RESULT,
 
660
  //DRIZZLE_TYPE_UUID
 
661
  STRING_RESULT,
 
662
  //DRIZZLE_TYPE_MICROTIME
 
663
  STRING_RESULT,
 
664
  //DRIZZLE_TYPE_IPV6
 
665
  STRING_RESULT,
547
666
};
548
667
 
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)
 
668
bool test_if_important_data(const charset_info_st * const cs, 
 
669
                            const char *str,
 
670
                            const char *strend)
569
671
{
570
672
  if (cs != &my_charset_bin)
571
673
    str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
572
674
  return (str < strend);
573
675
}
574
676
 
 
677
void *Field::operator new(size_t size)
 
678
{
 
679
  return memory::sql_alloc(size);
 
680
}
 
681
 
 
682
void *Field::operator new(size_t size, memory::Root *mem_root)
 
683
{
 
684
  return mem_root->alloc(size);
 
685
}
 
686
 
 
687
enum_field_types Field::field_type_merge(enum_field_types a,
 
688
                                         enum_field_types b)
 
689
{
 
690
  assert(a < enum_field_types_size);
 
691
  assert(b < enum_field_types_size);
 
692
  return field_types_merge_rules[a][b];
 
693
}
575
694
 
576
695
Item_result Field::result_merge_type(enum_field_types field_type)
577
696
{
578
 
  assert(field_type <= DRIZZLE_TYPE_MAX);
 
697
  assert(field_type < enum_field_types_size);
579
698
  return field_types_result_type[field_type];
580
699
}
581
700
 
582
 
 
583
701
bool Field::eq(Field *field)
584
702
{
585
703
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
586
704
          null_bit == field->null_bit);
587
705
}
588
706
 
589
 
 
590
707
uint32_t Field::pack_length() const
591
708
{
592
709
  return field_length;
593
710
}
594
711
 
595
 
 
596
712
uint32_t Field::pack_length_in_rec() const
597
713
{
598
714
  return pack_length();
599
715
}
600
716
 
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
 
 
620
717
uint32_t Field::data_length()
621
718
{
622
719
  return pack_length();
623
720
}
624
721
 
625
 
 
626
722
uint32_t Field::used_length()
627
723
{
628
724
  return pack_length();
629
725
}
630
726
 
631
 
 
632
727
uint32_t Field::sort_length() const
633
728
{
634
729
  return pack_length();
635
730
}
636
731
 
637
 
 
638
732
uint32_t Field::max_data_length() const
639
733
{
640
734
  return pack_length();
641
735
}
642
736
 
643
 
 
644
737
int Field::reset(void)
645
738
{
646
739
  memset(ptr, 0, pack_length());
647
740
  return 0;
648
741
}
649
742
 
650
 
 
651
743
void Field::reset_fields()
652
744
{}
653
745
 
654
 
 
655
746
void Field::set_default()
656
747
{
657
 
  my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
 
748
  ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->getInsertRecord());
658
749
  memcpy(ptr, ptr + l_offset, pack_length());
659
750
  if (null_ptr)
660
751
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
 
752
 
 
753
  if (this == table->next_number_field)
 
754
    table->auto_increment_field_not_null= false;
661
755
}
662
756
 
663
 
 
664
757
bool Field::binary() const
665
758
{
666
 
  return 1;
 
759
  return true;
667
760
}
668
761
 
669
 
 
670
762
bool Field::zero_pack() const
671
763
{
672
 
  return 1;
 
764
  return true;
673
765
}
674
766
 
675
 
 
676
767
enum ha_base_keytype Field::key_type() const
677
768
{
678
769
  return HA_KEYTYPE_BINARY;
679
770
}
680
771
 
681
 
 
682
772
uint32_t Field::key_length() const
683
773
{
684
774
  return pack_length();
685
775
}
686
776
 
687
 
 
688
777
enum_field_types Field::real_type() const
689
778
{
690
779
  return type();
691
780
}
692
781
 
693
 
 
694
782
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
695
783
{
696
784
  return cmp(a, b);
697
785
}
698
786
 
699
 
 
700
787
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
701
788
{
702
789
  return memcmp(a,b,pack_length());
703
790
}
704
791
 
705
 
 
706
792
int Field::cmp_offset(uint32_t row_offset)
707
793
{
708
794
  return cmp(ptr,ptr+row_offset);
709
795
}
710
796
 
711
 
 
712
797
int Field::cmp_binary_offset(uint32_t row_offset)
713
798
{
714
799
  return cmp_binary(ptr, ptr+row_offset);
715
800
}
716
801
 
717
 
 
718
802
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
719
803
{
720
804
  return cmp(a, b);
721
805
}
722
806
 
723
 
 
724
807
int Field::key_cmp(const unsigned char *str, uint32_t)
725
808
{
726
809
  return cmp(ptr,str);
727
810
}
728
811
 
729
 
 
730
812
uint32_t Field::decimals() const
731
813
{
732
814
  return 0;
733
815
}
734
816
 
735
 
 
736
 
bool Field::is_null(my_ptrdiff_t row_offset)
737
 
{
738
 
  return null_ptr ?
739
 
    (null_ptr[row_offset] & null_bit ? true : false) :
740
 
    table->null_row;
741
 
}
742
 
 
743
 
 
744
 
bool Field::is_real_null(my_ptrdiff_t row_offset)
745
 
{
746
 
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
747
 
}
748
 
 
749
 
 
750
 
bool Field::is_null_in_record(const unsigned char *record)
751
 
{
752
 
  if (!null_ptr)
753
 
    return false;
754
 
  return test(record[(uint32_t) (null_ptr -table->record[0])] &
755
 
              null_bit);
756
 
}
757
 
 
758
 
 
759
 
bool Field::is_null_in_record_with_offset(my_ptrdiff_t offset)
760
 
{
761
 
  if (!null_ptr)
762
 
    return false;
763
 
  return test(null_ptr[offset] & null_bit);
764
 
}
765
 
 
766
 
 
767
 
void Field::set_null(my_ptrdiff_t row_offset)
 
817
bool Field::is_null(ptrdiff_t row_offset) const
 
818
{
 
819
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : table->null_row;
 
820
}
 
821
 
 
822
bool Field::is_real_null(ptrdiff_t row_offset) const
 
823
{
 
824
  return null_ptr && (null_ptr[row_offset] & null_bit);
 
825
}
 
826
 
 
827
bool Field::is_null_in_record(const unsigned char *record) const
 
828
{
 
829
  return null_ptr && test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
 
830
}
 
831
 
 
832
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset) const
 
833
{
 
834
  return null_ptr && test(null_ptr[with_offset] & null_bit);
 
835
}
 
836
 
 
837
void Field::set_null(ptrdiff_t row_offset)
768
838
{
769
839
  if (null_ptr)
770
840
    null_ptr[row_offset]|= null_bit;
771
841
}
772
842
 
773
 
 
774
 
void Field::set_notnull(my_ptrdiff_t row_offset)
 
843
void Field::set_notnull(ptrdiff_t row_offset)
775
844
{
776
845
  if (null_ptr)
777
846
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
778
847
}
779
848
 
780
 
 
781
 
bool Field::maybe_null(void)
 
849
bool Field::maybe_null(void) const
782
850
{
783
851
  return null_ptr != 0 || table->maybe_null;
784
852
}
785
853
 
786
 
 
787
 
bool Field::real_maybe_null(void)
 
854
bool Field::real_maybe_null(void) const
788
855
{
789
856
  return null_ptr != 0;
790
857
}
791
858
 
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
 
 
805
859
bool Field::type_can_have_key_part(enum enum_field_types type)
806
860
{
807
 
  switch (type) {
 
861
  switch (type) 
 
862
  {
808
863
  case DRIZZLE_TYPE_VARCHAR:
809
864
  case DRIZZLE_TYPE_BLOB:
810
865
    return true;
813
868
  }
814
869
}
815
870
 
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
 
 
829
871
int Field::warn_if_overflow(int op_result)
830
872
{
831
873
  if (op_result == E_DEC_OVERFLOW)
832
874
  {
833
875
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
834
 
    return 1;
 
876
    return E_DEC_OVERFLOW;
835
877
  }
836
878
  if (op_result == E_DEC_TRUNCATED)
837
879
  {
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 */
 
880
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
 
881
    return E_DEC_TRUNCATED;
840
882
  }
841
883
  return 0;
842
884
}
843
885
 
844
 
 
845
886
void Field::init(Table *table_arg)
846
887
{
847
888
  orig_table= table= table_arg;
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
 
 
 
889
}
929
890
 
930
891
/// This is used as a table name when the table structure is not set up
931
 
Field::Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
 
892
Field::Field(unsigned char *ptr_arg,
 
893
             uint32_t length_arg,
 
894
             unsigned char *null_ptr_arg,
932
895
             unsigned char null_bit_arg,
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)
 
896
             utype unireg_check_arg, 
 
897
             const char *field_name_arg) :
 
898
    ptr(ptr_arg),
 
899
    null_ptr(null_ptr_arg),
 
900
    table(NULL),
 
901
    orig_table(NULL),
 
902
    field_name(field_name_arg),
 
903
    key_start(0),
 
904
    part_of_key(0),
 
905
    part_of_key_not_clustered(0),
 
906
    part_of_sortkey(0),
 
907
    unireg_check(unireg_check_arg),
 
908
    field_length(length_arg),
 
909
    flags(null_ptr ? 0: NOT_NULL_FLAG),
 
910
    field_index(0),
 
911
    null_bit(null_bit_arg),
 
912
    is_created_from_null_item(false)
942
913
{
943
 
  flags=null_ptr ? 0: NOT_NULL_FLAG;
944
 
  comment.str= (char*) "";
945
 
  comment.length=0;
946
 
  field_index= 0;
947
914
}
948
915
 
949
 
 
950
 
void Field::hash(uint32_t *nr, uint32_t *nr2)
 
916
void Field::hash(uint32_t *nr, uint32_t *nr2) const
951
917
{
952
918
  if (is_null())
953
919
  {
956
922
  else
957
923
  {
958
924
    uint32_t len= pack_length();
959
 
    const CHARSET_INFO * const cs= charset();
 
925
    const charset_info_st * const cs= charset();
960
926
    cs->coll->hash_sort(cs, ptr, len, nr, nr2);
961
927
  }
962
928
}
963
929
 
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
 
 
974
930
void Field::copy_from_tmp(int row_offset)
975
931
{
976
932
  memcpy(ptr,ptr+row_offset,pack_length());
983
939
  }
984
940
}
985
941
 
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)
1020
 
{
1021
 
  int res;
 
942
int Field::store_and_check(enum_check_fields check_level,
 
943
                           const char *to, 
 
944
                           uint32_t length,
 
945
                           const charset_info_st * const cs)
 
946
 
 
947
{
1022
948
  enum_check_fields old_check_level= table->in_use->count_cuted_fields;
1023
949
  table->in_use->count_cuted_fields= check_level;
1024
 
  res= store(to, length, cs);
 
950
  int res= store(to, length, cs);
1025
951
  table->in_use->count_cuted_fields= old_check_level;
1026
952
  return res;
1027
953
}
1028
954
 
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)
 
955
unsigned char *Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool)
1070
956
{
1071
957
  uint32_t length= pack_length();
1072
958
  set_if_smaller(length, max_length);
1074
960
  return to+length;
1075
961
}
1076
962
 
1077
 
 
1078
963
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
1079
964
{
1080
 
  unsigned char *result= this->pack(to, from, UINT32_MAX,
1081
 
                                    table->s->db_low_byte_first);
1082
 
  return(result);
 
965
  return this->pack(to, from, UINT32_MAX, table->getShare()->db_low_byte_first);
1083
966
}
1084
967
 
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)
 
968
const unsigned char *Field::unpack(unsigned char* to,
 
969
                                   const unsigned char *from, 
 
970
                                   uint32_t param_data,
 
971
                                   bool)
1119
972
{
1120
973
  uint32_t length=pack_length();
1121
974
  int from_type= 0;
1141
994
            param_data : length;
1142
995
 
1143
996
  memcpy(to, from, param_data > length ? length : len);
1144
 
  return from+len;
1145
 
}
1146
 
 
1147
 
 
1148
 
const unsigned char *Field::unpack(unsigned char* to,
1149
 
                                   const unsigned char *from)
1150
 
{
1151
 
  const unsigned char *result= unpack(to, from, 0U,
1152
 
                                      table->s->db_low_byte_first);
1153
 
  return(result);
1154
 
}
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
 
 
1176
 
my_decimal *Field::val_decimal(my_decimal *)
 
997
  return (from + len);
 
998
}
 
999
 
 
1000
const unsigned char *Field::unpack(unsigned char* to, const unsigned char *from)
 
1001
{
 
1002
  return unpack(to, from, 0, table->getShare()->db_low_byte_first);
 
1003
}
 
1004
 
 
1005
type::Decimal *Field::val_decimal(type::Decimal *) const
1177
1006
{
1178
1007
  /* This never have to be called */
1179
 
  assert(0);
 
1008
  assert(false);
1180
1009
  return 0;
1181
1010
}
1182
1011
 
1183
1012
 
1184
 
void Field::make_field(Send_field *field)
 
1013
void Field::make_field(SendField *field)
1185
1014
{
1186
 
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
 
1015
  if (orig_table && orig_table->getShare()->getSchemaName() && *orig_table->getShare()->getSchemaName())
1187
1016
  {
1188
 
    field->db_name= orig_table->s->db.str;
1189
 
    field->org_table_name= orig_table->s->table_name.str;
 
1017
    field->db_name= orig_table->getShare()->getSchemaName();
 
1018
    field->org_table_name= orig_table->getShare()->getTableName();
1190
1019
  }
1191
1020
  else
1192
1021
    field->org_table_name= field->db_name= "";
1193
1022
  if (orig_table)
1194
1023
  {
1195
 
    field->table_name= orig_table->alias;
 
1024
    field->table_name= orig_table->getAlias();
1196
1025
    field->org_col_name= field_name;
1197
1026
  }
1198
1027
  else
1202
1031
  }
1203
1032
  field->col_name= field_name;
1204
1033
  field->charsetnr= charset()->number;
1205
 
  field->length=field_length;
1206
 
  field->type=type();
1207
 
  field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
 
1034
  field->length= field_length;
 
1035
  field->type= type();
 
1036
  field->flags= table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
1208
1037
  field->decimals= 0;
1209
1038
}
1210
1039
 
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
 
*/
1223
 
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
 
1040
int64_t Field::convert_decimal2int64_t(const type::Decimal *val, bool, int *err)
1224
1041
{
1225
1042
  int64_t i;
1226
 
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
1043
  if (warn_if_overflow(val->val_int32(E_DEC_ERROR &
1227
1044
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
1228
 
                                      val, false, &i)))
 
1045
                                      false, &i)))
1229
1046
  {
1230
1047
    i= (val->sign() ? INT64_MIN : INT64_MAX);
1231
1048
    *err= 1;
1233
1050
  return i;
1234
1051
}
1235
1052
 
1236
 
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
 
1053
uint32_t Field::fill_cache_field(CacheField *copy)
1237
1054
{
1238
1055
  uint32_t store_length;
1239
1056
  copy->str=ptr;
1243
1060
  {
1244
1061
    copy->blob_field=(Field_blob*) this;
1245
1062
    copy->strip=0;
1246
 
    copy->length-= table->s->blob_ptr_size;
 
1063
    copy->length-= table->getShare()->sizeBlobPtr();
1247
1064
    return copy->length;
1248
1065
  }
1249
1066
  else
1254
1071
  return copy->length+ store_length;
1255
1072
}
1256
1073
 
1257
 
 
1258
 
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1259
 
{
1260
 
  char buff[40];
1261
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1262
 
  if (!(res=val_str(&tmp)) ||
1263
 
      str_to_datetime_with_warn(res->ptr(), res->length(),
1264
 
                                ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
1265
 
    return 1;
1266
 
  return 0;
1267
 
}
1268
 
 
1269
 
bool Field::get_time(DRIZZLE_TIME *ltime)
1270
 
{
1271
 
  char buff[40];
1272
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1273
 
  if (!(res=val_str(&tmp)) ||
1274
 
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
1275
 
    return 1;
1276
 
  return 0;
1277
 
}
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
 
 
1286
 
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
1287
 
{
1288
 
  char buff[MAX_DATE_STRING_REP_LENGTH];
1289
 
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
1290
 
  return store(buff, length, &my_charset_bin);
1291
 
}
1292
 
 
1293
 
 
1294
 
bool Field::optimize_range(uint32_t idx, uint32_t part)
1295
 
{
1296
 
  return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
1297
 
}
1298
 
 
1299
 
 
1300
 
Field *Field::new_field(MEM_ROOT *root, Table *new_table, bool)
1301
 
{
1302
 
  Field *tmp;
1303
 
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1304
 
    return 0;
1305
 
 
 
1074
bool Field::get_date(type::Time &ltime, uint32_t fuzzydate) const
 
1075
{
 
1076
  char buff[type::Time::MAX_STRING_LENGTH];
 
1077
  String tmp(buff,sizeof(buff),&my_charset_bin);
 
1078
 
 
1079
  assert(getTable() and getTable()->getSession());
 
1080
 
 
1081
  String* res= val_str_internal(&tmp);
 
1082
  return not res or str_to_datetime_with_warn(*getTable()->getSession(), *res, ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR;
 
1083
}
 
1084
 
 
1085
bool Field::get_time(type::Time &ltime) const
 
1086
{
 
1087
  char buff[type::Time::MAX_STRING_LENGTH];
 
1088
  String tmp(buff,sizeof(buff),&my_charset_bin);
 
1089
 
 
1090
  String* res= val_str_internal(&tmp);
 
1091
  return not res or str_to_time_with_warn(*getTable()->getSession(), *res, ltime);
 
1092
}
 
1093
 
 
1094
int Field::store_time(type::Time &ltime, type::timestamp_t)
 
1095
{
 
1096
  String tmp;
 
1097
  ltime.convert(tmp);
 
1098
  return store(tmp.ptr(), tmp.length(), &my_charset_bin);
 
1099
}
 
1100
 
 
1101
bool Field::optimize_range(uint32_t idx, uint32_t)
 
1102
{
 
1103
  return test(table->index_flags(idx) & HA_READ_RANGE);
 
1104
}
 
1105
 
 
1106
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
 
1107
{
 
1108
  Field* tmp= (Field*) root->memdup(this,size_of());
1306
1109
  if (tmp->table->maybe_null)
1307
1110
    tmp->flags&= ~NOT_NULL_FLAG;
1308
1111
  tmp->table= new_table;
1309
 
  tmp->key_start.init(0);
1310
 
  tmp->part_of_key.init(0);
1311
 
  tmp->part_of_sortkey.init(0);
 
1112
  tmp->key_start.reset();
 
1113
  tmp->part_of_key.reset();
 
1114
  tmp->part_of_sortkey.reset();
1312
1115
  tmp->unireg_check= Field::NONE;
1313
 
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
 
1116
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
1314
1117
  tmp->reset_fields();
1315
1118
  return tmp;
1316
1119
}
1317
1120
 
1318
 
 
1319
 
Field *Field::new_key_field(MEM_ROOT *root, Table *new_table,
1320
 
                            unsigned char *new_ptr, unsigned char *new_null_ptr,
 
1121
Field *Field::new_key_field(memory::Root *root, Table *new_table,
 
1122
                            unsigned char *new_ptr,
 
1123
                            unsigned char *new_null_ptr,
1321
1124
                            uint32_t new_null_bit)
1322
1125
{
1323
 
  Field *tmp;
1324
 
  if ((tmp= new_field(root, new_table, table == new_table)))
1325
 
  {
1326
 
    tmp->ptr=      new_ptr;
1327
 
    tmp->null_ptr= new_null_ptr;
1328
 
    tmp->null_bit= new_null_bit;
1329
 
  }
1330
 
  return tmp;
1331
 
}
1332
 
 
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)
1337
 
{
1338
 
  Field *tmp;
1339
 
  if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1340
 
  {
1341
 
    tmp->init(new_table);
1342
 
    tmp->move_field_offset((my_ptrdiff_t) (new_table->record[0] -
1343
 
                                           new_table->s->default_values));
1344
 
  }
1345
 
  return tmp;
1346
 
}
1347
 
 
1348
 
 
1349
 
uint32_t Field::is_equal(Create_field *new_field)
1350
 
{
1351
 
  return (new_field->sql_type == real_type());
1352
 
}
1353
 
 
1354
 
/**
1355
 
  @retval
1356
 
    1  if the fields are equally defined
1357
 
  @retval
1358
 
    0  if the fields are unequally defined
1359
 
*/
 
1126
  Field *tmp= new_field(root, new_table, table == new_table);
 
1127
  tmp->ptr= new_ptr;
 
1128
  tmp->null_ptr= new_null_ptr;
 
1129
  tmp->null_bit= new_null_bit;
 
1130
  return tmp;
 
1131
}
 
1132
 
 
1133
Field *Field::clone(memory::Root *root, Table *new_table)
 
1134
{
 
1135
  Field *tmp= (Field*) root->memdup(this,size_of());
 
1136
  tmp->init(new_table);
 
1137
  tmp->move_field_offset((ptrdiff_t) (new_table->getInsertRecord() - new_table->getDefaultValues()));
 
1138
  return tmp;
 
1139
}
 
1140
 
 
1141
uint32_t Field::is_equal(CreateField *new_field_ptr)
 
1142
{
 
1143
  return new_field_ptr->sql_type == real_type();
 
1144
}
1360
1145
 
1361
1146
bool Field::eq_def(Field *field)
1362
1147
{
1363
 
  if (real_type() != field->real_type() || charset() != field->charset() ||
1364
 
      pack_length() != field->pack_length())
1365
 
    return 0;
1366
 
  return 1;
 
1148
  return real_type() == field->real_type() && charset() == field->charset() && pack_length() == field->pack_length();
1367
1149
}
1368
1150
 
1369
 
/**
1370
 
  @return
1371
 
  returns 1 if the fields are equally defined
1372
 
*/
1373
1151
bool Field_enum::eq_def(Field *field)
1374
1152
{
1375
1153
  if (!Field::eq_def(field))
1376
1154
    return 0;
 
1155
 
1377
1156
  TYPELIB *from_lib=((Field_enum*) field)->typelib;
1378
1157
 
1379
1158
  if (typelib->count < from_lib->count)
1380
1159
    return 0;
 
1160
 
1381
1161
  for (uint32_t i=0 ; i < from_lib->count ; i++)
 
1162
  {
1382
1163
    if (my_strnncoll(field_charset,
1383
 
                     (const unsigned char*)typelib->type_names[i],
1384
 
                     strlen(typelib->type_names[i]),
1385
 
                     (const unsigned char*)from_lib->type_names[i],
1386
 
                     strlen(from_lib->type_names[i])))
 
1164
                     (const unsigned char*)typelib->type_names[i], strlen(typelib->type_names[i]),
 
1165
                     (const unsigned char*)from_lib->type_names[i], strlen(from_lib->type_names[i])))
1387
1166
      return 0;
 
1167
  }
 
1168
 
1388
1169
  return 1;
1389
1170
}
1390
1171
 
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
 
 
1754
1172
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
1755
1173
{
1756
 
  switch (type) {
1757
 
  case DRIZZLE_TYPE_VARCHAR:     return (length + (length < 256 ? 1: 2));
1758
 
  case DRIZZLE_TYPE_TINY        : return 1;
 
1174
  switch (type) 
 
1175
  {
 
1176
  case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
 
1177
  case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
 
1178
  case DRIZZLE_TYPE_MICROTIME: return field::Microtime::max_string_length();
 
1179
  case DRIZZLE_TYPE_TIMESTAMP: return field::Epoch::max_string_length();
 
1180
  case DRIZZLE_TYPE_BOOLEAN: return field::Boolean::max_string_length();
 
1181
  case DRIZZLE_TYPE_IPV6: return field::IPv6::max_string_length();
1759
1182
  case DRIZZLE_TYPE_DATE:
1760
 
  case DRIZZLE_TYPE_TIME:   return 3;
1761
 
  case DRIZZLE_TYPE_TIMESTAMP:
1762
 
  case DRIZZLE_TYPE_LONG        : return 4;
 
1183
  case DRIZZLE_TYPE_ENUM:
 
1184
  case DRIZZLE_TYPE_LONG: return 4;
1763
1185
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
 
1186
  case DRIZZLE_TYPE_TIME:
1764
1187
  case DRIZZLE_TYPE_DATETIME:
1765
1188
  case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
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;
 
1189
  case DRIZZLE_TYPE_NULL: return 0;
 
1190
  case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
 
1191
  case DRIZZLE_TYPE_DECIMAL:
 
1192
                          break;
1773
1193
  }
 
1194
 
 
1195
  assert(0);
 
1196
  abort();
1774
1197
}
1775
1198
 
1776
 
 
1777
1199
uint32_t pack_length_to_packflag(uint32_t type)
1778
1200
{
1779
 
  switch (type) {
1780
 
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
1781
 
    case 2: assert(1);
1782
 
    case 3: assert(1);
1783
 
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
1784
 
    case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
 
1201
  switch (type) 
 
1202
  {
 
1203
  case 1: return 1 << FIELDFLAG_PACK_SHIFT;
 
1204
  case 2: assert(0);
 
1205
  case 3: assert(0);
 
1206
  case 4: return f_settype(DRIZZLE_TYPE_LONG);
 
1207
  case 8: return f_settype(DRIZZLE_TYPE_LONGLONG);
1785
1208
  }
 
1209
  assert(false);
1786
1210
  return 0;                                     // This shouldn't happen
1787
1211
}
1788
1212
 
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
 
 
1975
1213
/*****************************************************************************
1976
1214
 Warning handling
1977
1215
*****************************************************************************/
1978
1216
 
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)
 
1217
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
 
1218
                        drizzled::error_t code,
 
1219
                        int cuted_increment)
2002
1220
{
2003
1221
  /*
2004
1222
    If this field was created only for type conversion purposes it
2016
1234
}
2017
1235
 
2018
1236
 
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)
 
1237
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
 
1238
                                 drizzled::error_t code,
 
1239
                                 const char *str, 
 
1240
                                 uint32_t str_length,
 
1241
                                 type::timestamp_t ts_type, 
 
1242
                                 int cuted_increment)
2040
1243
{
2041
 
  Session *session= table ? table->in_use : current_session;
2042
 
  if ((session->really_abort_on_warning() &&
 
1244
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
 
1245
 
 
1246
  if ((session->abortOnWarning() and
2043
1247
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
2044
1248
      set_warning(level, code, cuted_increment))
2045
 
    make_truncated_value_warning(session, level, str, str_length, ts_type,
2046
 
                                 field_name);
 
1249
    make_truncated_value_warning(*session, level, str_ref(str, str_length), ts_type, field_name);
2047
1250
}
2048
1251
 
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)
 
1252
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
 
1253
                                 drizzled::error_t code,
 
1254
                                 int64_t nr, 
 
1255
                                 type::timestamp_t ts_type,
 
1256
                                 int cuted_increment)
2069
1257
{
2070
 
  Session *session= table ? table->in_use : current_session;
2071
 
  if (session->really_abort_on_warning() ||
 
1258
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
 
1259
 
 
1260
  if (session->abortOnWarning() or
2072
1261
      set_warning(level, code, cuted_increment))
2073
1262
  {
2074
 
    char str_nr[22];
2075
 
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
2076
 
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr), 
2077
 
                                 ts_type, field_name);
 
1263
    char str_nr[DECIMAL_LONGLONG_DIGITS];
 
1264
    char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
 
1265
    make_truncated_value_warning(*session, level, str_ref(str_nr, (uint32_t) (str_end - str_nr)), ts_type, field_name);
2078
1266
  }
2079
1267
}
2080
1268
 
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)
 
1269
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
 
1270
                                 const drizzled::error_t code,
 
1271
                                 double nr, 
 
1272
                                 type::timestamp_t ts_type)
2099
1273
{
2100
 
  Session *session= table ? table->in_use : current_session;
2101
 
  if (session->really_abort_on_warning() ||
 
1274
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
 
1275
 
 
1276
  if (session->abortOnWarning() or
2102
1277
      set_warning(level, code, 1))
2103
1278
  {
2104
1279
    /* DBL_DIG is enough to print '-[digits].E+###' */
2105
1280
    char str_nr[DBL_DIG + 8];
2106
 
    uint32_t str_len= sprintf(str_nr, "%g", nr);
2107
 
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
2108
 
                                 field_name);
 
1281
    uint32_t str_len= snprintf(str_nr, sizeof(str_nr), "%g", nr);
 
1282
    make_truncated_value_warning(*session, level, str_ref(str_nr, str_len), ts_type, field_name);
2109
1283
  }
2110
1284
}
2111
1285
 
 
1286
bool Field::isReadSet() const 
 
1287
 
1288
  return table->isReadSet(field_index); 
 
1289
}
 
1290
 
 
1291
bool Field::isWriteSet()
 
1292
 
1293
  return table->isWriteSet(field_index); 
 
1294
}
 
1295
 
 
1296
void Field::setReadSet(bool arg)
 
1297
{
 
1298
  if (arg)
 
1299
    table->setReadSet(field_index);
 
1300
  else
 
1301
    table->clearReadSet(field_index);
 
1302
}
 
1303
 
 
1304
void Field::setWriteSet(bool arg)
 
1305
{
 
1306
  if (arg)
 
1307
    table->setWriteSet(field_index);
 
1308
  else
 
1309
    table->clearWriteSet(field_index);
 
1310
}
 
1311
 
 
1312
void Field::pack_num(uint64_t arg, unsigned char *destination)
 
1313
{
 
1314
  if (not destination)
 
1315
    destination= ptr;
 
1316
 
 
1317
  int64_tstore(destination, arg);
 
1318
}
 
1319
 
 
1320
void Field::pack_num(uint32_t arg, unsigned char *destination)
 
1321
{
 
1322
  if (not destination)
 
1323
    destination= ptr;
 
1324
 
 
1325
  longstore(destination, arg);
 
1326
}
 
1327
 
 
1328
uint64_t Field::unpack_num(uint64_t &destination, const unsigned char *arg) const
 
1329
{
 
1330
  if (not arg)
 
1331
    arg= ptr;
 
1332
 
 
1333
  int64_tget(destination, arg);
 
1334
 
 
1335
  return destination;
 
1336
}
 
1337
 
 
1338
uint32_t Field::unpack_num(uint32_t &destination, const unsigned char *arg) const
 
1339
{
 
1340
  if (not arg)
 
1341
    arg= ptr;
 
1342
 
 
1343
  longget(destination, arg);
 
1344
 
 
1345
  return destination;
 
1346
}
 
1347
 
 
1348
std::ostream& operator<<(std::ostream& output, const Field &field)
 
1349
{
 
1350
  output << "Field:(";
 
1351
  output <<  field.field_name;
 
1352
  output << ", ";
 
1353
  output << drizzled::display::type(field.real_type());
 
1354
  output << ", { ";
 
1355
 
 
1356
  if (field.flags & NOT_NULL_FLAG)
 
1357
    output << " NOT_NULL";
 
1358
 
 
1359
  if (field.flags & PRI_KEY_FLAG)
 
1360
    output << ", PRIMARY KEY";
 
1361
 
 
1362
  if (field.flags & UNIQUE_KEY_FLAG)
 
1363
    output << ", UNIQUE KEY";
 
1364
 
 
1365
  if (field.flags & MULTIPLE_KEY_FLAG)
 
1366
    output << ", MULTIPLE KEY";
 
1367
 
 
1368
  if (field.flags & BLOB_FLAG)
 
1369
    output << ", BLOB";
 
1370
 
 
1371
  if (field.flags & UNSIGNED_FLAG)
 
1372
    output << ", UNSIGNED";
 
1373
 
 
1374
  if (field.flags & BINARY_FLAG)
 
1375
    output << ", BINARY";
 
1376
  output << "}, ";
 
1377
  output << ")";
 
1378
 
 
1379
  return output;  // for multiple << operators.
 
1380
}
 
1381
 
 
1382
} /* namespace drizzled */