~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 20:26:28 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321202628-nh6qsi825m4d4av6
Removing the queues.[h,cc] files from the mysys directory. The only place
where they are needed now is in the MyISAM storage engine. Thus, I moved the
files there and updated the files in the MyISAM storage engine
appropriately.

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/timestamp.h>
 
46
#include <drizzled/field/datetime.h>
 
47
#include <drizzled/field/varstring.h>
27
48
 
28
 
// Maximum allowed exponent value for converting string to decimal
29
 
#define MAX_EXPONENT 1024
30
49
 
31
50
/*****************************************************************************
32
51
  Instansiate templates and static variables
38
57
#endif
39
58
 
40
59
 
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
 
  },
 
60
static enum_field_types
 
61
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
 
62
{
84
63
  /* DRIZZLE_TYPE_TINY -> */
85
64
  {
86
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
87
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
88
 
  //DRIZZLE_TYPE_LONG
 
65
    //DRIZZLE_TYPE_TINY
 
66
    DRIZZLE_TYPE_TINY,
 
67
    //DRIZZLE_TYPE_LONG
89
68
    DRIZZLE_TYPE_LONG,
90
 
  //DRIZZLE_TYPE_DOUBLE
 
69
    //DRIZZLE_TYPE_DOUBLE
91
70
    DRIZZLE_TYPE_DOUBLE,
92
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
93
 
    DRIZZLE_TYPE_TINY,        DRIZZLE_TYPE_VARCHAR,
94
 
  //DRIZZLE_TYPE_LONGLONG
 
71
    //DRIZZLE_TYPE_NULL
 
72
    DRIZZLE_TYPE_TINY,
 
73
    //DRIZZLE_TYPE_TIMESTAMP
 
74
    DRIZZLE_TYPE_VARCHAR,
 
75
    //DRIZZLE_TYPE_LONGLONG
95
76
    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
 
77
    //DRIZZLE_TYPE_DATETIME
 
78
    DRIZZLE_TYPE_VARCHAR,
 
79
    //DRIZZLE_TYPE_DATE
 
80
    DRIZZLE_TYPE_VARCHAR,
 
81
    //DRIZZLE_TYPE_VARCHAR
 
82
    DRIZZLE_TYPE_VARCHAR,
 
83
    //DRIZZLE_TYPE_VIRTUAL
 
84
    DRIZZLE_TYPE_VIRTUAL,
 
85
    //DRIZZLE_TYPE_NEWDECIMAL
 
86
    DRIZZLE_TYPE_NEWDECIMAL,
 
87
    //DRIZZLE_TYPE_ENUM
 
88
    DRIZZLE_TYPE_VARCHAR,
 
89
    //DRIZZLE_TYPE_BLOB
105
90
    DRIZZLE_TYPE_BLOB,
106
91
  },
107
92
  /* DRIZZLE_TYPE_LONG -> */
108
93
  {
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
 
94
    //DRIZZLE_TYPE_TINY
 
95
    DRIZZLE_TYPE_LONG,
 
96
    //DRIZZLE_TYPE_LONG
 
97
    DRIZZLE_TYPE_LONG,
 
98
    //DRIZZLE_TYPE_DOUBLE
114
99
    DRIZZLE_TYPE_DOUBLE,
115
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
116
 
    DRIZZLE_TYPE_LONG,         DRIZZLE_TYPE_VARCHAR,
117
 
  //DRIZZLE_TYPE_LONGLONG
 
100
    //DRIZZLE_TYPE_NULL
 
101
    DRIZZLE_TYPE_LONG,
 
102
    //DRIZZLE_TYPE_TIMESTAMP
 
103
    DRIZZLE_TYPE_VARCHAR,
 
104
    //DRIZZLE_TYPE_LONGLONG
118
105
    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
 
106
    //DRIZZLE_TYPE_DATETIME
 
107
    DRIZZLE_TYPE_VARCHAR,
 
108
    //DRIZZLE_TYPE_DATE
 
109
    DRIZZLE_TYPE_VARCHAR,
 
110
    //DRIZZLE_TYPE_VARCHAR
 
111
    DRIZZLE_TYPE_VARCHAR,
 
112
    //DRIZZLE_TYPE_VIRTUAL
 
113
    DRIZZLE_TYPE_VIRTUAL,
 
114
    //DRIZZLE_TYPE_NEWDECIMAL
 
115
    DRIZZLE_TYPE_NEWDECIMAL,
 
116
    //DRIZZLE_TYPE_ENUM
 
117
    DRIZZLE_TYPE_VARCHAR,
 
118
    //DRIZZLE_TYPE_BLOB
128
119
    DRIZZLE_TYPE_BLOB,
129
120
  },
130
121
  /* DRIZZLE_TYPE_DOUBLE -> */
131
122
  {
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
 
123
    //DRIZZLE_TYPE_TINY
 
124
    DRIZZLE_TYPE_DOUBLE,
 
125
    //DRIZZLE_TYPE_LONG
 
126
    DRIZZLE_TYPE_DOUBLE,
 
127
    //DRIZZLE_TYPE_DOUBLE
 
128
    DRIZZLE_TYPE_DOUBLE,
 
129
    //DRIZZLE_TYPE_NULL
 
130
    DRIZZLE_TYPE_DOUBLE,
 
131
    //DRIZZLE_TYPE_TIMESTAMP
 
132
    DRIZZLE_TYPE_VARCHAR,
 
133
    //DRIZZLE_TYPE_LONGLONG
 
134
    DRIZZLE_TYPE_DOUBLE,
 
135
    //DRIZZLE_TYPE_DATETIME
 
136
    DRIZZLE_TYPE_VARCHAR,
 
137
    //DRIZZLE_TYPE_DATE
 
138
    DRIZZLE_TYPE_VARCHAR,
 
139
    //DRIZZLE_TYPE_VARCHAR
 
140
    DRIZZLE_TYPE_VARCHAR,
 
141
    //DRIZZLE_TYPE_VIRTUAL
 
142
    DRIZZLE_TYPE_VIRTUAL,
 
143
    //DRIZZLE_TYPE_NEWDECIMAL
 
144
    DRIZZLE_TYPE_DOUBLE,
 
145
    //DRIZZLE_TYPE_ENUM
 
146
    DRIZZLE_TYPE_VARCHAR,
 
147
    //DRIZZLE_TYPE_BLOB
151
148
    DRIZZLE_TYPE_BLOB,
152
149
  },
153
150
  /* DRIZZLE_TYPE_NULL -> */
