~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
 *
2023.2.1 by Brian Aker
Merge in BOOL type.
4
 *  Copyright (C) 2010 Brian Aker
520.1.25 by Monty Taylor
Removed the split.
5
 *  Copyright (C) 2008 MySQL
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
 */
1 by brian
clean slate
21
22
/**
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
23
 * @file This file implements the Field class and API
24
 */
1 by brian
clean slate
25
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
26
#include "config.h"
1502.3.1 by iwamatsu at nigauri
Add cstdio include to files needing it. Fixes the build on some debian
27
#include <cstdio>
1 by brian
clean slate
28
#include <errno.h>
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
29
#include <float.h>
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
30
#include "drizzled/sql_select.h"
31
#include "drizzled/error.h"
32
#include "drizzled/field/str.h"
33
#include "drizzled/field/num.h"
34
#include "drizzled/field/blob.h"
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
35
#include "drizzled/field/boolean.h"
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
36
#include "drizzled/field/enum.h"
37
#include "drizzled/field/null.h"
38
#include "drizzled/field/date.h"
39
#include "drizzled/field/decimal.h"
40
#include "drizzled/field/real.h"
41
#include "drizzled/field/double.h"
2007 by Brian Aker
Refactor naming for integers.
42
#include "drizzled/field/int32.h"
43
#include "drizzled/field/int64.h"
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
44
#include "drizzled/field/num.h"
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
45
#include "drizzled/field/time.h"
1999.4.9 by Brian Aker
Created EPOCH
46
#include "drizzled/field/epoch.h"
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
47
#include "drizzled/field/datetime.h"
2046.2.1 by Brian Aker
First pass on micro timestamp.
48
#include "drizzled/field/microtime.h"
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
49
#include "drizzled/field/varstring.h"
1996.2.1 by Brian Aker
uuid type code.
50
#include "drizzled/field/uuid.h"
1237.9.8 by Monty Taylor
Fixed solaris build.
51
#include "drizzled/time_functions.h"
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
52
#include "drizzled/internal/m_string.h"
1 by brian
clean slate
53
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
54
#include "drizzled/display.h"
55
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
56
namespace drizzled
57
{
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
58
1 by brian
clean slate
59
/*****************************************************************************
60
  Instansiate templates and static variables
61
*****************************************************************************/
62
520.1.25 by Monty Taylor
Removed the split.
63
static enum_field_types
1996.2.1 by Brian Aker
uuid type code.
64
field_types_merge_rules [enum_field_types_size][enum_field_types_size]=
1 by brian
clean slate
65
{
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
66
  /* DRIZZLE_TYPE_LONG -> */
67
  {
520.1.25 by Monty Taylor
Removed the split.
68
    //DRIZZLE_TYPE_LONG
69
    DRIZZLE_TYPE_LONG,
70
    //DRIZZLE_TYPE_DOUBLE
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
71
    DRIZZLE_TYPE_DOUBLE,
520.1.25 by Monty Taylor
Removed the split.
72
    //DRIZZLE_TYPE_NULL
73
    DRIZZLE_TYPE_LONG,
74
    //DRIZZLE_TYPE_TIMESTAMP
75
    DRIZZLE_TYPE_VARCHAR,
76
    //DRIZZLE_TYPE_LONGLONG
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
77
    DRIZZLE_TYPE_LONGLONG,
520.1.25 by Monty Taylor
Removed the split.
78
    //DRIZZLE_TYPE_DATETIME
79
    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
80
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
81
    DRIZZLE_TYPE_VARCHAR,
82
    //DRIZZLE_TYPE_VARCHAR
83
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
84
    //DRIZZLE_TYPE_DECIMAL
85
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
86
    //DRIZZLE_TYPE_ENUM
87
    DRIZZLE_TYPE_VARCHAR,
88
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
89
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
90
    //DRIZZLE_TYPE_TIME
91
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
92
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
93
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
94
    //DRIZZLE_TYPE_UUID
95
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
96
    //DRIZZLE_TYPE_MICROTIME
97
    DRIZZLE_TYPE_VARCHAR,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
98
  },
99
  /* DRIZZLE_TYPE_DOUBLE -> */
100
  {
520.1.25 by Monty Taylor
Removed the split.
101
    //DRIZZLE_TYPE_LONG
102
    DRIZZLE_TYPE_DOUBLE,
103
    //DRIZZLE_TYPE_DOUBLE
104
    DRIZZLE_TYPE_DOUBLE,
105
    //DRIZZLE_TYPE_NULL
106
    DRIZZLE_TYPE_DOUBLE,
107
    //DRIZZLE_TYPE_TIMESTAMP
108
    DRIZZLE_TYPE_VARCHAR,
109
    //DRIZZLE_TYPE_LONGLONG
110
    DRIZZLE_TYPE_DOUBLE,
111
    //DRIZZLE_TYPE_DATETIME
112
    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
113
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
114
    DRIZZLE_TYPE_VARCHAR,
115
    //DRIZZLE_TYPE_VARCHAR
116
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
117
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
118
    DRIZZLE_TYPE_DOUBLE,
119
    //DRIZZLE_TYPE_ENUM
120
    DRIZZLE_TYPE_VARCHAR,
121
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
122
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
123
    //DRIZZLE_TYPE_TIME
124
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
125
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
126
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
127
    //DRIZZLE_TYPE_UUID
128
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
129
    //DRIZZLE_TYPE_MICROTIME
130
    DRIZZLE_TYPE_VARCHAR,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
131
  },
132
  /* DRIZZLE_TYPE_NULL -> */
133
  {
520.1.25 by Monty Taylor
Removed the split.
134
    //DRIZZLE_TYPE_LONG
398 by Brian Aker
Remove short.
135
    DRIZZLE_TYPE_LONG,
520.1.25 by Monty Taylor
Removed the split.
136
    //DRIZZLE_TYPE_DOUBLE
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
137
    DRIZZLE_TYPE_DOUBLE,
520.1.25 by Monty Taylor
Removed the split.
138
    //DRIZZLE_TYPE_NULL
139
    DRIZZLE_TYPE_NULL,
140
    //DRIZZLE_TYPE_TIMESTAMP
141
    DRIZZLE_TYPE_TIMESTAMP,
142
    //DRIZZLE_TYPE_LONGLONG
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
143
    DRIZZLE_TYPE_LONGLONG,
520.1.25 by Monty Taylor
Removed the split.
144
    //DRIZZLE_TYPE_DATETIME
222 by Brian Aker
Remove YEAR field type
145
    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
146
    //DRIZZLE_TYPE_DATE
147
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
148
    //DRIZZLE_TYPE_VARCHAR
149
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
150
    //DRIZZLE_TYPE_DECIMAL
151
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
152
    //DRIZZLE_TYPE_ENUM
153
    DRIZZLE_TYPE_ENUM,
154
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
155
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
156
    //DRIZZLE_TYPE_TIME
157
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
158
    //DRIZZLE_TYPE_BOOLEAN
159
    DRIZZLE_TYPE_BOOLEAN,
1996.2.1 by Brian Aker
uuid type code.
160
    //DRIZZLE_TYPE_UUID
161
    DRIZZLE_TYPE_UUID,
2046.2.1 by Brian Aker
First pass on micro timestamp.
162
    //DRIZZLE_TYPE_MICROTIME
163
    DRIZZLE_TYPE_MICROTIME,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
164
  },
165
  /* DRIZZLE_TYPE_TIMESTAMP -> */
166
  {
520.1.25 by Monty Taylor
Removed the split.
167
    //DRIZZLE_TYPE_LONG
168
    DRIZZLE_TYPE_VARCHAR,
169
    //DRIZZLE_TYPE_DOUBLE
170
    DRIZZLE_TYPE_VARCHAR,
171
    //DRIZZLE_TYPE_NULL
172
    DRIZZLE_TYPE_TIMESTAMP,
173
    //DRIZZLE_TYPE_TIMESTAMP
174
    DRIZZLE_TYPE_TIMESTAMP,
175
    //DRIZZLE_TYPE_LONGLONG
176
    DRIZZLE_TYPE_VARCHAR,
177
    //DRIZZLE_TYPE_DATETIME
178
    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
179
    //DRIZZLE_TYPE_DATE
180
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
181
    //DRIZZLE_TYPE_VARCHAR
182
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
183
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
184
    DRIZZLE_TYPE_VARCHAR,
185
    //DRIZZLE_TYPE_ENUM
186
    DRIZZLE_TYPE_VARCHAR,
187
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
188
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
189
    //DRIZZLE_TYPE_TIME
190
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
191
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
192
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
193
    //DRIZZLE_TYPE_UUID
194
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
195
    //DRIZZLE_TYPE_MICROTIME
196
    DRIZZLE_TYPE_VARCHAR,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
197
  },
198
  /* DRIZZLE_TYPE_LONGLONG -> */
199
  {
520.1.25 by Monty Taylor
Removed the split.
200
    //DRIZZLE_TYPE_LONG
201
    DRIZZLE_TYPE_LONGLONG,
202
    //DRIZZLE_TYPE_DOUBLE
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
203
    DRIZZLE_TYPE_DOUBLE,
520.1.25 by Monty Taylor
Removed the split.
204
    //DRIZZLE_TYPE_NULL
205
    DRIZZLE_TYPE_LONGLONG,
206
    //DRIZZLE_TYPE_TIMESTAMP
207
    DRIZZLE_TYPE_VARCHAR,
208
    //DRIZZLE_TYPE_LONGLONG
209
    DRIZZLE_TYPE_LONGLONG,
210
    //DRIZZLE_TYPE_DATETIME
211
    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
212
    //DRIZZLE_TYPE_DATE
213
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
214
    //DRIZZLE_TYPE_VARCHAR
215
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
216
    //DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_ENUM
217
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
218
    DRIZZLE_TYPE_VARCHAR,
219
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
220
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
221
    //DRIZZLE_TYPE_TIME
222
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
223
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
224
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
225
    //DRIZZLE_TYPE_UUID
226
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
227
    //DRIZZLE_TYPE_MICROTIME
228
    DRIZZLE_TYPE_VARCHAR,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
229
  },
230
  /* DRIZZLE_TYPE_DATETIME -> */
231
  {
520.1.25 by Monty Taylor
Removed the split.
232
    //DRIZZLE_TYPE_LONG
233
    DRIZZLE_TYPE_VARCHAR,
234
    //DRIZZLE_TYPE_DOUBLE
235
    DRIZZLE_TYPE_VARCHAR,
236
    //DRIZZLE_TYPE_NULL
237
    DRIZZLE_TYPE_DATETIME,
238
    //DRIZZLE_TYPE_TIMESTAMP
239
    DRIZZLE_TYPE_DATETIME,
240
    //DRIZZLE_TYPE_LONGLONG
241
    DRIZZLE_TYPE_VARCHAR,
242
    //DRIZZLE_TYPE_DATETIME
243
    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
244
    //DRIZZLE_TYPE_DATE
245
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
246
    //DRIZZLE_TYPE_VARCHAR
247
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
248
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
249
    DRIZZLE_TYPE_VARCHAR,
250
    //DRIZZLE_TYPE_ENUM
251
    DRIZZLE_TYPE_VARCHAR,
252
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
253
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
254
    //DRIZZLE_TYPE_TIME
255
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
256
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
257
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
258
    //DRIZZLE_TYPE_UUID
259
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
260
    //DRIZZLE_TYPE_MICROTIME
261
    DRIZZLE_TYPE_VARCHAR,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
262
  },
575.5.1 by David Axmark
Changed NEWDATE to DATE. One failing test but I think its somewhere else in the code
263
  /* DRIZZLE_TYPE_DATE -> */
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
264
  {
520.1.25 by Monty Taylor
Removed the split.
265
    //DRIZZLE_TYPE_LONG
266
    DRIZZLE_TYPE_VARCHAR,
267
    //DRIZZLE_TYPE_DOUBLE
268
    DRIZZLE_TYPE_VARCHAR,
269
    //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
270
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
271
    //DRIZZLE_TYPE_TIMESTAMP
272
    DRIZZLE_TYPE_DATETIME,
273
    //DRIZZLE_TYPE_LONGLONG
274
    DRIZZLE_TYPE_VARCHAR,
275
    //DRIZZLE_TYPE_DATETIME
276
    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
277
    //DRIZZLE_TYPE_DATE
278
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
279
    //DRIZZLE_TYPE_VARCHAR
280
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
281
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
282
    DRIZZLE_TYPE_VARCHAR,
283
    //DRIZZLE_TYPE_ENUM
284
    DRIZZLE_TYPE_VARCHAR,
285
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
286
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
287
    //DRIZZLE_TYPE_TIME
288
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
289
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
290
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
291
    //DRIZZLE_TYPE_UUID
292
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
293
    //DRIZZLE_TYPE_MICROTIME
294
    DRIZZLE_TYPE_VARCHAR,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
295
  },
296
  /* DRIZZLE_TYPE_VARCHAR -> */
297
  {
520.1.25 by Monty Taylor
Removed the split.
298
    //DRIZZLE_TYPE_LONG
299
    DRIZZLE_TYPE_VARCHAR,
300
    //DRIZZLE_TYPE_DOUBLE
301
    DRIZZLE_TYPE_VARCHAR,
302
    //DRIZZLE_TYPE_NULL
303
    DRIZZLE_TYPE_VARCHAR,
304
    //DRIZZLE_TYPE_TIMESTAMP
305
    DRIZZLE_TYPE_VARCHAR,
306
    //DRIZZLE_TYPE_LONGLONG
307
    DRIZZLE_TYPE_VARCHAR,
308
    //DRIZZLE_TYPE_DATETIME
309
    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
310
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
311
    DRIZZLE_TYPE_VARCHAR,
312
    //DRIZZLE_TYPE_VARCHAR
313
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
314
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
315
    DRIZZLE_TYPE_VARCHAR,
316
    //DRIZZLE_TYPE_ENUM
317
    DRIZZLE_TYPE_VARCHAR,
318
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
319
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
320
    //DRIZZLE_TYPE_TIME
321
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
322
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
323
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
324
    //DRIZZLE_TYPE_UUID
325
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
326
    //DRIZZLE_TYPE_MICROTIME
327
    DRIZZLE_TYPE_VARCHAR,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
328
  },
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
329
  /* DRIZZLE_TYPE_DECIMAL -> */
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
330
  {
520.1.25 by Monty Taylor
Removed the split.
331
    //DRIZZLE_TYPE_LONG
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
332
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
333
    //DRIZZLE_TYPE_DOUBLE
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
334
    DRIZZLE_TYPE_DOUBLE,
520.1.25 by Monty Taylor
Removed the split.
335
    //DRIZZLE_TYPE_NULL
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
336
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
337
    //DRIZZLE_TYPE_TIMESTAMP
338
    DRIZZLE_TYPE_VARCHAR,
339
    //DRIZZLE_TYPE_LONGLONG
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
340
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
341
    //DRIZZLE_TYPE_DATETIME
342
    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
343
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
344
    DRIZZLE_TYPE_VARCHAR,
345
    //DRIZZLE_TYPE_VARCHAR
346
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
347
    //DRIZZLE_TYPE_DECIMAL
348
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
349
    //DRIZZLE_TYPE_ENUM
350
    DRIZZLE_TYPE_VARCHAR,
351
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
352
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
353
    //DRIZZLE_TYPE_TIME
354
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
355
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
356
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
357
    //DRIZZLE_TYPE_UUID
358
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
359
    //DRIZZLE_TYPE_MICROTIME
360
    DRIZZLE_TYPE_VARCHAR,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
361
  },
362
  /* DRIZZLE_TYPE_ENUM -> */
363
  {
520.1.25 by Monty Taylor
Removed the split.
364
    //DRIZZLE_TYPE_LONG
365
    DRIZZLE_TYPE_VARCHAR,
366
    //DRIZZLE_TYPE_DOUBLE
367
    DRIZZLE_TYPE_VARCHAR,
368
    //DRIZZLE_TYPE_NULL
369
    DRIZZLE_TYPE_ENUM,
370
    //DRIZZLE_TYPE_TIMESTAMP
371
    DRIZZLE_TYPE_VARCHAR,
372
    //DRIZZLE_TYPE_LONGLONG
373
    DRIZZLE_TYPE_VARCHAR,
374
    //DRIZZLE_TYPE_DATETIME
375
    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
376
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
377
    DRIZZLE_TYPE_VARCHAR,
378
    //DRIZZLE_TYPE_VARCHAR
379
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
380
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
381
    DRIZZLE_TYPE_VARCHAR,
382
    //DRIZZLE_TYPE_ENUM
383
    DRIZZLE_TYPE_VARCHAR,
384
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
385
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
386
    //DRIZZLE_TYPE_TIME
387
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
388
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
389
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
390
    //DRIZZLE_TYPE_UUID
391
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
392
    //DRIZZLE_TYPE_MICROTIME
393
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
394
   },
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
395
  /* DRIZZLE_TYPE_BLOB -> */
396
  {
520.1.25 by Monty Taylor
Removed the split.
397
    //DRIZZLE_TYPE_LONG
398
    DRIZZLE_TYPE_BLOB,
399
    //DRIZZLE_TYPE_DOUBLE
400
    DRIZZLE_TYPE_BLOB,
401
    //DRIZZLE_TYPE_NULL
402
    DRIZZLE_TYPE_BLOB,
403
    //DRIZZLE_TYPE_TIMESTAMP
404
    DRIZZLE_TYPE_BLOB,
405
    //DRIZZLE_TYPE_LONGLONG
406
    DRIZZLE_TYPE_BLOB,
407
    //DRIZZLE_TYPE_DATETIME
408
    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
409
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
410
    DRIZZLE_TYPE_BLOB,
411
    //DRIZZLE_TYPE_VARCHAR
412
    DRIZZLE_TYPE_BLOB,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
413
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
414
    DRIZZLE_TYPE_BLOB,
415
    //DRIZZLE_TYPE_ENUM
416
    DRIZZLE_TYPE_BLOB,
417
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
418
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
419
    //DRIZZLE_TYPE_TIME
420
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
421
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
422
    DRIZZLE_TYPE_VARCHAR,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
423
    //DRIZZLE_TYPE_UUID
424
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
425
    //DRIZZLE_TYPE_MICROTIME
426
    DRIZZLE_TYPE_VARCHAR,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
427
  },
428
  /* DRIZZLE_TYPE_TIME -> */
429
  {
430
    //DRIZZLE_TYPE_LONG
431
    DRIZZLE_TYPE_VARCHAR,
432
    //DRIZZLE_TYPE_DOUBLE
433
    DRIZZLE_TYPE_VARCHAR,
434
    //DRIZZLE_TYPE_NULL
435
    DRIZZLE_TYPE_TIME,
436
    //DRIZZLE_TYPE_TIMESTAMP
437
    DRIZZLE_TYPE_VARCHAR,
438
    //DRIZZLE_TYPE_LONGLONG
439
    DRIZZLE_TYPE_VARCHAR,
440
    //DRIZZLE_TYPE_DATETIME
441
    DRIZZLE_TYPE_VARCHAR,
442
    //DRIZZLE_TYPE_DATE
443
    DRIZZLE_TYPE_VARCHAR,
444
    //DRIZZLE_TYPE_VARCHAR
445
    DRIZZLE_TYPE_VARCHAR,
446
    //DRIZZLE_TYPE_DECIMAL
447
    DRIZZLE_TYPE_VARCHAR,
448
    //DRIZZLE_TYPE_VARCHAR,
449
    DRIZZLE_TYPE_VARCHAR,
450
    //DRIZZLE_TYPE_BLOB
451
    DRIZZLE_TYPE_BLOB,
452
    //DRIZZLE_TYPE_TIME
453
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
454
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
455
    DRIZZLE_TYPE_VARCHAR,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
456
    //DRIZZLE_TYPE_UUID
457
    DRIZZLE_TYPE_UUID,
2046.2.1 by Brian Aker
First pass on micro timestamp.
458
    //DRIZZLE_TYPE_MICROTIME
459
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
460
  },
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
461
  /* DRIZZLE_TYPE_BOOLEAN -> */
2023.2.1 by Brian Aker
Merge in BOOL type.
462
  {
463
    //DRIZZLE_TYPE_LONG
464
    DRIZZLE_TYPE_VARCHAR,
465
    //DRIZZLE_TYPE_DOUBLE
466
    DRIZZLE_TYPE_VARCHAR,
467
    //DRIZZLE_TYPE_NULL
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
468
    DRIZZLE_TYPE_BOOLEAN,
2023.2.1 by Brian Aker
Merge in BOOL type.
469
    //DRIZZLE_TYPE_TIMESTAMP
470
    DRIZZLE_TYPE_VARCHAR,
471
    //DRIZZLE_TYPE_LONGLONG
472
    DRIZZLE_TYPE_VARCHAR,
473
    //DRIZZLE_TYPE_DATETIME
474
    DRIZZLE_TYPE_VARCHAR,
475
    //DRIZZLE_TYPE_DATE
476
    DRIZZLE_TYPE_VARCHAR,
477
    //DRIZZLE_TYPE_VARCHAR
478
    DRIZZLE_TYPE_VARCHAR,
479
    //DRIZZLE_TYPE_DECIMAL
480
    DRIZZLE_TYPE_VARCHAR,
481
    //DRIZZLE_TYPE_VARCHAR,
482
    DRIZZLE_TYPE_VARCHAR,
483
    //DRIZZLE_TYPE_BLOB
484
    DRIZZLE_TYPE_BLOB,
485
    //DRIZZLE_TYPE_TIME
486
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
487
    //DRIZZLE_TYPE_BOOLEAN
488
    DRIZZLE_TYPE_BOOLEAN,
2023.2.1 by Brian Aker
Merge in BOOL type.
489
    //DRIZZLE_TYPE_UUID
490
    DRIZZLE_TYPE_VARCHAR,
2046.2.1 by Brian Aker
First pass on micro timestamp.
491
    //DRIZZLE_TYPE_MICROTIME
492
    DRIZZLE_TYPE_VARCHAR,
2023.2.1 by Brian Aker
Merge in BOOL type.
493
  },
1996.2.1 by Brian Aker
uuid type code.
494
  /* DRIZZLE_TYPE_UUID -> */
495
  {
496
    //DRIZZLE_TYPE_LONG
497
    DRIZZLE_TYPE_VARCHAR,
498
    //DRIZZLE_TYPE_DOUBLE
499
    DRIZZLE_TYPE_VARCHAR,
500
    //DRIZZLE_TYPE_NULL
501
    DRIZZLE_TYPE_UUID,
502
    //DRIZZLE_TYPE_TIMESTAMP
503
    DRIZZLE_TYPE_VARCHAR,
504
    //DRIZZLE_TYPE_LONGLONG
505
    DRIZZLE_TYPE_VARCHAR,
506
    //DRIZZLE_TYPE_DATETIME
507
    DRIZZLE_TYPE_VARCHAR,
508
    //DRIZZLE_TYPE_DATE
509
    DRIZZLE_TYPE_VARCHAR,
510
    //DRIZZLE_TYPE_VARCHAR
511
    DRIZZLE_TYPE_VARCHAR,
512
    //DRIZZLE_TYPE_DECIMAL
513
    DRIZZLE_TYPE_VARCHAR,
514
    //DRIZZLE_TYPE_VARCHAR,
515
    DRIZZLE_TYPE_VARCHAR,
516
    //DRIZZLE_TYPE_BLOB
517
    DRIZZLE_TYPE_BLOB,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
518
    //DRIZZLE_TYPE_TIME
519
    DRIZZLE_TYPE_TIME,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
520
    //DRIZZLE_TYPE_BOOLEAN
2023.2.1 by Brian Aker
Merge in BOOL type.
521
    DRIZZLE_TYPE_VARCHAR,
1996.2.1 by Brian Aker
uuid type code.
522
    //DRIZZLE_TYPE_UUID
523
    DRIZZLE_TYPE_UUID,
2046.2.1 by Brian Aker
First pass on micro timestamp.
524
    //DRIZZLE_TYPE_MICROTIME
525
    DRIZZLE_TYPE_VARCHAR,
526
  },
527
  /* DRIZZLE_TYPE_MICROTIME -> */
528
  {
529
    //DRIZZLE_TYPE_LONG
530
    DRIZZLE_TYPE_VARCHAR,
531
    //DRIZZLE_TYPE_DOUBLE
532
    DRIZZLE_TYPE_VARCHAR,
533
    //DRIZZLE_TYPE_NULL
534
    DRIZZLE_TYPE_MICROTIME,
535
    //DRIZZLE_TYPE_TIMESTAMP
536
    DRIZZLE_TYPE_VARCHAR,
537
    //DRIZZLE_TYPE_LONGLONG
538
    DRIZZLE_TYPE_VARCHAR,
539
    //DRIZZLE_TYPE_DATETIME
540
    DRIZZLE_TYPE_VARCHAR,
541
    //DRIZZLE_TYPE_DATE
542
    DRIZZLE_TYPE_VARCHAR,
543
    //DRIZZLE_TYPE_VARCHAR
544
    DRIZZLE_TYPE_VARCHAR,
545
    //DRIZZLE_TYPE_DECIMAL
546
    DRIZZLE_TYPE_VARCHAR,
547
    //DRIZZLE_TYPE_VARCHAR,
548
    DRIZZLE_TYPE_VARCHAR,
549
    //DRIZZLE_TYPE_BLOB
550
    DRIZZLE_TYPE_BLOB,
551
    //DRIZZLE_TYPE_TIME
552
    DRIZZLE_TYPE_TIME,
553
    //DRIZZLE_TYPE_BOOLEAN
554
    DRIZZLE_TYPE_VARCHAR,
555
    //DRIZZLE_TYPE_UUID
556
    DRIZZLE_TYPE_UUID,
557
    //DRIZZLE_TYPE_MICROTIME
558
    DRIZZLE_TYPE_MICROTIME,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
559
  },
1 by brian
clean slate
560
};
561
1996.2.1 by Brian Aker
uuid type code.
562
static Item_result field_types_result_type [enum_field_types_size]=
1 by brian
clean slate
563
{
398 by Brian Aker
Remove short.
564
  //DRIZZLE_TYPE_LONG
565
  INT_RESULT,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
566
  //DRIZZLE_TYPE_DOUBLE
166 by Brian Aker
Removal of FLOAT type
567
  REAL_RESULT,
520.1.26 by Monty Taylor
Fixed some formatting.
568
  //DRIZZLE_TYPE_NULL
569
  STRING_RESULT,
570
  //DRIZZLE_TYPE_TIMESTAMP
571
  STRING_RESULT,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
572
  //DRIZZLE_TYPE_LONGLONG
167 by Brian Aker
Remove old 3byte int
573
  INT_RESULT,
222 by Brian Aker
Remove YEAR field type
574
  //DRIZZLE_TYPE_DATETIME
575
  STRING_RESULT,
575.5.1 by David Axmark
Changed NEWDATE to DATE. One failing test but I think its somewhere else in the code
576
  //DRIZZLE_TYPE_DATE
520.1.26 by Monty Taylor
Fixed some formatting.
577
  STRING_RESULT,
578
  //DRIZZLE_TYPE_VARCHAR
579
  STRING_RESULT,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
580
  //DRIZZLE_TYPE_DECIMAL   
896.5.1 by Jay Pipes
Removes the TIME column type and related time functions.
581
  DECIMAL_RESULT,           
582
  //DRIZZLE_TYPE_ENUM
583
  STRING_RESULT,
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
584
  //DRIZZLE_TYPE_BLOB
585
  STRING_RESULT,
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
586
  //DRIZZLE_TYPE_TIME
587
  STRING_RESULT,
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
588
  //DRIZZLE_TYPE_BOOLEAN
2023.2.3 by Brian Aker
Merge in fixes for DD to make use of BOOLEAN as a type.
589
  STRING_RESULT,
1996.2.1 by Brian Aker
uuid type code.
590
  //DRIZZLE_TYPE_UUID
591
  STRING_RESULT,
2046.2.1 by Brian Aker
First pass on micro timestamp.
592
  //DRIZZLE_TYPE_MICROTIME
593
  STRING_RESULT,
1 by brian
clean slate
594
};
595
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
596
bool test_if_important_data(const CHARSET_INFO * const cs, 
597
                            const char *str,
598
                            const char *strend)
1 by brian
clean slate
599
{
600
  if (cs != &my_charset_bin)
601
    str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
602
  return (str < strend);
603
}
604
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
605
void *Field::operator new(size_t size)
606
{
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
607
  return memory::sql_alloc(size);
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
608
}
609
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
610
void *Field::operator new(size_t size, memory::Root *mem_root)
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
611
{
1485 by Brian Aker
Updates to confine memroot
612
  return mem_root->alloc_root(static_cast<uint32_t>(size));
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
613
}
614
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
615
enum_field_types Field::field_type_merge(enum_field_types a,
616
                                         enum_field_types b)
617
{
1996.2.1 by Brian Aker
uuid type code.
618
  assert(a < enum_field_types_size);
619
  assert(b < enum_field_types_size);
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
620
  return field_types_merge_rules[a][b];
621
}
622
1 by brian
clean slate
623
Item_result Field::result_merge_type(enum_field_types field_type)
624
{
1996.2.1 by Brian Aker
uuid type code.
625
  assert(field_type < enum_field_types_size);
520.1.25 by Monty Taylor
Removed the split.
626
  return field_types_result_type[field_type];
1 by brian
clean slate
627
}
628
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
629
bool Field::eq(Field *field)
630
{
631
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
632
          null_bit == field->null_bit);
633
}
634
635
uint32_t Field::pack_length() const
636
{
637
  return field_length;
638
}
639
640
uint32_t Field::pack_length_in_rec() const
641
{
642
  return pack_length();
643
}
644
645
uint32_t Field::data_length()
646
{
647
  return pack_length();
648
}
649
650
uint32_t Field::used_length()
651
{
652
  return pack_length();
653
}
654
655
uint32_t Field::sort_length() const
656
{
657
  return pack_length();
658
}
659
660
uint32_t Field::max_data_length() const
661
{
662
  return pack_length();
663
}
664
665
int Field::reset(void)
666
{
667
  memset(ptr, 0, pack_length());
668
  return 0;
669
}
670
671
void Field::reset_fields()
672
{}
673
674
void Field::set_default()
675
{
1672.3.6 by Brian Aker
First pass in encapsulating row
676
  ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->getInsertRecord());
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
677
  memcpy(ptr, ptr + l_offset, pack_length());
