~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2009-05-11 17:50:22 UTC
  • Revision ID: brian@gaz-20090511175022-y35q9ky6uh9ldcjt
Replacing Sun employee copyright headers (aka... anything done by a Sun
employee is copyright by Sun).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
 
 
 
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
 */
16
20
 
17
21
/**
18
22
  @file
23
27
#include <drizzled/server_includes.h>
24
28
#include "sql_select.h"
25
29
#include <errno.h>
26
 
#include <drizzled/drizzled_error_messages.h>
 
30
#include <drizzled/error.h>
 
31
#include <drizzled/field/str.h>
 
32
#include <drizzled/field/longstr.h>
 
33
#include <drizzled/field/num.h>
 
34
#include <drizzled/field/blob.h>
 
35
#include <drizzled/field/enum.h>
 
36
#include <drizzled/field/null.h>
 
37
#include <drizzled/field/date.h>
 
38
#include <drizzled/field/decimal.h>
 
39
#include <drizzled/field/real.h>
 
40
#include <drizzled/field/double.h>
 
41
#include <drizzled/field/long.h>
 
42
#include <drizzled/field/int64_t.h>
 
43
#include <drizzled/field/num.h>
 
44
#include <drizzled/field/timestamp.h>
 
45
#include <drizzled/field/datetime.h>
 
46
#include <drizzled/field/varstring.h>
27
47
 
28
 
// Maximum allowed exponent value for converting string to decimal
29
 
#define MAX_EXPONENT 1024
30
48
 
31
49
/*****************************************************************************
32
50
  Instansiate templates and static variables
38
56
#endif
39
57
 
40
58
 
41
 
/*
42
 
  Rules for merging different types of fields in UNION
43
 
 
44
 
  NOTE: to avoid 256*256 table, gap in table types numeration is skiped
45
 
  following #defines describe that gap and how to canculate number of fields
46
 
  and index of field in thia array.
47
 
*/
48
 
#define FIELDTYPE_TEAR_FROM (DRIZZLE_TYPE_VARCHAR + 1)
49
 
#define FIELDTYPE_TEAR_TO   (DRIZZLE_TYPE_NEWDECIMAL - 1)
50
 
#define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO))
51
 
inline int field_type2index (enum_field_types field_type)
52
 
{
53
 
  return (field_type < FIELDTYPE_TEAR_FROM ?
54
 
          field_type :
55
 
          ((int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) - 1);
56
 
}
57
 
 
58
 
 
59
 
static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]=
60
 