154
151
  {
155
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
156
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
157
 
  //DRIZZLE_TYPE_LONG
 
152
    //DRIZZLE_TYPE_TINY
 
153
    DRIZZLE_TYPE_TINY,
 
154
    //DRIZZLE_TYPE_LONG
158
155
    DRIZZLE_TYPE_LONG,
159
 
  //DRIZZLE_TYPE_DOUBLE
 
156
    //DRIZZLE_TYPE_DOUBLE
160
157
    DRIZZLE_TYPE_DOUBLE,
161
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
162
 
    DRIZZLE_TYPE_NULL,        DRIZZLE_TYPE_TIMESTAMP,
163
 
  //DRIZZLE_TYPE_LONGLONG
 
158
    //DRIZZLE_TYPE_NULL
 
159
    DRIZZLE_TYPE_NULL,
 
160
    //DRIZZLE_TYPE_TIMESTAMP
 
161
    DRIZZLE_TYPE_TIMESTAMP,
 
162
    //DRIZZLE_TYPE_LONGLONG
164
163
    DRIZZLE_TYPE_LONGLONG,
165
 
  //DRIZZLE_TYPE_TIME
166
 
    DRIZZLE_TYPE_TIME,
167
 
  //DRIZZLE_TYPE_DATETIME
 
164
    //DRIZZLE_TYPE_DATETIME
168
165
    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
 
166
    //DRIZZLE_TYPE_DATE
 
167
    DRIZZLE_TYPE_DATE,
 
168
    //DRIZZLE_TYPE_VARCHAR
 
169
    DRIZZLE_TYPE_VARCHAR,
 
170
    //DRIZZLE_TYPE_VIRTUAL
 
171
    DRIZZLE_TYPE_VIRTUAL,
 
172
    //DRIZZLE_TYPE_NEWDECIMAL
 
173
    DRIZZLE_TYPE_NEWDECIMAL,
 
174
    //DRIZZLE_TYPE_ENUM
 
175
    DRIZZLE_TYPE_ENUM,
 
176
    //DRIZZLE_TYPE_BLOB
174
177
    DRIZZLE_TYPE_BLOB,
175
178
  },
176
179
  /* DRIZZLE_TYPE_TIMESTAMP -> */
177
180
  {
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
 
181
    //DRIZZLE_TYPE_TINY
 
182
    DRIZZLE_TYPE_VARCHAR,
 
183
    //DRIZZLE_TYPE_LONG
 
184
    DRIZZLE_TYPE_VARCHAR,
 
185
    //DRIZZLE_TYPE_DOUBLE
 
186
    DRIZZLE_TYPE_VARCHAR,
 
187
    //DRIZZLE_TYPE_NULL
 
188
    DRIZZLE_TYPE_TIMESTAMP,
 
189
    //DRIZZLE_TYPE_TIMESTAMP
 
190
    DRIZZLE_TYPE_TIMESTAMP,
 
191
    //DRIZZLE_TYPE_LONGLONG
 
192
    DRIZZLE_TYPE_VARCHAR,
 
193
    //DRIZZLE_TYPE_DATETIME
 
194
    DRIZZLE_TYPE_DATETIME,
 
195
    //DRIZZLE_TYPE_DATE
 
196
    DRIZZLE_TYPE_DATE,
 
197
    //DRIZZLE_TYPE_VARCHAR
 
198
    DRIZZLE_TYPE_VARCHAR,
 
199
    //DRIZZLE_TYPE_VIRTUAL
 
200
    DRIZZLE_TYPE_VIRTUAL,
 
201
    //DRIZZLE_TYPE_NEWDECIMAL
 
202
    DRIZZLE_TYPE_VARCHAR,
 
203
    //DRIZZLE_TYPE_ENUM
 
204
    DRIZZLE_TYPE_VARCHAR,
 
205
    //DRIZZLE_TYPE_BLOB
197
206
    DRIZZLE_TYPE_BLOB,
198
207
  },
199
208
  /* DRIZZLE_TYPE_LONGLONG -> */
200
209
  {
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
 
210
    //DRIZZLE_TYPE_TINY
 
211
    DRIZZLE_TYPE_LONGLONG,
 
212
    //DRIZZLE_TYPE_LONG
 
213
    DRIZZLE_TYPE_LONGLONG,
 
214
    //DRIZZLE_TYPE_DOUBLE
206
215
    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
 
216
    //DRIZZLE_TYPE_NULL
 
217
    DRIZZLE_TYPE_LONGLONG,
 
218
    //DRIZZLE_TYPE_TIMESTAMP
 
219
    DRIZZLE_TYPE_VARCHAR,
 
220
    //DRIZZLE_TYPE_LONGLONG
 
221
    DRIZZLE_TYPE_LONGLONG,
 
222
    //DRIZZLE_TYPE_DATETIME
 
223
    DRIZZLE_TYPE_VARCHAR,
 
224
    //DRIZZLE_TYPE_DATE
 
225
    DRIZZLE_TYPE_DATE,
 
226
    //DRIZZLE_TYPE_VARCHAR
 
227
    DRIZZLE_TYPE_VARCHAR,
 
228
    //DRIZZLE_TYPE_VIRTUAL
 
229
    DRIZZLE_TYPE_VIRTUAL,
 
230
    //DRIZZLE_TYPE_NEWDECIMAL
 
231
    //DRIZZLE_TYPE_ENUM
 
232
    DRIZZLE_TYPE_NEWDECIMAL,
 
233
    DRIZZLE_TYPE_VARCHAR,
 
234
    //DRIZZLE_TYPE_BLOB
243
235
    DRIZZLE_TYPE_BLOB,
244
236
  },
245
237
  /* DRIZZLE_TYPE_DATETIME -> */
246
238
  {
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
 
239
    //DRIZZLE_TYPE_TINY
 
240
    DRIZZLE_TYPE_VARCHAR,
 
241
    //DRIZZLE_TYPE_LONG
 
242
    DRIZZLE_TYPE_VARCHAR,
 
243
    //DRIZZLE_TYPE_DOUBLE
 
244
    DRIZZLE_TYPE_VARCHAR,
 
245
    //DRIZZLE_TYPE_NULL
 
246
    DRIZZLE_TYPE_DATETIME,
 
247
    //DRIZZLE_TYPE_TIMESTAMP
 
248
    DRIZZLE_TYPE_DATETIME,
 
249
    //DRIZZLE_TYPE_LONGLONG
 
250
    DRIZZLE_TYPE_VARCHAR,
 
251
    //DRIZZLE_TYPE_DATETIME
 
252
    DRIZZLE_TYPE_DATETIME,
 
253
    //DRIZZLE_TYPE_DATE
 
254
    DRIZZLE_TYPE_DATE,
 
255
    //DRIZZLE_TYPE_VARCHAR
 
256
    DRIZZLE_TYPE_VARCHAR,
 
257
    //DRIZZLE_TYPE_VIRTUAL
 
258
    DRIZZLE_TYPE_VIRTUAL,
 
259
    //DRIZZLE_TYPE_NEWDECIMAL
 
260
    DRIZZLE_TYPE_VARCHAR,
 
261
    //DRIZZLE_TYPE_ENUM
 
262
    DRIZZLE_TYPE_VARCHAR,
 
263
    //DRIZZLE_TYPE_BLOB
266
264
    DRIZZLE_TYPE_BLOB,
267
265
  },
268
 
  /* DRIZZLE_TYPE_NEWDATE -> */
 
266
  /* DRIZZLE_TYPE_DATE -> */