678
  if (null_ptr)
679
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
1008.3.2 by Stewart Smith
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.
680
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
681
  if (this == table->next_number_field)
682
    table->auto_increment_field_not_null= false;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
683
}
684
685
bool Field::binary() const
686
{
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
687
  return true;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
688
}
689
690
bool Field::zero_pack() const
691
{
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
692
  return true;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
693
}
694
695
enum ha_base_keytype Field::key_type() const
696
{
697
  return HA_KEYTYPE_BINARY;
698
}
699
700
uint32_t Field::key_length() const
701
{
702
  return pack_length();
703
}
704
705
enum_field_types Field::real_type() const
706
{
707
  return type();
708
}
709
710
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
711
{
712
  return cmp(a, b);
713
}
714
715
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
716
{
717
  return memcmp(a,b,pack_length());
718
}
719
720
int Field::cmp_offset(uint32_t row_offset)
721
{
722
  return cmp(ptr,ptr+row_offset);
723
}
724
725
int Field::cmp_binary_offset(uint32_t row_offset)
726
{
727
  return cmp_binary(ptr, ptr+row_offset);
728
}
729
730
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
731
{
732
  return cmp(a, b);
733
}
734
735
int Field::key_cmp(const unsigned char *str, uint32_t)
736
{
737
  return cmp(ptr,str);
738
}
739
740
uint32_t Field::decimals() const
741
{
742
  return 0;
743
}
744
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
745
bool Field::is_null(ptrdiff_t row_offset)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
746
{
747
  return null_ptr ?
748
    (null_ptr[row_offset] & null_bit ? true : false) :
749
    table->null_row;
750
}
751
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
752
bool Field::is_real_null(ptrdiff_t row_offset)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
753
{
754
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
755
}
756
757
bool Field::is_null_in_record(const unsigned char *record)
758
{
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
759
  if (! null_ptr)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
760
    return false;
1672.3.6 by Brian Aker
First pass in encapsulating row
761
  return test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
762
}
763
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
764
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
765
{
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
766
  if (! null_ptr)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
767
    return false;
779.3.10 by Monty Taylor
Turned on -Wshadow.
768
  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.
769
}
770
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
771
void Field::set_null(ptrdiff_t row_offset)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
772
{
773
  if (null_ptr)
774
    null_ptr[row_offset]|= null_bit;
775
}
776
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
777
void Field::set_notnull(ptrdiff_t row_offset)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
778
{
779
  if (null_ptr)
780
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
781
}
782
783
bool Field::maybe_null(void)
784
{
785
  return null_ptr != 0 || table->maybe_null;
786
}
787
788
bool Field::real_maybe_null(void)
789
{
790
  return null_ptr != 0;
791
}
792
1 by brian
clean slate
793
bool Field::type_can_have_key_part(enum enum_field_types type)
794
{
795
  switch (type) {
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
796
  case DRIZZLE_TYPE_VARCHAR:
797
  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
798
    return true;
1 by brian
clean slate
799
  default:
51.1.56 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on field.h/cc
800
    return false;
1 by brian
clean slate
801
  }
802
}
803
804
int Field::warn_if_overflow(int op_result)
805
{
806
  if (op_result == E_DEC_OVERFLOW)
807
  {
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
808
    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
809
    return E_DEC_OVERFLOW;
1 by brian
clean slate
810
  }
811
  if (op_result == E_DEC_TRUNCATED)
812
  {
970.2.1 by Padraig O'Sullivan
Fix for bug337038. Now we error on data truncation with decimal values but
813
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
814
    return E_DEC_TRUNCATED;
1 by brian
clean slate
815
  }
816
  return 0;
817
}
818
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
819
void Field::init(Table *table_arg)
820
{
821
  orig_table= table= table_arg;
822
}
823
1 by brian
clean slate
824
/// This is used as a table name when the table structure is not set up
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
825
Field::Field(unsigned char *ptr_arg,
826
             uint32_t length_arg,
827
             unsigned char *null_ptr_arg,
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
828
             unsigned char null_bit_arg,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
829
             utype unireg_check_arg, 
2134.1.2 by Brian Aker
Init the field class correctly.
830
             const char *field_name_arg) :
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
831
    ptr(ptr_arg),
