~drizzle-trunk/drizzle/development

520.1.25 by Monty Taylor
Removed the split.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 MySQL
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
1 by brian
clean slate
20
21
/**
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
22
 * @file This file implements the Field class and API
23
 */
1 by brian
clean slate
24
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
25
#include "config.h"
1502.3.1 by iwamatsu at nigauri
Add cstdio include to files needing it. Fixes the build on some debian
26
#include <cstdio>
1 by brian
clean slate
27
#include <errno.h>
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
28
#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...
29
#include "drizzled/sql_select.h"
30
#include "drizzled/error.h"
31
#include "drizzled/field/str.h"
32
#include "drizzled/field/num.h"
33
#include "drizzled/field/blob.h"
34
#include "drizzled/field/enum.h"
35
#include "drizzled/field/null.h"
36
#include "drizzled/field/date.h"
37
#include "drizzled/field/decimal.h"
38
#include "drizzled/field/real.h"
39
#include "drizzled/field/double.h"
40
#include "drizzled/field/long.h"
41
#include "drizzled/field/int64_t.h"
42
#include "drizzled/field/num.h"
43
#include "drizzled/field/timestamp.h"
44
#include "drizzled/field/datetime.h"
45
#include "drizzled/field/varstring.h"
1237.9.8 by Monty Taylor
Fixed solaris build.
46
#include "drizzled/time_functions.h"
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
47
#include "drizzled/internal/m_string.h"
1 by brian
clean slate
48
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
49
namespace drizzled
50
{
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
51
1 by brian
clean slate
52
/*****************************************************************************
53
  Instansiate templates and static variables
54
*****************************************************************************/
55
520.1.25 by Monty Taylor
Removed the split.
56
static enum_field_types
57
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
1 by brian
clean slate
58
{
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
59
  /* DRIZZLE_TYPE_LONG -> */
60
  {
520.1.25 by Monty Taylor
Removed the split.
61
    //DRIZZLE_TYPE_LONG
62
    DRIZZLE_TYPE_LONG,
63
    //DRIZZLE_TYPE_DOUBLE
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
64
    DRIZZLE_TYPE_DOUBLE,
520.1.25 by Monty Taylor
Removed the split.
65
    //DRIZZLE_TYPE_NULL
66
    DRIZZLE_TYPE_LONG,
67
    //DRIZZLE_TYPE_TIMESTAMP
68
    DRIZZLE_TYPE_VARCHAR,
69
    //DRIZZLE_TYPE_LONGLONG
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
70
    DRIZZLE_TYPE_LONGLONG,
520.1.25 by Monty Taylor
Removed the split.
71
    //DRIZZLE_TYPE_DATETIME
72
    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
73
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
74
    DRIZZLE_TYPE_VARCHAR,
75
    //DRIZZLE_TYPE_VARCHAR
76
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
77
    //DRIZZLE_TYPE_DECIMAL
78
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
79
    //DRIZZLE_TYPE_ENUM
80
    DRIZZLE_TYPE_VARCHAR,
81
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
82
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
83
  },
84
  /* DRIZZLE_TYPE_DOUBLE -> */
85
  {
520.1.25 by Monty Taylor
Removed the split.
86
    //DRIZZLE_TYPE_LONG
87
    DRIZZLE_TYPE_DOUBLE,
88
    //DRIZZLE_TYPE_DOUBLE
89
    DRIZZLE_TYPE_DOUBLE,
90
    //DRIZZLE_TYPE_NULL
91
    DRIZZLE_TYPE_DOUBLE,
92
    //DRIZZLE_TYPE_TIMESTAMP
93
    DRIZZLE_TYPE_VARCHAR,
94
    //DRIZZLE_TYPE_LONGLONG
95
    DRIZZLE_TYPE_DOUBLE,
96
    //DRIZZLE_TYPE_DATETIME
97
    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
98
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
99
    DRIZZLE_TYPE_VARCHAR,
100
    //DRIZZLE_TYPE_VARCHAR
101
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
102
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
103
    DRIZZLE_TYPE_DOUBLE,
104
    //DRIZZLE_TYPE_ENUM
105
    DRIZZLE_TYPE_VARCHAR,
106
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
107
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
108
  },
109
  /* DRIZZLE_TYPE_NULL -> */
110
  {
520.1.25 by Monty Taylor
Removed the split.
111
    //DRIZZLE_TYPE_LONG
398 by Brian Aker
Remove short.
112
    DRIZZLE_TYPE_LONG,
520.1.25 by Monty Taylor
Removed the split.
113
    //DRIZZLE_TYPE_DOUBLE
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
114
    DRIZZLE_TYPE_DOUBLE,
520.1.25 by Monty Taylor
Removed the split.
115
    //DRIZZLE_TYPE_NULL
116
    DRIZZLE_TYPE_NULL,
117
    //DRIZZLE_TYPE_TIMESTAMP
118
    DRIZZLE_TYPE_TIMESTAMP,
119
    //DRIZZLE_TYPE_LONGLONG
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
120
    DRIZZLE_TYPE_LONGLONG,
520.1.25 by Monty Taylor
Removed the split.
121
    //DRIZZLE_TYPE_DATETIME
222 by Brian Aker
Remove YEAR field type
122
    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
123
    //DRIZZLE_TYPE_DATE
124
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
125
    //DRIZZLE_TYPE_VARCHAR
126
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
127
    //DRIZZLE_TYPE_DECIMAL
128
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
129
    //DRIZZLE_TYPE_ENUM
130
    DRIZZLE_TYPE_ENUM,
131
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
132
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
133
  },
134
  /* DRIZZLE_TYPE_TIMESTAMP -> */
135
  {
520.1.25 by Monty Taylor
Removed the split.
136
    //DRIZZLE_TYPE_LONG
137
    DRIZZLE_TYPE_VARCHAR,
138
    //DRIZZLE_TYPE_DOUBLE
139
    DRIZZLE_TYPE_VARCHAR,
140
    //DRIZZLE_TYPE_NULL
141
    DRIZZLE_TYPE_TIMESTAMP,
142
    //DRIZZLE_TYPE_TIMESTAMP
143
    DRIZZLE_TYPE_TIMESTAMP,
144
    //DRIZZLE_TYPE_LONGLONG
145
    DRIZZLE_TYPE_VARCHAR,
146
    //DRIZZLE_TYPE_DATETIME
147
    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
148
    //DRIZZLE_TYPE_DATE
149
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
150
    //DRIZZLE_TYPE_VARCHAR
151
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
152
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
153
    DRIZZLE_TYPE_VARCHAR,
154
    //DRIZZLE_TYPE_ENUM
155
    DRIZZLE_TYPE_VARCHAR,
156
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
157
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
158
  },
159
  /* DRIZZLE_TYPE_LONGLONG -> */
160
  {
520.1.25 by Monty Taylor
Removed the split.
161
    //DRIZZLE_TYPE_LONG
162
    DRIZZLE_TYPE_LONGLONG,
163
    //DRIZZLE_TYPE_DOUBLE
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
164
    DRIZZLE_TYPE_DOUBLE,
520.1.25 by Monty Taylor
Removed the split.
165
    //DRIZZLE_TYPE_NULL
166
    DRIZZLE_TYPE_LONGLONG,
167
    //DRIZZLE_TYPE_TIMESTAMP
168
    DRIZZLE_TYPE_VARCHAR,
169
    //DRIZZLE_TYPE_LONGLONG
170
    DRIZZLE_TYPE_LONGLONG,
171
    //DRIZZLE_TYPE_DATETIME
172
    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
173
    //DRIZZLE_TYPE_DATE
174
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
175
    //DRIZZLE_TYPE_VARCHAR
176
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
177
    //DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_ENUM
178
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
179
    DRIZZLE_TYPE_VARCHAR,
180
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
181
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
182
  },
183
  /* DRIZZLE_TYPE_DATETIME -> */
184
  {
520.1.25 by Monty Taylor
Removed the split.
185
    //DRIZZLE_TYPE_LONG
186
    DRIZZLE_TYPE_VARCHAR,
187
    //DRIZZLE_TYPE_DOUBLE
188
    DRIZZLE_TYPE_VARCHAR,
189
    //DRIZZLE_TYPE_NULL
190
    DRIZZLE_TYPE_DATETIME,
191
    //DRIZZLE_TYPE_TIMESTAMP
192
    DRIZZLE_TYPE_DATETIME,
193
    //DRIZZLE_TYPE_LONGLONG
194
    DRIZZLE_TYPE_VARCHAR,
195
    //DRIZZLE_TYPE_DATETIME
196
    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
197
    //DRIZZLE_TYPE_DATE
198
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
199
    //DRIZZLE_TYPE_VARCHAR
200
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
201
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
202
    DRIZZLE_TYPE_VARCHAR,
203
    //DRIZZLE_TYPE_ENUM
204
    DRIZZLE_TYPE_VARCHAR,
205
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
206
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
207
  },
575.5.1 by David Axmark
Changed NEWDATE to DATE. One failing test but I think its somewhere else in the code
208
  /* DRIZZLE_TYPE_DATE -> */
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
209
  {
520.1.25 by Monty Taylor
Removed the split.
210
    //DRIZZLE_TYPE_LONG
211
    DRIZZLE_TYPE_VARCHAR,
212
    //DRIZZLE_TYPE_DOUBLE
213
    DRIZZLE_TYPE_VARCHAR,
214
    //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
215
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
216
    //DRIZZLE_TYPE_TIMESTAMP
217
    DRIZZLE_TYPE_DATETIME,
218
    //DRIZZLE_TYPE_LONGLONG
219
    DRIZZLE_TYPE_VARCHAR,
220
    //DRIZZLE_TYPE_DATETIME
221
    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
222
    //DRIZZLE_TYPE_DATE
223
    DRIZZLE_TYPE_DATE,
520.1.25 by Monty Taylor
Removed the split.
224
    //DRIZZLE_TYPE_VARCHAR
225
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
226
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
227
    DRIZZLE_TYPE_VARCHAR,
228
    //DRIZZLE_TYPE_ENUM
229
    DRIZZLE_TYPE_VARCHAR,
230
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
231
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
232
  },
233
  /* DRIZZLE_TYPE_VARCHAR -> */
234
  {
520.1.25 by Monty Taylor
Removed the split.
235
    //DRIZZLE_TYPE_LONG
236
    DRIZZLE_TYPE_VARCHAR,
237
    //DRIZZLE_TYPE_DOUBLE
238
    DRIZZLE_TYPE_VARCHAR,
239
    //DRIZZLE_TYPE_NULL
240
    DRIZZLE_TYPE_VARCHAR,
241
    //DRIZZLE_TYPE_TIMESTAMP
242
    DRIZZLE_TYPE_VARCHAR,
243
    //DRIZZLE_TYPE_LONGLONG
244
    DRIZZLE_TYPE_VARCHAR,
245
    //DRIZZLE_TYPE_DATETIME
246
    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
247
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
248
    DRIZZLE_TYPE_VARCHAR,
249
    //DRIZZLE_TYPE_VARCHAR
250
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
251
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
252
    DRIZZLE_TYPE_VARCHAR,
253
    //DRIZZLE_TYPE_ENUM
254
    DRIZZLE_TYPE_VARCHAR,
255
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
256
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
257
  },
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
258
  /* DRIZZLE_TYPE_DECIMAL -> */
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
259
  {
520.1.25 by Monty Taylor
Removed the split.
260
    //DRIZZLE_TYPE_LONG
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
261
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
262
    //DRIZZLE_TYPE_DOUBLE
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
263
    DRIZZLE_TYPE_DOUBLE,
520.1.25 by Monty Taylor
Removed the split.
264
    //DRIZZLE_TYPE_NULL
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
265
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
266
    //DRIZZLE_TYPE_TIMESTAMP
267
    DRIZZLE_TYPE_VARCHAR,
268
    //DRIZZLE_TYPE_LONGLONG
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
269
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
270
    //DRIZZLE_TYPE_DATETIME
271
    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
272
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
273
    DRIZZLE_TYPE_VARCHAR,
274
    //DRIZZLE_TYPE_VARCHAR
275
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
276
    //DRIZZLE_TYPE_DECIMAL
277
    DRIZZLE_TYPE_DECIMAL,
520.1.25 by Monty Taylor
Removed the split.
278
    //DRIZZLE_TYPE_ENUM
279
    DRIZZLE_TYPE_VARCHAR,
280
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
281
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
282
  },
283
  /* DRIZZLE_TYPE_ENUM -> */
284
  {
520.1.25 by Monty Taylor
Removed the split.
285
    //DRIZZLE_TYPE_LONG
286
    DRIZZLE_TYPE_VARCHAR,
287
    //DRIZZLE_TYPE_DOUBLE
288
    DRIZZLE_TYPE_VARCHAR,
289
    //DRIZZLE_TYPE_NULL
290
    DRIZZLE_TYPE_ENUM,
291
    //DRIZZLE_TYPE_TIMESTAMP
292
    DRIZZLE_TYPE_VARCHAR,
293
    //DRIZZLE_TYPE_LONGLONG
294
    DRIZZLE_TYPE_VARCHAR,
295
    //DRIZZLE_TYPE_DATETIME
296
    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
297
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
298
    DRIZZLE_TYPE_VARCHAR,
299
    //DRIZZLE_TYPE_VARCHAR
300
    DRIZZLE_TYPE_VARCHAR,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
301
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
302
    DRIZZLE_TYPE_VARCHAR,
303
    //DRIZZLE_TYPE_ENUM
304
    DRIZZLE_TYPE_VARCHAR,
305
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
306
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
307
  },
308
  /* DRIZZLE_TYPE_BLOB -> */
309
  {
520.1.25 by Monty Taylor
Removed the split.
310
    //DRIZZLE_TYPE_LONG
311
    DRIZZLE_TYPE_BLOB,
312
    //DRIZZLE_TYPE_DOUBLE
313
    DRIZZLE_TYPE_BLOB,
314
    //DRIZZLE_TYPE_NULL
315
    DRIZZLE_TYPE_BLOB,
316
    //DRIZZLE_TYPE_TIMESTAMP
317
    DRIZZLE_TYPE_BLOB,
318
    //DRIZZLE_TYPE_LONGLONG
319
    DRIZZLE_TYPE_BLOB,
320
    //DRIZZLE_TYPE_DATETIME
321
    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
322
    //DRIZZLE_TYPE_DATE
520.1.25 by Monty Taylor
Removed the split.
323
    DRIZZLE_TYPE_BLOB,
324
    //DRIZZLE_TYPE_VARCHAR
325
    DRIZZLE_TYPE_BLOB,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
326
    //DRIZZLE_TYPE_DECIMAL
520.1.25 by Monty Taylor
Removed the split.
327
    DRIZZLE_TYPE_BLOB,
328
    //DRIZZLE_TYPE_ENUM
329
    DRIZZLE_TYPE_BLOB,
330
    //DRIZZLE_TYPE_BLOB
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
331
    DRIZZLE_TYPE_BLOB,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
332
  },
1 by brian
clean slate
333
};
334
520.1.25 by Monty Taylor
Removed the split.
335
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
1 by brian
clean slate
336
{
398 by Brian Aker
Remove short.
337
  //DRIZZLE_TYPE_LONG
338
  INT_RESULT,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
339
  //DRIZZLE_TYPE_DOUBLE
166 by Brian Aker
Removal of FLOAT type
340
  REAL_RESULT,
520.1.26 by Monty Taylor
Fixed some formatting.
341
  //DRIZZLE_TYPE_NULL
342
  STRING_RESULT,
343
  //DRIZZLE_TYPE_TIMESTAMP
344
  STRING_RESULT,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
345
  //DRIZZLE_TYPE_LONGLONG
167 by Brian Aker
Remove old 3byte int
346
  INT_RESULT,
222 by Brian Aker
Remove YEAR field type
347
  //DRIZZLE_TYPE_DATETIME
348
  STRING_RESULT,
575.5.1 by David Axmark
Changed NEWDATE to DATE. One failing test but I think its somewhere else in the code
349
  //DRIZZLE_TYPE_DATE
520.1.26 by Monty Taylor
Fixed some formatting.
350
  STRING_RESULT,
351
  //DRIZZLE_TYPE_VARCHAR
352
  STRING_RESULT,
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
353
  //DRIZZLE_TYPE_DECIMAL   
896.5.1 by Jay Pipes
Removes the TIME column type and related time functions.
354
  DECIMAL_RESULT,           
355
  //DRIZZLE_TYPE_ENUM
356
  STRING_RESULT,
240 by Brian Aker
Removed old/dead VARCHAR type from pre-5.0
357
  //DRIZZLE_TYPE_BLOB
358
  STRING_RESULT,
1 by brian
clean slate
359
};
360
1055.2.7 by Jay Pipes
More documentation cleanup for Field class
361
bool test_if_important_data(const CHARSET_INFO * const cs, 
362
                            const char *str,
363
                            const char *strend)
1 by brian
clean slate
364
{
365
  if (cs != &my_charset_bin)
366
    str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
367
  return (str < strend);
368
}
369
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
370
void *Field::operator new(size_t size)
371
{
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
372
  return memory::sql_alloc(size);
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
373
}
374
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
375
void *Field::operator new(size_t size, memory::Root *mem_root)
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
376
{
1485 by Brian Aker
Updates to confine memroot
377
  return mem_root->alloc_root(static_cast<uint32_t>(size));
1241.9.51 by Monty Taylor
More mysys stuff out of headers.
378
}
379
1055.2.9 by Jay Pipes
Removes dead get_blob_type_from_length() function. We only have one type of BLOB now...
380
enum_field_types Field::field_type_merge(enum_field_types a,
381
                                         enum_field_types b)
382
{
383
  assert(a <= DRIZZLE_TYPE_MAX);
384
  assert(b <= DRIZZLE_TYPE_MAX);
385
  return field_types_merge_rules[a][b];
386
}
387
1 by brian
clean slate
388
Item_result Field::result_merge_type(enum_field_types field_type)
389
{
520.1.25 by Monty Taylor
Removed the split.
390
  assert(field_type <= DRIZZLE_TYPE_MAX);
391
  return field_types_result_type[field_type];
1 by brian
clean slate
392
}
393
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
394
bool Field::eq(Field *field)
395
{
396
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
397
          null_bit == field->null_bit);
398
}
399
400
uint32_t Field::pack_length() const
401
{
402
  return field_length;
403
}
404
405
uint32_t Field::pack_length_in_rec() const
406
{
407
  return pack_length();
408
}
409
410
uint32_t Field::data_length()
411
{
412
  return pack_length();
413
}
414
415
uint32_t Field::used_length()
416
{
417
  return pack_length();
418
}
419
420
uint32_t Field::sort_length() const
421
{
422
  return pack_length();
423
}
424
425
uint32_t Field::max_data_length() const
426
{
427
  return pack_length();
428
}
429
430
int Field::reset(void)
431
{
432
  memset(ptr, 0, pack_length());
433
  return 0;
434
}
435
436
void Field::reset_fields()
437
{}
438
439
void Field::set_default()
440
{
1672.3.6 by Brian Aker
First pass in encapsulating row
441
  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.
442
  memcpy(ptr, ptr + l_offset, pack_length());
443
  if (null_ptr)
444
    *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.
445
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
446
  if (this == table->next_number_field)
447
    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.
448
}
449
450
bool Field::binary() const
451
{
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
452
  return true;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
453
}
454
455
bool Field::zero_pack() const
456
{
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
457
  return true;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
458
}
459
460
enum ha_base_keytype Field::key_type() const
461
{
462
  return HA_KEYTYPE_BINARY;
463
}
464
465
uint32_t Field::key_length() const
466
{
467
  return pack_length();
468
}
469
470
enum_field_types Field::real_type() const
471
{
472
  return type();
473
}
474
475
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
476
{
477
  return cmp(a, b);
478
}
479
480
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
481
{
482
  return memcmp(a,b,pack_length());
483
}
484
485
int Field::cmp_offset(uint32_t row_offset)
486
{
487
  return cmp(ptr,ptr+row_offset);
488
}
489
490
int Field::cmp_binary_offset(uint32_t row_offset)
491
{
492
  return cmp_binary(ptr, ptr+row_offset);
493
}
494
495
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
496
{
497
  return cmp(a, b);
498
}
499
500
int Field::key_cmp(const unsigned char *str, uint32_t)
501
{
502
  return cmp(ptr,str);
503
}
504
505
uint32_t Field::decimals() const
506
{
507
  return 0;
508
}
509
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
510
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.
511
{
512
  return null_ptr ?
513
    (null_ptr[row_offset] & null_bit ? true : false) :
514
    table->null_row;
515
}
516
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
517
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.
518
{
519
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
520
}
521
522
bool Field::is_null_in_record(const unsigned char *record)
523
{
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
524
  if (! null_ptr)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
525
    return false;
1672.3.6 by Brian Aker
First pass in encapsulating row
526
  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.
527
}
528
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
529
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.
530
{
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
531
  if (! null_ptr)
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
532
    return false;
779.3.10 by Monty Taylor
Turned on -Wshadow.
533
  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.
534
}
535
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
536
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.
537
{
538
  if (null_ptr)
539
    null_ptr[row_offset]|= null_bit;
540
}
541
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
542
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.
543
{
544
  if (null_ptr)
545
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
546
}
547
548
bool Field::maybe_null(void)
549
{
550
  return null_ptr != 0 || table->maybe_null;
551
}
552
553
bool Field::real_maybe_null(void)
554
{
555
  return null_ptr != 0;
556
}
557
1 by brian
clean slate
558
bool Field::type_can_have_key_part(enum enum_field_types type)
559
{
560
  switch (type) {
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
561
  case DRIZZLE_TYPE_VARCHAR:
562
  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
563
    return true;
1 by brian
clean slate
564
  default:
51.1.56 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on field.h/cc
565
    return false;
1 by brian
clean slate
566
  }
567
}
568
569
int Field::warn_if_overflow(int op_result)
570
{
571
  if (op_result == E_DEC_OVERFLOW)
572
  {
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
573
    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
574
    return E_DEC_OVERFLOW;
1 by brian
clean slate
575
  }
576
  if (op_result == E_DEC_TRUNCATED)
577
  {
970.2.1 by Padraig O'Sullivan
Fix for bug337038. Now we error on data truncation with decimal values but
578
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
579
    return E_DEC_TRUNCATED;
1 by brian
clean slate
580
  }
581
  return 0;
582
}
583
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
584
void Field::init(Table *table_arg)
585
{
586
  orig_table= table= table_arg;
587
}
588
1 by brian
clean slate
589
/// 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.
590
Field::Field(unsigned char *ptr_arg,
591
             uint32_t length_arg,
592
             unsigned char *null_ptr_arg,
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
593
             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.
594
             utype unireg_check_arg, 
595
             const char *field_name_arg)
