~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2009-02-20 22:48:37 UTC
  • Revision ID: brian@tangent.org-20090220224837-fw5wrf46n4ru3e6a
First pass of stripping uint

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/virtual_column_info.h>
 
32
#include <drizzled/field/str.h>
 
33
#include <drizzled/field/longstr.h>
 
34
#include <drizzled/field/num.h>
 
35
#include <drizzled/field/blob.h>
 
36
#include <drizzled/field/enum.h>
 
37
#include <drizzled/field/null.h>
 
38
#include <drizzled/field/date.h>
 
39
#include <drizzled/field/decimal.h>
 
40
#include <drizzled/field/real.h>
 
41
#include <drizzled/field/double.h>
 
42
#include <drizzled/field/long.h>
 
43
#include <drizzled/field/int64_t.h>
 
44
#include <drizzled/field/num.h>
 
45
#include <drizzled/field/timetype.h>
 
46
#include <drizzled/field/timestamp.h>
 
47
#include <drizzled/field/datetime.h>
 
48
#include <drizzled/field/varstring.h>
27
49
 
28
 
// Maximum allowed exponent value for converting string to decimal
29
 
#define MAX_EXPONENT 1024
30
50
 
31
51
/*****************************************************************************
32
52
  Instansiate templates and static variables
38
58
#endif
39
59
 
40
60
 
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
 
  },
 
61
static enum_field_types
 
62
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
 
63
{
84
64
  /* DRIZZLE_TYPE_TINY -> */
85
65
  {
86
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
87
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
88
 
  //DRIZZLE_TYPE_LONG
 
66
    //DRIZZLE_TYPE_TINY
 
67
    DRIZZLE_TYPE_TINY,
 
68
    //DRIZZLE_TYPE_LONG
89
69
    DRIZZLE_TYPE_LONG,
90
 
  //DRIZZLE_TYPE_DOUBLE
 
70
    //DRIZZLE_TYPE_DOUBLE
91
71
    DRIZZLE_TYPE_DOUBLE,
92
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
93
 
    DRIZZLE_TYPE_TINY,        DRIZZLE_TYPE_VARCHAR,
94
 
  //DRIZZLE_TYPE_LONGLONG
 
72
    //DRIZZLE_TYPE_NULL
 
73
    DRIZZLE_TYPE_TINY,
 
74
    //DRIZZLE_TYPE_TIMESTAMP
 
75
    DRIZZLE_TYPE_VARCHAR,
 
76
    //DRIZZLE_TYPE_LONGLONG
95
77
    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
 
78
    //DRIZZLE_TYPE_TIME
 
79
    DRIZZLE_TYPE_VARCHAR,
 
80
    //DRIZZLE_TYPE_DATETIME
 
81
    DRIZZLE_TYPE_VARCHAR,
 
82
    //DRIZZLE_TYPE_DATE
 
83
    DRIZZLE_TYPE_VARCHAR,
 
84
    //DRIZZLE_TYPE_VARCHAR
 
85
    DRIZZLE_TYPE_VARCHAR,
 
86
    //DRIZZLE_TYPE_VIRTUAL
 
87
    DRIZZLE_TYPE_VIRTUAL,
 
88
    //DRIZZLE_TYPE_NEWDECIMAL
 
89
    DRIZZLE_TYPE_NEWDECIMAL,
 
90
    //DRIZZLE_TYPE_ENUM
 
91
    DRIZZLE_TYPE_VARCHAR,
 
92
    //DRIZZLE_TYPE_BLOB
105
93
    DRIZZLE_TYPE_BLOB,
106
94
  },
107
95
  /* DRIZZLE_TYPE_LONG -> */
108
96
  {
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
 
97
    //DRIZZLE_TYPE_TINY
 
98
    DRIZZLE_TYPE_LONG,
 
99
    //DRIZZLE_TYPE_LONG
 
100
    DRIZZLE_TYPE_LONG,
 
101
    //DRIZZLE_TYPE_DOUBLE
114
102
    DRIZZLE_TYPE_DOUBLE,
115
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
116
 
    DRIZZLE_TYPE_LONG,         DRIZZLE_TYPE_VARCHAR,
117
 
  //DRIZZLE_TYPE_LONGLONG
 
103
    //DRIZZLE_TYPE_NULL
 
104
    DRIZZLE_TYPE_LONG,
 
105
    //DRIZZLE_TYPE_TIMESTAMP
 
106
    DRIZZLE_TYPE_VARCHAR,
 
107
    //DRIZZLE_TYPE_LONGLONG
118
108
    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
 
109
    //DRIZZLE_TYPE_TIME
 
110
    DRIZZLE_TYPE_VARCHAR,
 
111
    //DRIZZLE_TYPE_DATETIME
 
112
    DRIZZLE_TYPE_VARCHAR,
 
113
    //DRIZZLE_TYPE_DATE
 
114
    DRIZZLE_TYPE_VARCHAR,
 
115
    //DRIZZLE_TYPE_VARCHAR
 
116
    DRIZZLE_TYPE_VARCHAR,
 
117
    //DRIZZLE_TYPE_VIRTUAL
 
118
    DRIZZLE_TYPE_VIRTUAL,
 
119
    //DRIZZLE_TYPE_NEWDECIMAL
 
120
    DRIZZLE_TYPE_NEWDECIMAL,
 
121
    //DRIZZLE_TYPE_ENUM
 
122
    DRIZZLE_TYPE_VARCHAR,
 
123
    //DRIZZLE_TYPE_BLOB
128
124
    DRIZZLE_TYPE_BLOB,
129
125
  },
130
126
  /* DRIZZLE_TYPE_DOUBLE -> */
131
127
  {
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
 
128
    //DRIZZLE_TYPE_TINY
 
129
    DRIZZLE_TYPE_DOUBLE,
 
130
    //DRIZZLE_TYPE_LONG
 
131
    DRIZZLE_TYPE_DOUBLE,
 
132
    //DRIZZLE_TYPE_DOUBLE
 
133
    DRIZZLE_TYPE_DOUBLE,
 
134
    //DRIZZLE_TYPE_NULL
 
135
    DRIZZLE_TYPE_DOUBLE,
 
136
    //DRIZZLE_TYPE_TIMESTAMP
 
137
    DRIZZLE_TYPE_VARCHAR,
 
138
    //DRIZZLE_TYPE_LONGLONG
 
139
    DRIZZLE_TYPE_DOUBLE,
 
140
    //DRIZZLE_TYPE_TIME
 
141
    DRIZZLE_TYPE_VARCHAR,
 
142
    //DRIZZLE_TYPE_DATETIME
 
143
    DRIZZLE_TYPE_VARCHAR,
 
144
    //DRIZZLE_TYPE_DATE
 
145
    DRIZZLE_TYPE_VARCHAR,
 
146
    //DRIZZLE_TYPE_VARCHAR
 
147
    DRIZZLE_TYPE_VARCHAR,
 
148
    //DRIZZLE_TYPE_VIRTUAL
 
149
    DRIZZLE_TYPE_VIRTUAL,
 
150
    //DRIZZLE_TYPE_NEWDECIMAL
 
151
    DRIZZLE_TYPE_DOUBLE,
 
152
    //DRIZZLE_TYPE_ENUM
 
153
    DRIZZLE_TYPE_VARCHAR,
 
154
    //DRIZZLE_TYPE_BLOB
151
155
    DRIZZLE_TYPE_BLOB,
152
156
  },