{
61
 
  /* DRIZZLE_TYPE_DECIMAL -> */
62
 
  {
63
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
64
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_NEWDECIMAL,
65
 
  //DRIZZLE_TYPE_LONG
66
 
    DRIZZLE_TYPE_NEWDECIMAL,
67
 
  //DRIZZLE_TYPE_DOUBLE
68
 
    DRIZZLE_TYPE_DOUBLE,
69
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
70
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
71
 
  //DRIZZLE_TYPE_LONGLONG
72
 
    DRIZZLE_TYPE_NEWDECIMAL,
73
 
  //DRIZZLE_TYPE_TIME
74
 
    DRIZZLE_TYPE_VARCHAR,
75
 
  //DRIZZLE_TYPE_DATETIME
76
 
    DRIZZLE_TYPE_VARCHAR,
77
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
78
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
79
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
80
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
81
 
  //DRIZZLE_TYPE_BLOB
82
 
    DRIZZLE_TYPE_BLOB,
83
 
  },
 
59
static enum_field_types
 
60
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
 
61
{
84
62
  /* DRIZZLE_TYPE_TINY -> */
85
63
  {
86
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
87
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
88
 
  //DRIZZLE_TYPE_LONG
 
64
    //DRIZZLE_TYPE_TINY
 
65
    DRIZZLE_TYPE_TINY,
 
66
    //DRIZZLE_TYPE_LONG
89
67
    DRIZZLE_TYPE_LONG,
90
 
  //DRIZZLE_TYPE_DOUBLE
 
68
    //DRIZZLE_TYPE_DOUBLE
91
69
    DRIZZLE_TYPE_DOUBLE,
92
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
93
 
    DRIZZLE_TYPE_TINY,        DRIZZLE_TYPE_VARCHAR,
94
 
  //DRIZZLE_TYPE_LONGLONG
 
70
    //DRIZZLE_TYPE_NULL
 
71
    DRIZZLE_TYPE_TINY,
 
72
    //DRIZZLE_TYPE_TIMESTAMP
 
73
    DRIZZLE_TYPE_VARCHAR,
 
74
    //DRIZZLE_TYPE_LONGLONG
95
75
    DRIZZLE_TYPE_LONGLONG,
96
 
  //DRIZZLE_TYPE_TIME
97
 
    DRIZZLE_TYPE_VARCHAR,
98
 
  //DRIZZLE_TYPE_DATETIME
99
 
    DRIZZLE_TYPE_VARCHAR,
100
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
101
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
102
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
103
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
104
 
  //DRIZZLE_TYPE_BLOB
 
76
    //DRIZZLE_TYPE_DATETIME
 
77
    DRIZZLE_TYPE_VARCHAR,
 
78
    //DRIZZLE_TYPE_DATE
 
79
    DRIZZLE_TYPE_VARCHAR,
 
80
    //DRIZZLE_TYPE_VARCHAR
 
81
    DRIZZLE_TYPE_VARCHAR,
 
82
    //DRIZZLE_TYPE_NEWDECIMAL
 
83
    DRIZZLE_TYPE_NEWDECIMAL,
 
84
    //DRIZZLE_TYPE_ENUM
 
85
    DRIZZLE_TYPE_VARCHAR,
 
86
    //DRIZZLE_TYPE_BLOB
105
87
    DRIZZLE_TYPE_BLOB,
106
88
  },
107
89
  /* DRIZZLE_TYPE_LONG -> */
108
90
  {
109
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
110
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONG,
111
 
  //DRIZZLE_TYPE_LONG
112
 
    DRIZZLE_TYPE_LONG,
113
 
  //DRIZZLE_TYPE_DOUBLE
 
91
    //DRIZZLE_TYPE_TINY
 
92
    DRIZZLE_TYPE_LONG,
 
93
    //DRIZZLE_TYPE_LONG
 
94
    DRIZZLE_TYPE_LONG,
 
95
    //DRIZZLE_TYPE_DOUBLE
114
96
    DRIZZLE_TYPE_DOUBLE,
115
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
116
 
    DRIZZLE_TYPE_LONG,         DRIZZLE_TYPE_VARCHAR,
117
 
  //DRIZZLE_TYPE_LONGLONG
 
97
    //DRIZZLE_TYPE_NULL
 
98
    DRIZZLE_TYPE_LONG,
 
99
    //DRIZZLE_TYPE_TIMESTAMP
 
100
    DRIZZLE_TYPE_VARCHAR,
 
101
    //DRIZZLE_TYPE_LONGLONG
118
102
    DRIZZLE_TYPE_LONGLONG,
119
 
  //DRIZZLE_TYPE_TIME
120
 
    DRIZZLE_TYPE_VARCHAR,
121
 
  //DRIZZLE_TYPE_DATETIME
122
 
    DRIZZLE_TYPE_VARCHAR,
123
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
124
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
125
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
126
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
127
 
  //DRIZZLE_TYPE_BLOB
 
103
    //DRIZZLE_TYPE_DATETIME
 
104
    DRIZZLE_TYPE_VARCHAR,
 
105
    //DRIZZLE_TYPE_DATE
 
106
    DRIZZLE_TYPE_VARCHAR,
 
107
    //DRIZZLE_TYPE_VARCHAR
 
108
    DRIZZLE_TYPE_VARCHAR,
 
109
    //DRIZZLE_TYPE_NEWDECIMAL
 
110
    DRIZZLE_TYPE_NEWDECIMAL,
 
111
    //DRIZZLE_TYPE_ENUM
 
112
    DRIZZLE_TYPE_VARCHAR,
 
113
    //DRIZZLE_TYPE_BLOB
128
114
    DRIZZLE_TYPE_BLOB,
129
115
  },
130
116
  /* DRIZZLE_TYPE_DOUBLE -> */
131
117
  {
132
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
133
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_DOUBLE,
134
 
  //DRIZZLE_TYPE_LONG
135
 
    DRIZZLE_TYPE_DOUBLE,
136
 
  //DRIZZLE_TYPE_DOUBLE
137
 
    DRIZZLE_TYPE_DOUBLE,
138
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
139
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
140
 
  //DRIZZLE_TYPE_LONGLONG
141
 
    DRIZZLE_TYPE_DOUBLE,
142
 
  //DRIZZLE_TYPE_TIME
143
 
    DRIZZLE_TYPE_VARCHAR,
144
 
  //DRIZZLE_TYPE_DATETIME
145
 
    DRIZZLE_TYPE_VARCHAR,
146
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
147
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
148
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
149
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
150
 
  //DRIZZLE_TYPE_BLOB
 
118
    //DRIZZLE_TYPE_TINY
 
119
    DRIZZLE_TYPE_DOUBLE,
 
120
    //DRIZZLE_TYPE_LONG
 
121
    DRIZZLE_TYPE_DOUBLE,
 
122
    //DRIZZLE_TYPE_DOUBLE
 
123
    DRIZZLE_TYPE_DOUBLE,
 
124
    //DRIZZLE_TYPE_NULL
 
125
    DRIZZLE_TYPE_DOUBLE,
 
126
    //DRIZZLE_TYPE_TIMESTAMP
 
127
    DRIZZLE_TYPE_VARCHAR,
 
128
    //DRIZZLE_TYPE_LONGLONG
 
129
    DRIZZLE_TYPE_DOUBLE,
 
130
    //DRIZZLE_TYPE_DATETIME
 
131
    DRIZZLE_TYPE_VARCHAR,
 
132
    //DRIZZLE_TYPE_DATE
 
133
    DRIZZLE_TYPE_VARCHAR,
 
134
    //DRIZZLE_TYPE_VARCHAR
 
135
    DRIZZLE_TYPE_VARCHAR,
 
136
    //DRIZZLE_TYPE_NEWDECIMAL
 
137
    DRIZZLE_TYPE_DOUBLE,
 
138
    //DRIZZLE_TYPE_ENUM
 
139
    DRIZZLE_TYPE_VARCHAR,
 
140
    //DRIZZLE_TYPE_BLOB
151
141
    DRIZZLE_TYPE_BLOB,
152
142
  },
153
143
  /* DRIZZLE_TYPE_NULL -> */
154
144
  {
155
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
156
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
157
 
  //DRIZZLE_TYPE_LONG
 
145
    //DRIZZLE_TYPE_TINY
 
146
    DRIZZLE_TYPE_TINY,
 
147
    //DRIZZLE_TYPE_LONG
158
148
    DRIZZLE_TYPE_LONG,
159
 
  //DRIZZLE_TYPE_DOUBLE
 
149
    //DRIZZLE_TYPE_DOUBLE
160
150
    DRIZZLE_TYPE_DOUBLE,
161
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
162
 
    DRIZZLE_TYPE_NULL,        DRIZZLE_TYPE_TIMESTAMP,
163
 
  //DRIZZLE_TYPE_LONGLONG
 
151
    //DRIZZLE_TYPE_NULL
 
152
    DRIZZLE_TYPE_NULL,
 
153
    //DRIZZLE_TYPE_TIMESTAMP
 
154
    DRIZZLE_TYPE_TIMESTAMP,
 
155
    //DRIZZLE_TYPE_LONGLONG
164
156
    DRIZZLE_TYPE_LONGLONG,
165
 
  //DRIZZLE_TYPE_TIME
166
 
    DRIZZLE_TYPE_TIME,
167
 
  //DRIZZLE_TYPE_DATETIME
 
157
    //DRIZZLE_TYPE_DATETIME
168
158
    DRIZZLE_TYPE_DATETIME,
169
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
170
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
171
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
172
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_ENUM,
173
 
  //DRIZZLE_TYPE_BLOB
 
159
    //DRIZZLE_TYPE_DATE
 
160
    DRIZZLE_TYPE_DATE,
 
161
    //DRIZZLE_TYPE_VARCHAR
 
162
    DRIZZLE_TYPE_VARCHAR,
 
163
    //DRIZZLE_TYPE_NEWDECIMAL
 
164
    DRIZZLE_TYPE_NEWDECIMAL,
 
165
    //DRIZZLE_TYPE_ENUM
 
166
    DRIZZLE_TYPE_ENUM,
 
167
    //DRIZZLE_TYPE_BLOB
174
168
    DRIZZLE_TYPE_BLOB,
175
169
  },
176
170
  /* DRIZZLE_TYPE_TIMESTAMP -> */
177
171
  {
178
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
179
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
180
 
  //DRIZZLE_TYPE_LONG
181
 
    DRIZZLE_TYPE_VARCHAR,
182
 
  //DRIZZLE_TYPE_DOUBLE
183
 
    DRIZZLE_TYPE_VARCHAR,
184
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
185
 
    DRIZZLE_TYPE_TIMESTAMP,   DRIZZLE_TYPE_TIMESTAMP,
186
 
  //DRIZZLE_TYPE_LONGLONG
187
 
    DRIZZLE_TYPE_VARCHAR,
188
 
  //DRIZZLE_TYPE_TIME
189
 
    DRIZZLE_TYPE_DATETIME,
190
 
  //DRIZZLE_TYPE_DATETIME
191
 
    DRIZZLE_TYPE_DATETIME,
192
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
193
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
194
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
195
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
196
 
  //DRIZZLE_TYPE_BLOB
 
172
    //DRIZZLE_TYPE_TINY
 
173
    DRIZZLE_TYPE_VARCHAR,
 
174
    //DRIZZLE_TYPE_LONG
 
175
    DRIZZLE_TYPE_VARCHAR,
 
176
    //DRIZZLE_TYPE_DOUBLE
 
177
    DRIZZLE_TYPE_VARCHAR,
 
178
    //DRIZZLE_TYPE_NULL
 
179
    DRIZZLE_TYPE_TIMESTAMP,
 
180
    //DRIZZLE_TYPE_TIMESTAMP
 
181
    DRIZZLE_TYPE_TIMESTAMP,
 
182
    //DRIZZLE_TYPE_LONGLONG
 
183
    DRIZZLE_TYPE_VARCHAR,
 
184
    //DRIZZLE_TYPE_DATETIME
 
185
    DRIZZLE_TYPE_DATETIME,
 
186
    //DRIZZLE_TYPE_DATE
 
187
    DRIZZLE_TYPE_DATE,
 
188
    //DRIZZLE_TYPE_VARCHAR
 
189
    DRIZZLE_TYPE_VARCHAR,
 
190
    //DRIZZLE_TYPE_NEWDECIMAL
 
191
    DRIZZLE_TYPE_VARCHAR,
 
192
    //DRIZZLE_TYPE_ENUM
 
193
    DRIZZLE_TYPE_VARCHAR,
 
194
    //DRIZZLE_TYPE_BLOB
197
195
    DRIZZLE_TYPE_BLOB,
198
196
  },
199
197
  /* DRIZZLE_TYPE_LONGLONG -> */
200
198
  {
201
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
202
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONGLONG,
203
 
  //DRIZZLE_TYPE_LONG
204
 
    DRIZZLE_TYPE_LONGLONG,
205
 
  //DRIZZLE_TYPE_DOUBLE
 
199
    //DRIZZLE_TYPE_TINY
 
200
    DRIZZLE_TYPE_LONGLONG,
 
201
    //DRIZZLE_TYPE_LONG
 
202
    DRIZZLE_TYPE_LONGLONG,
 
203
    //DRIZZLE_TYPE_DOUBLE
206
204
    DRIZZLE_TYPE_DOUBLE,
207
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
208
 
    DRIZZLE_TYPE_LONGLONG,    DRIZZLE_TYPE_VARCHAR,
209
 
  //DRIZZLE_TYPE_LONGLONG
210
 
    DRIZZLE_TYPE_LONGLONG,
211
 
  //DRIZZLE_TYPE_TIME
212
 
    DRIZZLE_TYPE_VARCHAR,
213
 
  //DRIZZLE_TYPE_DATETIME
214
 
    DRIZZLE_TYPE_VARCHAR,
215
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
216
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
217
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
218
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
219
 
  //DRIZZLE_TYPE_BLOB
220
 
    DRIZZLE_TYPE_BLOB,
221
 
  },
222
 
  /* DRIZZLE_TYPE_TIME -> */
223
 
  {
224
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
225
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
226
 
  //DRIZZLE_TYPE_LONG
227
 
    DRIZZLE_TYPE_VARCHAR,
228
 
  //DRIZZLE_TYPE_DOUBLE
229
 
    DRIZZLE_TYPE_VARCHAR,
230
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
231
 
    DRIZZLE_TYPE_TIME,        DRIZZLE_TYPE_DATETIME,
232
 
  //DRIZZLE_TYPE_LONGLONG
233
 
    DRIZZLE_TYPE_VARCHAR,
234
 
  //DRIZZLE_TYPE_TIME
235
 
    DRIZZLE_TYPE_TIME,
236
 
  //DRIZZLE_TYPE_DATETIME
237
 
    DRIZZLE_TYPE_DATETIME,
238
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
239
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
240
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
241
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
242
 
  //DRIZZLE_TYPE_BLOB
 
205
    //DRIZZLE_TYPE_NULL
 
206
    DRIZZLE_TYPE_LONGLONG,
 
207
    //DRIZZLE_TYPE_TIMESTAMP
 
208
    DRIZZLE_TYPE_VARCHAR,
 
209
    //DRIZZLE_TYPE_LONGLONG
 
210
    DRIZZLE_TYPE_LONGLONG,
 
211
    //DRIZZLE_TYPE_DATETIME
 
212
    DRIZZLE_TYPE_VARCHAR,
 
213
    //DRIZZLE_TYPE_DATE
 
214
    DRIZZLE_TYPE_DATE,
 
215
    //DRIZZLE_TYPE_VARCHAR
 
216
    DRIZZLE_TYPE_VARCHAR,
 
217
    //DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
 
218
    DRIZZLE_TYPE_NEWDECIMAL,
 
219
    DRIZZLE_TYPE_VARCHAR,
 
220
    //DRIZZLE_TYPE_BLOB
243
221
    DRIZZLE_TYPE_BLOB,
244
222
  },
245
223
  /* DRIZZLE_TYPE_DATETIME -> */
246
224
  {
247
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
248
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
249
 
  //DRIZZLE_TYPE_LONG
250
 
    DRIZZLE_TYPE_VARCHAR,
251
 
  //DRIZZLE_TYPE_DOUBLE
252
 
    DRIZZLE_TYPE_VARCHAR,
253
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
254
 
    DRIZZLE_TYPE_DATETIME,    DRIZZLE_TYPE_DATETIME,
255
 
  //DRIZZLE_TYPE_LONGLONG
256
 
    DRIZZLE_TYPE_VARCHAR,
257
 
  //DRIZZLE_TYPE_TIME
258
 
    DRIZZLE_TYPE_DATETIME,
259
 
  //DRIZZLE_TYPE_DATETIME
260
 
    DRIZZLE_TYPE_DATETIME,
261
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
262
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
263
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
264
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
265
 
  //DRIZZLE_TYPE_BLOB
 
225
    //DRIZZLE_TYPE_TINY
 
226
    DRIZZLE_TYPE_VARCHAR,
 
227
    //DRIZZLE_TYPE_LONG
 
228
    DRIZZLE_TYPE_VARCHAR,
 
229
    //DRIZZLE_TYPE_DOUBLE
 
230
    DRIZZLE_TYPE_VARCHAR,
 
231
    //DRIZZLE_TYPE_NULL
 
232
    DRIZZLE_TYPE_DATETIME,
 
233
    //DRIZZLE_TYPE_TIMESTAMP
 
234
    DRIZZLE_TYPE_DATETIME,
 
235
    //DRIZZLE_TYPE_LONGLONG
 
236
    DRIZZLE_TYPE_VARCHAR,
 
237
    //DRIZZLE_TYPE_DATETIME
 
238
    DRIZZLE_TYPE_DATETIME,
 
239
    //DRIZZLE_TYPE_DATE
 
240
    DRIZZLE_TYPE_DATE,
 
241
    //DRIZZLE_TYPE_VARCHAR
 
242
    DRIZZLE_TYPE_VARCHAR,
 
243
    //DRIZZLE_TYPE_NEWDECIMAL
 
244
    DRIZZLE_TYPE_VARCHAR,
 
245
    //DRIZZLE_TYPE_ENUM
 
246
    DRIZZLE_TYPE_VARCHAR,
 
247
    //DRIZZLE_TYPE_BLOB
266
248
    DRIZZLE_TYPE_BLOB,
267
249
  },
268
 
  /* DRIZZLE_TYPE_NEWDATE -> */
 
250
  /* DRIZZLE_TYPE_DATE -> */
269
251
  {
270
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
271
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
272
 
  //DRIZZLE_TYPE_LONG
273
 
    DRIZZLE_TYPE_VARCHAR,
274
 
  //DRIZZLE_TYPE_DOUBLE
275
 
    DRIZZLE_TYPE_VARCHAR,
276
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
277
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_DATETIME,
278
 
  //DRIZZLE_TYPE_LONGLONG
279
 
    DRIZZLE_TYPE_VARCHAR,
280
 
  //DRIZZLE_TYPE_TIME
281
 
    DRIZZLE_TYPE_DATETIME,
282
 
  //DRIZZLE_TYPE_DATETIME
283
 
    DRIZZLE_TYPE_DATETIME,
284
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
285
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
286
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
287
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
288
 
  //DRIZZLE_TYPE_BLOB
 
252
    //DRIZZLE_TYPE_TINY
 
253
    DRIZZLE_TYPE_VARCHAR,
 
254
    //DRIZZLE_TYPE_LONG
 
255
    DRIZZLE_TYPE_VARCHAR,
 
256
    //DRIZZLE_TYPE_DOUBLE
 
257
    DRIZZLE_TYPE_VARCHAR,
 
258
    //DRIZZLE_TYPE_NULL
 
259
    DRIZZLE_TYPE_DATE,
 
260
    //DRIZZLE_TYPE_TIMESTAMP
 
261
    DRIZZLE_TYPE_DATETIME,
 
262
    //DRIZZLE_TYPE_LONGLONG
 
263
    DRIZZLE_TYPE_VARCHAR,
 
264
    //DRIZZLE_TYPE_DATETIME
 
265
    DRIZZLE_TYPE_DATETIME,
 
266
    //DRIZZLE_TYPE_DATE
 
267
    DRIZZLE_TYPE_DATE,
 
268
    //DRIZZLE_TYPE_VARCHAR
 
269
    DRIZZLE_TYPE_VARCHAR,
 
270
    //DRIZZLE_TYPE_NEWDECIMAL
 
271
    DRIZZLE_TYPE_VARCHAR,
 
272
    //DRIZZLE_TYPE_ENUM
 
273
    DRIZZLE_TYPE_VARCHAR,
 
274
    //DRIZZLE_TYPE_BLOB
289
275
    DRIZZLE_TYPE_BLOB,
290
276
  },
291
277
  /* DRIZZLE_TYPE_VARCHAR -> */
292
278
  {
293
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
294
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
295
 
  //DRIZZLE_TYPE_LONG
296
 
    DRIZZLE_TYPE_VARCHAR,
297
 
  //DRIZZLE_TYPE_DOUBLE
298
 
    DRIZZLE_TYPE_VARCHAR,
299
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
300
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
301
 
  //DRIZZLE_TYPE_LONGLONG
302
 
    DRIZZLE_TYPE_VARCHAR,
303
 
  //DRIZZLE_TYPE_TIME
304
 
    DRIZZLE_TYPE_VARCHAR,
305
 
  //DRIZZLE_TYPE_DATETIME
306
 
    DRIZZLE_TYPE_VARCHAR,
307
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
308
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
309
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
310
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
311
 
  //DRIZZLE_TYPE_BLOB
 
279
    //DRIZZLE_TYPE_TINY
 
280
    DRIZZLE_TYPE_VARCHAR,
 
281
    //DRIZZLE_TYPE_LONG
 
282
    DRIZZLE_TYPE_VARCHAR,
 
283
    //DRIZZLE_TYPE_DOUBLE
 
284
    DRIZZLE_TYPE_VARCHAR,
 
285
    //DRIZZLE_TYPE_NULL
 
286
    DRIZZLE_TYPE_VARCHAR,
 
287
    //DRIZZLE_TYPE_TIMESTAMP
 
288
    DRIZZLE_TYPE_VARCHAR,
 
289
    //DRIZZLE_TYPE_LONGLONG
 
290
    DRIZZLE_TYPE_VARCHAR,
 
291
    //DRIZZLE_TYPE_DATETIME
 
292
    DRIZZLE_TYPE_VARCHAR,
 
293
    //DRIZZLE_TYPE_DATE
 
294
    DRIZZLE_TYPE_VARCHAR,
 
295
    //DRIZZLE_TYPE_VARCHAR
 
296
    DRIZZLE_TYPE_VARCHAR,
 
297
    //DRIZZLE_TYPE_NEWDECIMAL
 
298
    DRIZZLE_TYPE_VARCHAR,
 
299
    //DRIZZLE_TYPE_ENUM
 
300
    DRIZZLE_TYPE_VARCHAR,
 
301
    //DRIZZLE_TYPE_BLOB
312
302
    DRIZZLE_TYPE_BLOB,
313
303
  },
314
304
  /* DRIZZLE_TYPE_NEWDECIMAL -> */
315
305
  {
316
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
317
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_NEWDECIMAL,
318
 
  //DRIZZLE_TYPE_LONG
319
 
    DRIZZLE_TYPE_NEWDECIMAL,
320
 
  //DRIZZLE_TYPE_DOUBLE
 
306
    //DRIZZLE_TYPE_TINY
 
307
    DRIZZLE_TYPE_NEWDECIMAL,
 
308
    //DRIZZLE_TYPE_LONG
 
309
    DRIZZLE_TYPE_NEWDECIMAL,
 
310
    //DRIZZLE_TYPE_DOUBLE
321
311
    DRIZZLE_TYPE_DOUBLE,
322
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
323
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
324
 
  //DRIZZLE_TYPE_LONGLONG
325
 
    DRIZZLE_TYPE_NEWDECIMAL,
326
 
  //DRIZZLE_TYPE_TIME
327
 
    DRIZZLE_TYPE_VARCHAR,
328
 
  //DRIZZLE_TYPE_DATETIME
329
 
    DRIZZLE_TYPE_VARCHAR,
330
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
331
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
332
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
333
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
334
 
  //DRIZZLE_TYPE_BLOB
 
312
    //DRIZZLE_TYPE_NULL
 
313
    DRIZZLE_TYPE_NEWDECIMAL,
 
314
    //DRIZZLE_TYPE_TIMESTAMP
 
315
    DRIZZLE_TYPE_VARCHAR,
 
316
    //DRIZZLE_TYPE_LONGLONG
 
317
    DRIZZLE_TYPE_NEWDECIMAL,
 
318
    //DRIZZLE_TYPE_DATETIME
 
319
    DRIZZLE_TYPE_VARCHAR,
 
320
    //DRIZZLE_TYPE_DATE
 
321
    DRIZZLE_TYPE_VARCHAR,
 
322
    //DRIZZLE_TYPE_VARCHAR
 
323
    DRIZZLE_TYPE_VARCHAR,
 
324
    //DRIZZLE_TYPE_NEWDECIMAL
 
325
    DRIZZLE_TYPE_NEWDECIMAL,
 
326
    //DRIZZLE_TYPE_ENUM
 
327
    DRIZZLE_TYPE_VARCHAR,
 
328
    //DRIZZLE_TYPE_BLOB
335
329
    DRIZZLE_TYPE_BLOB,
336
330
  },
337
331
  /* DRIZZLE_TYPE_ENUM -> */
338
332
  {
339
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
340
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
341
 
  //DRIZZLE_TYPE_LONG
342
 
    DRIZZLE_TYPE_VARCHAR,
343
 
  //DRIZZLE_TYPE_DOUBLE
344
 
    DRIZZLE_TYPE_VARCHAR,
345
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
346
 
    DRIZZLE_TYPE_ENUM,        DRIZZLE_TYPE_VARCHAR,
347
 
  //DRIZZLE_TYPE_LONGLONG
348
 
    DRIZZLE_TYPE_VARCHAR,
349
 
  //DRIZZLE_TYPE_TIME
350
 
    DRIZZLE_TYPE_VARCHAR,
351
 
  //DRIZZLE_TYPE_DATETIME
352
 
    DRIZZLE_TYPE_VARCHAR,
353
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
354
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
355
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
356
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
357
 
  //DRIZZLE_TYPE_BLOB
 
333
    //DRIZZLE_TYPE_TINY
 
334
    DRIZZLE_TYPE_VARCHAR,
 
335
    //DRIZZLE_TYPE_LONG
 
336
    DRIZZLE_TYPE_VARCHAR,
 
337
    //DRIZZLE_TYPE_DOUBLE
 
338
    DRIZZLE_TYPE_VARCHAR,
 
339
    //DRIZZLE_TYPE_NULL
 
340
    DRIZZLE_TYPE_ENUM,
 
341
    //DRIZZLE_TYPE_TIMESTAMP
 
342
    DRIZZLE_TYPE_VARCHAR,
 
343
    //DRIZZLE_TYPE_LONGLONG
 
344
    DRIZZLE_TYPE_VARCHAR,
 
345
    //DRIZZLE_TYPE_DATETIME
 
346
    DRIZZLE_TYPE_VARCHAR,
 
347
    //DRIZZLE_TYPE_DATE
 
348
    DRIZZLE_TYPE_VARCHAR,
 
349
    //DRIZZLE_TYPE_VARCHAR
 
350
    DRIZZLE_TYPE_VARCHAR,
 
351
    //DRIZZLE_TYPE_NEWDECIMAL
 
352
    DRIZZLE_TYPE_VARCHAR,
 
353
    //DRIZZLE_TYPE_ENUM
 
354
    DRIZZLE_TYPE_VARCHAR,
 
355
    //DRIZZLE_TYPE_BLOB
358
356
    DRIZZLE_TYPE_BLOB,
359
357
  },
360
358
  /* DRIZZLE_TYPE_BLOB -> */
361
359
  {
362
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
363
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
364
 
  //DRIZZLE_TYPE_LONG
365
 
    DRIZZLE_TYPE_BLOB,
366
 
  //DRIZZLE_TYPE_DOUBLE
367
 
    DRIZZLE_TYPE_BLOB,
368
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
369
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
370
 
  //DRIZZLE_TYPE_LONGLONG
371
 
    DRIZZLE_TYPE_BLOB,
372
 
  //DRIZZLE_TYPE_TIME
373
 
    DRIZZLE_TYPE_BLOB,
374
 
  //DRIZZLE_TYPE_DATETIME
375
 
    DRIZZLE_TYPE_BLOB,
376
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
377
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
378
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
379
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
380
 
  //DRIZZLE_TYPE_BLOB
 
360
    //DRIZZLE_TYPE_TINY
 
361
    DRIZZLE_TYPE_BLOB,
 
362
    //DRIZZLE_TYPE_LONG
 
363
    DRIZZLE_TYPE_BLOB,
 
364
    //DRIZZLE_TYPE_DOUBLE
 
365
    DRIZZLE_TYPE_BLOB,
 
366
    //DRIZZLE_TYPE_NULL
 
367
    DRIZZLE_TYPE_BLOB,
 
368
    //DRIZZLE_TYPE_TIMESTAMP
 
369
    DRIZZLE_TYPE_BLOB,
 
370
    //DRIZZLE_TYPE_LONGLONG
 
371
    DRIZZLE_TYPE_BLOB,
 
372
    //DRIZZLE_TYPE_DATETIME
 
373
    DRIZZLE_TYPE_BLOB,
 
374
    //DRIZZLE_TYPE_DATE
 
375
    DRIZZLE_TYPE_BLOB,
 
376
    //DRIZZLE_TYPE_VARCHAR
 
377
    DRIZZLE_TYPE_BLOB,
 
378
    //DRIZZLE_TYPE_NEWDECIMAL
 
379
    DRIZZLE_TYPE_BLOB,
 
380
    //DRIZZLE_TYPE_ENUM
 
381
    DRIZZLE_TYPE_BLOB,
 
382
    //DRIZZLE_TYPE_BLOB
381
383
    DRIZZLE_TYPE_BLOB,
382
384
  },
383
385
};
395
397
enum_field_types Field::field_type_merge(enum_field_types a,
396
398
                                         enum_field_types b)
397
399
{
398
 
  assert(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
399
 
  assert(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
400
 
  return field_types_merge_rules[field_type2index(a)]
401
 
                                [field_type2index(b)];
 
400
  assert(a <= DRIZZLE_TYPE_MAX);
 
401
  assert(b <= DRIZZLE_TYPE_MAX);
 
402
  return field_types_merge_rules[a][b];
402
403
}
403
404
 
404
405
 
405
 
static Item_result field_types_result_type [FIELDTYPE_NUM]=
 
406
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
406
407
{
407
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
408
 
  DECIMAL_RESULT,           INT_RESULT,
 
408
  //DRIZZLE_TYPE_TINY
 
409
  INT_RESULT,
409
410
  //DRIZZLE_TYPE_LONG
410
411
  INT_RESULT,
411
412
  //DRIZZLE_TYPE_DOUBLE
412
413
  REAL_RESULT,
413
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
414
 
  STRING_RESULT,            STRING_RESULT,
 
414
  //DRIZZLE_TYPE_NULL
 
415
  STRING_RESULT,
 
416
  //DRIZZLE_TYPE_TIMESTAMP
 
417
  STRING_RESULT,
415
418
  //DRIZZLE_TYPE_LONGLONG
416
419
  INT_RESULT,
417
 
  //DRIZZLE_TYPE_TIME
418
 
  STRING_RESULT,
419
420
  //DRIZZLE_TYPE_DATETIME
420
421
  STRING_RESULT,
421
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
422
 
  STRING_RESULT,            STRING_RESULT,
423
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
424
 
  DECIMAL_RESULT,           STRING_RESULT,
 
422
  //DRIZZLE_TYPE_DATE
 
423
  STRING_RESULT,
 
424
  //DRIZZLE_TYPE_VARCHAR
 
425
  STRING_RESULT,
 
426
  //DRIZZLE_TYPE_NEWDECIMAL   
 
427
  DECIMAL_RESULT,           
 
428
  //DRIZZLE_TYPE_ENUM
 
429
  STRING_RESULT,
425
430
  //DRIZZLE_TYPE_BLOB
426
431
  STRING_RESULT,
427
432
};
443
448
    true  - If string has some important data
444
449
*/
445
450
 
446
 
static bool
 
451
bool
447
452
test_if_important_data(const CHARSET_INFO * const cs, const char *str,
448
453
                       const char *strend)
449
454
{
453
458
}
454
459
 
455
460
 
456
 
/**
457
 
  Detect Item_result by given field type of UNION merge result.
458
 
 
459
 
  @param field_type  given field type
460
 
 
461
 
  @return
462
 
    Item_result (type of internal MySQL expression result)
463
 
*/
464
 
 
465
461
Item_result Field::result_merge_type(enum_field_types field_type)
466
462
{
467
 
  assert(field_type < FIELDTYPE_TEAR_FROM || field_type
468
 
              > FIELDTYPE_TEAR_TO);
469
 
  return field_types_result_type[field_type2index(field_type)];
470
 
}
 
463
  assert(field_type <= DRIZZLE_TYPE_MAX);
 
464
  return field_types_result_type[field_type];
 
465
}
 
466
 
 
467
 
 
468
bool Field::eq(Field *field)
 
469
{
 
470
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
 
471
          null_bit == field->null_bit);
 
472
}
 
473
 
 
474
 
 
475
uint32_t Field::pack_length() const
 
476
{
 
477
  return field_length;
 
478
}
 
479
 
 
480
 
 
481
uint32_t Field::pack_length_in_rec() const
 
482
{
 
483
  return pack_length();
 
484
}
 
485
 
 
486
 
 
487
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
 
488
{
 
489
  return field_metadata;
 
490
}
 
491
 
 
492
 
 
493
uint32_t Field::row_pack_length()
 
494
{
 
495
  return 0;
 
496
}
 
497
 
 
498
 
 
499
int Field::save_field_metadata(unsigned char *first_byte)
 
500
{
 
501
  return do_save_field_metadata(first_byte);
 
502
}
 
503
 
 
504
 
 
505
uint32_t Field::data_length()
 
506
{
 
507
  return pack_length();
 
508
}
 
509
 
 
510
 
 
511
uint32_t Field::used_length()
 
512
{
 
513
  return pack_length();
 
514
}
 
515
 
 
516
 
 
517
uint32_t Field::sort_length() const
 
518
{
 
519
  return pack_length();
 
520
}
 
521
 
 
522
 
 
523
uint32_t Field::max_data_length() const
 
524
{
 
525
  return pack_length();
 
526
}
 
527
 
 
528
 
 
529
int Field::reset(void)
 
530
{
 
531
  memset(ptr, 0, pack_length());
 
532
  return 0;
 
533
}
 
534
 
 
535
 
 
536
void Field::reset_fields()
 
537
{}
 
538
 
 
539
 
 
540
void Field::set_default()
 
541
{
 
542
  my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
 
543
  memcpy(ptr, ptr + l_offset, pack_length());
 
544
  if (null_ptr)
 
545
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
 
546
}
 
547
 
 
548
 
 
549
bool Field::binary() const
 
550
{
 
551
  return 1;
 
552
}
 
553
 
 
554
 
 
555
bool Field::zero_pack() const
 
556
{
 
557
  return 1;
 
558
}
 
559
 
 
560
 
 
561
enum ha_base_keytype Field::key_type() const
 
562
{
 
563
  return HA_KEYTYPE_BINARY;
 
564
}
 
565
 
 
566
 
 
567
uint32_t Field::key_length() const
 
568
{
 
569
  return pack_length();
 
570
}
 
571
 
 
572
 
 
573
enum_field_types Field::real_type() const
 
574
{
 
575
  return type();
 
576
}
 
577
 
 
578
 
 
579
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
 
580
{
 
581
  return cmp(a, b);
 
582
}
 
583
 
 
584
 
 
585
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
 
586
{
 
587
  return memcmp(a,b,pack_length());
 
588
}
 
589
 
 
590
 
 
591
int Field::cmp_offset(uint32_t row_offset)
 
592
{
 
593
  return cmp(ptr,ptr+row_offset);
 
594
}
 
595
 
 
596
 
 
597
int Field::cmp_binary_offset(uint32_t row_offset)
 
598
{
 
599
  return cmp_binary(ptr, ptr+row_offset);
 
600
}
 
601
 
 
602
 
 
603
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
 
604
{
 
605
  return cmp(a, b);
 
606
}
 
607
 
 
608
 
 
609
int Field::key_cmp(const unsigned char *str, uint32_t)
 
610
{
 
611
  return cmp(ptr,str);
 
612
}
 
613
 
 
614
 
 
615
uint32_t Field::decimals() const
 
616
{
 
617
  return 0;
 
618
}
 
619
 
 
620
 
 
621
bool Field::is_null(my_ptrdiff_t row_offset)
 
622
{
 
623
  return null_ptr ?
 
624
    (null_ptr[row_offset] & null_bit ? true : false) :
 
625
    table->null_row;
 
626
}
 
627
 
 
628
 
 
629
bool Field::is_real_null(my_ptrdiff_t row_offset)
 
630
{
 
631
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
 
632
}
 
633
 
 
634
 
 
635
bool Field::is_null_in_record(const unsigned char *record)
 
636
{
 
637
  if (!null_ptr)
 
638
    return false;
 
639
  return test(record[(uint32_t) (null_ptr -table->record[0])] &
 
640
              null_bit);
 
641
}
 
642
 
 
643
 
 
644
bool Field::is_null_in_record_with_offset(my_ptrdiff_t with_offset)
 
645
{
 
646
  if (!null_ptr)
 
647
    return false;
 
648
  return test(null_ptr[with_offset] & null_bit);
 
649
}
 
650
 
 
651
 
 
652
void Field::set_null(my_ptrdiff_t row_offset)
 
653
{
 
654
  if (null_ptr)
 
655
    null_ptr[row_offset]|= null_bit;
 
656
}
 
657
 
 
658
 
 
659
void Field::set_notnull(my_ptrdiff_t row_offset)
 
660
{
 
661
  if (null_ptr)
 
662
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
 
663
}
 
664
 
 
665
 
 
666
bool Field::maybe_null(void)
 
667
{
 
668
  return null_ptr != 0 || table->maybe_null;
 
669
}
 
670
 
 
671
 
 
672
bool Field::real_maybe_null(void)
 
673
{
 
674
  return null_ptr != 0;
 
675
}
 
676
 
 
677
 
 
678
size_t Field::last_null_byte() const
 
679
{
 
680
  size_t bytes= do_last_null_byte();
 
681
  assert(bytes <= table->getNullBytes());
 
682
  return bytes;
 
683
}
 
684
 
471
685
 
472
686
/*****************************************************************************
473
687
  Static help functions
474
688
*****************************************************************************/
475
689
 
476
 
 
477
 
/**
478
 
  Check whether a field type can be partially indexed by a key.
479
 
 
480
 
  This is a static method, rather than a virtual function, because we need
481
 
  to check the type of a non-Field in mysql_alter_table().
482
 
 
483
 
  @param type  field type
484
 
 
485
 
  @retval
486
 
    true  Type can have a prefixed key
487
 
  @retval
488
 
    false Type can not have a prefixed key
489
 
*/
490
 
 
491
690
bool Field::type_can_have_key_part(enum enum_field_types type)
492
691
{
493
692
  switch (type) {
501
700
 
502
701
 
503
702
/**
504
 
  Numeric fields base class constructor.
505
 
*/
506
 
Field_num::Field_num(unsigned char *ptr_arg,uint32_t len_arg, unsigned char *null_ptr_arg,
507
 
                     unsigned char null_bit_arg, utype unireg_check_arg,
508
 
                     const char *field_name_arg,
509
 
                     uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
510
 
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
511
 
         unireg_check_arg, field_name_arg),
512
 
  dec(dec_arg),decimal_precision(zero_arg),unsigned_flag(unsigned_arg)
513
 
{
514
 
  if (unsigned_flag)
515
 
    flags|=UNSIGNED_FLAG;
516
 
}
517
 
 
518
 
 
519
 
/**
520
 
  Test if given number is a int.
521
 
 
522
 
  @todo
523
 
    Make this multi-byte-character safe
524
 
 
525
 
  @param str            String to test
526
 
  @param length        Length of 'str'
527
 
  @param int_end        Pointer to char after last used digit
528
 
  @param cs             Character set
529
 
 
530
 
  @note
531
 
    This is called after one has called strntoull10rnd() function.
532
 
 
533
 
  @retval
534
 
    0   OK
535
 
  @retval
536
 
    1   error: empty string or wrong integer.
537
 
  @retval
538
 
    2   error: garbage at the end of string.
539
 
*/
540
 
 
541
 
int Field_num::check_int(const CHARSET_INFO * const cs, const char *str, int length, 
542
 
                         const char *int_end, int error)
543
 
{
544
 
  /* Test if we get an empty string or wrong integer */
545
 
  if (str == int_end || error == MY_ERRNO_EDOM)
546
 
  {
547
 
    char buff[128];
548
 
    String tmp(buff, (uint32_t) sizeof(buff), system_charset_info);
549
 
    tmp.copy(str, length, system_charset_info);
550
 
    push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
551
 
                        ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, 
552
 
                        ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
553
 
                        "integer", tmp.c_ptr(), field_name,
554
 
                        (uint32_t) table->in_use->row_count);
555
 
    return 1;
556
 
  }
557
 
  /* Test if we have garbage at the end of the given string. */
558
 
  if (test_if_important_data(cs, int_end, str + length))
559
 
  {
560
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
561
 
    return 2;
562
 
  }
563
 
  return 0;
564
 
}
565
 
 
566
 
 
567
 
/*
568
 
  Conver a string to an integer then check bounds.
569
 
  
570
 
  SYNOPSIS
571
 
    Field_num::get_int
572
 
    cs            Character set
573
 
    from          String to convert
574
 
    len           Length of the string
575
 
    rnd           OUT int64_t value
576
 
    unsigned_max  max unsigned value
577
 
    signed_min    min signed value
578
 
    signed_max    max signed value
579
 
 
580
 
  DESCRIPTION
581
 
    The function calls strntoull10rnd() to get an integer value then
582
 
    check bounds and errors returned. In case of any error a warning
583
 
    is raised.
584
 
 
585
 
  RETURN
586
 
    0   ok
587
 
    1   error
588
 
*/
589
 
 
590
 
bool Field_num::get_int(const CHARSET_INFO * const cs, const char *from, uint32_t len,
591
 
                        int64_t *rnd, uint64_t unsigned_max, 
592
 
                        int64_t signed_min, int64_t signed_max)
593
 
{
594
 
  char *end;
595
 
  int error;
596
 
  
597
 
  *rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len,
598
 
                                            unsigned_flag, &end,
599
 
                                            &error);
600
 
  if (unsigned_flag)
601
 
  {
602
 
 
603
 
    if ((((uint64_t) *rnd > unsigned_max) && (*rnd= (int64_t) unsigned_max)) ||
604
 
        error == MY_ERRNO_ERANGE)
605
 
    {
606
 
      goto out_of_range;
607
 
    }
608
 
  }
609
 
  else
610
 
  {
611
 
    if (*rnd < signed_min)
612
 
    {
613
 
      *rnd= signed_min;
614
 
      goto out_of_range;
615
 
    }
616
 
    else if (*rnd > signed_max)
617
 
    {
618
 
      *rnd= signed_max;
619
 
      goto out_of_range;
620
 
    }
621
 
  }
622
 
  if (table->in_use->count_cuted_fields &&
623
 
      check_int(cs, from, len, end, error))
624
 
    return 1;
625
 
  return 0;
626
 
 
627
 
out_of_range:
628
 
  set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
629
 
  return 1;
630
 
}
631
 
 
632
 
/**
633
703
  Process decimal library return codes and issue warnings for overflow and
634
704
  truncation.
635
705
 
636
706
  @param op_result  decimal library return code (E_DEC_* see include/decimal.h)
637
707
 
638
708
  @retval
639
 
    1  there was overflow
 
709
    E_DEC_OVERFLOW   there was overflow
 
710
    E_DEC_TRUNCATED  there was truncation
640
711
  @retval
641
 
    0  no error or some other errors except overflow
 
712
    0  no error or there was some other error except overflow or truncation
642
713
*/
643
714
 
644
715
int Field::warn_if_overflow(int op_result)
646
717
  if (op_result == E_DEC_OVERFLOW)
647
718
  {
648
719
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
649
 
    return 1;
 
720
    return E_DEC_OVERFLOW;
650
721
  }
651
722
  if (op_result == E_DEC_TRUNCATED)
652
723
  {
653
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
654
 
    /* We return 0 here as this is not a critical issue */
 
724
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
 
725
    return E_DEC_TRUNCATED;
655
726
  }
656
727
  return 0;
657
728
}
658
729
 