596
  :
597
    ptr(ptr_arg),
598
    null_ptr(null_ptr_arg),
599
    table(NULL),
600
    orig_table(NULL),
601
    field_name(field_name_arg),
602
    key_start(0),
603
    part_of_key(0),
604
    part_of_key_not_clustered(0),
605
    part_of_sortkey(0),
606
    unireg_check(unireg_check_arg),
607
    field_length(length_arg),
608
    null_bit(null_bit_arg),
609
    is_created_from_null_item(false)
1 by brian
clean slate
610
{
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
611
  flags= null_ptr ? 0: NOT_NULL_FLAG;
1 by brian
clean slate
612
  comment.str= (char*) "";
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
613
  comment.length= 0;
1 by brian
clean slate
614
  field_index= 0;
615
}
616
290 by Brian Aker
Update for ulong change over.
617
void Field::hash(uint32_t *nr, uint32_t *nr2)
1 by brian
clean slate
618
{
619
  if (is_null())
620
  {
621
    *nr^= (*nr << 1) | 1;
622
  }
623
  else
624
  {
438.1.13 by Brian Aker
uint cleanup.
625
    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.
626
    const CHARSET_INFO * const cs= charset();
1 by brian
clean slate
627
    cs->coll->hash_sort(cs, ptr, len, nr, nr2);
628
  }
629
}
630
631
void Field::copy_from_tmp(int row_offset)
632
{
633
  memcpy(ptr,ptr+row_offset,pack_length());
634
  if (null_ptr)
635
  {
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
636
    *null_ptr= (unsigned char) ((null_ptr[0] &
637
                                 (unsigned char) ~(uint32_t) null_bit) |
638
                                (null_ptr[row_offset] &
639
                                 (unsigned char) null_bit));
1 by brian
clean slate
640
  }
641
}
642
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
643
int Field::store(const char *to, 
644
                 uint32_t length,
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
645
                 const CHARSET_INFO * const cs,
1 by brian
clean slate
646
                 enum_check_fields check_level)