153
157
  /* DRIZZLE_TYPE_NULL -> */
154
158
  {
155
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
156
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
157
 
  //DRIZZLE_TYPE_LONG
 
159
    //DRIZZLE_TYPE_TINY
 
160
    DRIZZLE_TYPE_TINY,
 
161
    //DRIZZLE_TYPE_LONG
158
162
    DRIZZLE_TYPE_LONG,
159
 
  //DRIZZLE_TYPE_DOUBLE
 
163
    //DRIZZLE_TYPE_DOUBLE
160
164
    DRIZZLE_TYPE_DOUBLE,
161
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
162
 
    DRIZZLE_TYPE_NULL,        DRIZZLE_TYPE_TIMESTAMP,
163
 
  //DRIZZLE_TYPE_LONGLONG
 
165
    //DRIZZLE_TYPE_NULL
 
166
    DRIZZLE_TYPE_NULL,
 
167
    //DRIZZLE_TYPE_TIMESTAMP
 
168
    DRIZZLE_TYPE_TIMESTAMP,
 
169
    //DRIZZLE_TYPE_LONGLONG
164
170
    DRIZZLE_TYPE_LONGLONG,
165
 
  //DRIZZLE_TYPE_TIME
 
171
    //DRIZZLE_TYPE_TIME
166
172
    DRIZZLE_TYPE_TIME,
167
 
  //DRIZZLE_TYPE_DATETIME
 
173
    //DRIZZLE_TYPE_DATETIME
168
174
    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
 
175
    //DRIZZLE_TYPE_DATE
 
176
    DRIZZLE_TYPE_DATE,
 
177
    //DRIZZLE_TYPE_VARCHAR
 
178
    DRIZZLE_TYPE_VARCHAR,
 
179
    //DRIZZLE_TYPE_VIRTUAL
 
180
    DRIZZLE_TYPE_VIRTUAL,
 
181
    //DRIZZLE_TYPE_NEWDECIMAL
 
182
    DRIZZLE_TYPE_NEWDECIMAL,
 
183
    //DRIZZLE_TYPE_ENUM
 
184
    DRIZZLE_TYPE_ENUM,
 
185
    //DRIZZLE_TYPE_BLOB
174
186
    DRIZZLE_TYPE_BLOB,
175
187
  },
176
188
  /* DRIZZLE_TYPE_TIMESTAMP -> */
177
189
  {
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
 
190
    //DRIZZLE_TYPE_TINY
 
191
    DRIZZLE_TYPE_VARCHAR,
 
192
    //DRIZZLE_TYPE_LONG
 
193
    DRIZZLE_TYPE_VARCHAR,
 
194
    //DRIZZLE_TYPE_DOUBLE
 
195
    DRIZZLE_TYPE_VARCHAR,
 
196
    //DRIZZLE_TYPE_NULL
 
197
    DRIZZLE_TYPE_TIMESTAMP,
 
198
    //DRIZZLE_TYPE_TIMESTAMP
 
199
    DRIZZLE_TYPE_TIMESTAMP,
 
200
    //DRIZZLE_TYPE_LONGLONG
 
201
    DRIZZLE_TYPE_VARCHAR,
 
202
    //DRIZZLE_TYPE_TIME
 
203
    DRIZZLE_TYPE_DATETIME,
 
204
    //DRIZZLE_TYPE_DATETIME
 
205
    DRIZZLE_TYPE_DATETIME,
 
206
    //DRIZZLE_TYPE_DATE
 
207
    DRIZZLE_TYPE_DATE,
 
208
    //DRIZZLE_TYPE_VARCHAR
 
209
    DRIZZLE_TYPE_VARCHAR,
 
210
    //DRIZZLE_TYPE_VIRTUAL
 
211
    DRIZZLE_TYPE_VIRTUAL,
 
212
    //DRIZZLE_TYPE_NEWDECIMAL
 
213
    DRIZZLE_TYPE_VARCHAR,
 
214
    //DRIZZLE_TYPE_ENUM
 
215
    DRIZZLE_TYPE_VARCHAR,
 
216
    //DRIZZLE_TYPE_BLOB
197
217
    DRIZZLE_TYPE_BLOB,
198
218
  },
199
219
  /* DRIZZLE_TYPE_LONGLONG -> */
200
220
  {
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
 
221
    //DRIZZLE_TYPE_TINY
 
222
    DRIZZLE_TYPE_LONGLONG,
 
223
    //DRIZZLE_TYPE_LONG
 
224
    DRIZZLE_TYPE_LONGLONG,
 
225
    //DRIZZLE_TYPE_DOUBLE
206
226
    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
 
227
    //DRIZZLE_TYPE_NULL
 
228
    DRIZZLE_TYPE_LONGLONG,
 
229
    //DRIZZLE_TYPE_TIMESTAMP
 
230
    DRIZZLE_TYPE_VARCHAR,
 
231
    //DRIZZLE_TYPE_LONGLONG
 
232
    DRIZZLE_TYPE_LONGLONG,
 
233
    //DRIZZLE_TYPE_TIME
 
234
    DRIZZLE_TYPE_VARCHAR,
 
235
    //DRIZZLE_TYPE_DATETIME
 
236
    DRIZZLE_TYPE_VARCHAR,
 
237
    //DRIZZLE_TYPE_DATE
 
238
    DRIZZLE_TYPE_DATE,
 
239
    //DRIZZLE_TYPE_VARCHAR
 
240
    DRIZZLE_TYPE_VARCHAR,
 
241
    //DRIZZLE_TYPE_VIRTUAL
 
242
    DRIZZLE_TYPE_VIRTUAL,
 
243
    //DRIZZLE_TYPE_NEWDECIMAL
 
244
    //DRIZZLE_TYPE_ENUM
 
245
    DRIZZLE_TYPE_NEWDECIMAL,
 
246
    DRIZZLE_TYPE_VARCHAR,
 
247
    //DRIZZLE_TYPE_BLOB
220
248
    DRIZZLE_TYPE_BLOB,
221
249
  },
222
250
  /* DRIZZLE_TYPE_TIME -> */
223
251
  {
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
 
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_TIME,
 
260
    //DRIZZLE_TYPE_TIMESTAMP
 
261
    DRIZZLE_TYPE_DATETIME,
 
262
    //DRIZZLE_TYPE_LONGLONG
 
263
    DRIZZLE_TYPE_VARCHAR,
 
264
    //DRIZZLE_TYPE_TIME
 
265
    DRIZZLE_TYPE_TIME,
 
266
    //DRIZZLE_TYPE_DATETIME
 
267
    DRIZZLE_TYPE_DATETIME,
 
268
    //DRIZZLE_TYPE_DATE
 
269
    DRIZZLE_TYPE_DATE,
 
270
    //DRIZZLE_TYPE_VARCHAR
 
271
    DRIZZLE_TYPE_VARCHAR,
 
272
    //DRIZZLE_TYPE_VIRTUAL
 
273
    DRIZZLE_TYPE_VIRTUAL,
 
274
    //DRIZZLE_TYPE_NEWDECIMAL
 
275
    DRIZZLE_TYPE_VARCHAR,
 
276
    //DRIZZLE_TYPE_ENUM
 
277
    DRIZZLE_TYPE_VARCHAR,
 
278
    //DRIZZLE_TYPE_BLOB
243
279
    DRIZZLE_TYPE_BLOB,
244
280
  },