659
730
 
 
731
void Field::init(Table *table_arg)
 
732
{
 
733
  orig_table= table= table_arg;
 
734
  table_name= &table_arg->alias;
 
735
}
 
736
 
 
737
 
660
738
#ifdef NOT_USED
661
739
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
662
740
{
692
770
    return 1;
693
771
  if (*str == 'E' || *str == 'e')
694
772
  {
695
 
    if (length < 3 || (str[1] != '+' && str[1] != '-') || 
 
773
    if (length < 3 || (str[1] != '+' && str[1] != '-') ||
696
774
        !my_isdigit(cs,str[2]))
697
775
      return 0;
698
776
    length-=3;
737
815
 
738
816
/// This is used as a table name when the table structure is not set up
739
817
Field::Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
740
 
             unsigned char null_bit_arg,
741
 
             utype unireg_check_arg, const char *field_name_arg)
 
818
             unsigned char null_bit_arg,
 
819
             utype unireg_check_arg, const char *field_name_arg)
742
820
  :ptr(ptr_arg), null_ptr(null_ptr_arg),
743
821
   table(0), orig_table(0), table_name(0),
744
822
   field_name(field_name_arg),
745
823
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
746
824
   part_of_sortkey(0), unireg_check(unireg_check_arg),
747
 
   field_length(length_arg), null_bit(null_bit_arg), 
 
825
   field_length(length_arg), null_bit(null_bit_arg),
748
826
   is_created_from_null_item(false)
749
827
{
750
828
  flags=null_ptr ? 0: NOT_NULL_FLAG;
783
861
  memcpy(ptr,ptr+row_offset,pack_length());
784
862
  if (null_ptr)
785
863
  {
786
 
    *null_ptr= (unsigned char) ((null_ptr[0] & (unsigned char) ~(uint32_t) null_bit) | (null_ptr[row_offset] & (unsigned char) null_bit));
 
864
    *null_ptr= (unsigned char) ((null_ptr[0] &
 
865
                                 (unsigned char) ~(uint32_t) null_bit) |
 
866
                                (null_ptr[row_offset] &
 
867
                                 (unsigned char) null_bit));
787
868
  }
788
869
}
789
870
 
790
 
 
791
 
bool Field::send_binary(Protocol *protocol)
792
 
{
793
 
  char buff[MAX_FIELD_WIDTH];
794
 
  String tmp(buff,sizeof(buff),charset());
795
 
  val_str(&tmp);
796
 
  return protocol->store(tmp.ptr(), tmp.length(), tmp.charset());
797
 
}
798
 
 
799
 
 
800
871
/**
801
872
   Check to see if field size is compatible with destination.
802
873
 
803
874
   This method is used in row-based replication to verify that the slave's
804
 
   field size is less than or equal to the master's field size. The 
 
875
   field size is less than or equal to the master's field size. The
805
876
   encoded field metadata (from the master or source) is decoded and compared
806
 
   to the size of this field (the slave or destination). 
 
877
   to the size of this field (the slave or destination).
807
878
 
808
879
   @param   field_metadata   Encoded size in field metadata
809
880
 
818
889
}
819
890
 
820
891
 
821
 
int Field::store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
 
892
int Field::store(const char *to, uint32_t length,
 
893
                 const CHARSET_INFO * const cs,
822
894
                 enum_check_fields check_level)
823
895
{
824
896
  int res;
869
941
*/
870
942
unsigned char *
871
943
Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length,
872
 
            bool low_byte_first __attribute__((unused)))
 