647
{
648
  int res;
649
  enum_check_fields old_check_level= table->in_use->count_cuted_fields;
650
  table->in_use->count_cuted_fields= check_level;
651
  res= store(to, length, cs);
652
  table->in_use->count_cuted_fields= old_check_level;
653
  return res;
654
}
655
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
656
unsigned char *Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool)
1 by brian
clean slate
657
{
205 by Brian Aker
uint32 -> uin32_t
658
  uint32_t length= pack_length();
1 by brian
clean slate
659
  set_if_smaller(length, max_length);
660
  memcpy(to, from, length);
661
  return to+length;
662
}
663
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
664
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
665
{
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
666
  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.
667
  return(result);
668
}
669
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
670
const unsigned char *Field::unpack(unsigned char* to,
671
                                   const unsigned char *from, 
672
                                   uint32_t param_data,
673
                                   bool)
1 by brian
clean slate
674
{
438.1.13 by Brian Aker
uint cleanup.
675
  uint32_t length=pack_length();
1 by brian
clean slate
676
  int from_type= 0;
677
  /*
678
    If from length is > 255, it has encoded data in the upper bits. Need
679
    to mask it out.
680
  */
681
  if (param_data > 255)
682
  {
683
    from_type= (param_data & 0xff00) >> 8U;  // real_type.
684
    param_data= param_data & 0x00ff;        // length.
685
  }
686
687
  if ((param_data == 0) ||
688
      (length == param_data) ||
689
      (from_type != real_type()))
690
  {
691
    memcpy(to, from, length);
692
    return from+length;
693
  }
694
438.1.13 by Brian Aker
uint cleanup.
695
  uint32_t len= (param_data && (param_data < length)) ?
520.1.28 by Monty Taylor
Reverted too-big formatting change.
696
            param_data : length;
1 by brian
clean slate
697
698
  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.
699
  return (from + len);
1 by brian
clean slate
700
}
701
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
702
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.
703
{
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
704
  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.
705
  return(result);
706
}
707
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
708
my_decimal *Field::val_decimal(my_decimal *)
1 by brian
clean slate
709
{
710
  /* 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
711
  assert(0);
1 by brian
clean slate
712
  return 0;
713
}
714
715
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
716
void Field::make_field(SendField *field)
1 by brian
clean slate
717
{
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
718
  if (orig_table && orig_table->getShare()->getSchemaName() && *orig_table->getShare()->getSchemaName())
1 by brian
clean slate
719
  {
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
720
    field->db_name= orig_table->getShare()->getSchemaName();
721
    field->org_table_name= orig_table->getShare()->getTableName();
1 by brian
clean slate
722
  }
723
  else
724
    field->org_table_name= field->db_name= "";
725
  if (orig_table)
726
  {
1669.2.6 by Brian Aker
First pass through encapsulating getAlias() from table.
727
    field->table_name= orig_table->getAlias();
1 by brian
clean slate
728
    field->org_col_name= field_name;
729
  }
730
  else
731
  {
732
    field->table_name= "";
733
    field->org_col_name= "";
734
  }
735
  field->col_name= field_name;
736
  field->charsetnr= charset()->number;
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
737
  field->length= field_length;
738
  field->type= type();
739
  field->flags= table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
1 by brian
clean slate
740
  field->decimals= 0;
741
}
742
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
743
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
1 by brian
clean slate
744
{
152 by Brian Aker
longlong replacement
745
  int64_t i;
508 by Brian Aker
Second pass on unsigned
746
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
747
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
748
                                      val, false, &i)))
1 by brian
clean slate
749
  {
163 by Brian Aker
Merge Monty's code.
750
    i= (val->sign() ? INT64_MIN : INT64_MAX);
1 by brian
clean slate
751
    *err= 1;
752
  }
753
  return i;
754
}
755
1539.1.6 by Brian Aker
Update for Join structure changes.
756
uint32_t Field::fill_cache_field(CacheField *copy)
1 by brian
clean slate
757
{
438.1.13 by Brian Aker
uint cleanup.
758
  uint32_t store_length;
1 by brian
clean slate
759
  copy->str=ptr;
760
  copy->length=pack_length();
761
  copy->blob_field=0;
762
  if (flags & BLOB_FLAG)
763
  {
764
    copy->blob_field=(Field_blob*) this;
765
    copy->strip=0;
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
766
    copy->length-= table->getShare()->blob_ptr_size;
1 by brian
clean slate
767
    return copy->length;
768
  }
769
  else
770
  {
771
    copy->strip=0;
772
    store_length= 0;
773
  }
774
  return copy->length+ store_length;
775
}
776
438.1.13 by Brian Aker
uint cleanup.
777
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1 by brian
clean slate
778
{
779
  char buff[40];
780
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
781
  if (!(res=val_str(&tmp)) ||
782
      str_to_datetime_with_warn(res->ptr(), res->length(),
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
783
                                ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
1 by brian
clean slate
784
    return 1;
785
  return 0;
786
}
787
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
788
bool Field::get_time(DRIZZLE_TIME *ltime)
1 by brian
clean slate
789
{
790
  char buff[40];
791
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
792
  if (!(res=val_str(&tmp)) ||
793
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
794
    return 1;
795
  return 0;
796
}
797
575.1.2 by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead.
798
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
1 by brian
clean slate
799
{
800
  char buff[MAX_DATE_STRING_REP_LENGTH];
438.1.13 by Brian Aker
uint cleanup.
801
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
1 by brian
clean slate
802
  return store(buff, length, &my_charset_bin);
803
}
804
1235.1.12 by Brian Aker
Clean up index interface before moving to SE.
805
bool Field::optimize_range(uint32_t idx, uint32_t)
1 by brian
clean slate
806
{
1235.1.14 by Brian Aker
Final move of index flags up to Engine (new interface still needed).
807
  return test(table->index_flags(idx) & HA_READ_RANGE);
1 by brian
clean slate
808
}
809
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
810
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
1 by brian
clean slate
811
{
812
  Field *tmp;
1487 by Brian Aker
More updates for memory::Root
813
  if (!(tmp= (Field*) root->memdup_root((char*) this,size_of())))
1 by brian
clean slate
814
    return 0;
815
816
  if (tmp->table->maybe_null)
817
    tmp->flags&= ~NOT_NULL_FLAG;
818
  tmp->table= new_table;
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
819
  tmp->key_start.reset();
820
  tmp->part_of_key.reset();
821
  tmp->part_of_sortkey.reset();
1 by brian
clean slate
822
  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.
823
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
1 by brian
clean slate
824
  tmp->reset_fields();
825
  return tmp;
826
}
827
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
828
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.
829
                            unsigned char *new_ptr,
830
                            unsigned char *new_null_ptr,
438.1.13 by Brian Aker
uint cleanup.
831
                            uint32_t new_null_bit)
1 by brian
clean slate
832
{
833
  Field *tmp;
834
  if ((tmp= new_field(root, new_table, table == new_table)))
835
  {
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
836
    tmp->ptr= new_ptr;
1 by brian
clean slate
837
    tmp->null_ptr= new_null_ptr;
838
    tmp->null_bit= new_null_bit;
839
  }
840
  return tmp;
841
}
842
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
843
Field *Field::clone(memory::Root *root, Table *new_table)
1 by brian
clean slate
844
{
845
  Field *tmp;
1487 by Brian Aker
More updates for memory::Root
846
  if ((tmp= (Field*) root->memdup_root((char*) this,size_of())))
1 by brian
clean slate
847
  {
848
    tmp->init(new_table);
1672.3.6 by Brian Aker
First pass in encapsulating row
849
    tmp->move_field_offset((ptrdiff_t) (new_table->getInsertRecord() -
1574 by Brian Aker
Rollup patch for hiding tableshare.
850
                                           new_table->getDefaultValues()));
1 by brian
clean slate
851
  }
852
  return tmp;
853
}
854
855
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
856
uint32_t Field::is_equal(CreateField *new_field_ptr)
1 by brian
clean slate
857
{
779.3.10 by Monty Taylor
Turned on -Wshadow.
858
  return (new_field_ptr->sql_type == real_type());
1 by brian
clean slate
859
}
860
861
bool Field::eq_def(Field *field)
862
{
863
  if (real_type() != field->real_type() || charset() != field->charset() ||
864
      pack_length() != field->pack_length())
865
    return 0;
866
  return 1;
867
}
868
869
bool Field_enum::eq_def(Field *field)
870
{
871
  if (!Field::eq_def(field))
872
    return 0;
873
  TYPELIB *from_lib=((Field_enum*) field)->typelib;
874
875
  if (typelib->count < from_lib->count)
876
    return 0;
438.1.13 by Brian Aker
uint cleanup.
877
  for (uint32_t i=0 ; i < from_lib->count ; i++)
1 by brian
clean slate
878
    if (my_strnncoll(field_charset,
481 by Brian Aker
Remove all of uchar.
879
                     (const unsigned char*)typelib->type_names[i],
1 by brian
clean slate
880
                     strlen(typelib->type_names[i]),
481 by Brian Aker
Remove all of uchar.
881
                     (const unsigned char*)from_lib->type_names[i],
1 by brian
clean slate
882
                     strlen(from_lib->type_names[i])))
883
      return 0;
884
  return 1;
885
}
886
205 by Brian Aker
uint32 -> uin32_t
887
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
1 by brian
clean slate
888
{
889
  switch (type) {
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
890
  case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
1782.4.2 by Brian Aker
Convert date from 3 byte to 4 byte.
891
  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
892
  case DRIZZLE_TYPE_ENUM:
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
893
  case DRIZZLE_TYPE_LONG: return 4;
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
894
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
895
  case DRIZZLE_TYPE_DATETIME:
1782.4.1 by Brian Aker
Fix for 64bit issue around timestamp
896
  case DRIZZLE_TYPE_TIMESTAMP:
520.1.28 by Monty Taylor
Reverted too-big formatting change.
897
  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.
898
  case DRIZZLE_TYPE_NULL: return 0;
899
  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
900
  case DRIZZLE_TYPE_DECIMAL:
907.3.5 by Monty Taylor
Fixed new 64-bit caused solaris warnings.
901
    abort();
779.3.53 by Monty Taylor
Revert the fail.
902
  default:
903
    return 0;
1 by brian
clean slate
904
  }
905
}
906
438.1.13 by Brian Aker
uint cleanup.
907
uint32_t pack_length_to_packflag(uint32_t type)
1 by brian
clean slate
908
{
909
  switch (type) {
520.1.28 by Monty Taylor
Reverted too-big formatting change.
910
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
911
    case 2: assert(1);
912
    case 3: assert(1);
913
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
914
    case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
1 by brian
clean slate
915
  }
520.1.28 by Monty Taylor
Reverted too-big formatting change.
916
  return 0;					// This shouldn't happen
1 by brian
clean slate
917
}
918
919
/*****************************************************************************
920
 Warning handling
921
*****************************************************************************/
922
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
923
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
924
                        uint32_t code,
925
                        int cuted_increment)