832
    null_ptr(null_ptr_arg),
833
    table(NULL),
834
    orig_table(NULL),
835
    field_name(field_name_arg),
2134.1.2 by Brian Aker
Init the field class correctly.
836
    comment(NULL_LEX_STRING),
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
837
    key_start(0),
838
    part_of_key(0),
839
    part_of_key_not_clustered(0),
840
    part_of_sortkey(0),
841
    unireg_check(unireg_check_arg),
842
    field_length(length_arg),
2134.1.2 by Brian Aker
Init the field class correctly.
843
    flags(null_ptr ? 0: NOT_NULL_FLAG),
844
    field_index(0),
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
845
    null_bit(null_bit_arg),
846
    is_created_from_null_item(false)
1 by brian
clean slate
847
{
848
}
849
290 by Brian Aker
Update for ulong change over.
850
void Field::hash(uint32_t *nr, uint32_t *nr2)
1 by brian
clean slate
851
{
852
  if (is_null())
853
  {
854
    *nr^= (*nr << 1) | 1;
855
  }
856
  else
857
  {
438.1.13 by Brian Aker
uint cleanup.
858
    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.
859
    const CHARSET_INFO * const cs= charset();
1 by brian
clean slate
860
    cs->coll->hash_sort(cs, ptr, len, nr, nr2);
861
  }
862
}
863
864
void Field::copy_from_tmp(int row_offset)
865
{
866
  memcpy(ptr,ptr+row_offset,pack_length());
867
  if (null_ptr)
868
  {
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
869
    *null_ptr= (unsigned char) ((null_ptr[0] &
870
                                 (unsigned char) ~(uint32_t) null_bit) |
871
                                (null_ptr[row_offset] &
872
                                 (unsigned char) null_bit));
1 by brian
clean slate
873
  }
874
}
875
1996.2.1 by Brian Aker
uuid type code.
876
int Field::store_and_check(enum_check_fields check_level,
877
                           const char *to, 
878
                           uint32_t length,
879
                           const CHARSET_INFO * const cs)