944
            bool)
873
945
{
874
946
  uint32_t length= pack_length();
875
947
  set_if_smaller(length, max_length);
877
949
  return to+length;
878
950
}
879
951
 
 
952
 
 
953
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
 
954
{
 
955
  unsigned char *result= this->pack(to, from, UINT32_MAX,
 
956
                                    table->s->db_low_byte_first);
 
957
  return(result);
 
958
}
 
959
 
 
960
 
880
961
/**
881
962
   Unpack a field from row data.
882
963
 
909
990
*/
910
991
const unsigned char *
911
992
Field::unpack(unsigned char* to, const unsigned char *from, uint32_t param_data,
912
 
              bool low_byte_first __attribute__((unused)))
 
993
              bool)
913
994
{
914
995
  uint32_t length=pack_length();
915
996
  int from_type= 0;
939
1020
}
940
1021
 
941
1022
 
942
 
my_decimal *Field::val_decimal(my_decimal *decimal __attribute__((unused)))
 
1023
const unsigned char *Field::unpack(unsigned char* to,
 
1024
                                   const unsigned char *from)
 
1025
{
 
1026
  const unsigned char *result= unpack(to, from, 0U,
 
1027
                                      table->s->db_low_byte_first);
 
1028
  return(result);
 
1029
}
 
