~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2009-05-15 17:06:35 UTC
  • mto: This revision was merged to the branch mainline in revision 1023.
  • Revision ID: brian@gaz-20090515170635-croy1u63a3gqdn9n
Dead convert functions for character sets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
 
 
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 MySQL
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
16
20
 
17
21
/**
18
22
  @file
23
27
#include <drizzled/server_includes.h>
24
28
#include "sql_select.h"
25
29
#include <errno.h>
26
 
#include <drizzled/drizzled_error_messages.h>
 
30
#include <drizzled/error.h>
 
31
#include <drizzled/field/str.h>
 
32
#include <drizzled/field/longstr.h>
 
33
#include <drizzled/field/num.h>
 
34
#include <drizzled/field/blob.h>
 
35
#include <drizzled/field/enum.h>
 
36
#include <drizzled/field/null.h>
 
37
#include <drizzled/field/date.h>
 
38
#include <drizzled/field/decimal.h>
 
39
#include <drizzled/field/real.h>
 
40
#include <drizzled/field/double.h>
 
41
#include <drizzled/field/long.h>
 
42
#include <drizzled/field/int64_t.h>
 
43
#include <drizzled/field/num.h>
 
44
#include <drizzled/field/timestamp.h>
 
45
#include <drizzled/field/datetime.h>
 
46
#include <drizzled/field/varstring.h>
27
47
 
28
 
// Maximum allowed exponent value for converting string to decimal
29
 
#define MAX_EXPONENT 1024
30
48
 
31
49
/*****************************************************************************
32
50
  Instansiate templates and static variables
38
56
#endif
39
57
 
40
58
 
41
 
/*
42
 
  Rules for merging different types of fields in UNION
43
 
 
44
 
  NOTE: to avoid 256*256 table, gap in table types numeration is skiped
45
 
  following #defines describe that gap and how to canculate number of fields
46
 
  and index of field in thia array.
47
 
*/
48
 
#define FIELDTYPE_TEAR_FROM (DRIZZLE_TYPE_VARCHAR + 1)
49
 
#define FIELDTYPE_TEAR_TO   (DRIZZLE_TYPE_NEWDECIMAL - 1)
50
 
#define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO))
51
 
inline int field_type2index (enum_field_types field_type)
52
 
{
53
 
  return (field_type < FIELDTYPE_TEAR_FROM ?
54
 
          field_type :
55
 
          ((int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) - 1);
56
 
}
57
 
 
58
 
 
59
 
static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]=
60
 