245
281
  /* DRIZZLE_TYPE_DATETIME -> */
246
282
  {
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
 
283
    //DRIZZLE_TYPE_TINY
 
284
    DRIZZLE_TYPE_VARCHAR,
 
285
    //DRIZZLE_TYPE_LONG
 
286
    DRIZZLE_TYPE_VARCHAR,
 
287
    //DRIZZLE_TYPE_DOUBLE
 
288
    DRIZZLE_TYPE_VARCHAR,
 
289
    //DRIZZLE_TYPE_NULL
 
290
    DRIZZLE_TYPE_DATETIME,
 
291
    //DRIZZLE_TYPE_TIMESTAMP
 
292
    DRIZZLE_TYPE_DATETIME,
 
293
    //DRIZZLE_TYPE_LONGLONG
 
294
    DRIZZLE_TYPE_VARCHAR,
 
295
    //DRIZZLE_TYPE_TIME
 
296
    DRIZZLE_TYPE_DATETIME,
 
297
    //DRIZZLE_TYPE_DATETIME
 
298
    DRIZZLE_TYPE_DATETIME,
 
299
    //DRIZZLE_TYPE_DATE
 
300
    DRIZZLE_TYPE_DATE,
 
301
    //DRIZZLE_TYPE_VARCHAR
 
302
    DRIZZLE_TYPE_VARCHAR,
 
303
    //DRIZZLE_TYPE_VIRTUAL
 
304
    DRIZZLE_TYPE_VIRTUAL,
 
305
    //DRIZZLE_TYPE_NEWDECIMAL
 
306
    DRIZZLE_TYPE_VARCHAR,
 
307
    //DRIZZLE_TYPE_ENUM
 
308
    DRIZZLE_TYPE_VARCHAR,
 
309
    //DRIZZLE_TYPE_BLOB
266
310
    DRIZZLE_TYPE_BLOB,
267
311
  },
268
 
  /* DRIZZLE_TYPE_NEWDATE -> */
 
312
  /* DRIZZLE_TYPE_DATE -> */
269
313
  {
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
 
314
    //DRIZZLE_TYPE_TINY
 
315
    DRIZZLE_TYPE_VARCHAR,
 
316
    //DRIZZLE_TYPE_LONG
 
317
    DRIZZLE_TYPE_VARCHAR,
 
318
    //DRIZZLE_TYPE_DOUBLE
 
319
    DRIZZLE_TYPE_VARCHAR,
 
320
    //DRIZZLE_TYPE_NULL
 
321
    DRIZZLE_TYPE_DATE,
 
322
    //DRIZZLE_TYPE_TIMESTAMP
 
323
    DRIZZLE_TYPE_DATETIME,
 
324
    //DRIZZLE_TYPE_LONGLONG
 
325
    DRIZZLE_TYPE_VARCHAR,
 
326
    //DRIZZLE_TYPE_TIME
 
327
    DRIZZLE_TYPE_DATETIME,
 
328
    //DRIZZLE_TYPE_DATETIME
 
329
    DRIZZLE_TYPE_DATETIME,
 
330
    //DRIZZLE_TYPE_DATE
 
331
    DRIZZLE_TYPE_DATE,
 
332
    //DRIZZLE_TYPE_VARCHAR
 
333
    DRIZZLE_TYPE_VARCHAR,
 
334
    //DRIZZLE_TYPE_VIRTUAL
 
335
    DRIZZLE_TYPE_VIRTUAL,
 
336
    //DRIZZLE_TYPE_NEWDECIMAL
 
337
    DRIZZLE_TYPE_VARCHAR,
 
338
    //DRIZZLE_TYPE_ENUM
 
339
    DRIZZLE_TYPE_VARCHAR,
 
340
    //DRIZZLE_TYPE_BLOB
289
341
    DRIZZLE_TYPE_BLOB,
290
342
  },
291
343
  /* DRIZZLE_TYPE_VARCHAR -> */
292
344
  {
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
 
345
    //DRIZZLE_TYPE_TINY
 
346
    DRIZZLE_TYPE_VARCHAR,
 
347
    //DRIZZLE_TYPE_LONG
 
348
    DRIZZLE_TYPE_VARCHAR,
 
349
    //DRIZZLE_TYPE_DOUBLE
 
350
    DRIZZLE_TYPE_VARCHAR,
 
351
    //DRIZZLE_TYPE_NULL
 
352
    DRIZZLE_TYPE_VARCHAR,
 
353
    //DRIZZLE_TYPE_TIMESTAMP
 
354
    DRIZZLE_TYPE_VARCHAR,
 
355
    //DRIZZLE_TYPE_LONGLONG
 
356
    DRIZZLE_TYPE_VARCHAR,
 
357
    //DRIZZLE_TYPE_TIME
 
358
    DRIZZLE_TYPE_VARCHAR,
 
359
    //DRIZZLE_TYPE_DATETIME
 
360
    DRIZZLE_TYPE_VARCHAR,
 
361
    //DRIZZLE_TYPE_DATE
 
362
    DRIZZLE_TYPE_VARCHAR,
 
363
    //DRIZZLE_TYPE_VARCHAR
 
364
    DRIZZLE_TYPE_VARCHAR,
 
365
    //DRIZZLE_TYPE_VIRTUAL
 
366
    DRIZZLE_TYPE_VIRTUAL,
 
367
    //DRIZZLE_TYPE_NEWDECIMAL
 
368
    DRIZZLE_TYPE_VARCHAR,
 
369
    //DRIZZLE_TYPE_ENUM
 
370
    DRIZZLE_TYPE_VARCHAR,
 
371
    //DRIZZLE_TYPE_BLOB
312
372
    DRIZZLE_TYPE_BLOB,
313
373
  },
 
374
  /* DRIZZLE_TYPE_VIRTUAL -> */
 
375
  {
 
376
    //DRIZZLE_TYPE_TINY
 
377
    DRIZZLE_TYPE_VIRTUAL,
 
378
    //DRIZZLE_TYPE_LONG
 
379
    DRIZZLE_TYPE_VIRTUAL,
 
380
    //DRIZZLE_TYPE_DOUBLE
 
381
    DRIZZLE_TYPE_VIRTUAL,
 
382
    //DRIZZLE_TYPE_NULL
 
383
    DRIZZLE_TYPE_VIRTUAL,
 
384
    //DRIZZLE_TYPE_TIMESTAMP
 
385
    DRIZZLE_TYPE_VIRTUAL,
 
386
    //DRIZZLE_TYPE_LONGLONG
 
387
    DRIZZLE_TYPE_VIRTUAL,
 
388
    //DRIZZLE_TYPE_TIME
 
389
    DRIZZLE_TYPE_VIRTUAL,
 
390
    //DRIZZLE_TYPE_DATETIME
 
391
    DRIZZLE_TYPE_VIRTUAL,
 
392
    //DRIZZLE_TYPE_DATE
 
393
    DRIZZLE_TYPE_VIRTUAL,
 
394
    //DRIZZLE_TYPE_VARCHAR
 
395
    DRIZZLE_TYPE_VIRTUAL,
 
396
    //DRIZZLE_TYPE_VIRTUAL
 
397
    DRIZZLE_TYPE_VIRTUAL,
 
398
    //DRIZZLE_TYPE_NEWDECIMAL
 
399
    DRIZZLE_TYPE_VIRTUAL,
 
400
    //DRIZZLE_TYPE_ENUM
 
401
    DRIZZLE_TYPE_VIRTUAL,
 
402
    //DRIZZLE_TYPE_BLOB
 
403
    DRIZZLE_TYPE_VIRTUAL,
 
404
  },