269
267
  {
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
 
268
    //DRIZZLE_TYPE_TINY
 
269
    DRIZZLE_TYPE_VARCHAR,
 
270
    //DRIZZLE_TYPE_LONG
 
271
    DRIZZLE_TYPE_VARCHAR,
 
272
    //DRIZZLE_TYPE_DOUBLE
 
273
    DRIZZLE_TYPE_VARCHAR,
 
274
    //DRIZZLE_TYPE_NULL
 
275
    DRIZZLE_TYPE_DATE,
 
276
    //DRIZZLE_TYPE_TIMESTAMP
 
277
    DRIZZLE_TYPE_DATETIME,
 
278
    //DRIZZLE_TYPE_LONGLONG
 
279
    DRIZZLE_TYPE_VARCHAR,
 
280
    //DRIZZLE_TYPE_DATETIME
 
281
    DRIZZLE_TYPE_DATETIME,
 
282
    //DRIZZLE_TYPE_DATE
 
283
    DRIZZLE_TYPE_DATE,
 
284
    //DRIZZLE_TYPE_VARCHAR
 
285
    DRIZZLE_TYPE_VARCHAR,
 
286
    //DRIZZLE_TYPE_VIRTUAL
 
287
    DRIZZLE_TYPE_VIRTUAL,
 
288
    //DRIZZLE_TYPE_NEWDECIMAL
 
289
    DRIZZLE_TYPE_VARCHAR,
 
290
    //DRIZZLE_TYPE_ENUM
 
291
    DRIZZLE_TYPE_VARCHAR,
 
292
    //DRIZZLE_TYPE_BLOB
289
293
    DRIZZLE_TYPE_BLOB,
290
294
  },
291
295
  /* DRIZZLE_TYPE_VARCHAR -> */
292
296
  {
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
 
297
    //DRIZZLE_TYPE_TINY
 
298
    DRIZZLE_TYPE_VARCHAR,
 
299
    //DRIZZLE_TYPE_LONG
 
300
    DRIZZLE_TYPE_VARCHAR,
 
301
    //DRIZZLE_TYPE_DOUBLE
 
302
    DRIZZLE_TYPE_VARCHAR,
 
303
    //DRIZZLE_TYPE_NULL
 
304
    DRIZZLE_TYPE_VARCHAR,
 
305
    //DRIZZLE_TYPE_TIMESTAMP
 
306
    DRIZZLE_TYPE_VARCHAR,
 
307
    //DRIZZLE_TYPE_LONGLONG
 
308
    DRIZZLE_TYPE_VARCHAR,
 
309
    //DRIZZLE_TYPE_DATETIME
 
310
    DRIZZLE_TYPE_VARCHAR,
 
311
    //DRIZZLE_TYPE_DATE
 
312
    DRIZZLE_TYPE_VARCHAR,
 
313
    //DRIZZLE_TYPE_VARCHAR
 
314
    DRIZZLE_TYPE_VARCHAR,
 
315
    //DRIZZLE_TYPE_VIRTUAL
 
316
    DRIZZLE_TYPE_VIRTUAL,
 
317
    //DRIZZLE_TYPE_NEWDECIMAL
 
318
    DRIZZLE_TYPE_VARCHAR,
 
319
    //DRIZZLE_TYPE_ENUM
 
320
    DRIZZLE_TYPE_VARCHAR,
 
321
    //DRIZZLE_TYPE_BLOB
312
322
    DRIZZLE_TYPE_BLOB,
313
323
  },
 
324
  /* DRIZZLE_TYPE_VIRTUAL -> */
 
325
  {
 
326
    //DRIZZLE_TYPE_TINY
 
327
    DRIZZLE_TYPE_VIRTUAL,
 
328
    //DRIZZLE_TYPE_LONG
 
329
    DRIZZLE_TYPE_VIRTUAL,
 
330
    //DRIZZLE_TYPE_DOUBLE
 
331
    DRIZZLE_TYPE_VIRTUAL,
 
332
    //DRIZZLE_TYPE_NULL
 
333
    DRIZZLE_TYPE_VIRTUAL,
 
334
    //DRIZZLE_TYPE_TIMESTAMP
 
335
    DRIZZLE_TYPE_VIRTUAL,
 
336
    //DRIZZLE_TYPE_LONGLONG
 
337
    DRIZZLE_TYPE_VIRTUAL,
 
338
    //DRIZZLE_TYPE_DATETIME
 
339
    DRIZZLE_TYPE_VIRTUAL,
 
340
    //DRIZZLE_TYPE_DATE
 
341
    DRIZZLE_TYPE_VIRTUAL,
 
342
    //DRIZZLE_TYPE_VARCHAR
 
343
    DRIZZLE_TYPE_VIRTUAL,
 
344
    //DRIZZLE_TYPE_VIRTUAL
 
345
    DRIZZLE_TYPE_VIRTUAL,
 
346
    //DRIZZLE_TYPE_NEWDECIMAL
 
347
    DRIZZLE_TYPE_VIRTUAL,
 
348
    //DRIZZLE_TYPE_ENUM
 
349
    DRIZZLE_TYPE_VIRTUAL,
 
350
    //DRIZZLE_TYPE_BLOB
 
351
    DRIZZLE_TYPE_VIRTUAL,
 
352
  },
314
353
  /* DRIZZLE_TYPE_NEWDECIMAL -> */
315
354
  {
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
 
355
    //DRIZZLE_TYPE_TINY
 
356
    DRIZZLE_TYPE_NEWDECIMAL,
 
357
    //DRIZZLE_TYPE_LONG
 
358
    DRIZZLE_TYPE_NEWDECIMAL,
 
359
    //DRIZZLE_TYPE_DOUBLE
321
360
    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
 
361
    //DRIZZLE_TYPE_NULL
 
362
    DRIZZLE_TYPE_NEWDECIMAL,
 
363
    //DRIZZLE_TYPE_TIMESTAMP
 
364
    DRIZZLE_TYPE_VARCHAR,
 
365
    //DRIZZLE_TYPE_LONGLONG
 
366
    DRIZZLE_TYPE_NEWDECIMAL,
 
367
    //DRIZZLE_TYPE_DATETIME
 
368
    DRIZZLE_TYPE_VARCHAR,
 
369
    //DRIZZLE_TYPE_DATE
 
370
    DRIZZLE_TYPE_VARCHAR,
 
371
    //DRIZZLE_TYPE_VARCHAR
 
372
    DRIZZLE_TYPE_VARCHAR,
 
373
    //DRIZZLE_TYPE_VIRTUAL
 
374
    DRIZZLE_TYPE_VIRTUAL,
 
375
    //DRIZZLE_TYPE_NEWDECIMAL
 
376
    DRIZZLE_TYPE_NEWDECIMAL,
 
377
    //DRIZZLE_TYPE_ENUM
 
378
    DRIZZLE_TYPE_VARCHAR,
 
379
    //DRIZZLE_TYPE_BLOB
335
380
    DRIZZLE_TYPE_BLOB,
336
381
  },
337
382
  /* DRIZZLE_TYPE_ENUM -> */
338
383
  {
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
 
384
    //DRIZZLE_TYPE_TINY
 
385
    DRIZZLE_TYPE_VARCHAR,
 
386
    //DRIZZLE_TYPE_LONG
 
387
    DRIZZLE_TYPE_VARCHAR,
 
388
    //DRIZZLE_TYPE_DOUBLE
 
389
    DRIZZLE_TYPE_VARCHAR,
 
390
    //DRIZZLE_TYPE_NULL
 
391
    DRIZZLE_TYPE_ENUM,
 
392
    //DRIZZLE_TYPE_TIMESTAMP
 
393
    DRIZZLE_TYPE_VARCHAR,
 
394
    //DRIZZLE_TYPE_LONGLONG
 
395
    DRIZZLE_TYPE_VARCHAR,
 
396
    //DRIZZLE_TYPE_DATETIME
 
397
    DRIZZLE_TYPE_VARCHAR,
 
398
    //DRIZZLE_TYPE_DATE
 
399
    DRIZZLE_TYPE_VARCHAR,
 
400
    //DRIZZLE_TYPE_VARCHAR
 
401
    DRIZZLE_TYPE_VARCHAR,
 
402
    //DRIZZLE_TYPE_VIRTUAL
 
403
    DRIZZLE_TYPE_VIRTUAL,
 
404
    //DRIZZLE_TYPE_NEWDECIMAL
 
405
    DRIZZLE_TYPE_VARCHAR,
 
406
    //DRIZZLE_TYPE_ENUM
 
407
    DRIZZLE_TYPE_VARCHAR,
 
408
    //DRIZZLE_TYPE_BLOB
358
409
    DRIZZLE_TYPE_BLOB,
359
410
  },