880
1 by brian
clean slate
881
{
882
  int res;
883
  enum_check_fields old_check_level= table->in_use->count_cuted_fields;
884
  table->in_use->count_cuted_fields= check_level;
885
  res= store(to, length, cs);
886
  table->in_use->count_cuted_fields= old_check_level;
887
  return res;
888
}
889
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
890
unsigned char *Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool)
1 by brian
clean slate
891
{
205 by Brian Aker
uint32 -> uin32_t
892
  uint32_t length= pack_length();
1 by brian
clean slate
893
  set_if_smaller(length, max_length);
894
  memcpy(to, from, length);
895
  return to+length;
896
}
897
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
898
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
899
{
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
900
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->getShare()->db_low_byte_first);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
901
  return(result);
902
}
903
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
904
const unsigned char *Field::unpack(unsigned char* to,
905
                                   const unsigned char *from, 
906
                                   uint32_t param_data,
907
                                   bool)
1 by brian
clean slate
908
{
438.1.13 by Brian Aker
uint cleanup.
909
  uint32_t length=pack_length();
1 by brian
clean slate
910
  int from_type= 0;
911
  /*
912
    If from length is > 255, it has encoded data in the upper bits. Need
913
    to mask it out.
914
  */
915
  if (param_data > 255)
916
  {
917
    from_type= (param_data & 0xff00) >> 8U;  // real_type.
918
    param_data= param_data & 0x00ff;        // length.
919
  }
920
921
  if ((param_data == 0) ||
922
      (length == param_data) ||
923
      (from_type != real_type()))
924
  {
925
    memcpy(to, from, length);
926
    return from+length;
927
  }
928
438.1.13 by Brian Aker
uint cleanup.
929
  uint32_t len= (param_data && (param_data < length)) ?
520.1.28 by Monty Taylor
Reverted too-big formatting change.
930
            param_data : length;
1 by brian
clean slate
931
932
  memcpy(to, from, param_data > length ? length : len);
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
933
  return (from + len);
1 by brian
clean slate
934
}
935
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
936
const unsigned char *Field::unpack(unsigned char* to, const unsigned char *from)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
937
{
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
938
  const unsigned char *result= unpack(to, from, 0U, table->getShare()->db_low_byte_first);
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
939
  return(result);
940
}
941
2030.1.4 by Brian Aker
Change my_decimal to Decimal
942
type::Decimal *Field::val_decimal(type::Decimal *)
1 by brian
clean slate
943
{
944
  /* 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
945
  assert(0);
1 by brian
clean slate
946
  return 0;
947
}
948
949
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
950
void Field::make_field(SendField *field)
1 by brian
clean slate
951
{
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
952
  if (orig_table && orig_table->getShare()->getSchemaName() && *orig_table->getShare()->getSchemaName())
1 by brian
clean slate
953
  {
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
954
    field->db_name= orig_table->getShare()->getSchemaName();
955
    field->org_table_name= orig_table->getShare()->getTableName();
1 by brian
clean slate
956
  }
957
  else
958
    field->org_table_name= field->db_name= "";
959
  if (orig_table)
960
  {
1669.2.6 by Brian Aker
First pass through encapsulating getAlias() from table.
961
    field->table_name= orig_table->getAlias();
1 by brian
clean slate
962
    field->org_col_name= field_name;
963
  }
964
  else
965
  {
966
    field->table_name= "";
967
    field->org_col_name= "";
968
  }
969
  field->col_name= field_name;
970
  field->charsetnr= charset()->number;
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
971
  field->length= field_length;
972
  field->type= type();
973
  field->flags= table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
1 by brian
clean slate
974
  field->decimals= 0;
975
}
976
2030.1.4 by Brian Aker
Change my_decimal to Decimal
977
int64_t Field::convert_decimal2int64_t(const type::Decimal *val, bool, int *err)
1 by brian
clean slate
978
{
152 by Brian Aker
longlong replacement
979
  int64_t i;
2034.2.1 by Brian Aker
Move class_decimal2int to a method on Decimal.
980
  if (warn_if_overflow(val->val_int32(E_DEC_ERROR &
508 by Brian Aker
Second pass on unsigned
981
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
2034.2.1 by Brian Aker
Move class_decimal2int to a method on Decimal.
982
                                      false, &i)))
1 by brian
clean slate
983
  {
163 by Brian Aker
Merge Monty's code.
984
    i= (val->sign() ? INT64_MIN : INT64_MAX);
1 by brian
clean slate
985
    *err= 1;
986
  }
987
  return i;
988
}
989
1539.1.6 by Brian Aker
Update for Join structure changes.
990
uint32_t Field::fill_cache_field(CacheField *copy)
1 by brian
clean slate
991
{
438.1.13 by Brian Aker
uint cleanup.
992
  uint32_t store_length;
1 by brian
clean slate
993
  copy->str=ptr;
994
  copy->length=pack_length();
995
  copy->blob_field=0;
996
  if (flags & BLOB_FLAG)
997
  {
998
    copy->blob_field=(Field_blob*) this;
999
    copy->strip=0;
2134.1.4 by Brian Aker
Simple encapsulation for table.
1000
    copy->length-= table->getShare()->sizeBlobPtr();
1 by brian
clean slate
1001
    return copy->length;
1002
  }
1003
  else
1004
  {
1005
    copy->strip=0;
1006
    store_length= 0;
1007
  }
1008
  return copy->length+ store_length;
1009
}
1010
2137.1.9 by Brian Aker
Remove current_session usage in one location (we have the table's session to
1011
bool Field::get_date(type::Time &ltime, uint32_t fuzzydate)
1 by brian
clean slate
1012
{
2137.1.9 by Brian Aker
Remove current_session usage in one location (we have the table's session to
1013
  char buff[type::Time::MAX_STRING_LENGTH];
1 by brian
clean slate
1014
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
2114.5.1 by Brian Aker
Additional abstract around time (this also makes the abort_on_warnings in
1015
1016
  assert(getTable() and getTable()->getSession());
1017
1018
  if (not (res=val_str_internal(&tmp)) or
1019
      str_to_datetime_with_warn(getTable()->getSession(),
1020
                                res->ptr(), res->length(),
1021
                                &ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
1996.2.1 by Brian Aker
uuid type code.
1022
  {
2114.5.1 by Brian Aker
Additional abstract around time (this also makes the abort_on_warnings in
1023
    return true;
1996.2.1 by Brian Aker
uuid type code.
1024
  }
1025
2114.5.1 by Brian Aker
Additional abstract around time (this also makes the abort_on_warnings in
1026
  return false;
1 by brian
clean slate
1027
}
1028
2104.2.8 by Brian Aker
Merge in reference from pointer.
1029
bool Field::get_time(type::Time &ltime)
1 by brian
clean slate
1030
{
2137.1.9 by Brian Aker
Remove current_session usage in one location (we have the table's session to
1031
  char buff[type::Time::MAX_STRING_LENGTH];
1 by brian
clean slate
1032
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1996.2.1 by Brian Aker
uuid type code.
1033
2137.1.9 by Brian Aker
Remove current_session usage in one location (we have the table's session to
1034
  if (not (res= val_str_internal(&tmp)) or
1035
      str_to_time_with_warn(getTable()->getSession(), res->ptr(), res->length(), &ltime))
1996.2.1 by Brian Aker
uuid type code.
1036
  {
2114.5.1 by Brian Aker
Additional abstract around time (this also makes the abort_on_warnings in
1037
    return true;
1996.2.1 by Brian Aker
uuid type code.
1038
  }
1039
2114.5.1 by Brian Aker
Additional abstract around time (this also makes the abort_on_warnings in
1040
  return false;
1 by brian
clean slate
1041
}
1042
2104.2.7 by Brian Aker
Fix store_time to take reference.
1043
int Field::store_time(type::Time &ltime, type::timestamp_t)
1 by brian
clean slate
1044
{
2088.8.11 by Brian Aker
Fix additional output, swaps for the valus.
1045
  String tmp;
1046
2104.2.7 by Brian Aker
Fix store_time to take reference.
1047
  ltime.convert(tmp);
2088.8.11 by Brian Aker
Fix additional output, swaps for the valus.
1048
1049
  return store(tmp.ptr(), tmp.length(), &my_charset_bin);
1 by brian
clean slate
1050
}
1051
1235.1.12 by Brian Aker
Clean up index interface before moving to SE.
1052
bool Field::optimize_range(uint32_t idx, uint32_t)
1 by brian
clean slate
1053
{
1235.1.14 by Brian Aker
Final move of index flags up to Engine (new interface still needed).
1054
  return test(table->index_flags(idx) & HA_READ_RANGE);
1 by brian
clean slate
1055
}
1056
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
1057
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
1 by brian
clean slate
1058
{
1059
  Field *tmp;
1487 by Brian Aker
More updates for memory::Root
1060
  if (!(tmp= (Field*) root->memdup_root((char*) this,size_of())))
1 by brian
clean slate
1061
    return 0;
1062
1063
  if (tmp->table->maybe_null)
1064
    tmp->flags&= ~NOT_NULL_FLAG;
1065
  tmp->table= new_table;
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
1066
  tmp->key_start.reset();
1067
  tmp->part_of_key.reset();
1068
  tmp->part_of_sortkey.reset();
1 by brian
clean slate
1069
  tmp->unireg_check= Field::NONE;
1315.2.15 by Stewart Smith
remove the now unused SET_FLAG define. We don't have the SET field type, and this flag was never set.
1070
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
1 by brian
clean slate
1071
  tmp->reset_fields();
1072
  return tmp;
1073
}
1074
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
1075
Field *Field::new_key_field(memory::Root *root, Table *new_table,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1076
                            unsigned char *new_ptr,
1077
                            unsigned char *new_null_ptr,
438.1.13 by Brian Aker
uint cleanup.
1078
                            uint32_t new_null_bit)
1 by brian
clean slate
1079
{
1080
  Field *tmp;
1081
  if ((tmp= new_field(root, new_table, table == new_table)))
1082
  {
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1083
    tmp->ptr= new_ptr;
1 by brian
clean slate
1084
    tmp->null_ptr= new_null_ptr;
1085
    tmp->null_bit= new_null_bit;
1086
  }
1087
  return tmp;
1088
}
1089
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
1090
Field *Field::clone(memory::Root *root, Table *new_table)
1 by brian
clean slate
1091
{
1092
  Field *tmp;
1487 by Brian Aker
More updates for memory::Root
1093
  if ((tmp= (Field*) root->memdup_root((char*) this,size_of())))
1 by brian
clean slate
1094
  {
1095
    tmp->init(new_table);
1672.3.6 by Brian Aker
First pass in encapsulating row
1096
    tmp->move_field_offset((ptrdiff_t) (new_table->getInsertRecord() -
1574 by Brian Aker
Rollup patch for hiding tableshare.
1097
                                           new_table->getDefaultValues()));
1 by brian
clean slate
1098
  }
1099
  return tmp;
1100
}
1101
1102
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
1103
uint32_t Field::is_equal(CreateField *new_field_ptr)
1 by brian
clean slate
1104
{
779.3.10 by Monty Taylor
Turned on -Wshadow.
1105
  return (new_field_ptr->sql_type == real_type());
1 by brian
clean slate
1106
}
1107
1108
bool Field::eq_def(Field *field)
1109
{
1110
  if (real_type() != field->real_type() || charset() != field->charset() ||
1111
      pack_length() != field->pack_length())
1112
    return 0;
1113
  return 1;
1114
}
1115
1116
bool Field_enum::eq_def(Field *field)
1117
{
1118
  if (!Field::eq_def(field))
1119
    return 0;
2046.2.1 by Brian Aker
First pass on micro timestamp.
1120
1 by brian
clean slate
1121
  TYPELIB *from_lib=((Field_enum*) field)->typelib;
1122
1123
  if (typelib->count < from_lib->count)
1124
    return 0;
2046.2.1 by Brian Aker
First pass on micro timestamp.
1125
438.1.13 by Brian Aker
uint cleanup.
1126
  for (uint32_t i=0 ; i < from_lib->count ; i++)
2046.2.1 by Brian Aker
First pass on micro timestamp.
1127
  {
1 by brian
clean slate
1128
    if (my_strnncoll(field_charset,
481 by Brian Aker
Remove all of uchar.
1129
                     (const unsigned char*)typelib->type_names[i],
1 by brian
clean slate
1130
                     strlen(typelib->type_names[i]),
481 by Brian Aker
Remove all of uchar.
1131
                     (const unsigned char*)from_lib->type_names[i],
1 by brian
clean slate
1132
                     strlen(from_lib->type_names[i])))
1133
      return 0;
2046.2.1 by Brian Aker
First pass on micro timestamp.
1134
  }
1135
1 by brian
clean slate
1136
  return 1;
1137
}
1138
205 by Brian Aker
uint32 -> uin32_t
1139
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
1 by brian
clean slate
1140
{
1141
  switch (type) {
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
1142
  case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
1996.2.1 by Brian Aker
uuid type code.
1143
  case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
2046.2.1 by Brian Aker
First pass on micro timestamp.
1144
  case DRIZZLE_TYPE_MICROTIME: return field::Microtime::max_string_length();
1145
  case DRIZZLE_TYPE_TIMESTAMP: return field::Epoch::max_string_length();
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
1146
  case DRIZZLE_TYPE_BOOLEAN: return field::Boolean::max_string_length();
1782.4.2 by Brian Aker
Convert date from 3 byte to 4 byte.
1147
  case DRIZZLE_TYPE_DATE:
1782.4.4 by Brian Aker
Fix enum at being an intefer (which is what PG did, and it saves on
1148
  case DRIZZLE_TYPE_ENUM:
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
1149
  case DRIZZLE_TYPE_LONG: return 4;
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
1150
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
1151
  case DRIZZLE_TYPE_TIME:
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
1152
  case DRIZZLE_TYPE_DATETIME:
520.1.28 by Monty Taylor
Reverted too-big formatting change.
1153
  case DRIZZLE_TYPE_LONGLONG: return 8;	/* Don't crash if no int64_t */
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
1154
  case DRIZZLE_TYPE_NULL: return 0;
1155
  case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
1156
  case DRIZZLE_TYPE_DECIMAL:
1999.4.11 by Brian Aker
Fix issues with some columns incorrectly reporting NULL if they were of
1157
                          break;
1 by brian
clean slate
1158
  }