314
405
  /* DRIZZLE_TYPE_NEWDECIMAL -> */
315
406
  {
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
 
407
    //DRIZZLE_TYPE_TINY
 
408
    DRIZZLE_TYPE_NEWDECIMAL,
 
409
    //DRIZZLE_TYPE_LONG
 
410
    DRIZZLE_TYPE_NEWDECIMAL,
 
411
    //DRIZZLE_TYPE_DOUBLE
321
412
    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
 
413
    //DRIZZLE_TYPE_NULL
 
414
    DRIZZLE_TYPE_NEWDECIMAL,
 
415
    //DRIZZLE_TYPE_TIMESTAMP
 
416
    DRIZZLE_TYPE_VARCHAR,
 
417
    //DRIZZLE_TYPE_LONGLONG
 
418
    DRIZZLE_TYPE_NEWDECIMAL,
 
419
    //DRIZZLE_TYPE_TIME
 
420
    DRIZZLE_TYPE_VARCHAR,
 
421
    //DRIZZLE_TYPE_DATETIME
 
422
    DRIZZLE_TYPE_VARCHAR,
 
423
    //DRIZZLE_TYPE_DATE
 
424
    DRIZZLE_TYPE_VARCHAR,
 
425
    //DRIZZLE_TYPE_VARCHAR
 
426
    DRIZZLE_TYPE_VARCHAR,
 
427
    //DRIZZLE_TYPE_VIRTUAL
 
428
    DRIZZLE_TYPE_VIRTUAL,
 
429
    //DRIZZLE_TYPE_NEWDECIMAL
 
430
    DRIZZLE_TYPE_NEWDECIMAL,
 
431
    //DRIZZLE_TYPE_ENUM
 
432
    DRIZZLE_TYPE_VARCHAR,
 
433
    //DRIZZLE_TYPE_BLOB
335
434
    DRIZZLE_TYPE_BLOB,
336
435
  },
337
436
  /* DRIZZLE_TYPE_ENUM -> */
338
437
  {
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
 
438
    //DRIZZLE_TYPE_TINY
 
439
    DRIZZLE_TYPE_VARCHAR,
 
440
    //DRIZZLE_TYPE_LONG
 
441
    DRIZZLE_TYPE_VARCHAR,
 
442
    //DRIZZLE_TYPE_DOUBLE
 
443
    DRIZZLE_TYPE_VARCHAR,
 
444
    //DRIZZLE_TYPE_NULL
 
445
    DRIZZLE_TYPE_ENUM,
 
446
    //DRIZZLE_TYPE_TIMESTAMP
 
447
    DRIZZLE_TYPE_VARCHAR,
 
448
    //DRIZZLE_TYPE_LONGLONG
 
449
    DRIZZLE_TYPE_VARCHAR,
 
450
    //DRIZZLE_TYPE_TIME
 
451
    DRIZZLE_TYPE_VARCHAR,
 
452
    //DRIZZLE_TYPE_DATETIME
 
453
    DRIZZLE_TYPE_VARCHAR,
 
454
    //DRIZZLE_TYPE_DATE
 
455
    DRIZZLE_TYPE_VARCHAR,
 
456
    //DRIZZLE_TYPE_VARCHAR
 
457
    DRIZZLE_TYPE_VARCHAR,
 
458
    //DRIZZLE_TYPE_VIRTUAL
 
459
    DRIZZLE_TYPE_VIRTUAL,
 
460
    //DRIZZLE_TYPE_NEWDECIMAL
 
461
    DRIZZLE_TYPE_VARCHAR,
 
462
    //DRIZZLE_TYPE_ENUM
 
463
    DRIZZLE_TYPE_VARCHAR,
 
464
    //DRIZZLE_TYPE_BLOB
358
465
    DRIZZLE_TYPE_BLOB,
359
466
  },
360
467
  /* DRIZZLE_TYPE_BLOB -> */
361
468
  {
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
 
469
    //DRIZZLE_TYPE_TINY
 
470
    DRIZZLE_TYPE_BLOB,
 
471
    //DRIZZLE_TYPE_LONG
 
472
    DRIZZLE_TYPE_BLOB,
 
473
    //DRIZZLE_TYPE_DOUBLE
 
474
    DRIZZLE_TYPE_BLOB,
 
475
    //DRIZZLE_TYPE_NULL
 
476
    DRIZZLE_TYPE_BLOB,
 
477
    //DRIZZLE_TYPE_TIMESTAMP
 
478
    DRIZZLE_TYPE_BLOB,
 
479
    //DRIZZLE_TYPE_LONGLONG
 
480
    DRIZZLE_TYPE_BLOB,
 
481
    //DRIZZLE_TYPE_TIME
 
482
    DRIZZLE_TYPE_BLOB,
 
483
    //DRIZZLE_TYPE_DATETIME
 
484
    DRIZZLE_TYPE_BLOB,
 
485
    //DRIZZLE_TYPE_DATE
 
486
    DRIZZLE_TYPE_BLOB,
 
487
    //DRIZZLE_TYPE_VARCHAR
 
488
    DRIZZLE_TYPE_BLOB,
 
489
    //DRIZZLE_TYPE_VIRTUAL
 
490
    DRIZZLE_TYPE_VIRTUAL,
 
491
    //DRIZZLE_TYPE_NEWDECIMAL
 
492
    DRIZZLE_TYPE_BLOB,
 
493
    //DRIZZLE_TYPE_ENUM
 
494
    DRIZZLE_TYPE_BLOB,
 
495
    //DRIZZLE_TYPE_BLOB
381
496
    DRIZZLE_TYPE_BLOB,
382
497
  },
383
498
};
395
510
enum_field_types Field::field_type_merge(enum_field_types a,
396
511
                                         enum_field_types b)
397
512
{
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)];
 
513
  assert(a <= DRIZZLE_TYPE_MAX);
 
514
  assert(b <= DRIZZLE_TYPE_MAX);
 
515
  return field_types_merge_rules[a][b];
402
516
}
403
517
 
404
518
 
405
 
static Item_result field_types_result_type [FIELDTYPE_NUM]=
 