360
411
  /* DRIZZLE_TYPE_BLOB -> */
361
412
  {
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
 
413
    //DRIZZLE_TYPE_TINY
 
414
    DRIZZLE_TYPE_BLOB,
 
415
    //DRIZZLE_TYPE_LONG
 
416
    DRIZZLE_TYPE_BLOB,
 
417
    //DRIZZLE_TYPE_DOUBLE
 
418
    DRIZZLE_TYPE_BLOB,
 
419
    //DRIZZLE_TYPE_NULL
 
420
    DRIZZLE_TYPE_BLOB,
 
421
    //DRIZZLE_TYPE_TIMESTAMP
 
422
    DRIZZLE_TYPE_BLOB,
 
423
    //DRIZZLE_TYPE_LONGLONG
 
424
    DRIZZLE_TYPE_BLOB,
 
425
    //DRIZZLE_TYPE_DATETIME
 
426
    DRIZZLE_TYPE_BLOB,
 
427
    //DRIZZLE_TYPE_DATE
 
428
    DRIZZLE_TYPE_BLOB,
 
429
    //DRIZZLE_TYPE_VARCHAR
 
430
    DRIZZLE_TYPE_BLOB,
 
431
    //DRIZZLE_TYPE_VIRTUAL
 
432
    DRIZZLE_TYPE_VIRTUAL,
 
433
    //DRIZZLE_TYPE_NEWDECIMAL
 
434
    DRIZZLE_TYPE_BLOB,
 
435
    //DRIZZLE_TYPE_ENUM
 
436
    DRIZZLE_TYPE_BLOB,
 
437
    //DRIZZLE_TYPE_BLOB
381
438
    DRIZZLE_TYPE_BLOB,
382
439
  },
383
440
};
395
452
enum_field_types Field::field_type_merge(enum_field_types a,
396
453
                                         enum_field_types b)
397
454
{
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)];
 
455
  assert(a <= DRIZZLE_TYPE_MAX);
 
456
  assert(b <= DRIZZLE_TYPE_MAX);
 
457
  return field_types_merge_rules[a][b];
402
458
}
403
459
 
404
460
 
405
 
static Item_result field_types_result_type [FIELDTYPE_NUM]=
 
461
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
406
462
{
407
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
408
 
  DECIMAL_RESULT,           INT_RESULT,
 
463
  //DRIZZLE_TYPE_TINY
 
464
  INT_RESULT,
409
465
  //DRIZZLE_TYPE_LONG
410
466
  INT_RESULT,
411
467
  //DRIZZLE_TYPE_DOUBLE
412
468
  REAL_RESULT,
413
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
414
 
  STRING_RESULT,            STRING_RESULT,
 
469
  //DRIZZLE_TYPE_NULL
 
470
  STRING_RESULT,
 
471
  //DRIZZLE_TYPE_TIMESTAMP
 
472
  STRING_RESULT,
415
473
  //DRIZZLE_TYPE_LONGLONG
416
474
  INT_RESULT,
417
 
  //DRIZZLE_TYPE_TIME
418
 
  STRING_RESULT,
419
475
  //DRIZZLE_TYPE_DATETIME
420
476
  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,
 
477
  //DRIZZLE_TYPE_DATE
 
478
  STRING_RESULT,
 
479
  //DRIZZLE_TYPE_VARCHAR
 
480
  STRING_RESULT,
 
481
  //DRIZZLE_TYPE_VIRTUAL
 
482
  STRING_RESULT,
 
483
  //DRIZZLE_TYPE_NEWDECIMAL   
 
484
  DECIMAL_RESULT,           
 
485
  //DRIZZLE_TYPE_ENUM
 
486
  STRING_RESULT,
425
487
  //DRIZZLE_TYPE_BLOB
426
488
  STRING_RESULT,
427
489
};
443
505
    true  - If string has some important data
444
506
*/
445
507
 
446
 
static bool
 
508
bool
447
509
test_if_important_data(const CHARSET_INFO * const cs, const char *str,
448
510
                       const char *strend)
449
511
{
453
515
}
454
516
 
455
517
 
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
518
Item_result Field::result_merge_type(enum_field_types field_type)
466
519
{
467
 
  assert(field_type < FIELDTYPE_TEAR_FROM || field_type
468
 
              > FIELDTYPE_TEAR_TO);
469
 
  return field_types_result_type[field_type2index(field_type)];
470
 
}
 
520
  assert(field_type <= DRIZZLE_TYPE_MAX);
 
521
  return field_types_result_type[field_type];
 
522
}
 
523
 
 
524
 
 
525
bool Field::eq(Field *field)
 
526
{
 
527
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
 
528
          null_bit == field->null_bit);
 
529
}
 
530
 
 
531
 
 
532
uint32_t Field::pack_length() const
 
533
{
 
534
  return field_length;
 
535
}
 
536
 
 
537
 
 
538
uint32_t Field::pack_length_in_rec() const
 
539
{
 
540
  return pack_length();
 
541
}
 
542
 
 
543
 
 
544
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
 
545
{
 
546
  return field_metadata;
 
547
}
 
548
 
 
549
 
 
550
uint32_t Field::row_pack_length()
 
551
{
 
552
  return 0;
 
553
}
 
554
 
 
555
 
 
556
int Field::save_field_metadata(unsigned char *first_byte)
 
557
{
 
558
  return do_save_field_metadata(first_byte);
 
559
}
 
560
 
 
561
 
 
562
uint32_t Field::data_length()
 
563
{
 
564
  return pack_length();
 
565
}
 
566
 
 
567
 
 
568
uint32_t Field::used_length()
 
569
{
 
570
  return pack_length();
 
571
}
 
572
 
 
573
 
 
574
uint32_t Field::sort_length() const
 
575
{
 
576
  return pack_length();
 
577
}
 
578
 
 
579
 
 
580
uint32_t Field::max_data_length() const
 
581
{
 
582
  return pack_length();
 
583
}
 
584
 
 
585
 
 
586
int Field::reset(void)
 
587
{
 
588
  memset(ptr, 0, pack_length());
 
589
  return 0;
 
590
}
 
591
 
 
592
 
 
593
void Field::reset_fields()
 
594
{}
 
595
 
 
596
 
 
597
void Field::set_default()
 
598
{
 
599
  my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
 
600
  memcpy(ptr, ptr + l_offset, pack_length());
 
601
  if (null_ptr)
 
602
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
 
603
}
 
604
 
 
605
 
 
606
bool Field::binary() const
 
607
{
 
608
  return 1;
 
609
}
 
610
 
 
611
 
 
612
bool Field::zero_pack() const
 
613
{
 
614
  return 1;
 
615
}
 
616
 
 
617
 
 
618
enum ha_base_keytype Field::key_type() const
 
619
{
 
620
  return HA_KEYTYPE_BINARY;
 
621
}
 