1 by brian
clean slate
926
{
927
  /*
928
    If this field was created only for type conversion purposes it
929
    will have table == NULL.
930
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
931
  Session *session= table ? table->in_use : current_session;
932
  if (session->count_cuted_fields)
1 by brian
clean slate
933
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
934
    session->cuted_fields+= cuted_increment;
935
    push_warning_printf(session, level, code, ER(code), field_name,
936
                        session->row_count);
1 by brian
clean slate
937
    return 0;
938
  }
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
939
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
1 by brian
clean slate
940
}
941
942
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
943
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
944
                                 unsigned int code,
945
                                 const char *str, 
946
                                 uint32_t str_length,
947
                                 enum enum_drizzle_timestamp_type ts_type, 
948
                                 int cuted_increment)
1 by brian
clean slate
949
{
520.1.22 by Brian Aker
Second pass of thd cleanup
950
  Session *session= table ? table->in_use : current_session;
951
  if ((session->really_abort_on_warning() &&
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
952
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
1 by brian
clean slate
953
      set_warning(level, code, cuted_increment))
520.1.22 by Brian Aker
Second pass of thd cleanup
954
    make_truncated_value_warning(session, level, str, str_length, ts_type,
1 by brian
clean slate
955
                                 field_name);
956
}
957
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
958
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
959
                                 uint32_t code,
960
                                 int64_t nr, 
961
                                 enum enum_drizzle_timestamp_type ts_type,
962
                                 int cuted_increment)
1 by brian
clean slate
963
{
520.1.22 by Brian Aker
Second pass of thd cleanup
964
  Session *session= table ? table->in_use : current_session;
965
  if (session->really_abort_on_warning() ||
1 by brian
clean slate
966
      set_warning(level, code, cuted_increment))
967
  {
968
    char str_nr[22];
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
969
    char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
970
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
1 by brian
clean slate
971
                                 ts_type, field_name);
972
  }
973
}
974
1055.2.6 by Jay Pipes
Style cleanup in field.cc and move documentation into Field class in header file.
975
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
976
                                 const uint32_t code,
977
                                 double nr, 
978
                                 enum enum_drizzle_timestamp_type ts_type)
1 by brian
clean slate
979
{
520.1.22 by Brian Aker
Second pass of thd cleanup
980
  Session *session= table ? table->in_use : current_session;
981
  if (session->really_abort_on_warning() ||
1 by brian
clean slate
982
      set_warning(level, code, 1))
983
  {
984
    /* DBL_DIG is enough to print '-[digits].E+###' */
985
    char str_nr[DBL_DIG + 8];
1366.1.11 by Siddharth Prakash Singh
sprintf->snprintf continued
986
    uint32_t str_len= snprintf(str_nr, sizeof(str_nr), "%g", nr);
520.1.22 by Brian Aker
Second pass of thd cleanup
987
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
1 by brian
clean slate
988
                                 field_name);
