~drizzle-trunk/drizzle/development

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