1030
 
 
1031
 
 
1032
uint32_t Field::packed_col_length(const unsigned char *, uint32_t length)
 
1033
{
 
1034
  return length;
 
1035
}
 
1036
 
 
1037
 
 
1038
int Field::pack_cmp(const unsigned char *a, const unsigned char *b,
 
1039
                    uint32_t, bool)
 
1040
{
 
1041
  return cmp(a,b);
 
1042
}
 
1043
 
 
1044
 
 
1045
int Field::pack_cmp(const unsigned char *b, uint32_t, bool)
 
1046
{
 
1047
  return cmp(ptr,b);
 
1048
}
 
1049
 
 
1050
 
 
1051
my_decimal *Field::val_decimal(my_decimal *)
943
1052
{
944
1053
  /* This never have to be called */
945
1054
  assert(0);
947
1056
}
948
1057
 
949
1058
 
950
 
void Field_num::add_unsigned(String &res) const
951
 
{
952
 
  if (unsigned_flag)
953
 
    res.append(STRING_WITH_LEN(" unsigned"));
954
 
}
955
 
 
956
 
 
957
1059
void Field::make_field(Send_field *field)
958
1060
{
959
1061
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
993
1095
  @return
994
1096
    value converted from val
995
1097
*/
996
 
int64_t Field::convert_decimal2int64_t(const my_decimal *val,
997
 
                                         bool unsigned_flag, int *err)
 
1098
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
998
1099
{
999
1100
  int64_t i;
1000
 
  if (unsigned_flag)
1001
 
  {
1002
 
    if (val->sign())
1003
 
    {
1004
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1005
 
      i= 0;
1006
 
      *err= 1;
1007
 
    }
1008
 
    else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
1009
 
                                           ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
1010
 
                                           val, true, &i)))
1011
 
    {
1012
 
      i= ~(int64_t) 0;
1013
 
      *err= 1;
1014
 
    }
1015
 
  }
1016
 
  else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
1017
 
                                         ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
1018
 
                                         val, false, &i)))
 
1101
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
1102
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
 
1103
                                      val, false, &i)))
1019
1104
  {
1020
1105
    i= (val->sign() ? INT64_MIN : INT64_MAX);
1021
1106
    *err= 1;
1023
1108
  return i;
1024
1109
}
1025
1110
 
1026
 
 
1027
 
/**
1028
 
  Storing decimal in integer fields.
1029
 
 
1030
 
  @param val       value for storing
1031
 
 
1032
 
  @note
1033
 
    This method is used by all integer fields, real/decimal redefine it
1034
 
 
1035
 
  @retval
1036
 
    0     OK
1037
 
  @retval
1038
 
    !=0  error
1039
 
*/
1040
 
 
1041
 
int Field_num::store_decimal(const my_decimal *val)
1042
 
{
1043
 
  int err= 0;
1044
 
  int64_t i= convert_decimal2int64_t(val, unsigned_flag, &err);
1045
 
  return test(err | store(i, unsigned_flag));
1046
 
}
1047
 
 
1048
 
 
1049
 
/**
1050
 
  Return decimal value of integer field.
1051
 
 
1052
 
  @param decimal_value     buffer for storing decimal value
1053
 
 
1054
 
  @note
1055
 
    This method is used by all integer fields, real/decimal redefine it.
1056
 
    All int64_t values fit in our decimal buffer which cal store 8*9=72
1057
 
    digits of integer number
1058
 
 
1059
 
  @return
1060
 
    pointer to decimal buffer with value of field
1061
 
*/
1062
 
 
1063
 
my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
1064
 
{
1065
 
  assert(result_type() == INT_RESULT);
1066
 
  int64_t nr= val_int();
1067
 
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
1068
 
  return decimal_value;
1069
 
}
1070
 
 
1071
 
 
1072
 
Field_str::Field_str(unsigned char *ptr_arg,uint32_t len_arg, unsigned char *null_ptr_arg,
1073
 
                     unsigned char null_bit_arg, utype unireg_check_arg,
1074
 
                     const char *field_name_arg, const CHARSET_INFO * const charset_arg)
1075
 
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1076
 
         unireg_check_arg, field_name_arg)
1077
 
{
1078
 
  field_charset= charset_arg;
1079
 
  if (charset_arg->state & MY_CS_BINSORT)
1080
 
    flags|=BINARY_FLAG;
1081
 
  field_derivation= DERIVATION_IMPLICIT;
1082
 
}
1083
 
 
1084
 
 
1085
 