622
 
 
623
 
 
624
uint32_t Field::key_length() const
 
625
{
 
626
  return pack_length();
 
627
}
 
628
 
 
629
 
 
630
enum_field_types Field::real_type() const
 
631
{
 
632
  return type();
 
633
}
 
634
 
 
635
 
 
636
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
 
637
{
 
638
  return cmp(a, b);
 
639
}
 
640
 
 
641
 
 
642
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
 
643
{
 
644
  return memcmp(a,b,pack_length());
 
645
}
 
646
 
 
647
 
 
648
int Field::cmp_offset(uint32_t row_offset)
 
649
{
 
650
  return cmp(ptr,ptr+row_offset);
 
651
}
 
652
 
 
653
 
 
654
int Field::cmp_binary_offset(uint32_t row_offset)
 
655
{
 
656
  return cmp_binary(ptr, ptr+row_offset);
 
657
}
 
658
 
 
659
 
 
660
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
 
661
{
 
662
  return cmp(a, b);
 
663
}
 
664
 
 
665
 
 
666
int Field::key_cmp(const unsigned char *str, uint32_t)
 
667
{
 
668
  return cmp(ptr,str);
 
669
}
 
670
 
 
671
 
 
672
uint32_t Field::decimals() const
 
673
{
 
674
  return 0;
 
675
}
 
676
 
 
677
 
 
678
bool Field::is_null(my_ptrdiff_t row_offset)
 
679
{
 
680
  return null_ptr ?
 
681
    (null_ptr[row_offset] & null_bit ? true : false) :
 
682
    table->null_row;
 
683
}
 
684
 
 
685
 
 
686
bool Field::is_real_null(my_ptrdiff_t row_offset)
 
687
{
 
688
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
 
689
}
 
690
 
 
691
 
 
692
bool Field::is_null_in_record(const unsigned char *record)
 
693
{
 
694
  if (!null_ptr)
 
695
    return false;
 
696
  return test(record[(uint32_t) (null_ptr -table->record[0])] &
 
697
              null_bit);
 
698
}
 
699
 
 
700
 
 
701
bool Field::is_null_in_record_with_offset(my_ptrdiff_t with_offset)
 
702
{
 
703
  if (!null_ptr)
 
704
    return false;
 
705
  return test(null_ptr[with_offset] & null_bit);
 
706
}
 
707
 
 
708
 
 
709
void Field::set_null(my_ptrdiff_t row_offset)
 
710
{
 
711
  if (null_ptr)
 
712
    null_ptr[row_offset]|= null_bit;
 
713
}
 
714
 
 
715
 
 
716
void Field::set_notnull(my_ptrdiff_t row_offset)
 
717
{
 
718
  if (null_ptr)
 
719
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
 
720
}
 
721
 
 
722
 
 
723
bool Field::maybe_null(void)
 
724
{
 
725
  return null_ptr != 0 || table->maybe_null;
 
726
}
 
727
 
 
728
 
 
729
bool Field::real_maybe_null(void)
 
730
{
 
731
  return null_ptr != 0;
 
732
}
 
733
 
 
734
 
 
735
size_t Field::last_null_byte() const
 
736
{
 
737
  size_t bytes= do_last_null_byte();
 
738
  assert(bytes <= table->getNullBytes());
 
739
  return bytes;
 
740
}
 
741
 
471
742
 
472
743
/*****************************************************************************
473
744
  Static help functions
474
745
*****************************************************************************/
475
746
 
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
747
bool Field::type_can_have_key_part(enum enum_field_types type)
492
748
{
493
749
  switch (type) {
501
757
 
502
758
 
503
759
/**
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
760
  Process decimal library return codes and issue warnings for overflow and
634
761
  truncation.
635
762
 
657
784
}
658
785
 
659
786
 
 
787
void Field::init(Table *table_arg)
 
788
{
 
789
  orig_table= table= table_arg;
 
790
  table_name= &table_arg->alias;
 
791
}
 
792
 
 
793
 
660
794
#ifdef NOT_USED
661
795
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
662
796
{
692
826
    return 1;
693
827
  if (*str == 'E' || *str == 'e')
694
828
  {
695
 
    if (length < 3 || (str[1] != '+' && str[1] != '-') || 
 
829
    if (length < 3 || (str[1] != '+' && str[1] != '-') ||
696
830
        !my_isdigit(cs,str[2]))
697
831
      return 0;
698
832
    length-=3;
737
871
 
738
872
/// This is used as a table name when the table structure is not set up
739
873
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)
 
874
             unsigned char null_bit_arg,
 
875
             utype unireg_check_arg, const char *field_name_arg)
742
876
  :ptr(ptr_arg), null_ptr(null_ptr_arg),
743
877
   table(0), orig_table(0), table_name(0),
744
878
   field_name(field_name_arg),
745
879
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
746
880
   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)
 
881
   field_length(length_arg), null_bit(null_bit_arg),
 
882
   is_created_from_null_item(false),
 
883
   vcol_info(NULL), is_stored(true)
749
884
{
750
885
  flags=null_ptr ? 0: NOT_NULL_FLAG;
751
886
  comment.str= (char*) "";
783
918
  memcpy(ptr,ptr+row_offset,pack_length());
784
919
  if (null_ptr)
785
920
  {
786
 
    *null_ptr= (unsigned char) ((null_ptr[0] & (unsigned char) ~(uint32_t) null_bit) | (null_ptr[row_offset] & (unsigned char) null_bit));
 
921
    *null_ptr= (unsigned char) ((null_ptr[0] &
 
922
                                 (unsigned char) ~(uint32_t) null_bit) |
 
923
                                (null_ptr[row_offset] &
 
924
                                 (unsigned char) null_bit));
787
925
  }
788
926
}
789
927
 
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
928
/**
801
929
   Check to see if field size is compatible with destination.
802
930
 
803
931
   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 
 
932
   field size is less than or equal to the master's field size. The
805
933
   encoded field metadata (from the master or source) is decoded and compared
806
 
   to the size of this field (the slave or destination). 
 
934
   to the size of this field (the slave or destination).
807
935
 
808
936
   @param   field_metadata   Encoded size in field metadata
809
937
 
818
946
}
819
947
 
820
948
 
821
 
int Field::store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
 
949
int Field::store(const char *to, uint32_t length,
 
950
                 const CHARSET_INFO * const cs,
822
951
                 enum_check_fields check_level)
823
952
{
824
953
  int res;
869
998
*/
870
999
unsigned char *
871
1000
Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length,
872
 
            bool low_byte_first __attribute__((unused)))
 
1001
            bool)
873
1002
{
874
1003
  uint32_t length= pack_length();
875
1004
  set_if_smaller(length, max_length);
877
1006
  return to+length;
878
1007
}
879
1008
 
 
1009
 
 
1010
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
 
1011
{
 
1012
  unsigned char *result= this->pack(to, from, UINT32_MAX,
 
1013
                                    table->s->db_low_byte_first);
 
1014
  return(result);
 
1015
}
 
1016
 
 
1017
 
880
1018
/**
881
1019
   Unpack a field from row data.
882
1020
 
909
1047
*/
910
1048
const unsigned char *
911
1049
Field::unpack(unsigned char* to, const unsigned char *from, uint32_t param_data,
912
 
              bool low_byte_first __attribute__((unused)))
 
1050
              bool)