519
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
406
520
{
407
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
408
 
  DECIMAL_RESULT,           INT_RESULT,
 
521
  //DRIZZLE_TYPE_TINY
 
522
  INT_RESULT,
409
523
  //DRIZZLE_TYPE_LONG
410
524
  INT_RESULT,
411
525
  //DRIZZLE_TYPE_DOUBLE
412
526
  REAL_RESULT,
413
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
414
 
  STRING_RESULT,            STRING_RESULT,
 
527
  //DRIZZLE_TYPE_NULL
 
528
  STRING_RESULT,
 
529
  //DRIZZLE_TYPE_TIMESTAMP
 
530
  STRING_RESULT,
415
531
  //DRIZZLE_TYPE_LONGLONG
416
532
  INT_RESULT,
417
533
  //DRIZZLE_TYPE_TIME
418
534
  STRING_RESULT,
419
535
  //DRIZZLE_TYPE_DATETIME
420
536
  STRING_RESULT,
421
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
422
 
  STRING_RESULT,            STRING_RESULT,
 
537
  //DRIZZLE_TYPE_DATE
 
538
  STRING_RESULT,
 
539
  //DRIZZLE_TYPE_VARCHAR
 
540
  STRING_RESULT,
 
541
  //DRIZZLE_TYPE_VIRTUAL
 
542
  STRING_RESULT,
423
543
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
424
544
  DECIMAL_RESULT,           STRING_RESULT,
425
545
  //DRIZZLE_TYPE_BLOB
443
563
    true  - If string has some important data
444
564
*/
445
565
 
446
 
static bool
 
566
bool
447
567
test_if_important_data(const CHARSET_INFO * const cs, const char *str,
448
568
                       const char *strend)
449
569
{
453
573
}
454
574
 
455
575
 
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
576
Item_result Field::result_merge_type(enum_field_types field_type)
466
577
{
467
 
  assert(field_type < FIELDTYPE_TEAR_FROM || field_type
468
 
              > FIELDTYPE_TEAR_TO);
469
 
  return field_types_result_type[field_type2index(field_type)];
470
 
}
 
578
  assert(field_type <= DRIZZLE_TYPE_MAX);
 
579
  return field_types_result_type[field_type];
 
580
}
 
581
 
 
582
 
 
583
bool Field::eq(Field *field)
 
584
{
 
585
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
 
586
          null_bit == field->null_bit);
 
587
}
 
588
 
 
589
 
 
590
uint32_t Field::pack_length() const
 
591
{
 
592
  return field_length;
 
593
}
 
594
 
 
595
 
 
596
uint32_t Field::pack_length_in_rec() const
 
597
{
 
598
  return pack_length();
 
599
}
 
600
 
 
601
 
 
602
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
 
603
{
 
604
  return field_metadata;
 
605
}
 
606
 
 
607
 
 
608
uint32_t Field::row_pack_length()
 
609
{
 
610
  return 0;
 
611
}
 
612
 
 
613
 
 
614
int Field::save_field_metadata(unsigned char *first_byte)
 
615
{
 
616
  return do_save_field_metadata(first_byte);
 
617
}
 
618
 
 
619
 
 
620
uint32_t Field::data_length()
 
621
{
 
622
  return pack_length();
 
623
}
 
624
 
 
625
 
 
626
uint32_t Field::used_length()
 
627
{
 
628
  return pack_length();
 
629
}
 
630
 
 
631
 
 
632
uint32_t Field::sort_length() const
 
633
{
 
634
  return pack_length();
 
635
}
 
636
 
 
637
 
 
638
uint32_t Field::max_data_length() const
 
639
{
 
640
  return pack_length();
 
641
}
 
642
 
 
643
 
 
644
int Field::reset(void)
 
645
{
 
646
  memset(ptr, 0, pack_length());
 
647
  return 0;
 
648
}
 
649
 
 
650
 
 
651
void Field::reset_fields()
 
652
{}
 
653
 
 
654
 
 
655
void Field::set_default()
 
656
{
 
657
  my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
 
658
  memcpy(ptr, ptr + l_offset, pack_length());
 
659
  if (null_ptr)
 
660
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
 
661
}
 
662
 
 
663
 
 
664
bool Field::binary() const
 
665
{
 
666
  return 1;
 
667
}
 
668
 
 
669
 
 
670
bool Field::zero_pack() const
 
671
{
 
672
  return 1;
 
673
}
 
674
 
 
675
 
 
676
enum ha_base_keytype Field::key_type() const
 
677
{
 
678
  return HA_KEYTYPE_BINARY;
 
679
}
 
680
 
 
681
 
 
682
uint32_t Field::key_length() const
 
683
{
 
684
  return pack_length();
 
685
}
 
686
 
 
687
 
 
688
enum_field_types Field::real_type() const
 
689
{
 
690
  return type();
 
691
}
 
692
 
 
693
 
 
694
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
 
695
{
 
696
  return cmp(a, b);
 
697
}
 
698
 
 
699
 
 
700
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
 
701
{
 
702
  return memcmp(a,b,pack_length());
 
703
}
 
704
 
 
705
 
 
706
int Field::cmp_offset(uint32_t row_offset)
 
707
{
 
708
  return cmp(ptr,ptr+row_offset);
 
709
}
 
710
 
 
711
 
 
712
int Field::cmp_binary_offset(uint32_t row_offset)
 
713
{
 
714
  return cmp_binary(ptr, ptr+row_offset);
 
715
}
 
716
 
 
717
 
 
718
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
 
719
{
 
720
  return cmp(a, b);
 
721
}
 
722
 
 
723
 
 
724
int Field::key_cmp(const unsigned char *str, uint32_t)
 
725
{
 
726
  return cmp(ptr,str);
 
727
}
 
728
 
 
729
 
 
730
uint32_t Field::decimals() const
 
731
{
 
732
  return 0;
 
733
}
 
734
 
 
735
 
 
736
bool Field::is_null(my_ptrdiff_t row_offset)
 
737
{
 
738
  return null_ptr ?
 
739
    (null_ptr[row_offset] & null_bit ? true : false) :
 
740
    table->null_row;
 
741
}
 
742
 
 
743
 
 
744
bool Field::is_real_null(my_ptrdiff_t row_offset)
 
745
{
 
746
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
 
747
}
 
748
 
 
749
 
 
750
bool Field::is_null_in_record(const unsigned char *record)
 
751
{
 
752
  if (!null_ptr)
 
753
    return false;
 
754
  return test(record[(uint32_t) (null_ptr -table->record[0])] &
 
755
              null_bit);
 
756
}
 
757
 
 
758
 
 
759
bool Field::is_null_in_record_with_offset(my_ptrdiff_t with_offset)
 
760
{
 
761
  if (!null_ptr)
 
762
    return false;
 
763
  return test(null_ptr[with_offset] & null_bit);
 
764
}
 
765
 
 
766
 
 
767
void Field::set_null(my_ptrdiff_t row_offset)
 
768
{
 
769
  if (null_ptr)
 
770
    null_ptr[row_offset]|= null_bit;
 
771
}
 
772
 
 
773
 
 
774
void Field::set_notnull(my_ptrdiff_t row_offset)
 
775
{
 
776
  if (null_ptr)
 
777
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
 
778
}
 
779
 
 
780
 
 
781
bool Field::maybe_null(void)
 
782
{
 
783
  return null_ptr != 0 || table->maybe_null;
 
784
}
 
785
 
 
786
 
 
787
bool Field::real_maybe_null(void)
 
788
{
 
789
  return null_ptr != 0;
 
790
}
 
791
 
 
792
 
 
793
size_t Field::last_null_byte() const
 
794
{
 
795
  size_t bytes= do_last_null_byte();
 
796
  assert(bytes <= table->getNullBytes());
 
797
  return bytes;
 
798
}
 
799
 
471
800
 
