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