913
1051
{
914
1052
  uint32_t length=pack_length();
915
1053
  int from_type= 0;
939
1077
}
940
1078
 
941
1079
 
942
 
my_decimal *Field::val_decimal(my_decimal *decimal __attribute__((unused)))
 
1080
const unsigned char *Field::unpack(unsigned char* to,
 
1081
                                   const unsigned char *from)
 
1082
{
 
1083
  const unsigned char *result= unpack(to, from, 0U,
 
1084
                                      table->s->db_low_byte_first);
 
1085
  return(result);
 
1086
}
 
1087
 
 
1088
 
 
1089
uint32_t Field::packed_col_length(const unsigned char *, uint32_t length)
 
1090
{
 
1091
  return length;
 
1092
}
 
1093
 
 
1094
 
 
1095
int Field::pack_cmp(const unsigned char *a, const unsigned char *b,
 
1096
                    uint32_t, bool)
 
1097
{
 
1098
  return cmp(a,b);
 
1099
}
 
1100
 
 
1101
 
 
1102
int Field::pack_cmp(const unsigned char *b, uint32_t, bool)
 
1103
{
 
1104
  return cmp(ptr,b);
 
1105
}
 
1106
 
 
1107
 
 
1108
my_decimal *Field::val_decimal(my_decimal *)
943
1109
{
944
1110
  /* This never have to be called */
945
1111
  assert(0);
947
1113
}
948
1114
 
949
1115
 
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
1116
void Field::make_field(Send_field *field)
958
1117
{
959
1118
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
993
1152
  @return
994
1153
    value converted from val
995
1154
*/
996
 
int64_t Field::convert_decimal2int64_t(const my_decimal *val,
997
 
                                         bool unsigned_flag, int *err)
 
1155
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
998
1156
{
999
1157
  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)))
 
1158
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
1159
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
 
1160
                                      val, false, &i)))
1019
1161
  {
1020
1162
    i= (val->sign() ? INT64_MIN : INT64_MAX);
1021
1163
    *err= 1;
1023
1165
  return i;
1024
1166
}
1025
1167
 
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
1168
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
1130
1169
{
1131
1170
  uint32_t store_length;
1176
1215
    Needs to be changed if/when we want to support different time formats.
1177
1216
*/
1178
1217
 
1179
 
int Field::store_time(DRIZZLE_TIME *ltime,
1180
 
                      enum enum_drizzle_timestamp_type type_arg __attribute__((unused)))
 
1218
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
1181
1219
{
1182
1220
  char buff[MAX_DATE_STRING_REP_LENGTH];
1183
1221
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
1191
1229
}
1192
1230
 
1193
1231
 
1194
 
Field *Field::new_field(MEM_ROOT *root, Table *new_table,
1195
 
                        bool keep_type __attribute__((unused)))
 
1232
Field *Field::new_field(MEM_ROOT *root, Table *new_table, bool)
1196
1233
{
1197
1234
  Field *tmp;
1198
1235
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1241
1278
}
1242
1279
 
1243
1280
 
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
 
 
 
1281
uint32_t Field::is_equal(Create_field *new_field_ptr)
 
1282
{
 
1283
  return (new_field_ptr->sql_type == real_type());
 
1284
}
1606
1285
 
1607
1286
/**
1608
1287
  @retval
1641
1320
  return 1;
1642
1321
}
1643
1322
 
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
1323
/*****************************************************************************
1673
1324
  Handling of field and Create_field
1674
1325
*****************************************************************************/
1687
1338
    pack_length= calc_pack_length(sql_type, length);
1688
1339
    break;
1689
1340
  case DRIZZLE_TYPE_ENUM:
1690
 
    /* Pack_length already calculated in sql_parse.cc */
 
1341
    /* Pack_length already calculated in ::init() */
1691
1342
    length*= charset->mbmaxlen;
1692
1343
    key_length= pack_length;
1693
1344
    break;
1723
1374
              ((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
1724
1375
              (maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
1725
1376
              (is_unsigned ? 0 : FIELDFLAG_DECIMAL));
 
1377
  vcol_info= NULL;
 
1378
  is_stored= true;
1726
1379
}
1727
1380
 
1728
1381
 
1729
1382
/**
1730
1383
  Initialize field definition for create.
1731
1384
 
1732
 
  @param thd                   Thread handle
 
1385
  @param session                   Thread handle
1733
1386
  @param fld_name              Field name
1734
1387
  @param fld_type              Field type
1735
1388
  @param fld_length            Field length
1741
1394
  @param fld_change            Field change
1742
1395
  @param fld_interval_list     Interval list (if any)
1743
1396
  @param fld_charset           Field charset
 
1397
  @param fld_vcol_info         Virtual column data
1744
1398
 
1745
1399
  @retval
1746
1400
    false on success
1748
1402
    true  on error
1749
1403
*/
1750
1404
 
1751
 
bool Create_field::init(THD *thd __attribute__((unused)), char *fld_name, enum_field_types fld_type,
 
1405
bool Create_field::init(Session *, char *fld_name, enum_field_types fld_type,
1752
1406
                        char *fld_length, char *fld_decimals,
1753
1407
                        uint32_t fld_type_modifier, Item *fld_default_value,
1754
1408
                        Item *fld_on_update_value, LEX_STRING *fld_comment,
1755
1409
                        char *fld_change, List<String> *fld_interval_list,
1756
1410
                        const CHARSET_INFO * const fld_charset,
1757
 
                        uint32_t fld_geom_type __attribute__((unused)),
1758
 
                        enum column_format_type column_format)
 
1411
                        uint32_t, enum column_format_type column_format_in,
 
1412
                        virtual_column_info *fld_vcol_info)
1759
1413
{
1760
1414
  uint32_t sign_len, allowed_type_modifier= 0;
1761
1415
  uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
1764
1418
  field_name= fld_name;
1765
1419
  def= fld_default_value;
1766
1420
  flags= fld_type_modifier;
1767
 
  flags|= (((uint32_t)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
 
1421
  flags|= (((uint32_t)column_format_in & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
1768
1422
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
1769
1423
                 Field::NEXT_NUMBER : Field::NONE);
1770
1424
  decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
1784
1438
  interval_list.empty();
1785
1439
 
1786
1440
  comment= *fld_comment;
 
1441
  vcol_info= fld_vcol_info;
 
1442
  is_stored= true;
 
1443
 
 
1444
  /* Initialize data for a virtual field */
 
1445
  if (fld_type == DRIZZLE_TYPE_VIRTUAL)
 
1446
  {
 
1447
    assert(vcol_info && vcol_info->expr_item);
 
1448
    is_stored= vcol_info->get_field_stored();
 
1449
    /*
 
1450
      Perform per item-type checks to determine if the expression is
 
1451
      allowed for a virtual column.
 
1452
      Note that validation of the specific function is done later in
 
1453
      procedures open_table_from_share and fix_fields_vcol_func
 
1454
    */
 
1455
    switch (vcol_info->expr_item->type()) {
 
1456
    case Item::FUNC_ITEM:
 
1457
         if (((Item_func *)vcol_info->expr_item)->functype() == Item_func::FUNC_SP)
 
1458
         {
 
1459
           my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), field_name);
 
1460
           return(true);
 
1461
         }
 
1462
         break;
 
1463
    case Item::COPY_STR_ITEM:
 
1464
    case Item::FIELD_AVG_ITEM:
 
1465
    case Item::PROC_ITEM:
 
1466
    case Item::REF_ITEM:
 
1467
    case Item::FIELD_STD_ITEM:
 
1468
    case Item::FIELD_VARIANCE_ITEM:
 
1469
    case Item::INSERT_VALUE_ITEM:
 
1470
    case Item::SUBSELECT_ITEM:
 
1471
    case Item::CACHE_ITEM:
 
1472
    case Item::TYPE_HOLDER:
 
1473
    case Item::PARAM_ITEM:
 
1474
         my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), field_name);
 
1475
         return true;
 
1476
    default:
 
1477
      // Continue with the field creation
 
1478
      break;
 
1479
    }
 
1480
    /*
 
1481
      Make a field created for the real type.
 
1482
      Note that "real" and virtual fields differ from each other
 
1483
      only by Field::vcol_info, which is always 0 for normal columns.
 
1484
      vcol_info is updated for fields later in procedure open_binary_frm.
 
1485
    */
 
1486
    sql_type= fld_type= vcol_info->get_real_type();
 
1487
  }
 
1488
 
1787
1489
  /*
1788
1490
    Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
1789
1491
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
1846
1548
      /* Allow empty as default value. */
1847
1549
      String str,*res;
1848
1550
      res= fld_default_value->val_str(&str);
 
1551
      if (res->length())
 
1552
      {
 
1553
        my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
 
1554
                 fld_name);
 
1555
        return(true);
 
1556
      }
 
1557
 
1849
1558
    }