1996.2.1 by Brian Aker
uuid type code.
1159
1160
  assert(0);
1161
  abort();
1 by brian
clean slate
1162
}
1163
438.1.13 by Brian Aker
uint cleanup.
1164
uint32_t pack_length_to_packflag(uint32_t type)
1 by brian
clean slate
1165
{
1166
  switch (type) {
520.1.28 by Monty Taylor
Reverted too-big formatting change.
1167
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
1168
    case 2: assert(1);
1169
    case 3: assert(1);
1892.6.1 by Gustaf Thorslund
Replaced some more macro functions.
1170
    case 4: return f_settype(DRIZZLE_TYPE_LONG);
1171
    case 8: return f_settype(DRIZZLE_TYPE_LONGLONG);
1 by brian
clean slate
1172
  }
520.1.28 by Monty Taylor
Reverted too-big formatting change.
1173
  return 0;					// This shouldn't happen
1 by brian
clean slate
1174
}
1175
1176
/*****************************************************************************
1177
 Warning handling
1178
*****************************************************************************/
1179
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1180
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
2087.3.1 by Brian Aker
Entire convert over to time_t.
1181
                        drizzled::error_t code,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1182
                        int cuted_increment)
1 by brian
clean slate
1183
{
1184
  /*
1185
    If this field was created only for type conversion purposes it
1186
    will have table == NULL.
1187
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
1188
  Session *session= table ? table->in_use : current_session;
1189
  if (session->count_cuted_fields)
1 by brian
clean slate
1190
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1191
    session->cuted_fields+= cuted_increment;
1192
    push_warning_printf(session, level, code, ER(code), field_name,
1193
                        session->row_count);
1 by brian
clean slate
1194
    return 0;
1195
  }
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
1196
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
1 by brian
clean slate
1197
}
1198
1199
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1200
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
2087.3.1 by Brian Aker
Entire convert over to time_t.
1201
                                 drizzled::error_t code,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1202
                                 const char *str, 
1203
                                 uint32_t str_length,
2088.8.9 by Brian Aker
Merge in namespace of enum.
1204
                                 type::timestamp_t ts_type, 
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1205
                                 int cuted_increment)
1 by brian
clean slate
1206
{
2114.5.1 by Brian Aker
Additional abstract around time (this also makes the abort_on_warnings in
1207
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1208
2114.5.2 by Brian Aker
Just remove second ecapsulated method call.
1209
  if ((session->abortOnWarning() and
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
1210
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
1 by brian
clean slate
1211
      set_warning(level, code, cuted_increment))
520.1.22 by Brian Aker
Second pass of thd cleanup
1212
    make_truncated_value_warning(session, level, str, str_length, ts_type,
1 by brian
clean slate
1213
                                 field_name);
1214
}
1215
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1216
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
2087.3.1 by Brian Aker
Entire convert over to time_t.
1217
                                 drizzled::error_t code,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1218
                                 int64_t nr, 
2088.8.9 by Brian Aker
Merge in namespace of enum.
1219
                                 type::timestamp_t ts_type,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1220
                                 int cuted_increment)
1 by brian
clean slate
1221
{
2114.5.1 by Brian Aker
Additional abstract around time (this also makes the abort_on_warnings in
1222
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1223
2114.5.2 by Brian Aker
Just remove second ecapsulated method call.
1224
  if (session->abortOnWarning() or
1 by brian
clean slate
1225
      set_warning(level, code, cuted_increment))
1226
  {
2148.5.3 by Brian Aker
Remove hard coded array for numbers (this also fixes a couple of spots where
1227
    char str_nr[DECIMAL_LONGLONG_DIGITS];
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1228
    char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1229
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
1 by brian
clean slate
1230
                                 ts_type, field_name);
1231
  }
1232
}
1233
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1234
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
2087.3.1 by Brian Aker
Entire convert over to time_t.
1235
                                 const drizzled::error_t code,
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
1236
                                 double nr, 
2088.8.9 by Brian Aker
Merge in namespace of enum.
1237
                                 type::timestamp_t ts_type)
1 by brian
clean slate
1238
{
2114.5.1 by Brian Aker
Additional abstract around time (this also makes the abort_on_warnings in
1239
  Session *session= (getTable() and getTable()->getSession()) ? getTable()->getSession() : current_session;
1240
2114.5.2 by Brian Aker
Just remove second ecapsulated method call.
1241
  if (session->abortOnWarning() or
1 by brian
clean slate
1242
      set_warning(level, code, 1))
1243
  {
1244
    /* DBL_DIG is enough to print '-[digits].E+###' */
1245
    char str_nr[DBL_DIG + 8];
1366.1.11 by Siddharth Prakash Singh
sprintf->snprintf continued
1246
    uint32_t str_len= snprintf(str_nr, sizeof(str_nr), "%g", nr);
520.1.22 by Brian Aker
Second pass of thd cleanup
1247
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
1 by brian
clean slate
1248
                                 field_name);