989
  }
990
}
575.4.7 by Monty Taylor
More header cleanup.
991
1003.1.9 by Brian Aker
Patches for Jay (aka name changes)
992
bool Field::isReadSet() 
1003.1.6 by Brian Aker
Added interface for field to get read/write on its own.
993
{ 
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
994
  return table->isReadSet(field_index); 
1003.1.6 by Brian Aker
Added interface for field to get read/write on its own.
995
}
996
1003.1.9 by Brian Aker
Patches for Jay (aka name changes)
997
bool Field::isWriteSet()
1003.1.6 by Brian Aker
Added interface for field to get read/write on its own.
998
{ 
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
999
  return table->isWriteSet(field_index); 
1003.1.6 by Brian Aker
Added interface for field to get read/write on its own.
1000
}
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
1001
1002
void Field::setReadSet(bool arg)
1003
{
1004
  if (arg)
1005
    table->setReadSet(field_index);
1006
  else
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
1007
    table->clearReadSet(field_index);
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
1008
}
1009
1010
void Field::setWriteSet(bool arg)
1011
{
1012
  if (arg)
1013
    table->setWriteSet(field_index);
1014
  else
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
1015
    table->clearWriteSet(field_index);
1089.1.3 by Brian Aker
Fix protobuf to release memory. Add in assert() for wrong column usage. Fix
1016
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1017
1018
} /* namespace drizzled */