1850
1559
    flags|= BLOB_FLAG;
1851
1560
    break;
1882
1591
    if (fld_default_value)
1883
1592
    {
1884
1593
      /* Grammar allows only NOW() value for ON UPDATE clause */
1885
 
      if (fld_default_value->type() == Item::FUNC_ITEM && 
 
1594
      if (fld_default_value->type() == Item::FUNC_ITEM &&
1886
1595
          ((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
1887
1596
      {
1888
1597
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
1917
1626
                                              Field::NONE));
1918
1627
    }
1919
1628
    break;
1920
 
  case DRIZZLE_TYPE_NEWDATE:
1921
 
    length= 10;
1922
 
    break;
1923
 
  case DRIZZLE_TYPE_TIME:
 
1629
  case DRIZZLE_TYPE_DATE:
1924
1630
    length= 10;
1925
1631
    break;
1926
1632
  case DRIZZLE_TYPE_DATETIME:
1938
1644
      length= 1; /* See comment for DRIZZLE_TYPE_SET above. */
1939
1645
      break;
1940
1646
   }
 
1647
  case DRIZZLE_TYPE_VIRTUAL: // Must not happen
 
1648
    assert(0);
1941
1649
  }
1942
1650
  /* Remember the value of length */
1943
1651
  char_length= length;
1964
1672
}
1965
1673
 
1966
1674
 
1967
 
enum_field_types get_blob_type_from_length(uint32_t length __attribute__((unused)))
 