{
61
 
  /* DRIZZLE_TYPE_DECIMAL -> */
62
 
  {
63
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
64
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_NEWDECIMAL,
65
 
  //DRIZZLE_TYPE_LONG
66
 
    DRIZZLE_TYPE_NEWDECIMAL,
67
 
  //DRIZZLE_TYPE_DOUBLE
68
 
    DRIZZLE_TYPE_DOUBLE,
69
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
70
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
71
 
  //DRIZZLE_TYPE_LONGLONG
72
 
    DRIZZLE_TYPE_NEWDECIMAL,
73
 
  //DRIZZLE_TYPE_TIME
74
 
    DRIZZLE_TYPE_VARCHAR,
75
 
  //DRIZZLE_TYPE_DATETIME
76
 
    DRIZZLE_TYPE_VARCHAR,
77
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
78
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
79
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
80
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
81
 
  //DRIZZLE_TYPE_BLOB
82
 
    DRIZZLE_TYPE_BLOB,
83
 
  },
 
59
static enum_field_types
 
60
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
 
61
{
84
62
  /* DRIZZLE_TYPE_TINY -> */
85
63
  {
86
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
87
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
88
 
  //DRIZZLE_TYPE_LONG
 
64
    //DRIZZLE_TYPE_TINY
 
65
    DRIZZLE_TYPE_TINY,
 
66
    //DRIZZLE_TYPE_LONG
89
67
    DRIZZLE_TYPE_LONG,
90
 
  //DRIZZLE_TYPE_DOUBLE
 
68
    //DRIZZLE_TYPE_DOUBLE
91
69
    DRIZZLE_TYPE_DOUBLE,
92
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
93
 
    DRIZZLE_TYPE_TINY,        DRIZZLE_TYPE_VARCHAR,
94
 
  //DRIZZLE_TYPE_LONGLONG
 
70
    //DRIZZLE_TYPE_NULL
 
71
    DRIZZLE_TYPE_TINY,
 
72
    //DRIZZLE_TYPE_TIMESTAMP
 
73
    DRIZZLE_TYPE_VARCHAR,
 
74
    //DRIZZLE_TYPE_LONGLONG
95
75
    DRIZZLE_TYPE_LONGLONG,
96
 
  //DRIZZLE_TYPE_TIME
97
 
    DRIZZLE_TYPE_VARCHAR,
98
 
  //DRIZZLE_TYPE_DATETIME
99
 
    DRIZZLE_TYPE_VARCHAR,
100
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
101
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
102
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
103
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
104
 
  //DRIZZLE_TYPE_BLOB
 
76
    //DRIZZLE_TYPE_DATETIME
 
77
    DRIZZLE_TYPE_VARCHAR,
 
78
    //DRIZZLE_TYPE_DATE
 
79
    DRIZZLE_TYPE_VARCHAR,
 
80
    //DRIZZLE_TYPE_VARCHAR
 
81
    DRIZZLE_TYPE_VARCHAR,
 
82
    //DRIZZLE_TYPE_NEWDECIMAL
 
83
    DRIZZLE_TYPE_NEWDECIMAL,
 
84
    //DRIZZLE_TYPE_ENUM
 
85
    DRIZZLE_TYPE_VARCHAR,
 
86
    //DRIZZLE_TYPE_BLOB
105
87
    DRIZZLE_TYPE_BLOB,
106
88
  },
107
89
  /* DRIZZLE_TYPE_LONG -> */
108
90
  {
109
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
110
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONG,
111
 
  //DRIZZLE_TYPE_LONG
112
 
    DRIZZLE_TYPE_LONG,
113
 
  //DRIZZLE_TYPE_DOUBLE
 
91
    //DRIZZLE_TYPE_TINY
 
92
    DRIZZLE_TYPE_LONG,
 
93
    //DRIZZLE_TYPE_LONG
 
94
    DRIZZLE_TYPE_LONG,
 
95
    //DRIZZLE_TYPE_DOUBLE
114
96
    DRIZZLE_TYPE_DOUBLE,
115
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
116
 
    DRIZZLE_TYPE_LONG,         DRIZZLE_TYPE_VARCHAR,
117
 
  //DRIZZLE_TYPE_LONGLONG
 
97
    //DRIZZLE_TYPE_NULL
 
98
    DRIZZLE_TYPE_LONG,
 
99
    //DRIZZLE_TYPE_TIMESTAMP
 
100
    DRIZZLE_TYPE_VARCHAR,
 
101
    //DRIZZLE_TYPE_LONGLONG
118
102
    DRIZZLE_TYPE_LONGLONG,
119
 
  //DRIZZLE_TYPE_TIME
120
 
    DRIZZLE_TYPE_VARCHAR,
121
 
  //DRIZZLE_TYPE_DATETIME
122
 
    DRIZZLE_TYPE_VARCHAR,
123
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
124
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
125
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
126
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
127
 
  //DRIZZLE_TYPE_BLOB
 
103
    //DRIZZLE_TYPE_DATETIME
 
104
    DRIZZLE_TYPE_VARCHAR,
 
105
    //DRIZZLE_TYPE_DATE
 
106
    DRIZZLE_TYPE_VARCHAR,
 
107
    //DRIZZLE_TYPE_VARCHAR
 
108
    DRIZZLE_TYPE_VARCHAR,
 
109
    //DRIZZLE_TYPE_NEWDECIMAL
 
110
    DRIZZLE_TYPE_NEWDECIMAL,
 
111
    //DRIZZLE_TYPE_ENUM
 
112
    DRIZZLE_TYPE_VARCHAR,
 
113
    //DRIZZLE_TYPE_BLOB
128
114
    DRIZZLE_TYPE_BLOB,
129
115
  },
130
116
  /* DRIZZLE_TYPE_DOUBLE -> */
131
117
  {
132
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
133
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_DOUBLE,
134
 
  //DRIZZLE_TYPE_LONG
135
 
    DRIZZLE_TYPE_DOUBLE,
136
 
  //DRIZZLE_TYPE_DOUBLE
137
 
    DRIZZLE_TYPE_DOUBLE,
138
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
139
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
140
 
  //DRIZZLE_TYPE_LONGLONG
141
 
    DRIZZLE_TYPE_DOUBLE,
142
 
  //DRIZZLE_TYPE_TIME
143
 
    DRIZZLE_TYPE_VARCHAR,
144
 
  //DRIZZLE_TYPE_DATETIME
145
 
    DRIZZLE_TYPE_VARCHAR,
146
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
147
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
148
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
149
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
150
 
  //DRIZZLE_TYPE_BLOB
 
118
    //DRIZZLE_TYPE_TINY
 
119
    DRIZZLE_TYPE_DOUBLE,
 
120
    //DRIZZLE_TYPE_LONG
 
121
    DRIZZLE_TYPE_DOUBLE,
 
122
    //DRIZZLE_TYPE_DOUBLE
 
123
    DRIZZLE_TYPE_DOUBLE,
 
124
    //DRIZZLE_TYPE_NULL
 
125
    DRIZZLE_TYPE_DOUBLE,
 
126
    //DRIZZLE_TYPE_TIMESTAMP
 
127
    DRIZZLE_TYPE_VARCHAR,
 
128
    //DRIZZLE_TYPE_LONGLONG
 
129
    DRIZZLE_TYPE_DOUBLE,
 
130
    //DRIZZLE_TYPE_DATETIME
 
131
    DRIZZLE_TYPE_VARCHAR,
 
132
    //DRIZZLE_TYPE_DATE
 
133
    DRIZZLE_TYPE_VARCHAR,
 
134
    //DRIZZLE_TYPE_VARCHAR
 
135
    DRIZZLE_TYPE_VARCHAR,
 
136
    //DRIZZLE_TYPE_NEWDECIMAL
 
137
    DRIZZLE_TYPE_DOUBLE,
 
138
    //DRIZZLE_TYPE_ENUM
 
139
    DRIZZLE_TYPE_VARCHAR,
 
140
    //DRIZZLE_TYPE_BLOB
151
141
    DRIZZLE_TYPE_BLOB,
152
142
  },
153
143
  /* DRIZZLE_TYPE_NULL -> */
154
144
  {
155
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
156
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
157
 
  //DRIZZLE_TYPE_LONG
 
145
    //DRIZZLE_TYPE_TINY
 
146
    DRIZZLE_TYPE_TINY,
 
147
    //DRIZZLE_TYPE_LONG
158
148
    DRIZZLE_TYPE_LONG,
159
 
  //DRIZZLE_TYPE_DOUBLE
 
149
    //DRIZZLE_TYPE_DOUBLE
160
150
    DRIZZLE_TYPE_DOUBLE,
161
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
162
 
    DRIZZLE_TYPE_NULL,        DRIZZLE_TYPE_TIMESTAMP,
163
 
  //DRIZZLE_TYPE_LONGLONG
 
151
    //DRIZZLE_TYPE_NULL
 
152
    DRIZZLE_TYPE_NULL,
 
153
    //DRIZZLE_TYPE_TIMESTAMP
 
154
    DRIZZLE_TYPE_TIMESTAMP,
 
155
    //DRIZZLE_TYPE_LONGLONG
164
156
    DRIZZLE_TYPE_LONGLONG,
165
 
  //DRIZZLE_TYPE_TIME
166
 
    DRIZZLE_TYPE_TIME,
167
 
  //DRIZZLE_TYPE_DATETIME
 
157
    //DRIZZLE_TYPE_DATETIME
168
158
    DRIZZLE_TYPE_DATETIME,
169
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
170
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
171
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
172
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_ENUM,
173
 
  //DRIZZLE_TYPE_BLOB
 
159
    //DRIZZLE_TYPE_DATE
 
160
    DRIZZLE_TYPE_DATE,
 
161
    //DRIZZLE_TYPE_VARCHAR
 
162
    DRIZZLE_TYPE_VARCHAR,
 
163
    //DRIZZLE_TYPE_NEWDECIMAL
 
164
    DRIZZLE_TYPE_NEWDECIMAL,
 
165
    //DRIZZLE_TYPE_ENUM
 
166
    DRIZZLE_TYPE_ENUM,
 
167
    //DRIZZLE_TYPE_BLOB
174
168
    DRIZZLE_TYPE_BLOB,
175
169
  },
176
170
  /* DRIZZLE_TYPE_TIMESTAMP -> */
177
171
  {
178
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
179
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
180
 
  //DRIZZLE_TYPE_LONG
181
 
    DRIZZLE_TYPE_VARCHAR,
182
 
  //DRIZZLE_TYPE_DOUBLE
183
 
    DRIZZLE_TYPE_VARCHAR,
184
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
185
 
    DRIZZLE_TYPE_TIMESTAMP,   DRIZZLE_TYPE_TIMESTAMP,
186
 
  //DRIZZLE_TYPE_LONGLONG
187
 
    DRIZZLE_TYPE_VARCHAR,
188
 
  //DRIZZLE_TYPE_TIME
189
 
    DRIZZLE_TYPE_DATETIME,
190
 
  //DRIZZLE_TYPE_DATETIME
191
 
    DRIZZLE_TYPE_DATETIME,
192
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
193
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
194
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
195
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
196
 
  //DRIZZLE_TYPE_BLOB
 
172
    //DRIZZLE_TYPE_TINY
 
173
    DRIZZLE_TYPE_VARCHAR,
 
174
    //DRIZZLE_TYPE_LONG
 
175
    DRIZZLE_TYPE_VARCHAR,
 
176
    //DRIZZLE_TYPE_DOUBLE
 
177
    DRIZZLE_TYPE_VARCHAR,
 
178
    //DRIZZLE_TYPE_NULL
 
179
    DRIZZLE_TYPE_TIMESTAMP,
 
180
    //DRIZZLE_TYPE_TIMESTAMP
 
181
    DRIZZLE_TYPE_TIMESTAMP,
 
182
    //DRIZZLE_TYPE_LONGLONG
 
183
    DRIZZLE_TYPE_VARCHAR,
 
184
    //DRIZZLE_TYPE_DATETIME
 
185
    DRIZZLE_TYPE_DATETIME,
 
186
    //DRIZZLE_TYPE_DATE
 
187
    DRIZZLE_TYPE_DATE,
 
188
    //DRIZZLE_TYPE_VARCHAR
 
189
    DRIZZLE_TYPE_VARCHAR,
 
190
    //DRIZZLE_TYPE_NEWDECIMAL
 
191
    DRIZZLE_TYPE_VARCHAR,
 
192
    //DRIZZLE_TYPE_ENUM
 
193
    DRIZZLE_TYPE_VARCHAR,
 
194
    //DRIZZLE_TYPE_BLOB
197
195
    DRIZZLE_TYPE_BLOB,
198
196
  },
199
197
  /* DRIZZLE_TYPE_LONGLONG -> */
200
198
  {
201
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
202
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONGLONG,
203
 
  //DRIZZLE_TYPE_LONG
204
 
    DRIZZLE_TYPE_LONGLONG,
205
 
  //DRIZZLE_TYPE_DOUBLE
 
199
    //DRIZZLE_TYPE_TINY
 
200
    DRIZZLE_TYPE_LONGLONG,
 
201
    //DRIZZLE_TYPE_LONG
 
202
    DRIZZLE_TYPE_LONGLONG,
 
203
    //DRIZZLE_TYPE_DOUBLE
206
204
    DRIZZLE_TYPE_DOUBLE,
207
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
208
 
    DRIZZLE_TYPE_LONGLONG,    DRIZZLE_TYPE_VARCHAR,
209
 
  //DRIZZLE_TYPE_LONGLONG
210
 
    DRIZZLE_TYPE_LONGLONG,
211
 
  //DRIZZLE_TYPE_TIME
212
 
    DRIZZLE_TYPE_VARCHAR,
213
 
  //DRIZZLE_TYPE_DATETIME
214
 
    DRIZZLE_TYPE_VARCHAR,
215
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
216
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
217
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
218
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
219
 
  //DRIZZLE_TYPE_BLOB
220
 
    DRIZZLE_TYPE_BLOB,
221
 
  },
222
 
  /* DRIZZLE_TYPE_TIME -> */
223
 
  {
224
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
225
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
226
 
  //DRIZZLE_TYPE_LONG
227
 
    DRIZZLE_TYPE_VARCHAR,
228
 
  //DRIZZLE_TYPE_DOUBLE
229
 
    DRIZZLE_TYPE_VARCHAR,
230
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
231
 
    DRIZZLE_TYPE_TIME,        DRIZZLE_TYPE_DATETIME,
232
 
  //DRIZZLE_TYPE_LONGLONG
233
 
    DRIZZLE_TYPE_VARCHAR,
234
 
  //DRIZZLE_TYPE_TIME
235
 
    DRIZZLE_TYPE_TIME,
236
 
  //DRIZZLE_TYPE_DATETIME
237
 
    DRIZZLE_TYPE_DATETIME,
238
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
239
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
240
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
241
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
242
 
  //DRIZZLE_TYPE_BLOB
 
205
    //DRIZZLE_TYPE_NULL
 
206
    DRIZZLE_TYPE_LONGLONG,
 
207
    //DRIZZLE_TYPE_TIMESTAMP
 
208
    DRIZZLE_TYPE_VARCHAR,
 
209
    //DRIZZLE_TYPE_LONGLONG
 
210
    DRIZZLE_TYPE_LONGLONG,
 
211
    //DRIZZLE_TYPE_DATETIME
 
212
    DRIZZLE_TYPE_VARCHAR,
 
213
    //DRIZZLE_TYPE_DATE
 
214
    DRIZZLE_TYPE_DATE,
 
215
    //DRIZZLE_TYPE_VARCHAR
 
216
    DRIZZLE_TYPE_VARCHAR,
 
217
    //DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
 
218
    DRIZZLE_TYPE_NEWDECIMAL,
 
219
    DRIZZLE_TYPE_VARCHAR,
 
220
    //DRIZZLE_TYPE_BLOB
243
221
    DRIZZLE_TYPE_BLOB,
244
222
  },
245
223
  /* DRIZZLE_TYPE_DATETIME -> */
246
224
  {
247
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
248
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
249
 
  //DRIZZLE_TYPE_LONG
250
 
    DRIZZLE_TYPE_VARCHAR,
251
 
  //DRIZZLE_TYPE_DOUBLE
252
 
    DRIZZLE_TYPE_VARCHAR,
253
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
254
 
    DRIZZLE_TYPE_DATETIME,    DRIZZLE_TYPE_DATETIME,
255
 
  //DRIZZLE_TYPE_LONGLONG
256
 
    DRIZZLE_TYPE_VARCHAR,
257
 
  //DRIZZLE_TYPE_TIME
258
 
    DRIZZLE_TYPE_DATETIME,
259
 
  //DRIZZLE_TYPE_DATETIME
260
 
    DRIZZLE_TYPE_DATETIME,
261
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
262
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
263
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
264
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
265
 
  //DRIZZLE_TYPE_BLOB
 
225
    //DRIZZLE_TYPE_TINY
 
226
    DRIZZLE_TYPE_VARCHAR,
 
227
    //DRIZZLE_TYPE_LONG
 
228
    DRIZZLE_TYPE_VARCHAR,
 
229
    //DRIZZLE_TYPE_DOUBLE
 
230
    DRIZZLE_TYPE_VARCHAR,
 
231
    //DRIZZLE_TYPE_NULL
 
232
    DRIZZLE_TYPE_DATETIME,
 
233
    //DRIZZLE_TYPE_TIMESTAMP
 
234
    DRIZZLE_TYPE_DATETIME,
 
235
    //DRIZZLE_TYPE_LONGLONG
 
236
    DRIZZLE_TYPE_VARCHAR,
 
237
    //DRIZZLE_TYPE_DATETIME
 
238
    DRIZZLE_TYPE_DATETIME,
 
239
    //DRIZZLE_TYPE_DATE
 
240
    DRIZZLE_TYPE_DATE,
 
241
    //DRIZZLE_TYPE_VARCHAR
 
242
    DRIZZLE_TYPE_VARCHAR,
 
243
    //DRIZZLE_TYPE_NEWDECIMAL
 
244
    DRIZZLE_TYPE_VARCHAR,
 
245
    //DRIZZLE_TYPE_ENUM
 
246
    DRIZZLE_TYPE_VARCHAR,
 
247
    //DRIZZLE_TYPE_BLOB
266
248
    DRIZZLE_TYPE_BLOB,
267
249
  },
268
 
  /* DRIZZLE_TYPE_NEWDATE -> */
 
250
  /* DRIZZLE_TYPE_DATE -> */
269
251
  {
270
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
271
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
272
 
  //DRIZZLE_TYPE_LONG
273
 
    DRIZZLE_TYPE_VARCHAR,
274
 
  //DRIZZLE_TYPE_DOUBLE
275
 
    DRIZZLE_TYPE_VARCHAR,
276
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
277
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_DATETIME,
278
 
  //DRIZZLE_TYPE_LONGLONG
279
 
    DRIZZLE_TYPE_VARCHAR,
280
 
  //DRIZZLE_TYPE_TIME
281
 
    DRIZZLE_TYPE_DATETIME,
282
 
  //DRIZZLE_TYPE_DATETIME
283
 
    DRIZZLE_TYPE_DATETIME,
284
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
285
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
286
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
287
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
288
 
  //DRIZZLE_TYPE_BLOB
 
252
    //DRIZZLE_TYPE_TINY
 
253
    DRIZZLE_TYPE_VARCHAR,
 
254
    //DRIZZLE_TYPE_LONG
 
255
    DRIZZLE_TYPE_VARCHAR,
 
256
    //DRIZZLE_TYPE_DOUBLE
 
257
    DRIZZLE_TYPE_VARCHAR,
 
258
    //DRIZZLE_TYPE_NULL
 
259
    DRIZZLE_TYPE_DATE,
 
260
    //DRIZZLE_TYPE_TIMESTAMP
 
261
    DRIZZLE_TYPE_DATETIME,
 
262
    //DRIZZLE_TYPE_LONGLONG
 
263
    DRIZZLE_TYPE_VARCHAR,
 
264
    //DRIZZLE_TYPE_DATETIME
 
265
    DRIZZLE_TYPE_DATETIME,
 
266
    //DRIZZLE_TYPE_DATE
 
267
    DRIZZLE_TYPE_DATE,
 
268
    //DRIZZLE_TYPE_VARCHAR
 
269
    DRIZZLE_TYPE_VARCHAR,
 
270
    //DRIZZLE_TYPE_NEWDECIMAL
 
271
    DRIZZLE_TYPE_VARCHAR,
 
272
    //DRIZZLE_TYPE_ENUM
 
273
    DRIZZLE_TYPE_VARCHAR,
 
274
    //DRIZZLE_TYPE_BLOB
289
275
    DRIZZLE_TYPE_BLOB,
290
276
  },
291
277
  /* DRIZZLE_TYPE_VARCHAR -> */
292
278
  {
293
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
294
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
295
 
  //DRIZZLE_TYPE_LONG
296
 
    DRIZZLE_TYPE_VARCHAR,
297
 
  //DRIZZLE_TYPE_DOUBLE
298
 
    DRIZZLE_TYPE_VARCHAR,
299
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
300
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
301
 
  //DRIZZLE_TYPE_LONGLONG
302
 
    DRIZZLE_TYPE_VARCHAR,
303
 
  //DRIZZLE_TYPE_TIME
304
 
    DRIZZLE_TYPE_VARCHAR,
305
 
  //DRIZZLE_TYPE_DATETIME
306
 
    DRIZZLE_TYPE_VARCHAR,
307
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
308
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
309
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
310
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
311
 
  //DRIZZLE_TYPE_BLOB
 
279
    //DRIZZLE_TYPE_TINY
 
280
    DRIZZLE_TYPE_VARCHAR,
 
281
    //DRIZZLE_TYPE_LONG
 
282
    DRIZZLE_TYPE_VARCHAR,
 
283
    //DRIZZLE_TYPE_DOUBLE
 
284
    DRIZZLE_TYPE_VARCHAR,
 
285
    //DRIZZLE_TYPE_NULL
 
286
    DRIZZLE_TYPE_VARCHAR,
 
287
    //DRIZZLE_TYPE_TIMESTAMP
 
288
    DRIZZLE_TYPE_VARCHAR,
 
289
    //DRIZZLE_TYPE_LONGLONG
 
290
    DRIZZLE_TYPE_VARCHAR,
 
291
    //DRIZZLE_TYPE_DATETIME
 
292
    DRIZZLE_TYPE_VARCHAR,
 
293
    //DRIZZLE_TYPE_DATE
 
294
    DRIZZLE_TYPE_VARCHAR,
 
295
    //DRIZZLE_TYPE_VARCHAR
 
296
    DRIZZLE_TYPE_VARCHAR,
 
297
    //DRIZZLE_TYPE_NEWDECIMAL
 
298
    DRIZZLE_TYPE_VARCHAR,
 
299
    //DRIZZLE_TYPE_ENUM
 
300
    DRIZZLE_TYPE_VARCHAR,
 
301
    //DRIZZLE_TYPE_BLOB
312
302
    DRIZZLE_TYPE_BLOB,
313
303
  },
314
304
  /* DRIZZLE_TYPE_NEWDECIMAL -> */
315
305
  {
316
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
317
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_NEWDECIMAL,
318
 
  //DRIZZLE_TYPE_LONG
319
 
    DRIZZLE_TYPE_NEWDECIMAL,
320
 
  //DRIZZLE_TYPE_DOUBLE
 
306
    //DRIZZLE_TYPE_TINY
 
307
    DRIZZLE_TYPE_NEWDECIMAL,
 
308
    //DRIZZLE_TYPE_LONG
 
309
    DRIZZLE_TYPE_NEWDECIMAL,
 
310
    //DRIZZLE_TYPE_DOUBLE
321
311
    DRIZZLE_TYPE_DOUBLE,
322
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
323
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
324
 
  //DRIZZLE_TYPE_LONGLONG
325
 
    DRIZZLE_TYPE_NEWDECIMAL,
326
 
  //DRIZZLE_TYPE_TIME
327
 
    DRIZZLE_TYPE_VARCHAR,
328
 
  //DRIZZLE_TYPE_DATETIME
329
 
    DRIZZLE_TYPE_VARCHAR,
330
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
331
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
332
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
333
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
334
 
  //DRIZZLE_TYPE_BLOB
 
312
    //DRIZZLE_TYPE_NULL
 
313
    DRIZZLE_TYPE_NEWDECIMAL,
 
314
    //DRIZZLE_TYPE_TIMESTAMP
 
315
    DRIZZLE_TYPE_VARCHAR,
 
316
    //DRIZZLE_TYPE_LONGLONG
 
317
    DRIZZLE_TYPE_NEWDECIMAL,
 
318
    //DRIZZLE_TYPE_DATETIME
 
319
    DRIZZLE_TYPE_VARCHAR,
 
320
    //DRIZZLE_TYPE_DATE
 
321
    DRIZZLE_TYPE_VARCHAR,
 
322
    //DRIZZLE_TYPE_VARCHAR
 
323
    DRIZZLE_TYPE_VARCHAR,
 
324
    //DRIZZLE_TYPE_NEWDECIMAL
 
325
    DRIZZLE_TYPE_NEWDECIMAL,
 
326
    //DRIZZLE_TYPE_ENUM
 
327
    DRIZZLE_TYPE_VARCHAR,
 
328
    //DRIZZLE_TYPE_BLOB
335
329
    DRIZZLE_TYPE_BLOB,
336
330
  },
337
331
  /* DRIZZLE_TYPE_ENUM -> */
338
332
  {
339
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
340
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
341
 
  //DRIZZLE_TYPE_LONG
342
 
    DRIZZLE_TYPE_VARCHAR,
343
 
  //DRIZZLE_TYPE_DOUBLE
344
 
    DRIZZLE_TYPE_VARCHAR,
345
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
346
 
    DRIZZLE_TYPE_ENUM,        DRIZZLE_TYPE_VARCHAR,
347
 
  //DRIZZLE_TYPE_LONGLONG
348
 
    DRIZZLE_TYPE_VARCHAR,
349
 
  //DRIZZLE_TYPE_TIME
350
 
    DRIZZLE_TYPE_VARCHAR,
351
 
  //DRIZZLE_TYPE_DATETIME
352
 
    DRIZZLE_TYPE_VARCHAR,
353
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
354
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
355
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
356
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
357
 
  //DRIZZLE_TYPE_BLOB
 
333
    //DRIZZLE_TYPE_TINY
 
334
    DRIZZLE_TYPE_VARCHAR,
 
335
    //DRIZZLE_TYPE_LONG
 
336
    DRIZZLE_TYPE_VARCHAR,
 
337
    //DRIZZLE_TYPE_DOUBLE
 
338
    DRIZZLE_TYPE_VARCHAR,
 
339
    //DRIZZLE_TYPE_NULL
 
340
    DRIZZLE_TYPE_ENUM,
 
341
    //DRIZZLE_TYPE_TIMESTAMP
 
342
    DRIZZLE_TYPE_VARCHAR,
 
343
    //DRIZZLE_TYPE_LONGLONG
 
344
    DRIZZLE_TYPE_VARCHAR,
 
345
    //DRIZZLE_TYPE_DATETIME
 
346
    DRIZZLE_TYPE_VARCHAR,
 
347
    //DRIZZLE_TYPE_DATE
 
348
    DRIZZLE_TYPE_VARCHAR,
 
349
    //DRIZZLE_TYPE_VARCHAR
 
350
    DRIZZLE_TYPE_VARCHAR,
 
351
    //DRIZZLE_TYPE_NEWDECIMAL
 
352
    DRIZZLE_TYPE_VARCHAR,
 
353
    //DRIZZLE_TYPE_ENUM
 
354
    DRIZZLE_TYPE_VARCHAR,
 
355
    //DRIZZLE_TYPE_BLOB
358
356
    DRIZZLE_TYPE_BLOB,
359
357
  },
360
358
  /* DRIZZLE_TYPE_BLOB -> */
361
359
  {
362
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
363
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
364
 
  //DRIZZLE_TYPE_LONG
365
 
    DRIZZLE_TYPE_BLOB,
366
 
  //DRIZZLE_TYPE_DOUBLE
367
 
    DRIZZLE_TYPE_BLOB,
368
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
369
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
370
 
  //DRIZZLE_TYPE_LONGLONG
371
 
    DRIZZLE_TYPE_BLOB,
372
 
  //DRIZZLE_TYPE_TIME
373
 
    DRIZZLE_TYPE_BLOB,
374
 
  //DRIZZLE_TYPE_DATETIME
375
 
    DRIZZLE_TYPE_BLOB,
376
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
377
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
378
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
379
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
380
 
  //DRIZZLE_TYPE_BLOB
 
360
    //DRIZZLE_TYPE_TINY
 
361
    DRIZZLE_TYPE_BLOB,
 
362
    //DRIZZLE_TYPE_LONG
 
363
    DRIZZLE_TYPE_BLOB,
 
364
    //DRIZZLE_TYPE_DOUBLE
 
365
    DRIZZLE_TYPE_BLOB,
 
366
    //DRIZZLE_TYPE_NULL
 
367
    DRIZZLE_TYPE_BLOB,
 
368
    //DRIZZLE_TYPE_TIMESTAMP
 
369
    DRIZZLE_TYPE_BLOB,
 
370
    //DRIZZLE_TYPE_LONGLONG
 
371
    DRIZZLE_TYPE_BLOB,
 
372
    //DRIZZLE_TYPE_DATETIME
 
373
    DRIZZLE_TYPE_BLOB,
 
374
    //DRIZZLE_TYPE_DATE
 
375
    DRIZZLE_TYPE_BLOB,
 
376
    //DRIZZLE_TYPE_VARCHAR
 
377
    DRIZZLE_TYPE_BLOB,
 
378
    //DRIZZLE_TYPE_NEWDECIMAL
 
379
    DRIZZLE_TYPE_BLOB,
 
380
    //DRIZZLE_TYPE_ENUM
 
381
    DRIZZLE_TYPE_BLOB,
 
382
    //DRIZZLE_TYPE_BLOB
381
383
    DRIZZLE_TYPE_BLOB,
382
384
  },
383
385
};
395
397
enum_field_types Field::field_type_merge(enum_field_types a,
396
398
                                         enum_field_types b)
397
399
{
398
 
  assert(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
399
 
  assert(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
400
 
  return field_types_merge_rules[field_type2index(a)]
401
 
                                [field_type2index(b)];
 
400
  assert(a <= DRIZZLE_TYPE_MAX);
 
401
  assert(b <= DRIZZLE_TYPE_MAX);
 
402
  return field_types_merge_rules[a][b];
402
403
}
403
404
 
404
405
 
405
 
static Item_result field_types_result_type [FIELDTYPE_NUM]=
 
406
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
406
407
{
407
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
408
 
  DECIMAL_RESULT,           INT_RESULT,
 
408
  //DRIZZLE_TYPE_TINY
 
409
  INT_RESULT,
409
410
  //DRIZZLE_TYPE_LONG
410
411
  INT_RESULT,
411
412
  //DRIZZLE_TYPE_DOUBLE
412
413
  REAL_RESULT,
413
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
414
 
  STRING_RESULT,            STRING_RESULT,
 
414
  //DRIZZLE_TYPE_NULL
 
415
  STRING_RESULT,
 
416
  //DRIZZLE_TYPE_TIMESTAMP
 
417
  STRING_RESULT,
415
418
  //DRIZZLE_TYPE_LONGLONG
416
419
  INT_RESULT,
417
 
  //DRIZZLE_TYPE_TIME
418
 
  STRING_RESULT,
419
420
  //DRIZZLE_TYPE_DATETIME
420
421
  STRING_RESULT,
421
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
422
 
  STRING_RESULT,            STRING_RESULT,
423
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
424
 
  DECIMAL_RESULT,           STRING_RESULT,
 
422
  //DRIZZLE_TYPE_DATE
 
423
  STRING_RESULT,
 
424
  //DRIZZLE_TYPE_VARCHAR
 
425
  STRING_RESULT,
 
426
  //DRIZZLE_TYPE_NEWDECIMAL   
 
427
  DECIMAL_RESULT,           
 
428
  //DRIZZLE_TYPE_ENUM
 
429
  STRING_RESULT,
425
430
  //DRIZZLE_TYPE_BLOB
426
431
  STRING_RESULT,
427
432
};
443
448
    true  - If string has some important data
444
449
*/
445
450
 
446
 
static bool
 
451
bool
447
452
test_if_important_data(const CHARSET_INFO * const cs, const char *str,
448
453
                       const char *strend)
449
454
{
453
458
}
454
459
 
455
460
 
456
 
/**
457
 
  Detect Item_result by given field type of UNION merge result.
458
 
 
459
 
  @param field_type  given field type
460
 
 
461
 
  @return
462
 
    Item_result (type of internal MySQL expression result)
463
 
*/
464
 
 
465
461
Item_result Field::result_merge_type(enum_field_types field_type)
466
462
{
467
 
  assert(field_type < FIELDTYPE_TEAR_FROM || field_type
468
 
              > FIELDTYPE_TEAR_TO);
469
 
  return field_types_result_type[field_type2index(field_type)];
470
 
}
 
463
  assert(field_type <= DRIZZLE_TYPE_MAX);
 
464
  return field_types_result_type[field_type];
 
465
}
 
466
 
 
467
 
 
468
bool Field::eq(Field *field)
 
469
{
 
470
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
 
471
          null_bit == field->null_bit);
 
472
}
 
473
 
 
474
 
 
475
uint32_t Field::pack_length() const
 
476
{
 
477
  return field_length;
 
478
}
 
479
 
 
480
 
 
481
uint32_t Field::pack_length_in_rec() const
 
482
{
 
483
  return pack_length();
 
484
}
 
485
 
 
486
 
 
487
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
 
488
{
 
489
  return field_metadata;
 
490
}
 
491
 
 
492
 
 
493
uint32_t Field::row_pack_length()
 
494
{
 
495
  return 0;
 
496
}
 
497
 
 
498
 
 
499
int Field::save_field_metadata(unsigned char *first_byte)
 
500
{
 
501
  return do_save_field_metadata(first_byte);
 
502
}
 
503
 
 
504
 
 
505
uint32_t Field::data_length()
 
506
{
 
507
  return pack_length();
 
508
}
 
509
 
 
510
 
 
511
uint32_t Field::used_length()
 
512
{
 
513
  return pack_length();
 
514
}
 
515
 
 
516
 
 
517
uint32_t Field::sort_length() const
 
518
{
 
519
  return pack_length();
 
520
}
 
521
 
 
522
 
 
523
uint32_t Field::max_data_length() const
 
524
{
 
525
  return pack_length();
 
526
}
 
527
 
 
528
 
 
529
int Field::reset(void)
 
530
{
 
531
  memset(ptr, 0, pack_length());
 
532
  return 0;
 
533
}
 
534
 
 
535
 
 
536
void Field::reset_fields()
 
537
{}
 
538
 
 
539
 
 
540
void Field::set_default()
 
541
{
 
542
  my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
 
543
  memcpy(ptr, ptr + l_offset, pack_length());
 
544
  if (null_ptr)
 
545
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
 
546
 
 
547
  if(this == table->next_number_field)
 
548
    table->auto_increment_field_not_null= 0;
 
549
}
 
550
 
 
551
 
 
552
bool Field::binary() const
 
553
{
 
554
  return 1;
 
555
}
 
556
 
 
557
 
 
558
bool Field::zero_pack() const
 
559
{
 
560
  return 1;
 
561
}
 
562
 
 
563
 
 
564
enum ha_base_keytype Field::key_type() const
 
565
{
 
566
  return HA_KEYTYPE_BINARY;
 
567
}
 
568
 
 
569
 
 
570
uint32_t Field::key_length() const
 
571
{
 
572
  return pack_length();
 
573
}
 
574
 
 
575
 
 
576
enum_field_types Field::real_type() const
 
577
{
 
578
  return type();
 
579
}
 
580
 
 
581
 
 
582
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
 
583
{
 
584
  return cmp(a, b);
 
585
}
 
586
 
 
587
 
 
588
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
 
589
{
 
590
  return memcmp(a,b,pack_length());
 
591
}
 
592
 
 
593
 
 
594
int Field::cmp_offset(uint32_t row_offset)
 
595
{
 
596
  return cmp(ptr,ptr+row_offset);
 
597
}
 
598
 
 
599
 
 
600
int Field::cmp_binary_offset(uint32_t row_offset)
 
601
{
 
602
  return cmp_binary(ptr, ptr+row_offset);
 
603
}
 
604
 
 
605
 
 
606
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
 
607
{
 
608
  return cmp(a, b);
 
609
}
 
610
 
 
611
 
 
612
int Field::key_cmp(const unsigned char *str, uint32_t)
 
613
{
 
614
  return cmp(ptr,str);
 
615
}
 
616
 
 
617
 
 
618
uint32_t Field::decimals() const
 
619
{
 
620
  return 0;
 
621
}
 
622
 
 
623
 
 
624
bool Field::is_null(my_ptrdiff_t row_offset)
 
625
{
 
626
  return null_ptr ?
 
627
    (null_ptr[row_offset] & null_bit ? true : false) :
 
628
    table->null_row;
 
629
}
 
630
 
 
631
 
 
632
bool Field::is_real_null(my_ptrdiff_t row_offset)
 
633
{
 
634
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
 
635
}
 
636
 
 
637
 
 
638
bool Field::is_null_in_record(const unsigned char *record)
 
639
{
 
640
  if (!null_ptr)
 
641
    return false;
 
642
  return test(record[(uint32_t) (null_ptr -table->record[0])] &
 
643
              null_bit);
 
644
}
 
645
 
 
646
 
 
647
bool Field::is_null_in_record_with_offset(my_ptrdiff_t with_offset)
 
648
{
 
649
  if (!null_ptr)
 
650
    return false;
 
651
  return test(null_ptr[with_offset] & null_bit);
 
652
}
 
653
 
 
654
 
 
655
void Field::set_null(my_ptrdiff_t row_offset)
 
656
{
 
657
  if (null_ptr)
 
658
    null_ptr[row_offset]|= null_bit;
 
659
}
 
660
 
 
661
 
 
662
void Field::set_notnull(my_ptrdiff_t row_offset)
 
663
{
 
664
  if (null_ptr)
 
665
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
 
666
}
 
667
 
 
668
 
 
669
bool Field::maybe_null(void)
 
670
{
 
671
  return null_ptr != 0 || table->maybe_null;
 
672
}
 
673
 
 
674
 
 
675
bool Field::real_maybe_null(void)
 
676
{
 
677
  return null_ptr != 0;
 
678
}
 
679
 
 
680
 
 
681
size_t Field::last_null_byte() const
 
682
{
 
683
  size_t bytes= do_last_null_byte();
 
684
  assert(bytes <= table->getNullBytes());
 
685
  return bytes;
 
686
}
 
687
 
471
688
 
472
689
/*****************************************************************************
473
690
  Static help functions
474
691
*****************************************************************************/
475
692
 
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
693
bool Field::type_can_have_key_part(enum enum_field_types type)
492
694
{
493
695
  switch (type) {
501
703
 
502
704
 
503
705
/**
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
706
  Process decimal library return codes and issue warnings for overflow and
634
707
  truncation.
635
708
 
636
709
  @param op_result  decimal library return code (E_DEC_* see include/decimal.h)
637
710
 
638
711
  @retval
639
 
    1  there was overflow
 
712
    E_DEC_OVERFLOW   there was overflow
 
713
    E_DEC_TRUNCATED  there was truncation
640
714
  @retval
641
 
    0  no error or some other errors except overflow
 
715
    0  no error or there was some other error except overflow or truncation
642
716
*/
643
717
 
644
718
int Field::warn_if_overflow(int op_result)
646
720
  if (op_result == E_DEC_OVERFLOW)
647
721
  {
648
722
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
649
 
    return 1;
 
723
    return E_DEC_OVERFLOW;
650
724
  }
651
725
  if (op_result == E_DEC_TRUNCATED)
652
726
  {
653
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
654
 
    /* We return 0 here as this is not a critical issue */
 
727
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
 
728
    return E_DEC_TRUNCATED;
655
729
  }
656
730
  return 0;
657
731
}
658
732
 
659
733
 
 
734
void Field::init(Table *table_arg)
 
735
{
 
736
  orig_table= table= table_arg;
 
737
  table_name= &table_arg->alias;
 
738
}
 
739
 
 
740
 
660
741
#ifdef NOT_USED
661
742
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
662
743
{
692
773
    return 1;
693
774
  if (*str == 'E' || *str == 'e')
694
775
  {
695
 
    if (length < 3 || (str[1] != '+' && str[1] != '-') || 
 
776
    if (length < 3 || (str[1] != '+' && str[1] != '-') ||
696
777
        !my_isdigit(cs,str[2]))
697
778
      return 0;
698
779
    length-=3;
737
818
 
738
819
/// This is used as a table name when the table structure is not set up
739
820
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)
 
821
             unsigned char null_bit_arg,
 
822
             utype unireg_check_arg, const char *field_name_arg)
742
823
  :ptr(ptr_arg), null_ptr(null_ptr_arg),
743
824
   table(0), orig_table(0), table_name(0),
744
825
   field_name(field_name_arg),
745
826
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
746
827
   part_of_sortkey(0), unireg_check(unireg_check_arg),
747
 
   field_length(length_arg), null_bit(null_bit_arg), 
 
828
   field_length(length_arg), null_bit(null_bit_arg),
748
829
   is_created_from_null_item(false)
749
830
{
750
831
  flags=null_ptr ? 0: NOT_NULL_FLAG;
783
864
  memcpy(ptr,ptr+row_offset,pack_length());
784
865
  if (null_ptr)
785
866
  {
786
 
    *null_ptr= (unsigned char) ((null_ptr[0] & (unsigned char) ~(uint32_t) null_bit) | (null_ptr[row_offset] & (unsigned char) null_bit));
 
867
    *null_ptr= (unsigned char) ((null_ptr[0] &
 
868
                                 (unsigned char) ~(uint32_t) null_bit) |
 
869
                                (null_ptr[row_offset] &
 
870
                                 (unsigned char) null_bit));
787
871
  }
788
872
}
789
873
 
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
874
/**
801
875
   Check to see if field size is compatible with destination.
802
876
 
803
877
   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 
 
878
   field size is less than or equal to the master's field size. The
805
879
   encoded field metadata (from the master or source) is decoded and compared
806
 
   to the size of this field (the slave or destination). 
 
880
   to the size of this field (the slave or destination).
807
881
 
808
882
   @param   field_metadata   Encoded size in field metadata
809
883
 
818
892
}
819
893
 
820
894
 
821
 
int Field::store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
 
895
int Field::store(const char *to, uint32_t length,
 
896
                 const CHARSET_INFO * const cs,
822
897
                 enum_check_fields check_level)
823
898
{
824
899
  int res;
869
944
*/
870
945
unsigned char *
871
946
Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length,
872
 
            bool low_byte_first __attribute__((unused)))
 
947
            bool)
873
948
{
874
949
  uint32_t length= pack_length();
875
950
  set_if_smaller(length, max_length);
877
952
  return to+length;
878
953
}
879
954
 
 
955
 
 
956
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
 
957
{
 
958
  unsigned char *result= this->pack(to, from, UINT32_MAX,
 
959
                                    table->s->db_low_byte_first);
 
960
  return(result);
 
961
}
 
962
 
 
963
 
880
964
/**
881
965
   Unpack a field from row data.
882
966
 
909
993
*/
910
994
const unsigned char *
911
995
Field::unpack(unsigned char* to, const unsigned char *from, uint32_t param_data,
912
 
              bool low_byte_first __attribute__((unused)))
 
996
              bool)