void Field_num::make_field(Send_field *field)
1086
 
{
1087
 
  Field::make_field(field);
1088
 
  field->decimals= dec;
1089
 
}
1090
 
 
1091
 
/**
1092
 
  Decimal representation of Field_str.
1093
 
 
1094
 
  @param d         value for storing
1095
 
 
1096
 
  @note
1097
 
    Field_str is the base class for fields like Field_enum,
1098
 
    Field_date and some similar. Some dates use fraction and also
1099
 
    string value should be converted to floating point value according
1100
 
    our rules, so we use double to store value of decimal in string.
1101
 
 
1102
 
  @todo
1103
 
    use decimal2string?
1104
 
 
1105
 
  @retval
1106
 
    0     OK
1107
 
  @retval
1108
 
    !=0  error
1109
 
*/
1110
 
 
1111
 
int Field_str::store_decimal(const my_decimal *d)
1112
 
{
1113
 
  double val;
1114
 
  /* TODO: use decimal2string? */
1115
 
  int err= warn_if_overflow(my_decimal2double(E_DEC_FATAL_ERROR &
1116
 
                                            ~E_DEC_OVERFLOW, d, &val));
1117
 
  return err | store(val);
1118
 
}
1119
 
 
1120
 
 
1121
 
my_decimal *Field_str::val_decimal(my_decimal *decimal_value)
1122
 
{
1123
 
  int64_t nr= val_int();
1124
 
  int2my_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value);
1125
 
  return decimal_value;
1126
 
}
1127
 
 
1128
 
 
1129
1111
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
1130
1112
{
1131
1113
  uint32_t store_length;
1176
1158
    Needs to be changed if/when we want to support different time formats.
1177
1159
*/
1178
1160
 
1179
 
int Field::store_time(DRIZZLE_TIME *ltime,
1180
 
                      enum enum_drizzle_timestamp_type type_arg __attribute__((unused)))
 
1161
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
1181
1162
{
1182
1163
  char buff[MAX_DATE_STRING_REP_LENGTH];
1183
1164
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
1191
1172
}
1192
1173
 
1193
1174
 
1194
 
Field *Field::new_field(MEM_ROOT *root, Table *new_table,
1195
 
                        bool keep_type __attribute__((unused)))
 
1175
Field *Field::new_field(MEM_ROOT *root, Table *new_table, bool)
1196
1176
{
1197
1177
  Field *tmp;
1198
1178
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1201
1181
  if (tmp->table->maybe_null)
1202
1182
    tmp->flags&= ~NOT_NULL_FLAG;
1203
1183
  tmp->table= new_table;
1204
 
  tmp->key_start.init(0);
1205
 
  tmp->part_of_key.init(0);
1206
 
  tmp->part_of_sortkey.init(0);
 
1184
  tmp->key_start.reset();
 
1185
  tmp->part_of_key.reset();
 
1186
  tmp->part_of_sortkey.reset();
1207
1187
  tmp->unireg_check= Field::NONE;
1208
1188
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
1209
1189
  tmp->reset_fields();
1226
1206
}
1227
1207
 
1228
1208
 
1229
 
/* This is used to generate a field in Table from TABLE_SHARE */
 
1209
/* This is used to generate a field in Table from TableShare */
1230
1210
 
1231
1211
Field *Field::clone(MEM_ROOT *root, Table *new_table)
1232
1212
{
1241
1221
}
1242
1222
 
1243
1223
 
1244
 
/****************************************************************************
1245
 
** tiny int
1246
 
****************************************************************************/
1247
 
 
1248
 
int Field_tiny::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
1249
 
{
1250
 
  int error;
1251
 
  int64_t rnd;
1252
 
  
1253
 
  error= get_int(cs, from, len, &rnd, 255, -128, 127);
1254
 
  ptr[0]= unsigned_flag ? (char) (uint64_t) rnd : (char) rnd;
1255
 
  return error;
1256
 
}
1257
 
 
1258
 
 
1259
 
int Field_tiny::store(double nr)
1260
 
{
1261
 
  int error= 0;
1262
 
  nr=rint(nr);
1263
 
  if (unsigned_flag)
1264
 
  {
1265
 
    if (nr < 0.0)
1266
 
    {
1267
 
      *ptr=0;
1268
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1269
 
      error= 1;
1270
 
    }
1271
 
    else if (nr > 255.0)
1272
 
    {
1273
 
      *ptr=(char) 255;
1274
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1275
 
      error= 1;
1276
 
    }
1277
 
    else
1278
 
      *ptr=(char) nr;
1279
 
  }
1280
 
  else
1281
 
  {
1282
 
    if (nr < -128.0)
1283
 
    {
1284
 
      *ptr= (char) -128;
1285
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1286
 
      error= 1;
1287
 
    }
1288
 
    else if (nr > 127.0)
1289
 
    {
1290
 
      *ptr=127;
1291
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1292
 
      error= 1;
1293
 
    }
1294
 
    else
1295
 
      *ptr=(char) (int) nr;
1296
 
  }
1297
 
  return error;
1298
 
}
1299
 
 
1300
 
 
1301
 
int Field_tiny::store(int64_t nr, bool unsigned_val)
1302
 
{
1303
 
  int error= 0;
1304
 
 
1305
 
  if (unsigned_flag)
1306
 
  {
1307
 
    if (nr < 0 && !unsigned_val)
1308
 
    {
1309
 
      *ptr= 0;
1310
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1311
 
      error= 1;
1312
 
    }
1313
 
    else if ((uint64_t) nr > (uint64_t) 255)
1314
 
    {
1315
 
      *ptr= (char) 255;
1316
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1317
 
      error= 1;
1318
 
    }
1319
 
    else
1320
 
      *ptr=(char) nr;
1321
 
  }
1322
 
  else
1323
 
  {
1324
 
    if (nr < 0 && unsigned_val)
1325
 
      nr= 256;                                    // Generate overflow
1326
 
    if (nr < -128)
1327
 
    {
1328
 
      *ptr= (char) -128;
1329
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1330
 
      error= 1;
1331
 
    }
1332
 
    else if (nr > 127)
1333
 
    {
1334
 
      *ptr=127;
1335
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1336
 
      error= 1;
1337
 
    }
1338
 
    else
1339
 
      *ptr=(char) nr;
1340
 
  }
1341
 
  return error;
1342
 
}
1343
 
 
1344
 
 
1345
 
double Field_tiny::val_real(void)
1346
 
{
1347
 
  int tmp= unsigned_flag ? (int) ptr[0] :
1348
 
    (int) ((signed char*) ptr)[0];
1349
 
  return (double) tmp;
1350
 
}
1351
 
 
1352
 
 
1353
 
int64_t Field_tiny::val_int(void)
1354
 
{
1355
 
  int tmp= unsigned_flag ? (int) ptr[0] :
1356
 
    (int) ((signed char*) ptr)[0];
1357
 
  return (int64_t) tmp;
1358
 
}
1359
 
 
1360
 
 
1361
 
String *Field_tiny::val_str(String *val_buffer,
1362
 
                            String *val_ptr __attribute__((unused)))
1363
 
{
1364
 
  const CHARSET_INFO * const cs= &my_charset_bin;
1365
 
  uint32_t length;
1366
 
  uint32_t mlength=cmax(field_length+1,5*cs->mbmaxlen);
1367
 
  val_buffer->alloc(mlength);
1368
 
  char *to=(char*) val_buffer->ptr();
1369
 
 
1370
 
  if (unsigned_flag)
1371
 
    length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength, 10,
1372
 
                                           (long) *ptr);
1373
 
  else
1374
 
    length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength,-10,
1375
 
                                           (long) *((signed char*) ptr));
1376
 
  
1377
 
  val_buffer->length(length);
1378
 
 
1379
 
  return val_buffer;
1380
 
}
1381
 
 
1382
 
bool Field_tiny::send_binary(Protocol *protocol)
1383
 
{
1384
 
  return protocol->store_tiny((int64_t) (int8_t) ptr[0]);
1385
 
}
1386
 
 
1387
 
int Field_tiny::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
1388
 
{
1389
 
  signed char a,b;
1390
 
  a=(signed char) a_ptr[0]; b= (signed char) b_ptr[0];
1391
 
  if (unsigned_flag)
1392
 
    return ((unsigned char) a < (unsigned char) b) ? -1 : ((unsigned char) a > (unsigned char) b) ? 1 : 0;
1393
 
  return (a < b) ? -1 : (a > b) ? 1 : 0;
1394
 
}
1395
 
 
1396
 
void Field_tiny::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
1397
 
{
1398
 
  if (unsigned_flag)
1399
 
    *to= *ptr;
1400
 
  else
1401
 
    to[0] = (char) (ptr[0] ^ (unsigned char) 128);      /* Revers signbit */
1402
 
}
1403
 
 
1404
 
void Field_tiny::sql_type(String &res) const
1405
 
{
1406
 
  const CHARSET_INFO * const cs=res.charset();
1407
 
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
1408
 
                          "tinyint(%d)",(int) field_length));
1409
 
  add_unsigned(res);
1410
 
}
1411
 
 
1412
 
 
1413
 
/*
1414
 
  Report "not well formed" or "cannot convert" error
1415
 
  after storing a character string info a field.
1416
 
 
1417
 
  SYNOPSIS
1418
 
    check_string_copy_error()
1419
 
    field                    - Field
1420
 
    well_formed_error_pos    - where not well formed data was first met
1421
 
    cannot_convert_error_pos - where a not-convertable character was first met
1422
 
    end                      - end of the string
1423
 
    cs                       - character set of the string
1424
 
 
1425
 
  NOTES
1426
 
    As of version 5.0 both cases return the same error:
1427
 
  
1428
 
      "Invalid string value: 'xxx' for column 't' at row 1"
1429
 
  
1430
 
  Future versions will possibly introduce a new error message:
1431
 
 
1432
 
      "Cannot convert character string: 'xxx' for column 't' at row 1"
1433
 
 
1434
 
  RETURN
1435
 
    false - If errors didn't happen
1436
 
    true  - If an error happened
1437
 
*/
1438
 
 
1439
 
bool
1440
 
check_string_copy_error(Field_str *field,
1441
 
                        const char *well_formed_error_pos,
1442
 
                        const char *cannot_convert_error_pos,
1443
 
                        const char *end,
1444
 
                        const CHARSET_INFO * const cs)
1445
 