472
801
/*****************************************************************************
473
802
  Static help functions
474
803
*****************************************************************************/
475
804
 
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
805
bool Field::type_can_have_key_part(enum enum_field_types type)
492
806
{
493
807
  switch (type) {
501
815
 
502
816
 
503
817
/**
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
818
  Process decimal library return codes and issue warnings for overflow and
634
819
  truncation.
635
820
 
657
842
}
658
843
 
659
844
 
 
845
void Field::init(Table *table_arg)
 
846
{
 
847
  orig_table= table= table_arg;
 
848
  table_name= &table_arg->alias;
 
849
}
 
850
 
 
851
 
660
852
#ifdef NOT_USED
661
853
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
662
854
{
692
884
    return 1;
693
885
  if (*str == 'E' || *str == 'e')
694
886
  {
695
 
    if (length < 3 || (str[1] != '+' && str[1] != '-') || 
 
887
    if (length < 3 || (str[1] != '+' && str[1] != '-') ||
696
888
        !my_isdigit(cs,str[2]))
697
889
      return 0;
698
890
    length-=3;
737
929
 
738
930
/// This is used as a table name when the table structure is not set up
739
931
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)
 
932
             unsigned char null_bit_arg,
 
933
             utype unireg_check_arg, const char *field_name_arg)
742
934
  :ptr(ptr_arg), null_ptr(null_ptr_arg),
743
935
   table(0), orig_table(0), table_name(0),
744
936
   field_name(field_name_arg),
745
937
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
746
938
   part_of_sortkey(0), unireg_check(unireg_check_arg),
747
 
   field_length(length_arg), null_bit(null_bit_arg), 
748
 
   is_created_from_null_item(false)
 
939
   field_length(length_arg), null_bit(null_bit_arg),
 
940
   is_created_from_null_item(false),
 
941
   vcol_info(NULL), is_stored(true)
749
942
{
750
943
  flags=null_ptr ? 0: NOT_NULL_FLAG;
751
944
  comment.str= (char*) "";
783
976
  memcpy(ptr,ptr+row_offset,pack_length());
784
977
  if (null_ptr)
785
978
  {
786
 
    *null_ptr= (unsigned char) ((null_ptr[0] & (unsigned char) ~(uint32_t) null_bit) | (null_ptr[row_offset] & (unsigned char) null_bit));
 
979
    *null_ptr= (unsigned char) ((null_ptr[0] &
 
980
                                 (unsigned char) ~(uint32_t) null_bit) |
 
981
                                (null_ptr[row_offset] &
 
982
                                 (unsigned char) null_bit));
787
983
  }
788
984
}
789
985
 
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
986
/**
801
987
   Check to see if field size is compatible with destination.
802
988
 
803
989
   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 
 
990
   field size is less than or equal to the master's field size. The
805
991
   encoded field metadata (from the master or source) is decoded and compared
806
 
   to the size of this field (the slave or destination). 
 
992
   to the size of this field (the slave or destination).
807
993
 
808
994
   @param   field_metadata   Encoded size in field metadata
809
995
 
818
1004
}
819
1005
 
820
1006
 
821
 
int Field::store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
 
1007
int Field::store(const char *to, uint32_t length,
 
1008
                 const CHARSET_INFO * const cs,
822
1009
                 enum_check_fields check_level)
823
1010
{
824
1011
  int res;
869
1056
*/
870
1057
unsigned char *
871
1058
Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length,
872
 
            bool low_byte_first __attribute__((unused)))
 
1059
            bool)
873
1060
{
874
1061
  uint32_t length= pack_length();
875
1062
  set_if_smaller(length, max_length);
877
1064
  return to+length;
878
1065
}
879
1066
 
 
1067
 
 
1068
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
 
1069
{
 
1070
  unsigned char *result= this->pack(to, from, UINT32_MAX,
 
1071
                                    table->s->db_low_byte_first);
 
1072
  return(result);
 
1073
}
 
1074
 
 
1075
 
880
1076
/**
881
1077
   Unpack a field from row data.
882
1078
 
909
1105
*/
910
1106
const unsigned char *
911
1107
Field::unpack(unsigned char* to, const unsigned char *from, uint32_t param_data,
912
 
              bool low_byte_first __attribute__((unused)))
 
1108
              bool)
913
1109
{
914
1110
  uint32_t length=pack_length();
915
1111
  int from_type= 0;
939
1135
}
940
1136
 
941
1137
 
942
 
my_decimal *Field::val_decimal(my_decimal *decimal __attribute__((unused)))
 
1138
const unsigned char *Field::unpack(unsigned char* to,
 
1139
                                   const unsigned char *from)
 
1140
{
 
1141
  const unsigned char *result= unpack(to, from, 0U,
 
1142
                                      table->s->db_low_byte_first);
 
1143
  return(result);
 
1144
}
 
1145
 
 
1146
 
 
1147
uint32_t Field::packed_col_length(const unsigned char *, uint32_t length)
 
1148
{
 
1149
  return length;
 
1150
}
 
1151
 
 
1152
 
 
1153
int Field::pack_cmp(const unsigned char *a, const unsigned char *b,
 
1154
                    uint32_t, bool)
 
1155
{
 
1156
  return cmp(a,b);
 
1157
}
 
1158
 
 
1159
 
 
1160
int Field::pack_cmp(const unsigned char *b, uint32_t, bool)
 
1161
{
 
1162
  return cmp(ptr,b);
 
1163
}
 
1164
 
 
1165
 
 
1166
my_decimal *Field::val_decimal(my_decimal *)
943
1167
{
944
1168
  /* This never have to be called */
945
1169
  assert(0);
947
1171
}
948
1172
 
949
1173
 
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
1174
void Field::make_field(Send_field *field)
958
1175
{
959
1176
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
993
1210
  @return
994
1211
    value converted from val
995
1212
*/
996
 
int64_t Field::convert_decimal2int64_t(const my_decimal *val,
997
 
                                         bool unsigned_flag, int *err)
 
1213
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
998
1214
{
999
1215
  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)))
 
1216
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
1217
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
 
1218
                                      val, false, &i)))