913
997
{
914
998
  uint32_t length=pack_length();
915
999
  int from_type= 0;
939
1023
}
940
1024
 
941
1025
 
942
 
my_decimal *Field::val_decimal(my_decimal *decimal __attribute__((unused)))
 
1026
const unsigned char *Field::unpack(unsigned char* to,
 
1027
                                   const unsigned char *from)
 
1028
{
 
1029
  const unsigned char *result= unpack(to, from, 0U,
 
1030
                                      table->s->db_low_byte_first);
 
1031
  return(result);
 
1032
}
 
1033
 
 
1034
 
 
1035
uint32_t Field::packed_col_length(const unsigned char *, uint32_t length)
 
1036
{
 
1037
  return length;
 
1038
}
 
1039
 
 
1040
 
 
1041
int Field::pack_cmp(const unsigned char *a, const unsigned char *b,
 
1042
                    uint32_t, bool)
 
1043
{
 
1044
  return cmp(a,b);
 
1045
}
 
1046
 
 
1047
 
 
1048
int Field::pack_cmp(const unsigned char *b, uint32_t, bool)
 
1049
{
 
1050
  return cmp(ptr,b);
 
1051
}
 
1052
 
 
1053
 
 
1054
my_decimal *Field::val_decimal(my_decimal *)
943
1055
{
944
1056
  /* This never have to be called */
945
1057
  assert(0);
947
1059
}
948
1060
 