{
1446
 
  const char *pos, *end_orig;
1447
 
  char tmp[64], *t;
1448
 
  
1449
 
  if (!(pos= well_formed_error_pos) &&
1450
 
      !(pos= cannot_convert_error_pos))
1451
 
    return false;
1452
 
 
1453
 
  end_orig= end;
1454
 
  set_if_smaller(end, pos + 6);
1455
 
 
1456
 
  for (t= tmp; pos < end; pos++)
1457
 
  {
1458
 
    /*
1459
 
      If the source string is ASCII compatible (mbminlen==1)
1460
 
      and the source character is in ASCII printable range (0x20..0x7F),
1461
 
      then display the character as is.
1462
 
      
1463
 
      Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
1464
 
      or the source character is not in the printable range,
1465
 
      then print the character using HEX notation.
1466
 
    */
1467
 
    if (((unsigned char) *pos) >= 0x20 &&
1468
 
        ((unsigned char) *pos) <= 0x7F &&
1469
 
        cs->mbminlen == 1)
1470
 
    {
1471
 
      *t++= *pos;
1472
 
    }
1473
 
    else
1474
 
    {
1475
 
      *t++= '\\';
1476
 
      *t++= 'x';
1477
 
      *t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
1478
 
      *t++= _dig_vec_upper[((unsigned char) *pos) & 15];
1479
 
    }
1480
 
  }
1481
 
  if (end_orig > end)
1482
 
  {
1483
 
    *t++= '.';
1484
 
    *t++= '.';
1485
 
    *t++= '.';
1486
 
  }
1487
 
  *t= '\0';
1488
 
  push_warning_printf(field->table->in_use, 
1489
 
                      field->table->in_use->abort_on_warning ?
1490
 
                      DRIZZLE_ERROR::WARN_LEVEL_ERROR :
1491
 
                      DRIZZLE_ERROR::WARN_LEVEL_WARN,
1492
 
                      ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, 
1493
 
                      ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1494
 
                      "string", tmp, field->field_name,
1495
 
                      (uint32_t) field->table->in_use->row_count);
1496
 
  return true;
1497
 
}
1498
 
 
1499
 
 
1500
 
/*
1501
 
  Check if we lost any important data and send a truncation error/warning
1502
 
 
1503
 
  SYNOPSIS
1504
 
    Field_longstr::report_if_important_data()
1505
 
    ptr                      - Truncated rest of string
1506
 
    end                      - End of truncated string
1507
 
 
1508
 
  RETURN VALUES
1509
 
    0   - None was truncated (or we don't count cut fields)
1510
 
    2   - Some bytes was truncated
1511
 
 
1512
 
  NOTE
1513
 
    Check if we lost any important data (anything in a binary string,
1514
 
    or any non-space in others). If only trailing spaces was lost,
1515
 
    send a truncation note, otherwise send a truncation error.
1516
 
*/
1517
 
 
1518
 
int
1519
 
Field_longstr::report_if_important_data(const char *ptr, const char *end)
1520
 
{
1521
 
  if ((ptr < end) && table->in_use->count_cuted_fields)
1522
 
  {
1523
 
    if (test_if_important_data(field_charset, ptr, end))
1524
 
    {
1525
 
      if (table->in_use->abort_on_warning)
1526
 
        set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
1527
 
      else
1528
 
        set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
1529
 
    }
1530
 
    else /* If we lost only spaces then produce a NOTE, not a WARNING */
1531
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
1532
 
    return 2;
1533
 
  }
1534
 
  return 0;
1535
 
}
1536
 
 
1537
 
 
1538
 
/**
1539
 
  Store double value in Field_varstring.
1540
 
 
1541
 
  Pretty prints double number into field_length characters buffer.
1542
 
 
1543
 
  @param nr            number
1544
 
*/
1545
 
 
1546
 
int Field_str::store(double nr)
1547
 
{
1548
 
  char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
1549
 
  uint32_t local_char_length= field_length / charset()->mbmaxlen;
1550
 
  size_t length;
1551
 
  bool error;
1552
 
 
1553
 
  length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error);
1554
 
  if (error)
1555
 
  {
1556
 
    if (table->in_use->abort_on_warning)
1557
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
1558
 
    else
1559
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
1560
 
  }
1561
 
  return store(buff, length, charset());
1562
 
}
1563
 
 
1564
 
 
1565
 
uint32_t Field::is_equal(Create_field *new_field)
1566
 
{
1567
 
  return (new_field->sql_type == real_type());
1568
 
}
1569
 
 
1570
 
 
1571
 
/* If one of the fields is binary and the other one isn't return 1 else 0 */
1572
 
 
1573
 
bool Field_str::compare_str_field_flags(Create_field *new_field, uint32_t flag_arg)
1574
 