1019
1219
  {
1020
1220
    i= (val->sign() ? INT64_MIN : INT64_MAX);
1021
1221
    *err= 1;
1023
1223
  return i;
1024
1224
}
1025
1225
 
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
1226
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
1130
1227
{
1131
1228
  uint32_t store_length;
1176
1273
    Needs to be changed if/when we want to support different time formats.
1177
1274
*/
1178
1275
 
1179
 
int Field::store_time(DRIZZLE_TIME *ltime,
1180
 
                      enum enum_drizzle_timestamp_type type_arg __attribute__((unused)))
 
1276
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
1181
1277
{
1182
1278
  char buff[MAX_DATE_STRING_REP_LENGTH];
1183
1279
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
1191
1287
}
1192
1288
 
1193
1289
 
1194
 
Field *Field::new_field(MEM_ROOT *root, Table *new_table,
1195
 
                        bool keep_type __attribute__((unused)))
 
1290
Field *Field::new_field(MEM_ROOT *root, Table *new_table, bool)
1196
1291
{
1197
1292
  Field *tmp;
1198
1293
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1241
1336
}
1242
1337
 
1243
1338
 
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
 
 
 
1339
uint32_t Field::is_equal(Create_field *new_field_ptr)
 
1340
{
 
1341
  return (new_field_ptr->sql_type == real_type());
 
1342
}
1606
1343
 
1607
1344
/**
1608
1345
  @retval
1641
1378
  return 1;
1642
1379
}
1643
1380
 
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
1381
/*****************************************************************************
1673
1382
  Handling of field and Create_field
1674
1383
*****************************************************************************/
1687
1396
    pack_length= calc_pack_length(sql_type, length);
1688
1397
    break;
1689
1398
  case DRIZZLE_TYPE_ENUM:
1690
 
    /* Pack_length already calculated in sql_parse.cc */
 
1399
    /* Pack_length already calculated in ::init() */
1691
1400
    length*= charset->mbmaxlen;
1692
1401
    key_length= pack_length;
1693
1402
    break;
1723
1432
              ((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
1724
1433
              (maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
1725
1434
              (is_unsigned ? 0 : FIELDFLAG_DECIMAL));
 
1435
  vcol_info= NULL;
 
1436
  is_stored= true;
1726
1437
}
1727
1438
 
1728
1439
 
1729
1440
/**
1730
1441
  Initialize field definition for create.
1731
1442
 
1732
 
  @param thd                   Thread handle
 
1443
  @param session                   Thread handle
1733
1444
  @param fld_name              Field name
1734
1445
  @param fld_type              Field type
1735
1446
  @param fld_length            Field length
1741
1452
  @param fld_change            Field change
1742
1453
  @param fld_interval_list     Interval list (if any)
1743
1454
  @param fld_charset           Field charset
 
1455
  @param fld_vcol_info         Virtual column data
1744
1456
 
1745
1457
  @retval
1746
1458
    false on success
1748
1460
    true  on error
1749
1461
*/
1750
1462
 
1751
 
bool Create_field::init(THD *thd __attribute__((unused)), char *fld_name, enum_field_types fld_type,
 
1463
bool Create_field::init(Session *, char *fld_name, enum_field_types fld_type,
1752
1464
                        char *fld_length, char *fld_decimals,
1753
1465
                        uint32_t fld_type_modifier, Item *fld_default_value,
1754
1466
                        Item *fld_on_update_value, LEX_STRING *fld_comment,
1755
1467
                        char *fld_change, List<String> *fld_interval_list,
1756
1468
                        const CHARSET_INFO * const fld_charset,
1757
 
                        uint32_t fld_geom_type __attribute__((unused)),
1758
 
                        enum column_format_type column_format)
 
1469
                        uint32_t, enum column_format_type column_format_in,
 
1470
                        virtual_column_info *fld_vcol_info)
1759
1471
{
1760
1472
  uint32_t sign_len, allowed_type_modifier= 0;
1761
1473
  uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
1764
1476
  field_name= fld_name;
1765
1477
  def= fld_default_value;
1766
1478
  flags= fld_type_modifier;
1767
 
  flags|= (((uint32_t)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
 
1479
  flags|= (((uint32_t)column_format_in & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
1768
1480
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
1769
1481
                 Field::NEXT_NUMBER : Field::NONE);
1770
1482
  decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
1784
1496
  interval_list.empty();
1785
1497
 
1786
1498
  comment= *fld_comment;
 
1499
  vcol_info= fld_vcol_info;
 
1500
  is_stored= true;
 
1501
 
 
1502
  /* Initialize data for a virtual field */
 
1503
  if (fld_type == DRIZZLE_TYPE_VIRTUAL)
 
1504
  {
 
1505
    assert(vcol_info && vcol_info->expr_item);
 
1506
    is_stored= vcol_info->get_field_stored();
 
1507
    /*
 
1508
      Perform per item-type checks to determine if the expression is
 
1509
      allowed for a virtual column.
 
1510
      Note that validation of the specific function is done later in
 
1511
      procedures open_table_from_share and fix_fields_vcol_func
 
1512
    */
 
1513
    switch (vcol_info->expr_item->type()) {
 
1514
    case Item::FUNC_ITEM:
 
1515
         if (((Item_func *)vcol_info->expr_item)->functype() == Item_func::FUNC_SP)
 
1516
         {
 
1517
           my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), field_name);
 
1518
           return(true);
 
1519
         }
 
1520
         break;
 
1521
    case Item::COPY_STR_ITEM:
 
1522
    case Item::FIELD_AVG_ITEM:
 
1523
    case Item::PROC_ITEM:
 
1524
    case Item::REF_ITEM:
 
1525
    case Item::FIELD_STD_ITEM:
 
1526
    case Item::FIELD_VARIANCE_ITEM:
 
1527
    case Item::INSERT_VALUE_ITEM:
 
1528
    case Item::SUBSELECT_ITEM:
 
1529
    case Item::CACHE_ITEM:
 
1530
    case Item::TYPE_HOLDER:
 
1531
    case Item::PARAM_ITEM:
 
1532
         my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), field_name);
 
1533
         return true;
 
1534
         break;
 
1535
    default:
 
1536
      // Continue with the field creation
 
1537
      break;
 
1538
    }
 
1539
    /*
 
1540
      Make a field created for the real type.
 
1541
      Note that "real" and virtual fields differ from each other
 
1542
      only by Field::vcol_info, which is always 0 for normal columns.
 
1543
      vcol_info is updated for fields later in procedure open_binary_frm.
 
1544
    */
 
1545
    sql_type= fld_type= vcol_info->get_real_type();
 
1546
  }
 
1547
 
1787
1548
  /*
1788
1549
    Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
1789
1550
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
1882
1643
    if (fld_default_value)
1883
1644
    {
1884
1645
      /* Grammar allows only NOW() value for ON UPDATE clause */
1885
 
      if (fld_default_value->type() == Item::FUNC_ITEM && 
 
1646
      if (fld_default_value->type() == Item::FUNC_ITEM &&
1886
1647
          ((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
1887
1648
      {
1888
1649
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
1917
1678
                                              Field::NONE));
1918
1679
    }
1919
1680
    break;
1920
 
  case DRIZZLE_TYPE_NEWDATE:
 
1681
  case DRIZZLE_TYPE_DATE:
1921
1682
    length= 10;
1922
1683
    break;
1923
1684
  case DRIZZLE_TYPE_TIME:
1938
1699
      length= 1; /* See comment for DRIZZLE_TYPE_SET above. */
1939
1700
      break;
1940
1701
   }
 
1702
  case DRIZZLE_TYPE_VIRTUAL: // Must not happen
 
1703
    assert(0);
1941
1704
  }
1942
1705
  /* Remember the value of length */
1943
1706
  char_length= length;
1964
1727
}
1965
1728
 
1966
1729
 
1967
 
enum_field_types get_blob_type_from_length(uint32_t length __attribute__((unused)))
 
1730
enum_field_types get_blob_type_from_length(uint32_t)
1968
1731
{
1969
1732
  enum_field_types type;
1970
1733
 
1983
1746
  switch (type) {
1984
1747
  case DRIZZLE_TYPE_VARCHAR:     return (length + (length < 256 ? 1: 2));
1985
1748
  case DRIZZLE_TYPE_TINY        : return 1;
1986
 
  case DRIZZLE_TYPE_NEWDATE:
 
1749
  case DRIZZLE_TYPE_DATE:
1987
1750
  case DRIZZLE_TYPE_TIME:   return 3;
1988
1751
  case DRIZZLE_TYPE_TIMESTAMP:
1989
1752
  case DRIZZLE_TYPE_LONG        : return 4;
2004
1767
uint32_t pack_length_to_packflag(uint32_t type)
2005
1768
{
2006
1769
  switch (type) {
2007
 
    case 1: return f_settype((uint32_t) DRIZZLE_TYPE_TINY);
 
1770
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
2008
1771
    case 2: assert(1);
2009
1772
    case 3: assert(1);
2010
1773
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
2034
1797
  }
2035
1798
 
2036
1799
  switch (field_type) {
2037
 
  case DRIZZLE_TYPE_NEWDATE:
 
1800
  case DRIZZLE_TYPE_DATE:
2038
1801
  case DRIZZLE_TYPE_TIME:
2039
1802
  case DRIZZLE_TYPE_DATETIME:
2040
1803
  case DRIZZLE_TYPE_TIMESTAMP:
2067
1830
    if (interval)
2068
1831
    {
2069
1832
      if (f_is_enum(pack_flag))
 
1833
{
2070
1834
        return new Field_enum(ptr,field_length,null_pos,null_bit,
2071
1835
                                  unireg_check, field_name,
2072
 
                                  pack_length, interval, field_charset);
 
1836
                                  get_enum_pack_length(interval->count),
 
1837
                                  interval, field_charset);
 
1838
}
2073
1839
    }
2074
1840
  }
2075
1841
 
2087
1853
                            false,
2088
1854
                            f_is_dec(pack_flag)== 0);
2089
1855
  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);
 
1856
    assert(0);
2094
1857
  case DRIZZLE_TYPE_LONG:
2095
1858
    return new Field_long(ptr,field_length,null_pos,null_bit,
2096
1859
                           unireg_check, field_name,
2105
1868
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,
2106
1869
                               unireg_check, field_name, share,
2107
1870
                               field_charset);
2108
 
  case DRIZZLE_TYPE_NEWDATE:
2109
 
    return new Field_newdate(ptr,null_pos,null_bit,
 
1871
  case DRIZZLE_TYPE_DATE:
 
1872
    return new Field_date(ptr,null_pos,null_bit,
2110
1873
                             unireg_check, field_name, field_charset);
2111
1874
  case DRIZZLE_TYPE_TIME:
2112
1875
    return new Field_time(ptr,null_pos,null_bit,
2117
1880
  case DRIZZLE_TYPE_NULL:
2118
1881
    return new Field_null(ptr, field_length, unireg_check, field_name,
2119
1882
                          field_charset);
 
1883
  case DRIZZLE_TYPE_VIRTUAL:                    // Must not happen
 
1884
    assert(0);
2120
1885
  default:                                      // Impossible (Wrong version)
2121
1886
    break;
2122
1887
  }
2139
1904
  charset=    old_field->charset();             // May be NULL ptr
2140
1905
  comment=    old_field->comment;
2141
1906
  decimals=   old_field->decimals();
 
1907
  vcol_info=  old_field->vcol_info;
 
1908
  is_stored= old_field->is_stored;
2142
1909
 
2143
1910
  /* Fix if the original table had 4 byte pointer blobs */
2144
1911
  if (flags & BLOB_FLAG)
2171
1938
  if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
2172
1939
      old_field->ptr && orig_field &&
2173
1940
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
2174
 
       old_field->table->timestamp_field != old_field ||  /* timestamp field */ 
 
1941
       old_field->table->timestamp_field != old_field ||  /* timestamp field */
2175
1942
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
2176
1943
  {
2177
 
    char buff[MAX_FIELD_WIDTH];
2178
 
    String tmp(buff,sizeof(buff), charset);
2179
1944
    my_ptrdiff_t diff;
2180
1945
 
2181
1946
    /* Get the value from default_values */
2219
1984
    0 otherwise
2220
1985
*/
2221
1986
 
2222
 
bool 
 
1987
bool
2223
1988
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2224
1989
                   int cuted_increment)
2225
1990
{
2227
1992
    If this field was created only for type conversion purposes it
2228
1993
    will have table == NULL.
2229
1994
  */
2230
 
  THD *thd= table ? table->in_use : current_thd;
2231
 
  if (thd->count_cuted_fields)
 
1995
  Session *session= table ? table->in_use : current_session;
 
1996
  if (session->count_cuted_fields)
2232
1997
  {
2233
 
    thd->cuted_fields+= cuted_increment;
2234
 
    push_warning_printf(thd, level, code, ER(code), field_name,
2235
 
                        thd->row_count);
 
1998
    session->cuted_fields+= cuted_increment;
 
1999
    push_warning_printf(session, level, code, ER(code), field_name,
 
2000
                        session->row_count);
2236
2001
    return 0;
2237
2002
  }
2238
2003
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
2255
2020
    thread.
2256
2021
*/
2257
2022
 
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, 
 
2023
void
 
2024
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
 
2025
                            unsigned int code,
 
2026
                            const char *str, uint32_t str_length,
2262
2027
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
2263
2028
{
2264
 
  THD *thd= table ? table->in_use : current_thd;
2265
 
  if ((thd->really_abort_on_warning() &&
 
2029
  Session *session= table ? table->in_use : current_session;
 
2030
  if ((session->really_abort_on_warning() &&
2266
2031
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
2267
2032
      set_warning(level, code, cuted_increment))
2268
 
    make_truncated_value_warning(thd, level, str, str_length, ts_type,
 
2033
    make_truncated_value_warning(session, level, str, str_length, ts_type,
2269
2034
                                 field_name);
2270
2035
}
2271
2036
 
2285
2050
    thread.
2286
2051
*/
2287
2052
 
2288
 
void 
2289
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
2053
void
 
2054
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2290
2055
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
2291
2056
                            int cuted_increment)
2292
2057
{
2293
 
  THD *thd= table ? table->in_use : current_thd;
2294
 
  if (thd->really_abort_on_warning() ||
 
2058
  Session *session= table ? table->in_use : current_session;
 
2059
  if (session->really_abort_on_warning() ||
2295
2060
      set_warning(level, code, cuted_increment))
2296
2061
  {
2297
2062
    char str_nr[22];
2298
2063
    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), 
 
2064
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
2300
2065
                                 ts_type, field_name);
2301
2066
  }
2302
2067
}
2316
2081
    thread.
2317
2082
*/
2318
2083
 
2319
 
void 
2320
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
2084
void
 
2085
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, const uint32_t code,
2321
2086
                            double nr, enum enum_drizzle_timestamp_type ts_type)
2322
2087
{
2323
 
  THD *thd= table ? table->in_use : current_thd;
2324
 
  if (thd->really_abort_on_warning() ||
 
2088
  Session *session= table ? table->in_use : current_session;
 
2089
  if (session->really_abort_on_warning() ||
2325
2090
      set_warning(level, code, 1))
2326
2091
  {
2327
2092
    /* DBL_DIG is enough to print '-[digits].E+###' */
2328
2093
    char str_nr[DBL_DIG + 8];
2329
2094
    uint32_t str_len= sprintf(str_nr, "%g", nr);
2330
 
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
 
2095
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
2331
2096
                                 field_name);
2332
2097
  }
2333
2098
}
 
2099