949
1061
 
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
1062
void Field::make_field(Send_field *field)
958
1063
{
959
1064
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
993
1098
  @return
994
1099
    value converted from val
995
1100
*/
996
 
int64_t Field::convert_decimal2int64_t(const my_decimal *val,
997
 
                                         bool unsigned_flag, int *err)
 
1101
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
998
1102
{
999
1103
  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)))
 
1104
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
1105
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
 
1106
                                      val, false, &i)))
1019
1107
  {
1020
1108
    i= (val->sign() ? INT64_MIN : INT64_MAX);
1021
1109
    *err= 1;
1023
1111
  return i;
1024
1112
}
1025
1113
 
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
1114
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
1130
1115
{
1131
1116
  uint32_t store_length;
1176
1161
    Needs to be changed if/when we want to support different time formats.
1177
1162
*/
1178
1163
 
1179
 
int Field::store_time(DRIZZLE_TIME *ltime,
1180
 
                      enum enum_drizzle_timestamp_type type_arg __attribute__((unused)))
 
1164
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
1181
1165
{
1182
1166
  char buff[MAX_DATE_STRING_REP_LENGTH];
1183
1167
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
1191
1175
}
1192
1176
 
1193
1177
 
1194
 
Field *Field::new_field(MEM_ROOT *root, Table *new_table,
1195
 
                        bool keep_type __attribute__((unused)))
 
1178
Field *Field::new_field(MEM_ROOT *root, Table *new_table, bool)
1196
1179
{
1197
1180
  Field *tmp;
1198
1181
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1201
1184
  if (tmp->table->maybe_null)
1202
1185
    tmp->flags&= ~NOT_NULL_FLAG;
1203
1186
  tmp->table= new_table;
1204
 
  tmp->key_start.init(0);
1205
 
  tmp->part_of_key.init(0);
1206
 
  tmp->part_of_sortkey.init(0);
 
1187
  tmp->key_start.reset();
 
1188
  tmp->part_of_key.reset();
 
1189
  tmp->part_of_sortkey.reset();
1207
1190
  tmp->unireg_check= Field::NONE;
1208
1191
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
1209
1192
  tmp->reset_fields();
1226
1209
}
1227
1210
 
1228
1211
 
1229
 
/* This is used to generate a field in Table from TABLE_SHARE */
 
1212
/* This is used to generate a field in Table from TableShare */
1230
1213
 
1231
1214
Field *Field::clone(MEM_ROOT *root, Table *new_table)
1232
1215
{
1241
1224
}
1242
1225
 
1243
1226
 
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
 
 
 
1227
uint32_t Field::is_equal(Create_field *new_field_ptr)
 
1228
{
 
1229
  return (new_field_ptr->sql_type == real_type());
 
1230
}
1606
1231
 
1607
1232
/**
1608
1233
  @retval
1641
1266
  return 1;
1642
1267
}
1643
1268
 
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
1269
/*****************************************************************************
1673
1270
  Handling of field and Create_field
1674
1271
*****************************************************************************/
1687
1284
    pack_length= calc_pack_length(sql_type, length);
1688
1285
    break;
1689
1286
  case DRIZZLE_TYPE_ENUM:
1690
 
    /* Pack_length already calculated in sql_parse.cc */
 
1287
    /* Pack_length already calculated in ::init() */
1691
1288
    length*= charset->mbmaxlen;
1692
1289
    key_length= pack_length;
1693
1290
    break;
1729
1326
/**
1730
1327
  Initialize field definition for create.
1731
1328
 
1732
 
  @param thd                   Thread handle
 
1329
  @param session                   Thread handle
1733
1330
  @param fld_name              Field name
1734
1331
  @param fld_type              Field type
1735
1332
  @param fld_length            Field length
1748
1345
    true  on error
1749
1346
*/
1750
1347
 
1751
 
bool Create_field::init(THD *thd __attribute__((unused)), char *fld_name, enum_field_types fld_type,
 
1348
bool Create_field::init(Session *, char *fld_name, enum_field_types fld_type,
1752
1349
                        char *fld_length, char *fld_decimals,
1753
1350
                        uint32_t fld_type_modifier, Item *fld_default_value,
1754
1351
                        Item *fld_on_update_value, LEX_STRING *fld_comment,
1755
1352
                        char *fld_change, List<String> *fld_interval_list,
1756
1353
                        const CHARSET_INFO * const fld_charset,
1757
 
                        uint32_t fld_geom_type __attribute__((unused)),
1758
 
                        enum column_format_type column_format)
 
1354
                        uint32_t, enum column_format_type column_format_in)
 
1355
                        
1759
1356
{
1760
1357
  uint32_t sign_len, allowed_type_modifier= 0;
1761
1358
  uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
1764
1361
  field_name= fld_name;
1765
1362
  def= fld_default_value;
1766
1363
  flags= fld_type_modifier;
1767
 
  flags|= (((uint32_t)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
 
1364
  flags|= (((uint32_t)column_format_in & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
1768
1365
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
1769
1366
                 Field::NEXT_NUMBER : Field::NONE);
1770
1367
  decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
1784
1381
  interval_list.empty();
1785
1382
 
1786
1383
  comment= *fld_comment;
 
1384
 
1787
1385
  /*
1788
1386
    Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
1789
1387
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
1846
1444
      /* Allow empty as default value. */
1847
1445
      String str,*res;
1848
1446
      res= fld_default_value->val_str(&str);
 
1447
      if (res->length())
 
1448
      {
 
1449
        my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
 
1450
                 fld_name);
 
1451
        return(true);
 
1452
      }
 
1453
 
1849
1454
    }
1850
1455
    flags|= BLOB_FLAG;
1851
1456
    break;
1882
1487
    if (fld_default_value)
1883
1488
    {
1884
1489
      /* Grammar allows only NOW() value for ON UPDATE clause */
1885
 
      if (fld_default_value->type() == Item::FUNC_ITEM && 
 
1490
      if (fld_default_value->type() == Item::FUNC_ITEM &&
1886
1491
          ((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
1887
1492
      {
1888
1493
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
1917
1522
                                              Field::NONE));
1918
1523
    }
1919
1524
    break;
1920
 
  case DRIZZLE_TYPE_NEWDATE:
1921
 
    length= 10;
1922
 
    break;
1923
 
  case DRIZZLE_TYPE_TIME:
 
1525
  case DRIZZLE_TYPE_DATE:
1924
1526
    length= 10;
1925
1527
    break;
1926
1528
  case DRIZZLE_TYPE_DATETIME:
1964
1566
}
1965
1567
 
1966
1568
 
1967
 
enum_field_types get_blob_type_from_length(uint32_t length __attribute__((unused)))
 
1569
enum_field_types get_blob_type_from_length(uint32_t)
1968
1570
{
1969
1571
  enum_field_types type;
1970
1572
 
1983
1585
  switch (type) {
1984
1586
  case DRIZZLE_TYPE_VARCHAR:     return (length + (length < 256 ? 1: 2));
1985
1587
  case DRIZZLE_TYPE_TINY        : return 1;
1986
 
  case DRIZZLE_TYPE_NEWDATE:
1987
 
  case DRIZZLE_TYPE_TIME:   return 3;
 
1588
  case DRIZZLE_TYPE_DATE: return 3;
1988
1589
  case DRIZZLE_TYPE_TIMESTAMP:
1989
1590
  case DRIZZLE_TYPE_LONG        : return 4;
1990
1591
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
1994
1595
  case DRIZZLE_TYPE_BLOB:               return 4+portable_sizeof_char_ptr;
1995
1596
  case DRIZZLE_TYPE_ENUM:
1996
1597
  case DRIZZLE_TYPE_NEWDECIMAL:
1997
 
    abort(); return 0;                          // This shouldn't happen
 
1598
    abort();
1998
1599
  default:
1999
1600
    return 0;
2000
1601
  }
2004
1605
uint32_t pack_length_to_packflag(uint32_t type)
2005
1606
{
2006
1607
  switch (type) {
2007
 
    case 1: return f_settype((uint32_t) DRIZZLE_TYPE_TINY);
 
1608
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
2008
1609
    case 2: assert(1);
2009
1610
    case 3: assert(1);
2010
1611
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
2014
1615
}
2015
1616
 
2016
1617
 
2017
 
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
 
1618
Field *make_field(TableShare *share, MEM_ROOT *root,
 
1619
                  unsigned char *ptr, uint32_t field_length,
2018
1620
                  unsigned char *null_pos, unsigned char null_bit,
2019
1621
                  uint32_t pack_flag,
2020
1622
                  enum_field_types field_type,
2023
1625
                  TYPELIB *interval,
2024
1626
                  const char *field_name)
2025
1627
{
 
1628
  if(!root)
 
1629
    root= current_mem_root();
 
1630
 
2026
1631
  if (!f_maybe_null(pack_flag))
2027
1632
  {
2028
1633
    null_pos=0;
2034
1639
  }
2035
1640
 
2036
1641
  switch (field_type) {
2037
 
  case DRIZZLE_TYPE_NEWDATE:
2038
 
  case DRIZZLE_TYPE_TIME:
 
1642
  case DRIZZLE_TYPE_DATE:
2039
1643
  case DRIZZLE_TYPE_DATETIME:
2040
1644
  case DRIZZLE_TYPE_TIMESTAMP:
2041
1645
    field_charset= &my_charset_bin;
2047
1651
    if (!f_is_packed(pack_flag))
2048
1652
    {
2049
1653
      if (field_type == DRIZZLE_TYPE_VARCHAR)
2050
 
        return new Field_varstring(ptr,field_length,
 
1654
        return new (root) Field_varstring(ptr,field_length,
2051
1655
                                   HA_VARCHAR_PACKLENGTH(field_length),
2052
1656
                                   null_pos,null_bit,
2053
1657
                                   unireg_check, field_name,
2061
1665
                                      field_length);
2062
1666
 
2063
1667
    if (f_is_blob(pack_flag))
2064
 
      return new Field_blob(ptr,null_pos,null_bit,
 
1668
      return new (root) Field_blob(ptr,null_pos,null_bit,
2065
1669
                            unireg_check, field_name, share,
2066
1670
                            pack_length, field_charset);
2067
1671
    if (interval)
2068
1672
    {
2069
1673
      if (f_is_enum(pack_flag))
2070
 
        return new Field_enum(ptr,field_length,null_pos,null_bit,
 
1674
      {
 
1675
        return new (root) Field_enum(ptr,field_length,null_pos,null_bit,
2071
1676
                                  unireg_check, field_name,
2072
 
                                  pack_length, interval, field_charset);
 
1677
                                  get_enum_pack_length(interval->count),
 
1678
                                  interval, field_charset);
 
1679
      }
2073
1680
    }
2074
1681
  }
2075
1682
 
2076
1683
  switch (field_type) {
2077
1684
  case DRIZZLE_TYPE_NEWDECIMAL:
2078
 
    return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
 
1685
    return new (root) Field_new_decimal(ptr,field_length,null_pos,null_bit,
2079
1686
                                 unireg_check, field_name,
2080
1687
                                 f_decimals(pack_flag),
2081
1688
                                 f_is_decimal_precision(pack_flag) != 0,
2082
1689
                                 f_is_dec(pack_flag) == 0);
2083
1690
  case DRIZZLE_TYPE_DOUBLE:
2084
 
    return new Field_double(ptr,field_length,null_pos,null_bit,
 
1691
    return new (root) Field_double(ptr,field_length,null_pos,null_bit,
2085
1692
                            unireg_check, field_name,
2086
1693
                            f_decimals(pack_flag),
2087
1694
                            false,
2088
1695
                            f_is_dec(pack_flag)== 0);
2089
1696
  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);
 
1697
    assert(0);
2094
1698
  case DRIZZLE_TYPE_LONG:
2095
 
    return new Field_long(ptr,field_length,null_pos,null_bit,
 
1699
    return new (root) Field_long(ptr,field_length,null_pos,null_bit,
2096
1700
                           unireg_check, field_name,
2097
1701
                           false,
2098
1702
                           f_is_dec(pack_flag) == 0);
2099
1703
  case DRIZZLE_TYPE_LONGLONG:
2100
 
    return new Field_int64_t(ptr,field_length,null_pos,null_bit,
 
1704
    return new (root) Field_int64_t(ptr,field_length,null_pos,null_bit,
2101
1705
                              unireg_check, field_name,
2102
1706
                              false,
2103
1707
                              f_is_dec(pack_flag) == 0);
2104
1708
  case DRIZZLE_TYPE_TIMESTAMP:
2105
 
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,
 
1709
    return new (root) Field_timestamp(ptr,field_length, null_pos, null_bit,
2106
1710
                               unireg_check, field_name, share,
2107
1711
                               field_charset);
2108
 
  case DRIZZLE_TYPE_NEWDATE:
2109
 
    return new Field_newdate(ptr,null_pos,null_bit,
 
1712
  case DRIZZLE_TYPE_DATE:
 
1713
    return new (root) Field_date(ptr,null_pos,null_bit,
2110
1714
                             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
1715
  case DRIZZLE_TYPE_DATETIME:
2115
 
    return new Field_datetime(ptr,null_pos,null_bit,
 
1716
    return new (root) Field_datetime(ptr,null_pos,null_bit,
2116
1717
                              unireg_check, field_name, field_charset);
2117
1718
  case DRIZZLE_TYPE_NULL:
2118
 
    return new Field_null(ptr, field_length, unireg_check, field_name,
 
1719
    return new (root) Field_null(ptr, field_length, unireg_check, field_name,
2119
1720
                          field_charset);
2120
1721
  default:                                      // Impossible (Wrong version)
2121
1722
    break;
2168
1769
  def=0;
2169
1770
  char_length= length;
2170
1771
 
2171
 
  if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
 
1772
  if (!(flags & (NO_DEFAULT_VALUE_FLAG )) &&
2172
1773
      old_field->ptr && orig_field &&
2173
1774
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
2174
 
       old_field->table->timestamp_field != old_field ||  /* timestamp field */ 
 
1775
       old_field->table->timestamp_field != old_field ||  /* timestamp field */
2175
1776
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
2176
1777
  {
2177
 
    char buff[MAX_FIELD_WIDTH];
2178
 
    String tmp(buff,sizeof(buff), charset);
2179
1778
    my_ptrdiff_t diff;
2180
1779
 
2181
1780
    /* Get the value from default_values */
2219
1818
    0 otherwise
2220
1819
*/
2221
1820
 
2222
 
bool 
 
1821
bool
2223
1822
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2224
1823
                   int cuted_increment)
2225
1824
{
2227
1826
    If this field was created only for type conversion purposes it
2228
1827
    will have table == NULL.
2229
1828
  */
2230
 
  THD *thd= table ? table->in_use : current_thd;
2231
 
  if (thd->count_cuted_fields)
 
1829
  Session *session= table ? table->in_use : current_session;
 
1830
  if (session->count_cuted_fields)
2232
1831
  {
2233
 
    thd->cuted_fields+= cuted_increment;
2234
 
    push_warning_printf(thd, level, code, ER(code), field_name,
2235
 
                        thd->row_count);
 
1832
    session->cuted_fields+= cuted_increment;
 
1833
    push_warning_printf(session, level, code, ER(code), field_name,
 
1834
                        session->row_count);
2236
1835
    return 0;
2237
1836
  }
2238
1837
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
2255
1854
    thread.
2256
1855
*/
2257
1856
 
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, 
 
1857
void
 
1858
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
 
1859
                            unsigned int code,
 
1860
                            const char *str, uint32_t str_length,
2262
1861
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
2263
1862
{
2264
 
  THD *thd= table ? table->in_use : current_thd;
2265
 
  if ((thd->really_abort_on_warning() &&
 
1863
  Session *session= table ? table->in_use : current_session;
 
1864
  if ((session->really_abort_on_warning() &&
2266
1865
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
2267
1866
      set_warning(level, code, cuted_increment))
2268
 
    make_truncated_value_warning(thd, level, str, str_length, ts_type,
 
1867
    make_truncated_value_warning(session, level, str, str_length, ts_type,
2269
1868
                                 field_name);
2270
1869
}
2271
1870
 
2285
1884
    thread.
2286
1885
*/
2287
1886
 
2288
 
void 
2289
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
1887
void
 
1888
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
2290
1889
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
2291
1890
                            int cuted_increment)
2292
1891
{
2293
 
  THD *thd= table ? table->in_use : current_thd;
2294
 
  if (thd->really_abort_on_warning() ||
 
1892
  Session *session= table ? table->in_use : current_session;
 
1893
  if (session->really_abort_on_warning() ||
2295
1894
      set_warning(level, code, cuted_increment))
2296
1895
  {
2297
1896
    char str_nr[22];
2298
1897
    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), 
 
1898
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
2300
1899
                                 ts_type, field_name);
2301
1900
  }
2302
1901
}
2316
1915
    thread.
2317
1916
*/
2318
1917
 
2319
 
void 
2320
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
1918
void
 
1919
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, const uint32_t code,
2321
1920
                            double nr, enum enum_drizzle_timestamp_type ts_type)
2322
1921
{
2323
 
  THD *thd= table ? table->in_use : current_thd;
2324
 
  if (thd->really_abort_on_warning() ||
 
1922
  Session *session= table ? table->in_use : current_session;
 
1923
  if (session->really_abort_on_warning() ||
2325
1924
      set_warning(level, code, 1))
2326
1925
  {
2327
1926
    /* DBL_DIG is enough to print '-[digits].E+###' */
2328
1927
    char str_nr[DBL_DIG + 8];
2329
1928
    uint32_t str_len= sprintf(str_nr, "%g", nr);
2330
 
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
 
1929
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
2331
1930
                                 field_name);
2332
1931
  }
2333
1932
}
 
1933
 
 
1934
bool Field::isReadSet() 
 
1935
 
1936
  return table->isReadSet(field_index); 
 
1937
}
 
1938
 
 
1939
 
 
1940
bool Field::isWriteSet()
 
1941
 
1942
  return table->isWriteSet(field_index); 
 
1943
}
 
1944