{
1575
 
  return (((new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
1576
 
          !(flag_arg & (BINCMP_FLAG | BINARY_FLAG))) ||
1577
 
         (!(new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
1578
 
          (flag_arg & (BINCMP_FLAG | BINARY_FLAG))));
1579
 
}
1580
 
 
1581
 
 
1582
 
uint32_t Field_str::is_equal(Create_field *new_field)
1583
 
{
1584
 
  if (compare_str_field_flags(new_field, flags))
1585
 
    return 0;
1586
 
 
1587
 
  return ((new_field->sql_type == real_type()) &&
1588
 
          new_field->charset == field_charset &&
1589
 
          new_field->length == max_display_length());
1590
 
}
1591
 
 
1592
 
 
1593
 
int Field_longstr::store_decimal(const my_decimal *d)
1594
 
{
1595
 
  char buff[DECIMAL_MAX_STR_LENGTH+1];
1596
 
  String str(buff, sizeof(buff), &my_charset_bin);
1597
 
  my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
1598
 
  return store(str.ptr(), str.length(), str.charset());
1599
 
}
1600
 
 
1601
 
uint32_t Field_longstr::max_data_length() const
1602
 
{
1603
 
  return field_length + (field_length > 255 ? 2 : 1);
1604
 
}
1605
 
 
 
1224
uint32_t Field::is_equal(Create_field *new_field_ptr)
 
1225
{
 
1226
  return (new_field_ptr->sql_type == real_type());
 
1227
}
1606
1228
 
1607
1229
/**
1608
1230
  @retval
1641
1263
  return 1;
1642
1264
}
1643
1265
 
1644
 
/**
1645
 
  @return
1646
 
  returns 1 if the fields are equally defined
1647
 
*/
1648
 
bool Field_num::eq_def(Field *field)
1649
 
{
1650
 
  if (!Field::eq_def(field))
1651
 
    return 0;
1652
 
  Field_num *from_num= (Field_num*) field;
1653
 
 
1654
 
  if (unsigned_flag != from_num->unsigned_flag ||
1655
 
      dec != from_num->dec)
1656
 
    return 0;
1657
 
  return 1;
1658
 
}
1659
 
 
1660
 
 
1661
 
uint32_t Field_num::is_equal(Create_field *new_field)
1662
 
{
1663
 
  return ((new_field->sql_type == real_type()) &&
1664
 
          ((new_field->flags & UNSIGNED_FLAG) == (uint32_t) (flags &
1665
 
                                                         UNSIGNED_FLAG)) &&
1666
 
          ((new_field->flags & AUTO_INCREMENT_FLAG) ==
1667
 
           (uint32_t) (flags & AUTO_INCREMENT_FLAG)) &&
1668
 
          (new_field->length <= max_display_length()));
1669
 
}
1670
 
 
1671
 
 
1672
1266
/*****************************************************************************
1673
1267
  Handling of field and Create_field
1674
1268
*****************************************************************************/
1687
1281
    pack_length= calc_pack_length(sql_type, length);
1688
1282
    break;
1689
1283
  case DRIZZLE_TYPE_ENUM:
1690
 
    /* Pack_length already calculated in sql_parse.cc */
 
1284
    /* Pack_length already calculated in ::init() */
1691
1285
    length*= charset->mbmaxlen;
1692
1286
    key_length= pack_length;
1693
1287
    break;
1729
1323
/**
1730
1324
  Initialize field definition for create.
1731
1325
 
1732
 
  @param thd                   Thread handle
 
1326
  @param session                   Thread handle
1733
1327
  @param fld_name              Field name
1734
1328
  @param fld_type              Field type
1735
1329
  @param fld_length            Field length
1741
1335
  @param fld_change            Field change
1742
1336
  @param fld_interval_list     Interval list (if any)
1743
1337
  @param fld_charset           Field charset
 
1338
  @param fld_vcol_info         Virtual column data
1744
1339
 
1745
1340
  @retval
1746
1341
    false on success
1748
1343
    true  on error
1749
1344
*/
1750
1345
 
1751
 
bool Create_field::init(THD *thd __attribute__((unused)), char *fld_name, enum_field_types fld_type,
 
1346
bool Create_field::init(Session *, char *fld_name, enum_field_types fld_type,
1752
1347
                        char *fld_length, char *fld_decimals,
1753
1348
                        uint32_t fld_type_modifier, Item *fld_default_value,
1754
1349
                        Item *fld_on_update_value, LEX_STRING *fld_comment,
1755
1350
                        char *fld_change, List<String> *fld_interval_list,
1756
1351
                        const CHARSET_INFO * const fld_charset,
1757
 
                        uint32_t fld_geom_type __attribute__((unused)),
1758
 
                        enum column_format_type column_format)
 
1352
                        uint32_t, enum column_format_type column_format_in)
 
1353
                        
1759
1354
{
1760
1355
  uint32_t sign_len, allowed_type_modifier= 0;
1761
1356
  uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
1764
1359
  field_name= fld_name;
1765
1360
  def= fld_default_value;
1766
1361
  flags= fld_type_modifier;
1767
 
  flags|= (((uint32_t)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
 
1362
  flags|= (((uint32_t)column_format_in & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
1768
1363
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
1769
1364
                 Field::NEXT_NUMBER : Field::NONE);
1770
1365
  decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
1784
1379
  interval_list.empty();
1785
1380
 
1786
1381
  comment= *fld_comment;
 
1382
 
1787
1383
  /*
1788
1384
    Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
1789
1385
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
1846
1442
      /* Allow empty as default value. */
1847
1443
      String str,*res;
1848
1444
      res= fld_default_value->val_str(&str);
 
1445
      if (res->length())
 
1446
      {
 
1447
        my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
 
1448
                 fld_name);
 
1449
        return(true);
 
1450
      }
 
1451
 
1849
1452
    }
1850
1453
    flags|= BLOB_FLAG;
1851
1454
    break;
1882
1485
    if (fld_default_value)
1883
1486
    {
1884
1487
      /* Grammar allows only NOW() value for ON UPDATE clause */
1885
 
      if (fld_default_value->type() == Item::FUNC_ITEM && 
 
1488
      if (fld_default_value->type() == Item::FUNC_ITEM &&
1886
1489
          ((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
1887
1490
      {
1888
1491
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
1917
1520
                                              Field::NONE));
1918
1521
    }
1919
1522
    break;
1920
 
  case DRIZZLE_TYPE_NEWDATE:
1921
 
    length= 10;
1922
 
    break;
1923
 
  case DRIZZLE_TYPE_TIME:
 
1523
  case DRIZZLE_TYPE_DATE:
1924
1524
    length= 10;
1925
1525
    break;
1926
1526
  case DRIZZLE_TYPE_DATETIME:
1964
1564
}
1965
1565
 
1966
1566
 
1967
 
enum_field_types get_blob_type_from_length(uint32_t length __attribute__((unused)))
 
1567
enum_field_types get_blob_type_from_length(uint32_t)
1968
1568
{
1969
1569
  enum_field_types type;
1970
1570
 
1983
1583
  switch (type) {
1984
1584
  case DRIZZLE_TYPE_VARCHAR:     return (length + (length < 256 ? 1: 2));
1985
1585
  case DRIZZLE_TYPE_TINY        : return 1;
1986
 
  case DRIZZLE_TYPE_NEWDATE:
1987
 
  case DRIZZLE_TYPE_TIME:   return 3;
 
1586
  case DRIZZLE_TYPE_DATE: return 3;
1988
1587
  case DRIZZLE_TYPE_TIMESTAMP:
1989
1588
  case DRIZZLE_TYPE_LONG        : return 4;
1990
1589
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1994
1593
  case DRIZZLE_TYPE_BLOB:               return 4+portable_sizeof_char_ptr;
1995
1594
  case DRIZZLE_TYPE_ENUM:
1996
1595
  case DRIZZLE_TYPE_NEWDECIMAL:
1997
 
    abort(); return 0;                          // This shouldn't happen
 
1596
    abort();
1998
1597
  default:
1999
1598
    return 0;
2000
1599
  }
2004
1603
uint32_t pack_length_to_packflag(uint32_t type)
2005
1604
{
2006
1605
  switch (type) {
2007
 
    case 1: return f_settype((uint32_t) DRIZZLE_TYPE_TINY);
 
1606
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
2008
1607
    case 2: assert(1);
2009
1608
    case 3: assert(1);
2010
1609
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
2014
1613
}
2015
1614
 
2016
1615
 
2017
 
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
 
1616
Field *make_field(TableShare *share, MEM_ROOT *root,
 
1617
                  unsigned char *ptr, uint32_t field_length,
2018
1618
                  unsigned char *null_pos, unsigned char null_bit,
2019
1619
                  uint32_t pack_flag,
2020
1620
                  enum_field_types field_type,
2023
1623
                  TYPELIB *interval,
2024
1624
                  const char *field_name)
2025
1625
{
 
1626
  if(!root)
 
1627
    root= current_mem_root();
 
1628
 
2026
1629
  if (!f_maybe_null(pack_flag))
2027
1630
  {
2028
1631
    null_pos=0;
2034
1637
  }
2035
1638
 
2036
1639
  switch (field_type) {
2037
 
  case DRIZZLE_TYPE_NEWDATE:
2038
 
  case DRIZZLE_TYPE_TIME:
 
1640
  case DRIZZLE_TYPE_DATE:
2039
1641
  case DRIZZLE_TYPE_DATETIME:
2040
1642
  case DRIZZLE_TYPE_TIMESTAMP:
2041
1643
    field_charset= &my_charset_bin;
2047
1649
    if (!f_is_packed(pack_flag))
2048
1650
    {
2049
1651
      if (field_type == DRIZZLE_TYPE_VARCHAR)
2050
 
        return new Field_varstring(ptr,field_length,
 
1652
        return new (root) Field_varstring(ptr,field_length,
2051
1653
                                   HA_VARCHAR_PACKLENGTH(field_length),
2052
1654
                                   null_pos,null_bit,
2053
1655
                                   unireg_check, field_name,
2061
1663
                                      field_length);
2062
1664
 
2063
1665
    if (f_is_blob(pack_flag))
2064
 
      return new Field_blob(ptr,null_pos,null_bit,
 
1666
      return new (root) Field_blob(ptr,null_pos,null_bit,
2065
1667
                            unireg_check, field_name, share,
2066
1668
                            pack_length, field_charset);
2067
1669
    if (interval)
2068
1670
    {
2069
1671
      if (f_is_enum(pack_flag))
2070
 
        return new Field_enum(ptr,field_length,null_pos,null_bit,
 
1672
      {
 
1673
        return new (root) Field_enum(ptr,field_length,null_pos,null_bit,
2071
1674
                                  unireg_check, field_name,
2072
 
                                  pack_length, interval, field_charset);
 
1675
                                  get_enum_pack_length(interval->count),
 
1676
                                  interval, field_charset);
 
1677
      }
2073
1678
    }
2074
1679
  }
2075
1680
 
2076
1681
  switch (field_type) {
2077
1682
  case DRIZZLE_TYPE_NEWDECIMAL:
2078
 
    return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
 
1683
    return new (root) Field_new_decimal(ptr,field_length,null_pos,null_bit,
2079
1684
                                 unireg_check, field_name,
2080
1685
                                 f_decimals(pack_flag),
2081
1686
                                 f_is_decimal_precision(pack_flag) != 0,
2082
1687
                                 f_is_dec(pack_flag) == 0);
2083
1688
  case DRIZZLE_TYPE_DOUBLE:
2084
 
    return new Field_double(ptr,field_length,null_pos,null_bit,
 
1689
    return new (root) Field_double(ptr,field_length,null_pos,null_bit,
2085
1690
                            unireg_check, field_name,
2086
1691
                            f_decimals(pack_flag),
2087
1692
                            false,
2088
1693
                            f_is_dec(pack_flag)== 0);
2089
1694
  case DRIZZLE_TYPE_TINY:
2090
 
    return new Field_tiny(ptr,field_length,null_pos,null_bit,
2091
 
                          unireg_check, field_name,
2092
 
                          false,
2093
 
                          f_is_dec(pack_flag) == 0);
 
1695
    assert(0);
2094
1696
  case DRIZZLE_TYPE_LONG:
2095
 
    return new Field_long(ptr,field_length,null_pos,null_bit,
 
1697
    return new (root) Field_long(ptr,field_length,null_pos,null_bit,
2096
1698
                           unireg_check, field_name,
2097
1699
                           false,
2098
1700
                           f_is_dec(pack_flag) == 0);
2099
1701
  case DRIZZLE_TYPE_LONGLONG:
2100
 
    return new Field_int64_t(ptr,field_length,null_pos,null_bit,
 
1702
    return new (root) Field_int64_t(ptr,field_length,null_pos,null_bit,
2101
1703
                              unireg_check, field_name,
2102
1704
                              false,
2103
1705
                              f_is_dec(pack_flag) == 0);
2104
1706
  case DRIZZLE_TYPE_TIMESTAMP:
2105
 
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,
 
1707
    return new (root) Field_timestamp(ptr,field_length, null_pos, null_bit,
2106
1708
                               unireg_check, field_name, share,
2107
1709
                               field_charset);
2108
 
  case DRIZZLE_TYPE_NEWDATE:
2109
 
    return new Field_newdate(ptr,null_pos,null_bit,
 
1710
  case DRIZZLE_TYPE_DATE:
 
1711
    return new (root) Field_date(ptr,null_pos,null_bit,
2110
1712
                             unireg_check, field_name, field_charset);
2111
 
  case DRIZZLE_TYPE_TIME:
2112
 
    return new Field_time(ptr,null_pos,null_bit,
2113
 
                          unireg_check, field_name, field_charset);
2114
1713
  case DRIZZLE_TYPE_DATETIME:
2115
 
    return new Field_datetime(ptr,null_pos,null_bit,
 
1714
    return new (root) Field_datetime(ptr,null_pos,null_bit,
2116
1715
                              unireg_check, field_name, field_charset);
2117
1716
  case DRIZZLE_TYPE_NULL:
2118
 
    return new Field_null(ptr, field_length, unireg_check, field_name,
 
1717
    return new (root) Field_null(ptr, field_length, unireg_check, field_name,
2119
1718
                          field_charset);
2120
1719
  default:                                      // Impossible (Wrong version)
2121
1720
    break;
2168
1767
  def=0;
2169
1768
  char_length= length;
2170
1769
 
2171
 
  if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
 
1770
  if (!(flags & (NO_DEFAULT_VALUE_FLAG )) &&
2172
1771
      old_field->ptr && orig_field &&
2173
1772
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
2174
 
       old_field->table->timestamp_field != old_field ||  /* timestamp field */ 
 
1773
       old_field->table->timestamp_field != old_field ||  /* timestamp field */
2175
1774
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
2176
1775
  {
2177
 
    char buff[MAX_FIELD_WIDTH];
2178
 
    String tmp(buff,sizeof(buff), charset);
2179
1776
    my_ptrdiff_t diff;
2180
1777
 
2181
1778
    /* Get the value from default_values */
2219
1816
    0 otherwise
2220
1817
*/
2221
1818
 
2222
 
bool 
 
1819
bool
2223
1820
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2224
1821
                   int cuted_increment)
2225
1822
{
2227
1824
    If this field was created only for type conversion purposes it
2228
1825
    will have table == NULL.
2229
1826
  */
2230
 
  THD *thd= table ? table->in_use : current_thd;
2231
 
  if (thd->count_cuted_fields)
 
1827
  Session *session= table ? table->in_use : current_session;
 
1828
  if (session->count_cuted_fields)
2232
1829
  {
2233
 
    thd->cuted_fields+= cuted_increment;
2234
 
    push_warning_printf(thd, level, code, ER(code), field_name,
2235
 
                        thd->row_count);
 
1830
    session->cuted_fields+= cuted_increment;
 
1831
    push_warning_printf(session, level, code, ER(code), field_name,
 
1832
                        session->row_count);
2236
1833
    return 0;
2237
1834
  }
2238
1835
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
2255
1852
    thread.
2256
1853
*/
2257
1854
 
2258
 
void 
2259
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
2260
 
                            unsigned int code, 
2261
 
                            const char *str, uint32_t str_length, 
 
1855
void
 
1856
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
 
1857
                            unsigned int code,
 
1858
                            const char *str, uint32_t str_length,
2262
1859
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
2263
1860
{
2264
 
  THD *thd= table ? table->in_use : current_thd;
2265
 
  if ((thd->really_abort_on_warning() &&
 
1861
  Session *session= table ? table->in_use : current_session;
 
1862
  if ((session->really_abort_on_warning() &&
2266
1863
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
2267
1864
      set_warning(level, code, cuted_increment))
2268
 
    make_truncated_value_warning(thd, level, str, str_length, ts_type,
 
1865
    make_truncated_value_warning(session, level, str, str_length, ts_type,
2269
1866
                                 field_name);
2270
1867
}
2271
1868
 
2285
1882
    thread.
2286
1883
*/
2287
1884
 
2288
 
void 
2289
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
1885
void
 
1886
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2290
1887
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
2291
1888
                            int cuted_increment)
2292
1889
{
2293
 
  THD *thd= table ? table->in_use : current_thd;
2294
 
  if (thd->really_abort_on_warning() ||
 
1890
  Session *session= table ? table->in_use : current_session;
 
1891
  if (session->really_abort_on_warning() ||
2295
1892
      set_warning(level, code, cuted_increment))
2296
1893
  {
2297
1894
    char str_nr[22];
2298
1895
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
2299
 
    make_truncated_value_warning(thd, level, str_nr, (uint32_t) (str_end - str_nr), 
 
1896
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
2300
1897
                                 ts_type, field_name);
2301
1898
  }
2302
1899
}
2316
1913
    thread.
2317
1914
*/
2318
1915
 
2319
 
void 
2320
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
1916
void
 
1917
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, const uint32_t code,
2321
1918
                            double nr, enum enum_drizzle_timestamp_type ts_type)
2322
1919
{
2323
 
  THD *thd= table ? table->in_use : current_thd;
2324
 
  if (thd->really_abort_on_warning() ||
 
1920
  Session *session= table ? table->in_use : current_session;
 
1921
  if (session->really_abort_on_warning() ||
2325
1922
      set_warning(level, code, 1))
2326
1923
  {
2327
1924
    /* DBL_DIG is enough to print '-[digits].E+###' */
2328
1925
    char str_nr[DBL_DIG + 8];
2329
1926
    uint32_t str_len= sprintf(str_nr, "%g", nr);
2330
 
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
 
1927
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
2331
1928
                                 field_name);
2332
1929
  }
2333
1930
}
 
1931
 
 
1932
bool Field::isReadSet() 
 
1933
 
1934
  return table->isReadSet(field_index); 
 
1935
}
 
1936
 
 
1937
 
 
1938
bool Field::isWriteSet()
 
1939
 
1940
  return table->isWriteSet(field_index); 
 
1941
}
 
1942