1675
enum_field_types get_blob_type_from_length(uint32_t)
1968
1676
{
1969
1677
  enum_field_types type;
1970
1678
 
1983
1691
  switch (type) {
1984
1692
  case DRIZZLE_TYPE_VARCHAR:     return (length + (length < 256 ? 1: 2));
1985
1693
  case DRIZZLE_TYPE_TINY        : return 1;
1986
 
  case DRIZZLE_TYPE_NEWDATE:
1987
 
  case DRIZZLE_TYPE_TIME:   return 3;
 
1694
  case DRIZZLE_TYPE_DATE: return 3;
1988
1695
  case DRIZZLE_TYPE_TIMESTAMP:
1989
1696
  case DRIZZLE_TYPE_LONG        : return 4;
1990
1697
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1994
1701
  case DRIZZLE_TYPE_BLOB:               return 4+portable_sizeof_char_ptr;
1995
1702
  case DRIZZLE_TYPE_ENUM:
1996
1703
  case DRIZZLE_TYPE_NEWDECIMAL:
1997
 
    abort(); return 0;                          // This shouldn't happen
 
1704
    abort();
1998
1705
  default:
1999
1706
    return 0;
2000
1707
  }
2004
1711
uint32_t pack_length_to_packflag(uint32_t type)
2005
1712
{
2006
1713
  switch (type) {
2007
 
    case 1: return f_settype((uint32_t) DRIZZLE_TYPE_TINY);
 
1714
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
2008
1715
    case 2: assert(1);
2009
1716
    case 3: assert(1);
2010
1717
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
2014
1721
}
2015
1722
 
2016
1723
 
2017
 
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
 
1724
Field *make_field(TABLE_SHARE *share, MEM_ROOT *root,
 
1725
                  unsigned char *ptr, uint32_t field_length,
2018
1726
                  unsigned char *null_pos, unsigned char null_bit,
2019
1727
                  uint32_t pack_flag,
2020
1728
                  enum_field_types field_type,
2023
1731
                  TYPELIB *interval,
2024
1732
                  const char *field_name)
2025
1733
{
 
1734
  if(!root)
 
1735
    root= current_mem_root();
 
1736
 
2026
1737
  if (!f_maybe_null(pack_flag))
2027
1738
  {
2028
1739
    null_pos=0;
2034
1745
  }
2035
1746
 
2036
1747
  switch (field_type) {
2037
 
  case DRIZZLE_TYPE_NEWDATE:
2038
 
  case DRIZZLE_TYPE_TIME:
 
1748
  case DRIZZLE_TYPE_DATE:
2039
1749
  case DRIZZLE_TYPE_DATETIME:
2040
1750
  case DRIZZLE_TYPE_TIMESTAMP:
2041
1751
    field_charset= &my_charset_bin;
2047
1757
    if (!f_is_packed(pack_flag))
2048
1758
    {
2049
1759
      if (field_type == DRIZZLE_TYPE_VARCHAR)
2050
 
        return new Field_varstring(ptr,field_length,
 
1760
        return new (root) Field_varstring(ptr,field_length,
2051
1761
                                   HA_VARCHAR_PACKLENGTH(field_length),
2052
1762
                                   null_pos,null_bit,
2053
1763
                                   unireg_check, field_name,
2061
1771
                                      field_length);
2062
1772
 
2063
1773
    if (f_is_blob(pack_flag))
2064
 
      return new Field_blob(ptr,null_pos,null_bit,
 
1774
      return new (root) Field_blob(ptr,null_pos,null_bit,
2065
1775
                            unireg_check, field_name, share,
2066
1776
                            pack_length, field_charset);
2067
1777
    if (interval)
2068
1778
    {
2069
1779
      if (f_is_enum(pack_flag))
2070
 
        return new Field_enum(ptr,field_length,null_pos,null_bit,
 
1780
      {
 
1781
        return new (root) Field_enum(ptr,field_length,null_pos,null_bit,
2071
1782
                                  unireg_check, field_name,
2072
 
                                  pack_length, interval, field_charset);
 
1783
                                  get_enum_pack_length(interval->count),
 
1784
                                  interval, field_charset);
 
1785
      }
2073
1786
    }
2074
1787
  }
2075
1788
 
2076
1789
  switch (field_type) {
2077
1790
  case DRIZZLE_TYPE_NEWDECIMAL:
2078
 
    return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
 
1791
    return new (root) Field_new_decimal(ptr,field_length,null_pos,null_bit,
2079
1792
                                 unireg_check, field_name,
2080
1793
                                 f_decimals(pack_flag),
2081
1794
                                 f_is_decimal_precision(pack_flag) != 0,
2082
1795
                                 f_is_dec(pack_flag) == 0);
2083
1796
  case DRIZZLE_TYPE_DOUBLE:
2084
 
    return new Field_double(ptr,field_length,null_pos,null_bit,
 
1797
    return new (root) Field_double(ptr,field_length,null_pos,null_bit,
2085
1798
                            unireg_check, field_name,
2086
1799
                            f_decimals(pack_flag),
2087
1800
                            false,
2088
1801
                            f_is_dec(pack_flag)== 0);
2089
1802
  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);
 
1803
    assert(0);
2094
1804
  case DRIZZLE_TYPE_LONG:
2095
 
    return new Field_long(ptr,field_length,null_pos,null_bit,
 
1805
    return new (root) Field_long(ptr,field_length,null_pos,null_bit,
2096
1806
                           unireg_check, field_name,
2097
1807
                           false,
2098
1808
                           f_is_dec(pack_flag) == 0);
2099
1809
  case DRIZZLE_TYPE_LONGLONG:
2100
 
    return new Field_int64_t(ptr,field_length,null_pos,null_bit,
 
1810
    return new (root) Field_int64_t(ptr,field_length,null_pos,null_bit,
2101
1811
                              unireg_check, field_name,
2102
1812
                              false,
2103
1813
                              f_is_dec(pack_flag) == 0);
2104
1814
  case DRIZZLE_TYPE_TIMESTAMP:
2105
 
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,
 
1815
    return new (root) Field_timestamp(ptr,field_length, null_pos, null_bit,
2106
1816
                               unireg_check, field_name, share,
2107
1817
                               field_charset);
2108
 
  case DRIZZLE_TYPE_NEWDATE:
2109
 
    return new Field_newdate(ptr,null_pos,null_bit,
 
1818
  case DRIZZLE_TYPE_DATE:
 
1819
    return new (root) Field_date(ptr,null_pos,null_bit,
2110
1820
                             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
1821
  case DRIZZLE_TYPE_DATETIME:
2115
 
    return new Field_datetime(ptr,null_pos,null_bit,
 
1822
    return new (root) Field_datetime(ptr,null_pos,null_bit,
2116
1823
                              unireg_check, field_name, field_charset);
2117
1824
  case DRIZZLE_TYPE_NULL:
2118
 
    return new Field_null(ptr, field_length, unireg_check, field_name,
 
1825
    return new (root) Field_null(ptr, field_length, unireg_check, field_name,
2119
1826
                          field_charset);
 
1827
  case DRIZZLE_TYPE_VIRTUAL:                    // Must not happen
 
1828
    assert(0);
2120
1829
  default:                                      // Impossible (Wrong version)
2121
1830
    break;
2122
1831
  }
2139
1848
  charset=    old_field->charset();             // May be NULL ptr
2140
1849
  comment=    old_field->comment;
2141
1850
  decimals=   old_field->decimals();
 
1851
  vcol_info=  old_field->vcol_info;
 
1852
  is_stored= old_field->is_stored;
2142
1853
 
2143
1854
  /* Fix if the original table had 4 byte pointer blobs */
2144
1855
  if (flags & BLOB_FLAG)
2168
1879
  def=0;
2169
1880
  char_length= length;
2170
1881
 
2171
 
  if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
 
1882
  if (!(flags & (NO_DEFAULT_VALUE_FLAG )) &&
2172
1883
      old_field->ptr && orig_field &&
2173
1884
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
2174
 
       old_field->table->timestamp_field != old_field ||  /* timestamp field */ 
 
1885
       old_field->table->timestamp_field != old_field ||  /* timestamp field */
2175
1886
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
2176
1887
  {
2177
 
    char buff[MAX_FIELD_WIDTH];
2178
 
    String tmp(buff,sizeof(buff), charset);
2179
1888
    my_ptrdiff_t diff;
2180
1889
 
2181
1890
    /* Get the value from default_values */
2219
1928
    0 otherwise
2220
1929
*/
2221
1930
 
2222
 
bool 
 
1931
bool
2223
1932
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2224
1933
                   int cuted_increment)
2225
1934
{
2227
1936
    If this field was created only for type conversion purposes it
2228
1937
    will have table == NULL.
2229
1938
  */
2230
 
  THD *thd= table ? table->in_use : current_thd;
2231
 
  if (thd->count_cuted_fields)
 
1939
  Session *session= table ? table->in_use : current_session;
 
1940
  if (session->count_cuted_fields)
2232
1941
  {
2233
 
    thd->cuted_fields+= cuted_increment;
2234
 
    push_warning_printf(thd, level, code, ER(code), field_name,
2235
 
                        thd->row_count);
 
1942
    session->cuted_fields+= cuted_increment;
 
1943
    push_warning_printf(session, level, code, ER(code), field_name,
 
1944
                        session->row_count);
2236
1945
    return 0;
2237
1946
  }
2238
1947
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
2255
1964
    thread.
2256
1965
*/
2257
1966
 
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, 
 
1967
void
 
1968
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
 
1969
                            unsigned int code,
 
1970
                            const char *str, uint32_t str_length,
2262
1971
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
2263
1972
{
2264
 
  THD *thd= table ? table->in_use : current_thd;
2265
 
  if ((thd->really_abort_on_warning() &&
 
1973
  Session *session= table ? table->in_use : current_session;
 
1974
  if ((session->really_abort_on_warning() &&
2266
1975
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
2267
1976
      set_warning(level, code, cuted_increment))
2268
 
    make_truncated_value_warning(thd, level, str, str_length, ts_type,
 
1977
    make_truncated_value_warning(session, level, str, str_length, ts_type,
2269
1978
                                 field_name);
2270
1979
}
2271
1980
 
2285
1994
    thread.
2286
1995
*/
2287
1996
 
2288
 
void 
2289
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
1997
void
 
1998
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2290
1999
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
2291
2000
                            int cuted_increment)
2292
2001
{
2293
 
  THD *thd= table ? table->in_use : current_thd;
2294
 
  if (thd->really_abort_on_warning() ||
 
2002
  Session *session= table ? table->in_use : current_session;
 
2003
  if (session->really_abort_on_warning() ||
2295
2004
      set_warning(level, code, cuted_increment))
2296
2005
  {
2297
2006
    char str_nr[22];
2298
2007
    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), 
 
2008
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
2300
2009
                                 ts_type, field_name);
2301
2010
  }
2302
2011
}
2316
2025
    thread.
2317
2026
*/
2318
2027
 
2319
 
void 
2320
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
2028
void
 
2029
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, const uint32_t code,
2321
2030
                            double nr, enum enum_drizzle_timestamp_type ts_type)
2322
2031
{
2323
 
  THD *thd= table ? table->in_use : current_thd;
2324
 
  if (thd->really_abort_on_warning() ||
 
2032
  Session *session= table ? table->in_use : current_session;
 
2033
  if (session->really_abort_on_warning() ||
2325
2034
      set_warning(level, code, 1))
2326
2035
  {
2327
2036
    /* DBL_DIG is enough to print '-[digits].E+###' */
2328
2037
    char str_nr[DBL_DIG + 8];
2329
2038
    uint32_t str_len= sprintf(str_nr, "%g", nr);
2330
 
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
 
2039
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
2331
2040
                                 field_name);
2332
2041
  }
2333
2042
}
 
2043