1249
  }
1250
}
575.4.7 by Monty Taylor
More header cleanup.
1251
1003.1.9 by Brian Aker
Patches for Jay (aka name changes)
1252
bool Field::isReadSet() 
1003.1.6 by Brian Aker
Added interface for field to get read/write on its own.
1253
{ 
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
1254
  return table->isReadSet(field_index); 
1003.1.6 by Brian Aker
Added interface for field to get read/write on its own.
1255
}
1256
1003.1.9 by Brian Aker
Patches for Jay (aka name changes)
1257
bool Field::isWriteSet()
1003.1.6 by Brian Aker
Added interface for field to get read/write on its own.
1258
{ 
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
1259
  return table->isWriteSet(field_index); 
1003.1.6 by Brian Aker
Added interface for field to get read/write on its own.
1260
}
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
1261
1262
void Field::setReadSet(bool arg)
1263
{
1264
  if (arg)
1265
    table->setReadSet(field_index);
1266
  else
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
1267
    table->clearReadSet(field_index);
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
1268
}
1269
1270
void Field::setWriteSet(bool arg)
1271
{
1272
  if (arg)
1273
    table->setWriteSet(field_index);
1274
  else
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
1275
    table->clearWriteSet(field_index);
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
1276
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1277
2016.1.2 by Brian Aker
Fix for Solaris
1278
void Field::pack_num(uint64_t arg, unsigned char *destination)
1279
{
1280
  if (not destination)
1281
    destination= ptr;
1282
2016.1.7 by Brian Aker
Remove MyISAM flip bit, and make sure that we only pass in a good time_t to
1283
  int64_tstore(destination, arg);
2016.1.2 by Brian Aker
Fix for Solaris
1284
}
1285
2046.2.3 by Brian Aker
Add basic tests for microtime.
1286
void Field::pack_num(uint32_t arg, unsigned char *destination)
1287
{
1288
  if (not destination)
1289
    destination= ptr;
1290
1291
  longstore(destination, arg);
1292
}
1293
2016.1.2 by Brian Aker
Fix for Solaris
1294
uint64_t Field::unpack_num(uint64_t &destination, const unsigned char *arg) const
1295
{
1296
  if (not arg)
1297
    arg= ptr;
1298
2016.1.7 by Brian Aker
Remove MyISAM flip bit, and make sure that we only pass in a good time_t to
1299
  int64_tget(destination, arg);
2016.1.2 by Brian Aker
Fix for Solaris
1300
1301
  return destination;
1302
}
1303
2046.2.3 by Brian Aker
Add basic tests for microtime.
1304
uint32_t Field::unpack_num(uint32_t &destination, const unsigned char *arg) const
1305
{
1306
  if (not arg)
1307
    arg= ptr;
1308
1309
  longget(destination, arg);
1310
1311
  return destination;
1312
}
1313
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
1314
std::ostream& operator<<(std::ostream& output, const Field &field)
1315
{
1316
  output << "Field:(";
1317
  output <<  field.field_name;
1318
  output << ", ";
1319
  output << drizzled::display::type(field.real_type());
2008.2.4 by Brian Aker
Merge in additional fixes for sign, plus alter table, plus TIME on
1320
  output << ", { ";
1321
1322
  if (field.flags & NOT_NULL_FLAG)
1323
    output << " NOT_NULL";
1324
1325
  if (field.flags & PRI_KEY_FLAG)
1326
    output << ", PRIMARY KEY";
1327
1328
  if (field.flags & UNIQUE_KEY_FLAG)
1329
    output << ", UNIQUE KEY";
1330
1331
  if (field.flags & MULTIPLE_KEY_FLAG)
1332
    output << ", MULTIPLE KEY";
1333
1334
  if (field.flags & BLOB_FLAG)
1335
    output << ", BLOB";
1336
1337
  if (field.flags & UNSIGNED_FLAG)
1338
    output << ", UNSIGNED";
1339
1340
  if (field.flags & BINARY_FLAG)
1341
    output << ", BINARY";
1342
  output << "}, ";
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
1343
  output << ")";
1344
1345
  return output;  // for multiple << operators.
1346
}
1347
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1348
} /* namespace drizzled */