~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2009-12-29 01:38:38 UTC
  • mfrom: (1251.1.1 drizzle)
  • Revision ID: brian@gaz-20091229013838-03kb2z5xbqw03ddt
Merge of Diego fix.

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
 
  @file
 
22
 * @file This file implements the Field class and API
 
23
 */
19
24
 
20
 
  @brief
21
 
  This file implements classes defined in field.h
22
 
*/
23
 
#include <drizzled/server_includes.h>
24
 
#include "sql_select.h"
 
25
#include "config.h"
25
26
#include <errno.h>
26
 
#include <drizzled/drizzled_error_messages.h>
 
27
#include <float.h>
 
28
#include "drizzled/sql_select.h"
 
29
#include "drizzled/error.h"
 
30
#include "drizzled/field/str.h"
 
31
#include "drizzled/field/num.h"
 
32
#include "drizzled/field/blob.h"
 
33
#include "drizzled/field/enum.h"
 
34
#include "drizzled/field/null.h"
 
35
#include "drizzled/field/date.h"
 
36
#include "drizzled/field/decimal.h"
 
37
#include "drizzled/field/real.h"
 
38
#include "drizzled/field/double.h"
 
39
#include "drizzled/field/long.h"
 
40
#include "drizzled/field/int64_t.h"
 
41
#include "drizzled/field/num.h"
 
42
#include "drizzled/field/timestamp.h"
 
43
#include "drizzled/field/datetime.h"
 
44
#include "drizzled/field/varstring.h"
 
45
#include "drizzled/time_functions.h"
 
46
#include "drizzled/internal/m_string.h"
27
47
 
28
 
// Maximum allowed exponent value for converting string to decimal
29
 
#define MAX_EXPONENT 1024
 
48
using namespace drizzled;
30
49
 
31
50
/*****************************************************************************
32
51
  Instansiate templates and static variables
33
52
*****************************************************************************/
34
53
 
35
 
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
36
 
template class List<Create_field>;
37
 
template class List_iterator<Create_field>;
38
 
#endif
39
 
 
40
 
 
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_SHORT        DRIZZLE_TYPE_LONG
66
 
    DRIZZLE_TYPE_NEWDECIMAL,  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_DATE         DRIZZLE_TYPE_TIME
74
 
    DRIZZLE_TYPE_VARCHAR,     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
 
  },
84
 
  /* DRIZZLE_TYPE_TINY -> */
85
 
  {
86
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
87
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
88
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
89
 
    DRIZZLE_TYPE_SHORT,       DRIZZLE_TYPE_LONG,
90
 
  //DRIZZLE_TYPE_DOUBLE
91
 
    DRIZZLE_TYPE_DOUBLE,
92
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
93
 
    DRIZZLE_TYPE_TINY,        DRIZZLE_TYPE_VARCHAR,
94
 
  //DRIZZLE_TYPE_LONGLONG
95
 
    DRIZZLE_TYPE_LONGLONG,
96
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
97
 
    DRIZZLE_TYPE_VARCHAR,     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
105
 
    DRIZZLE_TYPE_BLOB,
106
 
  },
107
 
  /* DRIZZLE_TYPE_SHORT -> */
108
 
  {
109
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
110
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_SHORT,
111
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
112
 
    DRIZZLE_TYPE_SHORT,       DRIZZLE_TYPE_LONG,
113
 
  //DRIZZLE_TYPE_DOUBLE
114
 
    DRIZZLE_TYPE_DOUBLE,
115
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
116
 
    DRIZZLE_TYPE_SHORT,       DRIZZLE_TYPE_VARCHAR,
117
 
  //DRIZZLE_TYPE_LONGLONG
118
 
    DRIZZLE_TYPE_LONGLONG,
119
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
120
 
    DRIZZLE_TYPE_VARCHAR,     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
128
 
    DRIZZLE_TYPE_BLOB,
129
 
  },
 
54
static enum_field_types
 
55
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
 
56
{
130
57
  /* DRIZZLE_TYPE_LONG -> */
131
58
  {
132
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
133
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONG,
134
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
135
 
    DRIZZLE_TYPE_LONG,        DRIZZLE_TYPE_LONG,
136
 
  //DRIZZLE_TYPE_DOUBLE
 
59
    //DRIZZLE_TYPE_LONG
 
60
    DRIZZLE_TYPE_LONG,
 
61
    //DRIZZLE_TYPE_DOUBLE
137
62
    DRIZZLE_TYPE_DOUBLE,
138
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
139
 
    DRIZZLE_TYPE_LONG,         DRIZZLE_TYPE_VARCHAR,
140
 
  //DRIZZLE_TYPE_LONGLONG
 
63
    //DRIZZLE_TYPE_NULL
 
64
    DRIZZLE_TYPE_LONG,
 
65
    //DRIZZLE_TYPE_TIMESTAMP
 
66
    DRIZZLE_TYPE_VARCHAR,
 
67
    //DRIZZLE_TYPE_LONGLONG
141
68
    DRIZZLE_TYPE_LONGLONG,
142
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
143
 
    DRIZZLE_TYPE_VARCHAR,     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_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
150
 
  //DRIZZLE_TYPE_BLOB
 
69
    //DRIZZLE_TYPE_DATETIME
 
70
    DRIZZLE_TYPE_VARCHAR,
 
71
    //DRIZZLE_TYPE_DATE
 
72
    DRIZZLE_TYPE_VARCHAR,
 
73
    //DRIZZLE_TYPE_VARCHAR
 
74
    DRIZZLE_TYPE_VARCHAR,
 
75
    //DRIZZLE_TYPE_DECIMAL
 
76
    DRIZZLE_TYPE_DECIMAL,
 
77
    //DRIZZLE_TYPE_ENUM
 
78
    DRIZZLE_TYPE_VARCHAR,
 
79
    //DRIZZLE_TYPE_BLOB
151
80
    DRIZZLE_TYPE_BLOB,
152
81
  },
153
82
  /* DRIZZLE_TYPE_DOUBLE -> */
154
83
  {
155
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
156
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_DOUBLE,
157
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
158
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_DOUBLE,
159
 
  //DRIZZLE_TYPE_DOUBLE
160
 
    DRIZZLE_TYPE_DOUBLE,
161
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
162
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
163
 
  //DRIZZLE_TYPE_LONGLONG
164
 
    DRIZZLE_TYPE_DOUBLE,
165
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
166
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
167
 
  //DRIZZLE_TYPE_DATETIME
168
 
    DRIZZLE_TYPE_VARCHAR,
169
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
170
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
171
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
172
 
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
173
 
  //DRIZZLE_TYPE_BLOB
 
84
    //DRIZZLE_TYPE_LONG
 
85
    DRIZZLE_TYPE_DOUBLE,
 
86
    //DRIZZLE_TYPE_DOUBLE
 
87
    DRIZZLE_TYPE_DOUBLE,
 
88
    //DRIZZLE_TYPE_NULL
 
89
    DRIZZLE_TYPE_DOUBLE,
 
90
    //DRIZZLE_TYPE_TIMESTAMP
 
91
    DRIZZLE_TYPE_VARCHAR,
 
92
    //DRIZZLE_TYPE_LONGLONG
 
93
    DRIZZLE_TYPE_DOUBLE,
 
94
    //DRIZZLE_TYPE_DATETIME
 
95
    DRIZZLE_TYPE_VARCHAR,
 
96
    //DRIZZLE_TYPE_DATE
 
97
    DRIZZLE_TYPE_VARCHAR,
 
98
    //DRIZZLE_TYPE_VARCHAR
 
99
    DRIZZLE_TYPE_VARCHAR,
 
100
    //DRIZZLE_TYPE_DECIMAL
 
101
    DRIZZLE_TYPE_DOUBLE,
 
102
    //DRIZZLE_TYPE_ENUM
 
103
    DRIZZLE_TYPE_VARCHAR,
 
104
    //DRIZZLE_TYPE_BLOB
174
105
    DRIZZLE_TYPE_BLOB,
175
106
  },
176
107
  /* DRIZZLE_TYPE_NULL -> */
177
108
  {
178
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
179
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
180
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
181
 
    DRIZZLE_TYPE_SHORT,       DRIZZLE_TYPE_LONG,
182
 
  //DRIZZLE_TYPE_DOUBLE
 
109
    //DRIZZLE_TYPE_LONG
 
110
    DRIZZLE_TYPE_LONG,
 
111
    //DRIZZLE_TYPE_DOUBLE
183
112
    DRIZZLE_TYPE_DOUBLE,
184
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
185
 
    DRIZZLE_TYPE_NULL,        DRIZZLE_TYPE_TIMESTAMP,
186
 
  //DRIZZLE_TYPE_LONGLONG
 
113
    //DRIZZLE_TYPE_NULL
 
114
    DRIZZLE_TYPE_NULL,
 
115
    //DRIZZLE_TYPE_TIMESTAMP
 
116
    DRIZZLE_TYPE_TIMESTAMP,
 
117
    //DRIZZLE_TYPE_LONGLONG
187
118
    DRIZZLE_TYPE_LONGLONG,
188
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
189
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_TIME,
190
 
  //DRIZZLE_TYPE_DATETIME
 
119
    //DRIZZLE_TYPE_DATETIME
191
120
    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_NEWDECIMAL,  DRIZZLE_TYPE_ENUM,
196
 
  //DRIZZLE_TYPE_BLOB
 
121
    //DRIZZLE_TYPE_DATE
 
122
    DRIZZLE_TYPE_DATE,
 
123
    //DRIZZLE_TYPE_VARCHAR
 
124
    DRIZZLE_TYPE_VARCHAR,
 
125
    //DRIZZLE_TYPE_DECIMAL
 
126
    DRIZZLE_TYPE_DECIMAL,
 
127
    //DRIZZLE_TYPE_ENUM
 
128
    DRIZZLE_TYPE_ENUM,
 
129
    //DRIZZLE_TYPE_BLOB
197
130
    DRIZZLE_TYPE_BLOB,
198
131
  },
199
132
  /* DRIZZLE_TYPE_TIMESTAMP -> */
200
133
  {
201
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
202
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
203
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
204
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
205
 
  //DRIZZLE_TYPE_DOUBLE
206
 
    DRIZZLE_TYPE_VARCHAR,
207
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
208
 
    DRIZZLE_TYPE_TIMESTAMP,   DRIZZLE_TYPE_TIMESTAMP,
209
 
  //DRIZZLE_TYPE_LONGLONG
210
 
    DRIZZLE_TYPE_VARCHAR,
211
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
212
 
    DRIZZLE_TYPE_DATETIME,    DRIZZLE_TYPE_DATETIME,
213
 
  //DRIZZLE_TYPE_DATETIME
 
134
    //DRIZZLE_TYPE_LONG
 
135
    DRIZZLE_TYPE_VARCHAR,
 
136
    //DRIZZLE_TYPE_DOUBLE
 
137
    DRIZZLE_TYPE_VARCHAR,
 
138
    //DRIZZLE_TYPE_NULL
 
139
    DRIZZLE_TYPE_TIMESTAMP,
 
140
    //DRIZZLE_TYPE_TIMESTAMP
 
141
    DRIZZLE_TYPE_TIMESTAMP,
 
142
    //DRIZZLE_TYPE_LONGLONG
 
143
    DRIZZLE_TYPE_VARCHAR,
 
144
    //DRIZZLE_TYPE_DATETIME
214
145
    DRIZZLE_TYPE_DATETIME,
215
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
216
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
217
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
218
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
219
 
  //DRIZZLE_TYPE_BLOB
 
146
    //DRIZZLE_TYPE_DATE
 
147
    DRIZZLE_TYPE_DATE,
 
148
    //DRIZZLE_TYPE_VARCHAR
 
149
    DRIZZLE_TYPE_VARCHAR,
 
150
    //DRIZZLE_TYPE_DECIMAL
 
151
    DRIZZLE_TYPE_VARCHAR,
 
152
    //DRIZZLE_TYPE_ENUM
 
153
    DRIZZLE_TYPE_VARCHAR,
 
154
    //DRIZZLE_TYPE_BLOB
220
155
    DRIZZLE_TYPE_BLOB,
221
156
  },
222
157
  /* DRIZZLE_TYPE_LONGLONG -> */
223
158
  {
224
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
225
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONGLONG,
226
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
227
 
    DRIZZLE_TYPE_LONGLONG,    DRIZZLE_TYPE_LONGLONG,
228
 
  //DRIZZLE_TYPE_DOUBLE
 
159
    //DRIZZLE_TYPE_LONG
 
160
    DRIZZLE_TYPE_LONGLONG,
 
161
    //DRIZZLE_TYPE_DOUBLE
229
162
    DRIZZLE_TYPE_DOUBLE,
230
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
231
 
    DRIZZLE_TYPE_LONGLONG,    DRIZZLE_TYPE_VARCHAR,
232
 
  //DRIZZLE_TYPE_LONGLONG
233
 
    DRIZZLE_TYPE_LONGLONG,
234
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
235
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
236
 
  //DRIZZLE_TYPE_DATETIME
237
 
    DRIZZLE_TYPE_VARCHAR,
238
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
239
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
240
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
241
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
242
 
  //DRIZZLE_TYPE_BLOB
 
163
    //DRIZZLE_TYPE_NULL
 
164
    DRIZZLE_TYPE_LONGLONG,
 
165
    //DRIZZLE_TYPE_TIMESTAMP
 
166
    DRIZZLE_TYPE_VARCHAR,
 
167
    //DRIZZLE_TYPE_LONGLONG
 
168
    DRIZZLE_TYPE_LONGLONG,
 
169
    //DRIZZLE_TYPE_DATETIME
 
170
    DRIZZLE_TYPE_VARCHAR,
 
171
    //DRIZZLE_TYPE_DATE
 
172
    DRIZZLE_TYPE_DATE,
 
173
    //DRIZZLE_TYPE_VARCHAR
 
174
    DRIZZLE_TYPE_VARCHAR,
 
175
    //DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_ENUM
 
176
    DRIZZLE_TYPE_DECIMAL,
 
177
    DRIZZLE_TYPE_VARCHAR,
 
178
    //DRIZZLE_TYPE_BLOB
 
179
    DRIZZLE_TYPE_BLOB,
 
180
  },
 
181
  /* DRIZZLE_TYPE_DATETIME -> */
 
182
  {
 
183
    //DRIZZLE_TYPE_LONG
 
184
    DRIZZLE_TYPE_VARCHAR,
 
185
    //DRIZZLE_TYPE_DOUBLE
 
186
    DRIZZLE_TYPE_VARCHAR,
 
187
    //DRIZZLE_TYPE_NULL
 
188
    DRIZZLE_TYPE_DATETIME,
 
189
    //DRIZZLE_TYPE_TIMESTAMP
 
190
    DRIZZLE_TYPE_DATETIME,
 
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_DECIMAL
 
200
    DRIZZLE_TYPE_VARCHAR,
 
201
    //DRIZZLE_TYPE_ENUM
 
202
    DRIZZLE_TYPE_VARCHAR,
 
203
    //DRIZZLE_TYPE_BLOB
243
204
    DRIZZLE_TYPE_BLOB,
244
205
  },
245
206
  /* DRIZZLE_TYPE_DATE -> */
246
207
  {
247
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
248
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
249
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
250
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
251
 
  //DRIZZLE_TYPE_DOUBLE
252
 
    DRIZZLE_TYPE_VARCHAR,
253
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
254
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_DATETIME,
255
 
  //DRIZZLE_TYPE_LONGLONG
256
 
    DRIZZLE_TYPE_VARCHAR,
257
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
258
 
    DRIZZLE_TYPE_NEWDATE,     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
266
 
    DRIZZLE_TYPE_BLOB,
267
 
  },
268
 
  /* DRIZZLE_TYPE_TIME -> */
269
 
  {
270
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
271
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
272
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
273
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
274
 
  //DRIZZLE_TYPE_DOUBLE
275
 
    DRIZZLE_TYPE_VARCHAR,
276
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
277
 
    DRIZZLE_TYPE_TIME,        DRIZZLE_TYPE_DATETIME,
278
 
  //DRIZZLE_TYPE_LONGLONG
279
 
    DRIZZLE_TYPE_VARCHAR,
280
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
281
 
    DRIZZLE_TYPE_DATETIME,    DRIZZLE_TYPE_TIME,
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
289
 
    DRIZZLE_TYPE_BLOB,
290
 
  },
291
 
  /* DRIZZLE_TYPE_DATETIME -> */
292
 
  {
293
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
294
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
295
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
296
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
297
 
  //DRIZZLE_TYPE_DOUBLE
298
 
    DRIZZLE_TYPE_VARCHAR,
299
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
300
 
    DRIZZLE_TYPE_DATETIME,    DRIZZLE_TYPE_DATETIME,
301
 
  //DRIZZLE_TYPE_LONGLONG
302
 
    DRIZZLE_TYPE_VARCHAR,
303
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
304
 
    DRIZZLE_TYPE_DATETIME,    DRIZZLE_TYPE_DATETIME,
305
 
  //DRIZZLE_TYPE_DATETIME
306
 
    DRIZZLE_TYPE_DATETIME,
307
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
308
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
309
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
310
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
311
 
  //DRIZZLE_TYPE_BLOB
312
 
    DRIZZLE_TYPE_BLOB,
313
 
  },
314
 
  /* DRIZZLE_TYPE_NEWDATE -> */
315
 
  {
316
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
317
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
318
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
319
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
320
 
  //DRIZZLE_TYPE_DOUBLE
321
 
    DRIZZLE_TYPE_VARCHAR,
322
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
323
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_DATETIME,
324
 
  //DRIZZLE_TYPE_LONGLONG
325
 
    DRIZZLE_TYPE_VARCHAR,
326
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
327
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_DATETIME,
328
 
  //DRIZZLE_TYPE_DATETIME
329
 
    DRIZZLE_TYPE_DATETIME,
330
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
331
 
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
332
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
333
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
334
 
  //DRIZZLE_TYPE_BLOB
 
208
    //DRIZZLE_TYPE_LONG
 
209
    DRIZZLE_TYPE_VARCHAR,
 
210
    //DRIZZLE_TYPE_DOUBLE
 
211
    DRIZZLE_TYPE_VARCHAR,
 
212
    //DRIZZLE_TYPE_NULL
 
213
    DRIZZLE_TYPE_DATE,
 
214
    //DRIZZLE_TYPE_TIMESTAMP
 
215
    DRIZZLE_TYPE_DATETIME,
 
216
    //DRIZZLE_TYPE_LONGLONG
 
217
    DRIZZLE_TYPE_VARCHAR,
 
218
    //DRIZZLE_TYPE_DATETIME
 
219
    DRIZZLE_TYPE_DATETIME,
 
220
    //DRIZZLE_TYPE_DATE
 
221
    DRIZZLE_TYPE_DATE,
 
222
    //DRIZZLE_TYPE_VARCHAR
 
223
    DRIZZLE_TYPE_VARCHAR,
 
224
    //DRIZZLE_TYPE_DECIMAL
 
225
    DRIZZLE_TYPE_VARCHAR,
 
226
    //DRIZZLE_TYPE_ENUM
 
227
    DRIZZLE_TYPE_VARCHAR,
 
228
    //DRIZZLE_TYPE_BLOB
335
229
    DRIZZLE_TYPE_BLOB,
336
230
  },
337
231
  /* DRIZZLE_TYPE_VARCHAR -> */
338
232
  {
339
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
340
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
341
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
342
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
343
 
  //DRIZZLE_TYPE_DOUBLE
344
 
    DRIZZLE_TYPE_VARCHAR,
345
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
346
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
347
 
  //DRIZZLE_TYPE_LONGLONG
348
 
    DRIZZLE_TYPE_VARCHAR,
349
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
350
 
    DRIZZLE_TYPE_VARCHAR,     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
 
233
    //DRIZZLE_TYPE_LONG
 
234
    DRIZZLE_TYPE_VARCHAR,
 
235
    //DRIZZLE_TYPE_DOUBLE
 
236
    DRIZZLE_TYPE_VARCHAR,
 
237
    //DRIZZLE_TYPE_NULL
 
238
    DRIZZLE_TYPE_VARCHAR,
 
239
    //DRIZZLE_TYPE_TIMESTAMP
 
240
    DRIZZLE_TYPE_VARCHAR,
 
241
    //DRIZZLE_TYPE_LONGLONG
 
242
    DRIZZLE_TYPE_VARCHAR,
 
243
    //DRIZZLE_TYPE_DATETIME
 
244
    DRIZZLE_TYPE_VARCHAR,
 
245
    //DRIZZLE_TYPE_DATE
 
246
    DRIZZLE_TYPE_VARCHAR,
 
247
    //DRIZZLE_TYPE_VARCHAR
 
248
    DRIZZLE_TYPE_VARCHAR,
 
249
    //DRIZZLE_TYPE_DECIMAL
 
250
    DRIZZLE_TYPE_VARCHAR,
 
251
    //DRIZZLE_TYPE_ENUM
 
252
    DRIZZLE_TYPE_VARCHAR,
 
253
    //DRIZZLE_TYPE_BLOB
358
254
    DRIZZLE_TYPE_BLOB,
359
255
  },
360
 
  /* DRIZZLE_TYPE_NEWDECIMAL -> */
 
256
  /* DRIZZLE_TYPE_DECIMAL -> */
361
257
  {
362
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
363
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_NEWDECIMAL,
364
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
365
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_NEWDECIMAL,
366
 
  //DRIZZLE_TYPE_DOUBLE
 
258
    //DRIZZLE_TYPE_LONG
 
259
    DRIZZLE_TYPE_DECIMAL,
 
260
    //DRIZZLE_TYPE_DOUBLE
367
261
    DRIZZLE_TYPE_DOUBLE,
368
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
369
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
370
 
  //DRIZZLE_TYPE_LONGLONG
371
 
    DRIZZLE_TYPE_NEWDECIMAL,
372
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
373
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
374
 
  //DRIZZLE_TYPE_DATETIME
375
 
    DRIZZLE_TYPE_VARCHAR,
376
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
377
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
378
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
379
 
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
380
 
  //DRIZZLE_TYPE_BLOB
 
262
    //DRIZZLE_TYPE_NULL
 
263
    DRIZZLE_TYPE_DECIMAL,
 
264
    //DRIZZLE_TYPE_TIMESTAMP
 
265
    DRIZZLE_TYPE_VARCHAR,
 
266
    //DRIZZLE_TYPE_LONGLONG
 
267
    DRIZZLE_TYPE_DECIMAL,
 
268
    //DRIZZLE_TYPE_DATETIME
 
269
    DRIZZLE_TYPE_VARCHAR,
 
270
    //DRIZZLE_TYPE_DATE
 
271
    DRIZZLE_TYPE_VARCHAR,
 
272
    //DRIZZLE_TYPE_VARCHAR
 
273
    DRIZZLE_TYPE_VARCHAR,
 
274
    //DRIZZLE_TYPE_DECIMAL
 
275
    DRIZZLE_TYPE_DECIMAL,
 
276
    //DRIZZLE_TYPE_ENUM
 
277
    DRIZZLE_TYPE_VARCHAR,
 
278
    //DRIZZLE_TYPE_BLOB
381
279
    DRIZZLE_TYPE_BLOB,
382
280
  },
383
281
  /* DRIZZLE_TYPE_ENUM -> */
384
282
  {
385
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
386
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
387
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
388
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
389
 
  //DRIZZLE_TYPE_DOUBLE
390
 
    DRIZZLE_TYPE_VARCHAR,
391
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
392
 
    DRIZZLE_TYPE_ENUM,        DRIZZLE_TYPE_VARCHAR,
393
 
  //DRIZZLE_TYPE_LONGLONG
394
 
    DRIZZLE_TYPE_VARCHAR,
395
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
396
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
397
 
  //DRIZZLE_TYPE_DATETIME
398
 
    DRIZZLE_TYPE_VARCHAR,
399
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
400
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
401
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
402
 
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
403
 
  //DRIZZLE_TYPE_BLOB
 
283
    //DRIZZLE_TYPE_LONG
 
284
    DRIZZLE_TYPE_VARCHAR,
 
285
    //DRIZZLE_TYPE_DOUBLE
 
286
    DRIZZLE_TYPE_VARCHAR,
 
287
    //DRIZZLE_TYPE_NULL
 
288
    DRIZZLE_TYPE_ENUM,
 
289
    //DRIZZLE_TYPE_TIMESTAMP
 
290
    DRIZZLE_TYPE_VARCHAR,
 
291
    //DRIZZLE_TYPE_LONGLONG
 
292
    DRIZZLE_TYPE_VARCHAR,
 
293
    //DRIZZLE_TYPE_DATETIME
 
294
    DRIZZLE_TYPE_VARCHAR,
 
295
    //DRIZZLE_TYPE_DATE
 
296
    DRIZZLE_TYPE_VARCHAR,
 
297
    //DRIZZLE_TYPE_VARCHAR
 
298
    DRIZZLE_TYPE_VARCHAR,
 
299
    //DRIZZLE_TYPE_DECIMAL
 
300
    DRIZZLE_TYPE_VARCHAR,
 
301
    //DRIZZLE_TYPE_ENUM
 
302
    DRIZZLE_TYPE_VARCHAR,
 
303
    //DRIZZLE_TYPE_BLOB
404
304
    DRIZZLE_TYPE_BLOB,
405
305
  },
406
306
  /* DRIZZLE_TYPE_BLOB -> */
407
307
  {
408
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
409
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
410
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
411
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
412
 
  //DRIZZLE_TYPE_DOUBLE
413
 
    DRIZZLE_TYPE_BLOB,
414
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
415
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
416
 
  //DRIZZLE_TYPE_LONGLONG
417
 
    DRIZZLE_TYPE_BLOB,
418
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
419
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
420
 
  //DRIZZLE_TYPE_DATETIME
421
 
    DRIZZLE_TYPE_BLOB,
422
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
423
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
424
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
425
 
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
426
 
  //DRIZZLE_TYPE_BLOB
 
308
    //DRIZZLE_TYPE_LONG
 
309
    DRIZZLE_TYPE_BLOB,
 
310
    //DRIZZLE_TYPE_DOUBLE
 
311
    DRIZZLE_TYPE_BLOB,
 
312
    //DRIZZLE_TYPE_NULL
 
313
    DRIZZLE_TYPE_BLOB,
 
314
    //DRIZZLE_TYPE_TIMESTAMP
 
315
    DRIZZLE_TYPE_BLOB,
 
316
    //DRIZZLE_TYPE_LONGLONG
 
317
    DRIZZLE_TYPE_BLOB,
 
318
    //DRIZZLE_TYPE_DATETIME
 
319
    DRIZZLE_TYPE_BLOB,
 
320
    //DRIZZLE_TYPE_DATE
 
321
    DRIZZLE_TYPE_BLOB,
 
322
    //DRIZZLE_TYPE_VARCHAR
 
323
    DRIZZLE_TYPE_BLOB,
 
324
    //DRIZZLE_TYPE_DECIMAL
 
325
    DRIZZLE_TYPE_BLOB,
 
326
    //DRIZZLE_TYPE_ENUM
 
327
    DRIZZLE_TYPE_BLOB,
 
328
    //DRIZZLE_TYPE_BLOB
427
329
    DRIZZLE_TYPE_BLOB,
428
330
  },
429
331
};
430
332
 
431
 
/**
432
 
  Return type of which can carry value of both given types in UNION result.
433
 
 
434
 
  @param a  type for merging
435
 
  @param b  type for merging
436
 
 
437
 
  @return
438
 
    type of field
439
 
*/
440
 
 
441
 
enum_field_types Field::field_type_merge(enum_field_types a,
442
 
                                         enum_field_types b)
443
 
{
444
 
  assert(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
445
 
  assert(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
446
 
  return field_types_merge_rules[field_type2index(a)]
447
 
                                [field_type2index(b)];
448
 
}
449
 
 
450
 
 
451
 
static Item_result field_types_result_type [FIELDTYPE_NUM]=
452
 
{
453
 
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
454
 
  DECIMAL_RESULT,           INT_RESULT,
455
 
  //DRIZZLE_TYPE_SHORT        DRIZZLE_TYPE_LONG
456
 
  INT_RESULT,               INT_RESULT,
 
333
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
 
334
{
 
335
  //DRIZZLE_TYPE_LONG
 
336
  INT_RESULT,
457
337
  //DRIZZLE_TYPE_DOUBLE
458
338
  REAL_RESULT,
459
 
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
460
 
  STRING_RESULT,            STRING_RESULT,
 
339
  //DRIZZLE_TYPE_NULL
 
340
  STRING_RESULT,
 
341
  //DRIZZLE_TYPE_TIMESTAMP
 
342
  STRING_RESULT,
461
343
  //DRIZZLE_TYPE_LONGLONG
462
344
  INT_RESULT,
463
 
  //DRIZZLE_TYPE_DATE         DRIZZLE_TYPE_TIME
464
 
  STRING_RESULT,            STRING_RESULT,
465
345
  //DRIZZLE_TYPE_DATETIME
466
346
  STRING_RESULT,
467
 
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
468
 
  STRING_RESULT,            STRING_RESULT,
469
 
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
470
 
  DECIMAL_RESULT,           STRING_RESULT,
 
347
  //DRIZZLE_TYPE_DATE
 
348
  STRING_RESULT,
 
349
  //DRIZZLE_TYPE_VARCHAR
 
350
  STRING_RESULT,
 
351
  //DRIZZLE_TYPE_DECIMAL   
 
352
  DECIMAL_RESULT,           
 
353
  //DRIZZLE_TYPE_ENUM
 
354
  STRING_RESULT,
471
355
  //DRIZZLE_TYPE_BLOB
472
356
  STRING_RESULT,
473
357
};
474
358
 
475
 
 
476
 
/*
477
 
  Test if the given string contains important data:
478
 
  not spaces for character string,
479
 
  or any data for binary string.
480
 
 
481
 
  SYNOPSIS
482
 
    test_if_important_data()
483
 
    cs          Character set
484
 
    str         String to test
485
 
    strend      String end
486
 
 
487
 
  RETURN
488
 
    false - If string does not have important data
489
 
    true  - If string has some important data
490
 
*/
491
 
 
492
 
static bool
493
 
test_if_important_data(const CHARSET_INFO * const cs, const char *str,
494
 
                       const char *strend)
 
359
bool test_if_important_data(const CHARSET_INFO * const cs, 
 
360
                            const char *str,
 
361
                            const char *strend)
495
362
{
496
363
  if (cs != &my_charset_bin)
497
364
    str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
498
365
  return (str < strend);
499
366
}
500
367
 
501
 
 
502
 
/**
503
 
  Detect Item_result by given field type of UNION merge result.
504
 
 
505
 
  @param field_type  given field type
506
 
 
507
 
  @return
508
 
    Item_result (type of internal MySQL expression result)
509
 
*/
 
368
void *Field::operator new(size_t size)
 
369
{
 
370
  return memory::sql_alloc(size);
 
371
}
 
372
 
 
373
void *Field::operator new(size_t size, memory::Root *mem_root)
 
374
{
 
375
  return alloc_root(mem_root, static_cast<uint32_t>(size));
 
376
}
 
377
 
 
378
enum_field_types Field::field_type_merge(enum_field_types a,
 
379
                                         enum_field_types b)
 
380
{
 
381
  assert(a <= DRIZZLE_TYPE_MAX);
 
382
  assert(b <= DRIZZLE_TYPE_MAX);
 
383
  return field_types_merge_rules[a][b];
 
384
}
510
385
 
511
386
Item_result Field::result_merge_type(enum_field_types field_type)
512
387
{
513
 
  assert(field_type < FIELDTYPE_TEAR_FROM || field_type
514
 
              > FIELDTYPE_TEAR_TO);
515
 
  return field_types_result_type[field_type2index(field_type)];
516
 
}
517
 
 
518
 
/*****************************************************************************
519
 
  Static help functions
520
 
*****************************************************************************/
521
 
 
522
 
 
523
 
/**
524
 
  Check whether a field type can be partially indexed by a key.
525
 
 
526
 
  This is a static method, rather than a virtual function, because we need
527
 
  to check the type of a non-Field in mysql_alter_table().
528
 
 
529
 
  @param type  field type
530
 
 
531
 
  @retval
532
 
    true  Type can have a prefixed key
533
 
  @retval
534
 
    false Type can not have a prefixed key
535
 
*/
 
388
  assert(field_type <= DRIZZLE_TYPE_MAX);
 
389
  return field_types_result_type[field_type];
 
390
}
 
391
 
 
392
bool Field::eq(Field *field)
 
393
{
 
394
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
 
395
          null_bit == field->null_bit);
 
396
}
 
397
 
 
398
uint32_t Field::pack_length() const
 
399
{
 
400
  return field_length;
 
401
}
 
402
 
 
403
uint32_t Field::pack_length_in_rec() const
 
404
{
 
405
  return pack_length();
 
406
}
 
407
 
 
408
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
 
409
{
 
410
  return field_metadata;
 
411
}
 
412
 
 
413
uint32_t Field::row_pack_length()
 
414
{
 
415
  return 0;
 
416
}
 
417
 
 
418
uint32_t Field::data_length()
 
419
{
 
420
  return pack_length();
 
421
}
 
422
 
 
423
uint32_t Field::used_length()
 
424
{
 
425
  return pack_length();
 
426
}
 
427
 
 
428
uint32_t Field::sort_length() const
 
429
{
 
430
  return pack_length();
 
431
}
 
432
 
 
433
uint32_t Field::max_data_length() const
 
434
{
 
435
  return pack_length();
 
436
}
 
437
 
 
438
int Field::reset(void)
 
439
{
 
440
  memset(ptr, 0, pack_length());
 
441
  return 0;
 
442
}
 
443
 
 
444
void Field::reset_fields()
 
445
{}
 
446
 
 
447
void Field::set_default()
 
448
{
 
449
  ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->record[0]);
 
450
  memcpy(ptr, ptr + l_offset, pack_length());
 
451
  if (null_ptr)
 
452
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
 
453
 
 
454
  if (this == table->next_number_field)
 
455
    table->auto_increment_field_not_null= false;
 
456
}
 
457
 
 
458
bool Field::binary() const
 
459
{
 
460
  return true;
 
461
}
 
462
 
 
463
bool Field::zero_pack() const
 
464
{
 
465
  return true;
 
466
}
 
467
 
 
468
enum ha_base_keytype Field::key_type() const
 
469
{
 
470
  return HA_KEYTYPE_BINARY;
 
471
}
 
472
 
 
473
uint32_t Field::key_length() const
 
474
{
 
475
  return pack_length();
 
476
}
 
477
 
 
478
enum_field_types Field::real_type() const
 
479
{
 
480
  return type();
 
481
}
 
482
 
 
483
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
 
484
{
 
485
  return cmp(a, b);
 
486
}
 
487
 
 
488
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
 
489
{
 
490
  return memcmp(a,b,pack_length());
 
491
}
 
492
 
 
493
int Field::cmp_offset(uint32_t row_offset)
 
494
{
 
495
  return cmp(ptr,ptr+row_offset);
 
496
}
 
497
 
 
498
int Field::cmp_binary_offset(uint32_t row_offset)
 
499
{
 
500
  return cmp_binary(ptr, ptr+row_offset);
 
501
}
 
502
 
 
503
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
 
504
{
 
505
  return cmp(a, b);
 
506
}
 
507
 
 
508
int Field::key_cmp(const unsigned char *str, uint32_t)
 
509
{
 
510
  return cmp(ptr,str);
 
511
}
 
512
 
 
513
uint32_t Field::decimals() const
 
514
{
 
515
  return 0;
 
516
}
 
517
 
 
518
bool Field::is_null(ptrdiff_t row_offset)
 
519
{
 
520
  return null_ptr ?
 
521
    (null_ptr[row_offset] & null_bit ? true : false) :
 
522
    table->null_row;
 
523
}
 
524
 
 
525
bool Field::is_real_null(ptrdiff_t row_offset)
 
526
{
 
527
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
 
528
}
 
529
 
 
530
bool Field::is_null_in_record(const unsigned char *record)
 
531
{
 
532
  if (! null_ptr)
 
533
    return false;
 
534
  return test(record[(uint32_t) (null_ptr -table->record[0])] & null_bit);
 
535
}
 
536
 
 
537
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset)
 
538
{
 
539
  if (! null_ptr)
 
540
    return false;
 
541
  return test(null_ptr[with_offset] & null_bit);
 
542
}
 
543
 
 
544
void Field::set_null(ptrdiff_t row_offset)
 
545
{
 
546
  if (null_ptr)
 
547
    null_ptr[row_offset]|= null_bit;
 
548
}
 
549
 
 
550
void Field::set_notnull(ptrdiff_t row_offset)
 
551
{
 
552
  if (null_ptr)
 
553
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
 
554
}
 
555
 
 
556
bool Field::maybe_null(void)
 
557
{
 
558
  return null_ptr != 0 || table->maybe_null;
 
559
}
 
560
 
 
561
bool Field::real_maybe_null(void)
 
562
{
 
563
  return null_ptr != 0;
 
564
}
536
565
 
537
566
bool Field::type_can_have_key_part(enum enum_field_types type)
538
567
{
545
574
  }
546
575
}
547
576
 
548
 
 
549
 
/**
550
 
  Numeric fields base class constructor.
551
 
*/
552
 
Field_num::Field_num(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
553
 
                     uchar null_bit_arg, utype unireg_check_arg,
554
 
                     const char *field_name_arg,
555
 
                     uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
556
 
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
557
 
         unireg_check_arg, field_name_arg),
558
 
  dec(dec_arg),decimal_precision(zero_arg),unsigned_flag(unsigned_arg)
559
 
{
560
 
  if (unsigned_flag)
561
 
    flags|=UNSIGNED_FLAG;
562
 
}
563
 
 
564
 
 
565
 
/**
566
 
  Test if given number is a int.
567
 
 
568
 
  @todo
569
 
    Make this multi-byte-character safe
570
 
 
571
 
  @param str            String to test
572
 
  @param length        Length of 'str'
573
 
  @param int_end        Pointer to char after last used digit
574
 
  @param cs             Character set
575
 
 
576
 
  @note
577
 
    This is called after one has called strntoull10rnd() function.
578
 
 
579
 
  @retval
580
 
    0   OK
581
 
  @retval
582
 
    1   error: empty string or wrong integer.
583
 
  @retval
584
 
    2   error: garbage at the end of string.
585
 
*/
586
 
 
587
 
int Field_num::check_int(const CHARSET_INFO * const cs, const char *str, int length, 
588
 
                         const char *int_end, int error)
589
 
{
590
 
  /* Test if we get an empty string or wrong integer */
591
 
  if (str == int_end || error == MY_ERRNO_EDOM)
592
 
  {
593
 
    char buff[128];
594
 
    String tmp(buff, (uint32_t) sizeof(buff), system_charset_info);
595
 
    tmp.copy(str, length, system_charset_info);
596
 
    push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
597
 
                        ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, 
598
 
                        ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
599
 
                        "integer", tmp.c_ptr(), field_name,
600
 
                        (uint32_t) table->in_use->row_count);
601
 
    return 1;
602
 
  }
603
 
  /* Test if we have garbage at the end of the given string. */
604
 
  if (test_if_important_data(cs, int_end, str + length))
605
 
  {
606
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
607
 
    return 2;
608
 
  }
609
 
  return 0;
610
 
}
611
 
 
612
 
 
613
 
/*
614
 
  Conver a string to an integer then check bounds.
615
 
  
616
 
  SYNOPSIS
617
 
    Field_num::get_int
618
 
    cs            Character set
619
 
    from          String to convert
620
 
    len           Length of the string
621
 
    rnd           OUT int64_t value
622
 
    unsigned_max  max unsigned value
623
 
    signed_min    min signed value
624
 
    signed_max    max signed value
625
 
 
626
 
  DESCRIPTION
627
 
    The function calls strntoull10rnd() to get an integer value then
628
 
    check bounds and errors returned. In case of any error a warning
629
 
    is raised.
630
 
 
631
 
  RETURN
632
 
    0   ok
633
 
    1   error
634
 
*/
635
 
 
636
 
bool Field_num::get_int(const CHARSET_INFO * const cs, const char *from, uint len,
637
 
                        int64_t *rnd, uint64_t unsigned_max, 
638
 
                        int64_t signed_min, int64_t signed_max)
639
 
{
640
 
  char *end;
641
 
  int error;
642
 
  
643
 
  *rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len,
644
 
                                            unsigned_flag, &end,
645
 
                                            &error);
646
 
  if (unsigned_flag)
647
 
  {
648
 
 
649
 
    if ((((uint64_t) *rnd > unsigned_max) && (*rnd= (int64_t) unsigned_max)) ||
650
 
        error == MY_ERRNO_ERANGE)
651
 
    {
652
 
      goto out_of_range;
653
 
    }
654
 
  }
655
 
  else
656
 
  {
657
 
    if (*rnd < signed_min)
658
 
    {
659
 
      *rnd= signed_min;
660
 
      goto out_of_range;
661
 
    }
662
 
    else if (*rnd > signed_max)
663
 
    {
664
 
      *rnd= signed_max;
665
 
      goto out_of_range;
666
 
    }
667
 
  }
668
 
  if (table->in_use->count_cuted_fields &&
669
 
      check_int(cs, from, len, end, error))
670
 
    return 1;
671
 
  return 0;
672
 
 
673
 
out_of_range:
674
 
  set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
675
 
  return 1;
676
 
}
677
 
 
678
 
/**
679
 
  Process decimal library return codes and issue warnings for overflow and
680
 
  truncation.
681
 
 
682
 
  @param op_result  decimal library return code (E_DEC_* see include/decimal.h)
683
 
 
684
 
  @retval
685
 
    1  there was overflow
686
 
  @retval
687
 
    0  no error or some other errors except overflow
688
 
*/
689
 
 
690
577
int Field::warn_if_overflow(int op_result)
691
578
{
692
579
  if (op_result == E_DEC_OVERFLOW)
693
580
  {
694
581
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
695
 
    return 1;
 
582
    return E_DEC_OVERFLOW;
696
583
  }
697
584
  if (op_result == E_DEC_TRUNCATED)
698
585
  {
699
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
700
 
    /* We return 0 here as this is not a critical issue */
 
586
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
 
587
    return E_DEC_TRUNCATED;
701
588
  }
702
589
  return 0;
703
590
}
704
591
 
705
 
 
706
 
#ifdef NOT_USED
707
 
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
 
592
void Field::init(Table *table_arg)
708
593
{
709
 
  cs= system_charset_info; // QQ move test_if_real into CHARSET_INFO struct
710
 
 
711
 
  while (length && my_isspace(cs,*str))
712
 
  {                                             // Allow start space
713
 
    length--; str++;
714
 
  }
715
 
  if (!length)
716
 
    return 0;
717
 
  if (*str == '+' || *str == '-')
718
 
  {
719
 
    length--; str++;
720
 
    if (!length || !(my_isdigit(cs,*str) || *str == '.'))
721
 
      return 0;
722
 
  }
723
 
  while (length && my_isdigit(cs,*str))
724
 
  {
725
 
    length--; str++;
726
 
  }
727
 
  if (!length)
728
 
    return 1;
729
 
  if (*str == '.')
730
 
  {
731
 
    length--; str++;
732
 
    while (length && my_isdigit(cs,*str))
733
 
    {
734
 
      length--; str++;
735
 
    }
736
 
  }
737
 
  if (!length)
738
 
    return 1;
739
 
  if (*str == 'E' || *str == 'e')
740
 
  {
741
 
    if (length < 3 || (str[1] != '+' && str[1] != '-') || 
742
 
        !my_isdigit(cs,str[2]))
743
 
      return 0;
744
 
    length-=3;
745
 
    str+=3;
746
 
    while (length && my_isdigit(cs,*str))
747
 
    {
748
 
      length--; str++;
749
 
    }
750
 
  }
751
 
  for (; length ; length--, str++)
752
 
  {                                             // Allow end space
753
 
    if (!my_isspace(cs,*str))
754
 
      return 0;
755
 
  }
756
 
  return 1;
 
594
  orig_table= table= table_arg;
 
595
  table_name= &table_arg->alias;
757
596
}
758
 
#endif
759
 
 
760
 
 
761
 
/**
762
 
  Interpret field value as an integer but return the result as a string.
763
 
 
764
 
  This is used for printing bit_fields as numbers while debugging.
765
 
*/
766
597
 
767
598
String *Field::val_int_as_str(String *val_buffer, bool unsigned_val)
768
599
{
769
600
  const CHARSET_INFO * const cs= &my_charset_bin;
770
 
  uint length;
 
601
  uint32_t length;
771
602
  int64_t value= val_int();
772
603
 
773
604
  if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
774
605
    return 0;
775
 
  length= (uint) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
 
606
  length= (uint32_t) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
776
607
                                                MY_INT64_NUM_DECIMAL_DIGITS,
777
608
                                                unsigned_val ? 10 : -10,
778
609
                                                value);
780
611
  return val_buffer;
781
612
}
782
613
 
783
 
 
784
614
/// This is used as a table name when the table structure is not set up
785
 
Field::Field(uchar *ptr_arg,uint32_t length_arg,uchar *null_ptr_arg,
786
 
             uchar null_bit_arg,
787
 
             utype unireg_check_arg, const char *field_name_arg)
788
 
  :ptr(ptr_arg), null_ptr(null_ptr_arg),
789
 
   table(0), orig_table(0), table_name(0),
790
 
   field_name(field_name_arg),
791
 
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
792
 
   part_of_sortkey(0), unireg_check(unireg_check_arg),
793
 
   field_length(length_arg), null_bit(null_bit_arg), 
794
 
   is_created_from_null_item(false)
 
615
Field::Field(unsigned char *ptr_arg,
 
616
             uint32_t length_arg,
 
617
             unsigned char *null_ptr_arg,
 
618
             unsigned char null_bit_arg,
 
619
             utype unireg_check_arg, 
 
620
             const char *field_name_arg)
 
621
  :
 
622
    ptr(ptr_arg),
 
623
    null_ptr(null_ptr_arg),
 
624
    table(NULL),
 
625
    orig_table(NULL),
 
626
    table_name(NULL),
 
627
    field_name(field_name_arg),
 
628
    key_start(0),
 
629
    part_of_key(0),
 
630
    part_of_key_not_clustered(0),
 
631
    part_of_sortkey(0),
 
632
    unireg_check(unireg_check_arg),
 
633
    field_length(length_arg),
 
634
    null_bit(null_bit_arg),
 
635
    is_created_from_null_item(false)
795
636
{
796
 
  flags=null_ptr ? 0: NOT_NULL_FLAG;
 
637
  flags= null_ptr ? 0: NOT_NULL_FLAG;
797
638
  comment.str= (char*) "";
798
 
  comment.length=0;
 
639
  comment.length= 0;
799
640
  field_index= 0;
800
641
}
801
642
 
802
 
 
803
643
void Field::hash(uint32_t *nr, uint32_t *nr2)
804
644
{
805
645
  if (is_null())
808
648
  }
809
649
  else
810
650
  {
811
 
    uint len= pack_length();
 
651
    uint32_t len= pack_length();
812
652
    const CHARSET_INFO * const cs= charset();
813
653
    cs->coll->hash_sort(cs, ptr, len, nr, nr2);
814
654
  }
815
655
}
816
656
 
817
 
size_t
818
 
Field::do_last_null_byte() const
819
 
{
820
 
  assert(null_ptr == NULL || null_ptr >= table->record[0]);
821
 
  if (null_ptr)
822
 
    return (size_t) (null_ptr - table->record[0]) + 1;
823
 
  return LAST_NULL_BYTE_UNDEF;
824
 
}
825
 
 
826
 
 
827
657
void Field::copy_from_tmp(int row_offset)
828
658
{
829
659
  memcpy(ptr,ptr+row_offset,pack_length());
830
660
  if (null_ptr)
831
661
  {
832
 
    *null_ptr= (uchar) ((null_ptr[0] & (uchar) ~(uint) null_bit) | (null_ptr[row_offset] & (uchar) null_bit));
 
662
    *null_ptr= (unsigned char) ((null_ptr[0] &
 
663
                                 (unsigned char) ~(uint32_t) null_bit) |
 
664
                                (null_ptr[row_offset] &
 
665
                                 (unsigned char) null_bit));
833
666
  }
834
667
}
835
668
 
836
 
 
837
 
bool Field::send_binary(Protocol *protocol)
838
 
{
839
 
  char buff[MAX_FIELD_WIDTH];
840
 
  String tmp(buff,sizeof(buff),charset());
841
 
  val_str(&tmp);
842
 
  return protocol->store(tmp.ptr(), tmp.length(), tmp.charset());
843
 
}
844
 
 
845
 
 
846
 
/**
847
 
   Check to see if field size is compatible with destination.
848
 
 
849
 
   This method is used in row-based replication to verify that the slave's
850
 
   field size is less than or equal to the master's field size. The 
851
 
   encoded field metadata (from the master or source) is decoded and compared
852
 
   to the size of this field (the slave or destination). 
853
 
 
854
 
   @param   field_metadata   Encoded size in field metadata
855
 
 
856
 
   @retval 0 if this field's size is < the source field's size
857
 
   @retval 1 if this field's size is >= the source field's size
858
 
*/
859
 
int Field::compatible_field_size(uint field_metadata)
860
 
{
861
 
  uint const source_size= pack_length_from_metadata(field_metadata);
862
 
  uint const destination_size= row_pack_length();
 
669
int Field::compatible_field_size(uint32_t field_metadata)
 
670
{
 
671
  uint32_t const source_size= pack_length_from_metadata(field_metadata);
 
672
  uint32_t const destination_size= row_pack_length();
863
673
  return (source_size <= destination_size);
864
674
}
865
675
 
866
 
 
867
 
int Field::store(const char *to, uint length, const CHARSET_INFO * const cs,
 
676
int Field::store(const char *to, 
 
677
                 uint32_t length,
 
678
                 const CHARSET_INFO * const cs,
868
679
                 enum_check_fields check_level)
869
680
{
870
681
  int res;
875
686
  return res;
876
687
}
877
688
 
878
 
 
879
 
/**
880
 
   Pack the field into a format suitable for storage and transfer.
881
 
 
882
 
   To implement packing functionality, only the virtual function
883
 
   should be overridden. The other functions are just convenience
884
 
   functions and hence should not be overridden.
885
 
 
886
 
   The value of <code>low_byte_first</code> is dependent on how the
887
 
   packed data is going to be used: for local use, e.g., temporary
888
 
   store on disk or in memory, use the native format since that is
889
 
   faster. For data that is going to be transfered to other machines
890
 
   (e.g., when writing data to the binary log), data should always be
891
 
   stored in little-endian format.
892
 
 
893
 
   @note The default method for packing fields just copy the raw bytes
894
 
   of the record into the destination, but never more than
895
 
   <code>max_length</code> characters.
896
 
 
897
 
   @param to
898
 
   Pointer to memory area where representation of field should be put.
899
 
 
900
 
   @param from
901
 
   Pointer to memory area where record representation of field is
902
 
   stored.
903
 
 
904
 
   @param max_length
905
 
   Maximum length of the field, as given in the column definition. For
906
 
   example, for <code>CHAR(1000)</code>, the <code>max_length</code>
907
 
   is 1000. This information is sometimes needed to decide how to pack
908
 
   the data.
909
 
 
910
 
   @param low_byte_first
911
 
   @c true if integers should be stored little-endian, @c false if
912
 
   native format should be used. Note that for little-endian machines,
913
 
   the value of this flag is a moot point since the native format is
914
 
   little-endian.
915
 
*/
916
 
uchar *
917
 
Field::pack(uchar *to, const uchar *from, uint max_length,
918
 
            bool low_byte_first __attribute__((unused)))
 
689
unsigned char *Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool)
919
690
{
920
691
  uint32_t length= pack_length();
921
692
  set_if_smaller(length, max_length);
923
694
  return to+length;
924
695
}
925
696
 
926
 
/**
927
 
   Unpack a field from row data.
928
 
 
929
 
   This method is used to unpack a field from a master whose size of
930
 
   the field is less than that of the slave.
931
 
 
932
 
   The <code>param_data</code> parameter is a two-byte integer (stored
933
 
   in the least significant 16 bits of the unsigned integer) usually
934
 
   consisting of two parts: the real type in the most significant byte
935
 
   and a original pack length in the least significant byte.
936
 
 
937
 
   The exact layout of the <code>param_data</code> field is given by
938
 
   the <code>Table_map_log_event::save_field_metadata()</code>.
939
 
 
940
 
   This is the default method for unpacking a field. It just copies
941
 
   the memory block in byte order (of original pack length bytes or
942
 
   length of field, whichever is smaller).
943
 
 
944
 
   @param   to         Destination of the data
945
 
   @param   from       Source of the data
946
 
   @param   param_data Real type and original pack length of the field
947
 
                       data
948
 
 
949
 
   @param low_byte_first
950
 
   If this flag is @c true, all composite entities (e.g., lengths)
951
 
   should be unpacked in little-endian format; otherwise, the entities
952
 
   are unpacked in native order.
953
 
 
954
 
   @return  New pointer into memory based on from + length of the data
955
 
*/
956
 
const uchar *
957
 
Field::unpack(uchar* to, const uchar *from, uint param_data,
958
 
              bool low_byte_first __attribute__((unused)))
959
 
{
960
 
  uint length=pack_length();
 
697
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
 
698
{
 
699
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->s->db_low_byte_first);
 
700
  return(result);
 
701
}
 
702
 
 
703
const unsigned char *Field::unpack(unsigned char* to,
 
704
                                   const unsigned char *from, 
 
705
                                   uint32_t param_data,
 
706
                                   bool)
 
707
{
 
708
  uint32_t length=pack_length();
961
709
  int from_type= 0;
962
710
  /*
963
711
    If from length is > 255, it has encoded data in the upper bits. Need
977
725
    return from+length;
978
726
  }
979
727
 
980
 
  uint len= (param_data && (param_data < length)) ?
 
728
  uint32_t len= (param_data && (param_data < length)) ?
981
729
            param_data : length;
982
730
 
983
731
  memcpy(to, from, param_data > length ? length : len);
984
 
  return from+len;
985
 
}
986
 
 
987
 
 
988
 
my_decimal *Field::val_decimal(my_decimal *decimal __attribute__((unused)))
 
732
  return (from + len);
 
733
}
 
734
 
 
735
const unsigned char *Field::unpack(unsigned char* to, const unsigned char *from)
 
736
{
 
737
  const unsigned char *result= unpack(to, from, 0U, table->s->db_low_byte_first);
 
738
  return(result);
 
739
}
 
740
 
 
741
my_decimal *Field::val_decimal(my_decimal *)
989
742
{
990
743
  /* This never have to be called */
991
744
  assert(0);
993
746
}
994
747
 
995
748
 
996
 
void Field_num::add_unsigned(String &res) const
997
 
{
998
 
  if (unsigned_flag)
999
 
    res.append(STRING_WITH_LEN(" unsigned"));
1000
 
}
1001
 
 
1002
 
 
1003
 
void Field::make_field(Send_field *field)
 
749
void Field::make_field(SendField *field)
1004
750
{
1005
751
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
1006
752
  {
1021
767
  }
1022
768
  field->col_name= field_name;
1023
769
  field->charsetnr= charset()->number;
1024
 
  field->length=field_length;
1025
 
  field->type=type();
1026
 
  field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
 
770
  field->length= field_length;
 
771
  field->type= type();
 
772
  field->flags= table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
1027
773
  field->decimals= 0;
1028
774
}
1029
775
 
1030
 
 
1031
 
/**
1032
 
  Conversion from decimal to int64_t with checking overflow and
1033
 
  setting correct value (min/max) in case of overflow.
1034
 
 
1035
 
  @param val             value which have to be converted
1036
 
  @param unsigned_flag   type of integer in which we convert val
1037
 
  @param err             variable to pass error code
1038
 
 
1039
 
  @return
1040
 
    value converted from val
1041
 
*/
1042
 
int64_t Field::convert_decimal2int64_t(const my_decimal *val,
1043
 
                                         bool unsigned_flag, int *err)
 
776
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
1044
777
{
1045
778
  int64_t i;
1046
 
  if (unsigned_flag)
1047
 
  {
1048
 
    if (val->sign())
1049
 
    {
1050
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1051
 
      i= 0;
1052
 
      *err= 1;
1053
 
    }
1054
 
    else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
1055
 
                                           ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
1056
 
                                           val, true, &i)))
1057
 
    {
1058
 
      i= ~(int64_t) 0;
1059
 
      *err= 1;
1060
 
    }
1061
 
  }
1062
 
  else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
1063
 
                                         ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
1064
 
                                         val, false, &i)))
 
779
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
780
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
 
781
                                      val, false, &i)))
1065
782
  {
1066
783
    i= (val->sign() ? INT64_MIN : INT64_MAX);
1067
784
    *err= 1;
1069
786
  return i;
1070
787
}
1071
788
 
1072
 
 
1073
 
/**
1074
 
  Storing decimal in integer fields.
1075
 
 
1076
 
  @param val       value for storing
1077
 
 
1078
 
  @note
1079
 
    This method is used by all integer fields, real/decimal redefine it
1080
 
 
1081
 
  @retval
1082
 
    0     OK
1083
 
  @retval
1084
 
    !=0  error
1085
 
*/
1086
 
 
1087
 
int Field_num::store_decimal(const my_decimal *val)
1088
 
{
1089
 
  int err= 0;
1090
 
  int64_t i= convert_decimal2int64_t(val, unsigned_flag, &err);
1091
 
  return test(err | store(i, unsigned_flag));
1092
 
}
1093
 
 
1094
 
 
1095
 
/**
1096
 
  Return decimal value of integer field.
1097
 
 
1098
 
  @param decimal_value     buffer for storing decimal value
1099
 
 
1100
 
  @note
1101
 
    This method is used by all integer fields, real/decimal redefine it.
1102
 
    All int64_t values fit in our decimal buffer which cal store 8*9=72
1103
 
    digits of integer number
1104
 
 
1105
 
  @return
1106
 
    pointer to decimal buffer with value of field
1107
 
*/
1108
 
 
1109
 
my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
1110
 
{
1111
 
  assert(result_type() == INT_RESULT);
1112
 
  int64_t nr= val_int();
1113
 
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
1114
 
  return decimal_value;
1115
 
}
1116
 
 
1117
 
 
1118
 
Field_str::Field_str(uchar *ptr_arg,uint32_t len_arg, uchar *null_ptr_arg,
1119
 
                     uchar null_bit_arg, utype unireg_check_arg,
1120
 
                     const char *field_name_arg, const CHARSET_INFO * const charset_arg)
1121
 
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1122
 
         unireg_check_arg, field_name_arg)
1123
 
{
1124
 
  field_charset= charset_arg;
1125
 
  if (charset_arg->state & MY_CS_BINSORT)
1126
 
    flags|=BINARY_FLAG;
1127
 
  field_derivation= DERIVATION_IMPLICIT;
1128
 
}
1129
 
 
1130
 
 
1131
 
void Field_num::make_field(Send_field *field)
1132
 
{
1133
 
  Field::make_field(field);
1134
 
  field->decimals= dec;
1135
 
}
1136
 
 
1137
 
/**
1138
 
  Decimal representation of Field_str.
1139
 
 
1140
 
  @param d         value for storing
1141
 
 
1142
 
  @note
1143
 
    Field_str is the base class for fields like Field_enum,
1144
 
    Field_date and some similar. Some dates use fraction and also
1145
 
    string value should be converted to floating point value according
1146
 
    our rules, so we use double to store value of decimal in string.
1147
 
 
1148
 
  @todo
1149
 
    use decimal2string?
1150
 
 
1151
 
  @retval
1152
 
    0     OK
1153
 
  @retval
1154
 
    !=0  error
1155
 
*/
1156
 
 
1157
 
int Field_str::store_decimal(const my_decimal *d)
1158
 
{
1159
 
  double val;
1160
 
  /* TODO: use decimal2string? */
1161
 
  int err= warn_if_overflow(my_decimal2double(E_DEC_FATAL_ERROR &
1162
 
                                            ~E_DEC_OVERFLOW, d, &val));
1163
 
  return err | store(val);
1164
 
}
1165
 
 
1166
 
 
1167
 
my_decimal *Field_str::val_decimal(my_decimal *decimal_value)
1168
 
{
1169
 
  int64_t nr= val_int();
1170
 
  int2my_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value);
1171
 
  return decimal_value;
1172
 
}
1173
 
 
1174
 
 
1175
 
uint Field::fill_cache_field(CACHE_FIELD *copy)
1176
 
{
1177
 
  uint store_length;
 
789
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
 
790
{
 
791
  uint32_t store_length;
1178
792
  copy->str=ptr;
1179
793
  copy->length=pack_length();
1180
794
  copy->blob_field=0;
1193
807
  return copy->length+ store_length;
1194
808
}
1195
809
 
1196
 
 
1197
 
bool Field::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
 
810
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
1198
811
{
1199
812
  char buff[40];
1200
813
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1215
828
  return 0;
1216
829
}
1217
830
 
1218
 
/**
1219
 
  This is called when storing a date in a string.
1220
 
 
1221
 
  @note
1222
 
    Needs to be changed if/when we want to support different time formats.
1223
 
*/
1224
 
 
1225
 
int Field::store_time(DRIZZLE_TIME *ltime,
1226
 
                      timestamp_type type_arg __attribute__((unused)))
 
831
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
1227
832
{
1228
833
  char buff[MAX_DATE_STRING_REP_LENGTH];
1229
 
  uint length= (uint) my_TIME_to_str(ltime, buff);
 
834
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
1230
835
  return store(buff, length, &my_charset_bin);
1231
836
}
1232
837
 
1233
 
 
1234
 
bool Field::optimize_range(uint idx, uint part)
 
838
bool Field::optimize_range(uint32_t idx, uint32_t)
1235
839
{
1236
 
  return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
 
840
  return test(table->index_flags(idx) & HA_READ_RANGE);
1237
841
}
1238
842
 
1239
 
 
1240
 
Field *Field::new_field(MEM_ROOT *root, struct st_table *new_table,
1241
 
                        bool keep_type __attribute__((unused)))
 
843
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
1242
844
{
1243
845
  Field *tmp;
1244
846
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1247
849
  if (tmp->table->maybe_null)
1248
850
    tmp->flags&= ~NOT_NULL_FLAG;
1249
851
  tmp->table= new_table;
1250
 
  tmp->key_start.init(0);
1251
 
  tmp->part_of_key.init(0);
1252
 
  tmp->part_of_sortkey.init(0);
 
852
  tmp->key_start.reset();
 
853
  tmp->part_of_key.reset();
 
854
  tmp->part_of_sortkey.reset();
1253
855
  tmp->unireg_check= Field::NONE;
1254
856
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
1255
857
  tmp->reset_fields();
1256
858
  return tmp;
1257
859
}
1258
860
 
1259
 
 
1260
 
Field *Field::new_key_field(MEM_ROOT *root, struct st_table *new_table,
1261
 
                            uchar *new_ptr, uchar *new_null_ptr,
1262
 
                            uint new_null_bit)
 
861
Field *Field::new_key_field(memory::Root *root, Table *new_table,
 
862
                            unsigned char *new_ptr,
 
863
                            unsigned char *new_null_ptr,
 
864
                            uint32_t new_null_bit)
1263
865
{
1264
866
  Field *tmp;
1265
867
  if ((tmp= new_field(root, new_table, table == new_table)))
1266
868
  {
1267
 
    tmp->ptr=      new_ptr;
 
869
    tmp->ptr= new_ptr;
1268
870
    tmp->null_ptr= new_null_ptr;
1269
871
    tmp->null_bit= new_null_bit;
1270
872
  }
1271
873
  return tmp;
1272
874
}
1273
875
 
1274
 
 
1275
 
/* This is used to generate a field in TABLE from TABLE_SHARE */
1276
 
 
1277
 
Field *Field::clone(MEM_ROOT *root, struct st_table *new_table)
 
876
Field *Field::clone(memory::Root *root, Table *new_table)
1278
877
{
1279
878
  Field *tmp;
1280
879
  if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
1281
880
  {
1282
881
    tmp->init(new_table);
1283
 
    tmp->move_field_offset((my_ptrdiff_t) (new_table->record[0] -
 
882
    tmp->move_field_offset((ptrdiff_t) (new_table->record[0] -
1284
883
                                           new_table->s->default_values));
1285
884
  }
1286
885
  return tmp;
1287
886
}
1288
887
 
1289
888
 
1290
 
/****************************************************************************
1291
 
** tiny int
1292
 
****************************************************************************/
1293
 
 
1294
 
int Field_tiny::store(const char *from,uint len, const CHARSET_INFO * const cs)
1295
 
{
1296
 
  int error;
1297
 
  int64_t rnd;
1298
 
  
1299
 
  error= get_int(cs, from, len, &rnd, 255, -128, 127);
1300
 
  ptr[0]= unsigned_flag ? (char) (uint64_t) rnd : (char) rnd;
1301
 
  return error;
1302
 
}
1303
 
 
1304
 
 
1305
 
int Field_tiny::store(double nr)
1306
 
{
1307
 
  int error= 0;
1308
 
  nr=rint(nr);
1309
 
  if (unsigned_flag)
1310
 
  {
1311
 
    if (nr < 0.0)
1312
 
    {
1313
 
      *ptr=0;
1314
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1315
 
      error= 1;
1316
 
    }
1317
 
    else if (nr > 255.0)
1318
 
    {
1319
 
      *ptr=(char) 255;
1320
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1321
 
      error= 1;
1322
 
    }
1323
 
    else
1324
 
      *ptr=(char) nr;
1325
 
  }
1326
 
  else
1327
 
  {
1328
 
    if (nr < -128.0)
1329
 
    {
1330
 
      *ptr= (char) -128;
1331
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1332
 
      error= 1;
1333
 
    }
1334
 
    else if (nr > 127.0)
1335
 
    {
1336
 
      *ptr=127;
1337
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1338
 
      error= 1;
1339
 
    }
1340
 
    else
1341
 
      *ptr=(char) (int) nr;
1342
 
  }
1343
 
  return error;
1344
 
}
1345
 
 
1346
 
 
1347
 
int Field_tiny::store(int64_t nr, bool unsigned_val)
1348
 
{
1349
 
  int error= 0;
1350
 
 
1351
 
  if (unsigned_flag)
1352
 
  {
1353
 
    if (nr < 0 && !unsigned_val)
1354
 
    {
1355
 
      *ptr= 0;
1356
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1357
 
      error= 1;
1358
 
    }
1359
 
    else if ((uint64_t) nr > (uint64_t) 255)
1360
 
    {
1361
 
      *ptr= (char) 255;
1362
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1363
 
      error= 1;
1364
 
    }
1365
 
    else
1366
 
      *ptr=(char) nr;
1367
 
  }
1368
 
  else
1369
 
  {
1370
 
    if (nr < 0 && unsigned_val)
1371
 
      nr= 256;                                    // Generate overflow
1372
 
    if (nr < -128)
1373
 
    {
1374
 
      *ptr= (char) -128;
1375
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1376
 
      error= 1;
1377
 
    }
1378
 
    else if (nr > 127)
1379
 
    {
1380
 
      *ptr=127;
1381
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1382
 
      error= 1;
1383
 
    }
1384
 
    else
1385
 
      *ptr=(char) nr;
1386
 
  }
1387
 
  return error;
1388
 
}
1389
 
 
1390
 
 
1391
 
double Field_tiny::val_real(void)
1392
 
{
1393
 
  int tmp= unsigned_flag ? (int) ptr[0] :
1394
 
    (int) ((signed char*) ptr)[0];
1395
 
  return (double) tmp;
1396
 
}
1397
 
 
1398
 
 
1399
 
int64_t Field_tiny::val_int(void)
1400
 
{
1401
 
  int tmp= unsigned_flag ? (int) ptr[0] :
1402
 
    (int) ((signed char*) ptr)[0];
1403
 
  return (int64_t) tmp;
1404
 
}
1405
 
 
1406
 
 
1407
 
String *Field_tiny::val_str(String *val_buffer,
1408
 
                            String *val_ptr __attribute__((unused)))
1409
 
{
1410
 
  const CHARSET_INFO * const cs= &my_charset_bin;
1411
 
  uint length;
1412
 
  uint mlength=max(field_length+1,5*cs->mbmaxlen);
1413
 
  val_buffer->alloc(mlength);
1414
 
  char *to=(char*) val_buffer->ptr();
1415
 
 
1416
 
  if (unsigned_flag)
1417
 
    length= (uint) cs->cset->long10_to_str(cs,to,mlength, 10,
1418
 
                                           (long) *ptr);
1419
 
  else
1420
 
    length= (uint) cs->cset->long10_to_str(cs,to,mlength,-10,
1421
 
                                           (long) *((signed char*) ptr));
1422
 
  
1423
 
  val_buffer->length(length);
1424
 
 
1425
 
  return val_buffer;
1426
 
}
1427
 
 
1428
 
bool Field_tiny::send_binary(Protocol *protocol)
1429
 
{
1430
 
  return protocol->store_tiny((int64_t) (int8_t) ptr[0]);
1431
 
}
1432
 
 
1433
 
int Field_tiny::cmp(const uchar *a_ptr, const uchar *b_ptr)
1434
 
{
1435
 
  signed char a,b;
1436
 
  a=(signed char) a_ptr[0]; b= (signed char) b_ptr[0];
1437
 
  if (unsigned_flag)
1438
 
    return ((uchar) a < (uchar) b) ? -1 : ((uchar) a > (uchar) b) ? 1 : 0;
1439
 
  return (a < b) ? -1 : (a > b) ? 1 : 0;
1440
 
}
1441
 
 
1442
 
void Field_tiny::sort_string(uchar *to,uint length __attribute__((unused)))
1443
 
{
1444
 
  if (unsigned_flag)
1445
 
    *to= *ptr;
1446
 
  else
1447
 
    to[0] = (char) (ptr[0] ^ (uchar) 128);      /* Revers signbit */
1448
 
}
1449
 
 
1450
 
void Field_tiny::sql_type(String &res) const
1451
 
{
1452
 
  const CHARSET_INFO * const cs=res.charset();
1453
 
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
1454
 
                          "tinyint(%d)",(int) field_length));
1455
 
  add_unsigned(res);
1456
 
}
1457
 
 
1458
 
 
1459
 
/*
1460
 
  Report "not well formed" or "cannot convert" error
1461
 
  after storing a character string info a field.
1462
 
 
1463
 
  SYNOPSIS
1464
 
    check_string_copy_error()
1465
 
    field                    - Field
1466
 
    well_formed_error_pos    - where not well formed data was first met
1467
 
    cannot_convert_error_pos - where a not-convertable character was first met
1468
 
    end                      - end of the string
1469
 
    cs                       - character set of the string
1470
 
 
1471
 
  NOTES
1472
 
    As of version 5.0 both cases return the same error:
1473
 
  
1474
 
      "Invalid string value: 'xxx' for column 't' at row 1"
1475
 
  
1476
 
  Future versions will possibly introduce a new error message:
1477
 
 
1478
 
      "Cannot convert character string: 'xxx' for column 't' at row 1"
1479
 
 
1480
 
  RETURN
1481
 
    false - If errors didn't happen
1482
 
    true  - If an error happened
1483
 
*/
1484
 
 
1485
 
bool
1486
 
check_string_copy_error(Field_str *field,
1487
 
                        const char *well_formed_error_pos,
1488
 
                        const char *cannot_convert_error_pos,
1489
 
                        const char *end,
1490
 
                        const CHARSET_INFO * const cs)
1491
 
{
1492
 
  const char *pos, *end_orig;
1493
 
  char tmp[64], *t;
1494
 
  
1495
 
  if (!(pos= well_formed_error_pos) &&
1496
 
      !(pos= cannot_convert_error_pos))
1497
 
    return false;
1498
 
 
1499
 
  end_orig= end;
1500
 
  set_if_smaller(end, pos + 6);
1501
 
 
1502
 
  for (t= tmp; pos < end; pos++)
1503
 
  {
1504
 
    /*
1505
 
      If the source string is ASCII compatible (mbminlen==1)
1506
 
      and the source character is in ASCII printable range (0x20..0x7F),
1507
 
      then display the character as is.
1508
 
      
1509
 
      Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
1510
 
      or the source character is not in the printable range,
1511
 
      then print the character using HEX notation.
1512
 
    */
1513
 
    if (((unsigned char) *pos) >= 0x20 &&
1514
 
        ((unsigned char) *pos) <= 0x7F &&
1515
 
        cs->mbminlen == 1)
1516
 
    {
1517
 
      *t++= *pos;
1518
 
    }
1519
 
    else
1520
 
    {
1521
 
      *t++= '\\';
1522
 
      *t++= 'x';
1523
 
      *t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
1524
 
      *t++= _dig_vec_upper[((unsigned char) *pos) & 15];
1525
 
    }
1526
 
  }
1527
 
  if (end_orig > end)
1528
 
  {
1529
 
    *t++= '.';
1530
 
    *t++= '.';
1531
 
    *t++= '.';
1532
 
  }
1533
 
  *t= '\0';
1534
 
  push_warning_printf(field->table->in_use, 
1535
 
                      field->table->in_use->abort_on_warning ?
1536
 
                      DRIZZLE_ERROR::WARN_LEVEL_ERROR :
1537
 
                      DRIZZLE_ERROR::WARN_LEVEL_WARN,
1538
 
                      ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, 
1539
 
                      ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1540
 
                      "string", tmp, field->field_name,
1541
 
                      (uint32_t) field->table->in_use->row_count);
1542
 
  return true;
1543
 
}
1544
 
 
1545
 
 
1546
 
/*
1547
 
  Check if we lost any important data and send a truncation error/warning
1548
 
 
1549
 
  SYNOPSIS
1550
 
    Field_longstr::report_if_important_data()
1551
 
    ptr                      - Truncated rest of string
1552
 
    end                      - End of truncated string
1553
 
 
1554
 
  RETURN VALUES
1555
 
    0   - None was truncated (or we don't count cut fields)
1556
 
    2   - Some bytes was truncated
1557
 
 
1558
 
  NOTE
1559
 
    Check if we lost any important data (anything in a binary string,
1560
 
    or any non-space in others). If only trailing spaces was lost,
1561
 
    send a truncation note, otherwise send a truncation error.
1562
 
*/
1563
 
 
1564
 
int
1565
 
Field_longstr::report_if_important_data(const char *ptr, const char *end)
1566
 
{
1567
 
  if ((ptr < end) && table->in_use->count_cuted_fields)
1568
 
  {
1569
 
    if (test_if_important_data(field_charset, ptr, end))
1570
 
    {
1571
 
      if (table->in_use->abort_on_warning)
1572
 
        set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
1573
 
      else
1574
 
        set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
1575
 
    }
1576
 
    else /* If we lost only spaces then produce a NOTE, not a WARNING */
1577
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
1578
 
    return 2;
1579
 
  }
1580
 
  return 0;
1581
 
}
1582
 
 
1583
 
 
1584
 
/**
1585
 
  Store double value in Field_varstring.
1586
 
 
1587
 
  Pretty prints double number into field_length characters buffer.
1588
 
 
1589
 
  @param nr            number
1590
 
*/
1591
 
 
1592
 
int Field_str::store(double nr)
1593
 
{
1594
 
  char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
1595
 
  uint local_char_length= field_length / charset()->mbmaxlen;
1596
 
  size_t length;
1597
 
  bool error;
1598
 
 
1599
 
  length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error);
1600
 
  if (error)
1601
 
  {
1602
 
    if (table->in_use->abort_on_warning)
1603
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
1604
 
    else
1605
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
1606
 
  }
1607
 
  return store(buff, length, charset());
1608
 
}
1609
 
 
1610
 
 
1611
 
uint Field::is_equal(Create_field *new_field)
1612
 
{
1613
 
  return (new_field->sql_type == real_type());
1614
 
}
1615
 
 
1616
 
 
1617
 
/* If one of the fields is binary and the other one isn't return 1 else 0 */
1618
 
 
1619
 
bool Field_str::compare_str_field_flags(Create_field *new_field, uint32_t flag_arg)
1620
 
{
1621
 
  return (((new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
1622
 
          !(flag_arg & (BINCMP_FLAG | BINARY_FLAG))) ||
1623
 
         (!(new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
1624
 
          (flag_arg & (BINCMP_FLAG | BINARY_FLAG))));
1625
 
}
1626
 
 
1627
 
 
1628
 
uint Field_str::is_equal(Create_field *new_field)
1629
 
{
1630
 
  if (compare_str_field_flags(new_field, flags))
1631
 
    return 0;
1632
 
 
1633
 
  return ((new_field->sql_type == real_type()) &&
1634
 
          new_field->charset == field_charset &&
1635
 
          new_field->length == max_display_length());
1636
 
}
1637
 
 
1638
 
 
1639
 
int Field_longstr::store_decimal(const my_decimal *d)
1640
 
{
1641
 
  char buff[DECIMAL_MAX_STR_LENGTH+1];
1642
 
  String str(buff, sizeof(buff), &my_charset_bin);
1643
 
  my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
1644
 
  return store(str.ptr(), str.length(), str.charset());
1645
 
}
1646
 
 
1647
 
uint32_t Field_longstr::max_data_length() const
1648
 
{
1649
 
  return field_length + (field_length > 255 ? 2 : 1);
1650
 
}
1651
 
 
1652
 
 
1653
 
/****************************************************************************
1654
 
** enum type.
1655
 
** This is a string which only can have a selection of different values.
1656
 
** If one uses this string in a number context one gets the type number.
1657
 
****************************************************************************/
1658
 
 
1659
 
enum ha_base_keytype Field_enum::key_type() const
1660
 
{
1661
 
  switch (packlength) {
1662
 
  default: return HA_KEYTYPE_BINARY;
1663
 
  case 2: return HA_KEYTYPE_USHORT_INT;
1664
 
  case 3: return HA_KEYTYPE_UINT24;
1665
 
  case 4: return HA_KEYTYPE_ULONG_INT;
1666
 
  case 8: return HA_KEYTYPE_ULONGLONG;
1667
 
  }
1668
 
}
1669
 
 
1670
 
void Field_enum::store_type(uint64_t value)
1671
 
{
1672
 
  switch (packlength) {
1673
 
  case 1: ptr[0]= (uchar) value;  break;
1674
 
  case 2:
1675
 
#ifdef WORDS_BIGENDIAN
1676
 
  if (table->s->db_low_byte_first)
1677
 
  {
1678
 
    int2store(ptr,(unsigned short) value);
1679
 
  }
1680
 
  else
1681
 
#endif
1682
 
    shortstore(ptr,(unsigned short) value);
1683
 
  break;
1684
 
  case 3: int3store(ptr,(long) value); break;
1685
 
  case 4:
1686
 
#ifdef WORDS_BIGENDIAN
1687
 
  if (table->s->db_low_byte_first)
1688
 
  {
1689
 
    int4store(ptr,value);
1690
 
  }
1691
 
  else
1692
 
#endif
1693
 
    longstore(ptr,(long) value);
1694
 
  break;
1695
 
  case 8:
1696
 
#ifdef WORDS_BIGENDIAN
1697
 
  if (table->s->db_low_byte_first)
1698
 
  {
1699
 
    int8store(ptr,value);
1700
 
  }
1701
 
  else
1702
 
#endif
1703
 
    int64_tstore(ptr,value); break;
1704
 
  }
1705
 
}
1706
 
 
1707
 
 
1708
 
/**
1709
 
  @note
1710
 
    Storing a empty string in a enum field gives a warning
1711
 
    (if there isn't a empty value in the enum)
1712
 
*/
1713
 
 
1714
 
int Field_enum::store(const char *from, uint length, const CHARSET_INFO * const cs)
1715
 
{
1716
 
  int err= 0;
1717
 
  uint32_t not_used;
1718
 
  char buff[STRING_BUFFER_USUAL_SIZE];
1719
 
  String tmpstr(buff,sizeof(buff), &my_charset_bin);
1720
 
 
1721
 
  /* Convert character set if necessary */
1722
 
  if (String::needs_conversion(length, cs, field_charset, &not_used))
1723
 
  { 
1724
 
    uint dummy_errors;
1725
 
    tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
1726
 
    from= tmpstr.ptr();
1727
 
    length=  tmpstr.length();
1728
 
  }
1729
 
 
1730
 
  /* Remove end space */
1731
 
  length= field_charset->cset->lengthsp(field_charset, from, length);
1732
 
  uint tmp=find_type2(typelib, from, length, field_charset);
1733
 
  if (!tmp)
1734
 
  {
1735
 
    if (length < 6) // Can't be more than 99999 enums
1736
 
    {
1737
 
      /* This is for reading numbers with LOAD DATA INFILE */
1738
 
      char *end;
1739
 
      tmp=(uint) my_strntoul(cs,from,length,10,&end,&err);
1740
 
      if (err || end != from+length || tmp > typelib->count)
1741
 
      {
1742
 
        tmp=0;
1743
 
        set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
1744
 
      }
1745
 
      if (!table->in_use->count_cuted_fields)
1746
 
        err= 0;
1747
 
    }
1748
 
    else
1749
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
1750
 
  }
1751
 
  store_type((uint64_t) tmp);
1752
 
  return err;
1753
 
}
1754
 
 
1755
 
 
1756
 
int Field_enum::store(double nr)
1757
 
{
1758
 
  return Field_enum::store((int64_t) nr, false);
1759
 
}
1760
 
 
1761
 
 
1762
 
int Field_enum::store(int64_t nr,
1763
 
                      bool unsigned_val __attribute__((unused)))
1764
 
{
1765
 
  int error= 0;
1766
 
  if ((uint64_t) nr > typelib->count || nr == 0)
1767
 
  {
1768
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
1769
 
    if (nr != 0 || table->in_use->count_cuted_fields)
1770
 
    {
1771
 
      nr= 0;
1772
 
      error= 1;
1773
 
    }
1774
 
  }
1775
 
  store_type((uint64_t) (uint) nr);
1776
 
  return error;
1777
 
}
1778
 
 
1779
 
 
1780
 
double Field_enum::val_real(void)
1781
 
{
1782
 
  return (double) Field_enum::val_int();
1783
 
}
1784
 
 
1785
 
 
1786
 
int64_t Field_enum::val_int(void)
1787
 
{
1788
 
  switch (packlength) {
1789
 
  case 1:
1790
 
    return (int64_t) ptr[0];
1791
 
  case 2:
1792
 
  {
1793
 
    uint16_t tmp;
1794
 
#ifdef WORDS_BIGENDIAN
1795
 
    if (table->s->db_low_byte_first)
1796
 
      tmp=sint2korr(ptr);
1797
 
    else
1798
 
#endif
1799
 
      shortget(tmp,ptr);
1800
 
    return (int64_t) tmp;
1801
 
  }
1802
 
  case 3:
1803
 
    return (int64_t) uint3korr(ptr);
1804
 
  case 4:
1805
 
  {
1806
 
    uint32_t tmp;
1807
 
#ifdef WORDS_BIGENDIAN
1808
 
    if (table->s->db_low_byte_first)
1809
 
      tmp=uint4korr(ptr);
1810
 
    else
1811
 
#endif
1812
 
      longget(tmp,ptr);
1813
 
    return (int64_t) tmp;
1814
 
  }
1815
 
  case 8:
1816
 
  {
1817
 
    int64_t tmp;
1818
 
#ifdef WORDS_BIGENDIAN
1819
 
    if (table->s->db_low_byte_first)
1820
 
      tmp=sint8korr(ptr);
1821
 
    else
1822
 
#endif
1823
 
      int64_tget(tmp,ptr);
1824
 
    return tmp;
1825
 
  }
1826
 
  }
1827
 
  return 0;                                     // impossible
1828
 
}
1829
 
 
1830
 
 
1831
 
/**
1832
 
   Save the field metadata for enum fields.
1833
 
 
1834
 
   Saves the real type in the first byte and the pack length in the 
1835
 
   second byte of the field metadata array at index of *metadata_ptr and
1836
 
   *(metadata_ptr + 1).
1837
 
 
1838
 
   @param   metadata_ptr   First byte of field metadata
1839
 
 
1840
 
   @returns number of bytes written to metadata_ptr
1841
 
*/
1842
 
int Field_enum::do_save_field_metadata(uchar *metadata_ptr)
1843
 
{
1844
 
  *metadata_ptr= real_type();
1845
 
  *(metadata_ptr + 1)= pack_length();
1846
 
  return 2;
1847
 
}
1848
 
 
1849
 
 
1850
 
String *Field_enum::val_str(String *val_buffer __attribute__((unused)),
1851
 
                            String *val_ptr)
1852
 
{
1853
 
  uint tmp=(uint) Field_enum::val_int();
1854
 
  if (!tmp || tmp > typelib->count)
1855
 
    val_ptr->set("", 0, field_charset);
1856
 
  else
1857
 
    val_ptr->set((const char*) typelib->type_names[tmp-1],
1858
 
                 typelib->type_lengths[tmp-1],
1859
 
                 field_charset);
1860
 
  return val_ptr;
1861
 
}
1862
 
 
1863
 
int Field_enum::cmp(const uchar *a_ptr, const uchar *b_ptr)
1864
 
{
1865
 
  uchar *old= ptr;
1866
 
  ptr= (uchar*) a_ptr;
1867
 
  uint64_t a=Field_enum::val_int();
1868
 
  ptr= (uchar*) b_ptr;
1869
 
  uint64_t b=Field_enum::val_int();
1870
 
  ptr= old;
1871
 
  return (a < b) ? -1 : (a > b) ? 1 : 0;
1872
 
}
1873
 
 
1874
 
void Field_enum::sort_string(uchar *to,uint length __attribute__((unused)))
1875
 
{
1876
 
  uint64_t value=Field_enum::val_int();
1877
 
  to+=packlength-1;
1878
 
  for (uint i=0 ; i < packlength ; i++)
1879
 
  {
1880
 
    *to-- = (uchar) (value & 255);
1881
 
    value>>=8;
1882
 
  }
1883
 
}
1884
 
 
1885
 
 
1886
 
void Field_enum::sql_type(String &res) const
1887
 
{
1888
 
  char buffer[255];
1889
 
  String enum_item(buffer, sizeof(buffer), res.charset());
1890
 
 
1891
 
  res.length(0);
1892
 
  res.append(STRING_WITH_LEN("enum("));
1893
 
 
1894
 
  bool flag=0;
1895
 
  uint *len= typelib->type_lengths;
1896
 
  for (const char **pos= typelib->type_names; *pos; pos++, len++)
1897
 
  {
1898
 
    uint dummy_errors;
1899
 
    if (flag)
1900
 
      res.append(',');
1901
 
    /* convert to res.charset() == utf8, then quote */
1902
 
    enum_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
1903
 
    append_unescaped(&res, enum_item.ptr(), enum_item.length());
1904
 
    flag= 1;
1905
 
  }
1906
 
  res.append(')');
1907
 
}
1908
 
 
1909
 
 
1910
 
Field *Field_enum::new_field(MEM_ROOT *root, struct st_table *new_table,
1911
 
                             bool keep_type)
1912
 
{
1913
 
  Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type);
1914
 
  if (res)
1915
 
    res->typelib= copy_typelib(root, typelib);
1916
 
  return res;
1917
 
}
1918
 
 
1919
 
 
1920
 
/**
1921
 
  @retval
1922
 
    1  if the fields are equally defined
1923
 
  @retval
1924
 
    0  if the fields are unequally defined
1925
 
*/
 
889
uint32_t Field::is_equal(CreateField *new_field_ptr)
 
890
{
 
891
  return (new_field_ptr->sql_type == real_type());
 
892
}
1926
893
 
1927
894
bool Field::eq_def(Field *field)
1928
895
{
1932
899
  return 1;
1933
900
}
1934
901
 
1935
 
/**
1936
 
  @return
1937
 
  returns 1 if the fields are equally defined
1938
 
*/
1939
902
bool Field_enum::eq_def(Field *field)
1940
903
{
1941
904
  if (!Field::eq_def(field))
1944
907
 
1945
908
  if (typelib->count < from_lib->count)
1946
909
    return 0;
1947
 
  for (uint i=0 ; i < from_lib->count ; i++)
 
910
  for (uint32_t i=0 ; i < from_lib->count ; i++)
1948
911
    if (my_strnncoll(field_charset,
1949
 
                     (const uchar*)typelib->type_names[i],
 
912
                     (const unsigned char*)typelib->type_names[i],
1950
913
                     strlen(typelib->type_names[i]),
1951
 
                     (const uchar*)from_lib->type_names[i],
 
914
                     (const unsigned char*)from_lib->type_names[i],
1952
915
                     strlen(from_lib->type_names[i])))
1953
916
      return 0;
1954
917
  return 1;
1955
918
}
1956
919
 
1957
 
/**
1958
 
  @return
1959
 
  returns 1 if the fields are equally defined
1960
 
*/
1961
 
bool Field_num::eq_def(Field *field)
1962
 
{
1963
 
  if (!Field::eq_def(field))
1964
 
    return 0;
1965
 
  Field_num *from_num= (Field_num*) field;
1966
 
 
1967
 
  if (unsigned_flag != from_num->unsigned_flag ||
1968
 
      dec != from_num->dec)
1969
 
    return 0;
1970
 
  return 1;
1971
 
}
1972
 
 
1973
 
 
1974
 
uint Field_num::is_equal(Create_field *new_field)
1975
 
{
1976
 
  return ((new_field->sql_type == real_type()) &&
1977
 
          ((new_field->flags & UNSIGNED_FLAG) == (uint) (flags &
1978
 
                                                         UNSIGNED_FLAG)) &&
1979
 
          ((new_field->flags & AUTO_INCREMENT_FLAG) ==
1980
 
           (uint) (flags & AUTO_INCREMENT_FLAG)) &&
1981
 
          (new_field->length <= max_display_length()));
1982
 
}
1983
 
 
1984
 
 
1985
 
/*****************************************************************************
1986
 
  Handling of field and Create_field
1987
 
*****************************************************************************/
1988
 
 
1989
 
/**
1990
 
  Convert create_field::length from number of characters to number of bytes.
1991
 
*/
1992
 
 
1993
 
void Create_field::create_length_to_internal_length(void)
1994
 
{
1995
 
  switch (sql_type) {
1996
 
  case DRIZZLE_TYPE_BLOB:
1997
 
  case DRIZZLE_TYPE_VARCHAR:
1998
 
    length*= charset->mbmaxlen;
1999
 
    key_length= length;
2000
 
    pack_length= calc_pack_length(sql_type, length);
2001
 
    break;
2002
 
  case DRIZZLE_TYPE_ENUM:
2003
 
    /* Pack_length already calculated in sql_parse.cc */
2004
 
    length*= charset->mbmaxlen;
2005
 
    key_length= pack_length;
2006
 
    break;
2007
 
  case DRIZZLE_TYPE_NEWDECIMAL:
2008
 
    key_length= pack_length=
2009
 
      my_decimal_get_binary_size(my_decimal_length_to_precision(length,
2010
 
                                                                decimals,
2011
 
                                                                flags &
2012
 
                                                                UNSIGNED_FLAG),
2013
 
                                 decimals);
2014
 
    break;
2015
 
  default:
2016
 
    key_length= pack_length= calc_pack_length(sql_type, length);
2017
 
    break;
2018
 
  }
2019
 
}
2020
 
 
2021
 
 
2022
 
/**
2023
 
  Init for a tmp table field. To be extended if need be.
2024
 
*/
2025
 
void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
2026
 
                                      uint32_t length_arg, uint32_t decimals_arg,
2027
 
                                      bool maybe_null, bool is_unsigned)
2028
 
{
2029
 
  field_name= "";
2030
 
  sql_type= sql_type_arg;
2031
 
  char_length= length= length_arg;;
2032
 
  unireg_check= Field::NONE;
2033
 
  interval= 0;
2034
 
  charset= &my_charset_bin;
2035
 
  pack_flag= (FIELDFLAG_NUMBER |
2036
 
              ((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
2037
 
              (maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
2038
 
              (is_unsigned ? 0 : FIELDFLAG_DECIMAL));
2039
 
}
2040
 
 
2041
 
 
2042
 
/**
2043
 
  Initialize field definition for create.
2044
 
 
2045
 
  @param thd                   Thread handle
2046
 
  @param fld_name              Field name
2047
 
  @param fld_type              Field type
2048
 
  @param fld_length            Field length
2049
 
  @param fld_decimals          Decimal (if any)
2050
 
  @param fld_type_modifier     Additional type information
2051
 
  @param fld_default_value     Field default value (if any)
2052
 
  @param fld_on_update_value   The value of ON UPDATE clause
2053
 
  @param fld_comment           Field comment
2054
 
  @param fld_change            Field change
2055
 
  @param fld_interval_list     Interval list (if any)
2056
 
  @param fld_charset           Field charset
2057
 
 
2058
 
  @retval
2059
 
    false on success
2060
 
  @retval
2061
 
    true  on error
2062
 
*/
2063
 
 
2064
 
bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type,
2065
 
                        char *fld_length, char *fld_decimals,
2066
 
                        uint fld_type_modifier, Item *fld_default_value,
2067
 
                        Item *fld_on_update_value, LEX_STRING *fld_comment,
2068
 
                        char *fld_change, List<String> *fld_interval_list,
2069
 
                        const CHARSET_INFO * const fld_charset,
2070
 
                        uint fld_geom_type __attribute__((unused)),
2071
 
                        enum column_format_type column_format)
2072
 
{
2073
 
  uint sign_len, allowed_type_modifier= 0;
2074
 
  uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
2075
 
 
2076
 
  field= 0;
2077
 
  field_name= fld_name;
2078
 
  def= fld_default_value;
2079
 
  flags= fld_type_modifier;
2080
 
  flags|= (((uint)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
2081
 
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
2082
 
                 Field::NEXT_NUMBER : Field::NONE);
2083
 
  decimals= fld_decimals ? (uint)atoi(fld_decimals) : 0;
2084
 
  if (decimals >= NOT_FIXED_DEC)
2085
 
  {
2086
 
    my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
2087
 
             NOT_FIXED_DEC-1);
2088
 
    return(true);
2089
 
  }
2090
 
 
2091
 
  sql_type= fld_type;
2092
 
  length= 0;
2093
 
  change= fld_change;
2094
 
  interval= 0;
2095
 
  pack_length= key_length= 0;
2096
 
  charset= fld_charset;
2097
 
  interval_list.empty();
2098
 
 
2099
 
  comment= *fld_comment;
2100
 
  /*
2101
 
    Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
2102
 
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
2103
 
  */
2104
 
  if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
2105
 
      (fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
2106
 
    flags|= NO_DEFAULT_VALUE_FLAG;
2107
 
 
2108
 
  if (fld_length && !(length= (uint) atoi(fld_length)))
2109
 
    fld_length= 0; /* purecov: inspected */
2110
 
  sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
2111
 
 
2112
 
  switch (fld_type) {
2113
 
  case DRIZZLE_TYPE_TINY:
2114
 
    if (!fld_length)
2115
 
      length= MAX_TINYINT_WIDTH+sign_len;
2116
 
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
2117
 
    break;
2118
 
  case DRIZZLE_TYPE_SHORT:
2119
 
    if (!fld_length)
2120
 
      length= MAX_SMALLINT_WIDTH+sign_len;
2121
 
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
2122
 
    break;
2123
 
  case DRIZZLE_TYPE_LONG:
2124
 
    if (!fld_length)
2125
 
      length= MAX_INT_WIDTH+sign_len;
2126
 
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
2127
 
    break;
2128
 
  case DRIZZLE_TYPE_LONGLONG:
2129
 
    if (!fld_length)
2130
 
      length= MAX_BIGINT_WIDTH;
2131
 
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
2132
 
    break;
2133
 
  case DRIZZLE_TYPE_NULL:
2134
 
    break;
2135
 
  case DRIZZLE_TYPE_NEWDECIMAL:
2136
 
    my_decimal_trim(&length, &decimals);
2137
 
    if (length > DECIMAL_MAX_PRECISION)
2138
 
    {
2139
 
      my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
2140
 
               DECIMAL_MAX_PRECISION);
2141
 
      return(true);
2142
 
    }
2143
 
    if (length < decimals)
2144
 
    {
2145
 
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
2146
 
      return(true);
2147
 
    }
2148
 
    length=
2149
 
      my_decimal_precision_to_length(length, decimals,
2150
 
                                     fld_type_modifier & UNSIGNED_FLAG);
2151
 
    pack_length=
2152
 
      my_decimal_get_binary_size(length, decimals);
2153
 
    break;
2154
 
  case DRIZZLE_TYPE_VARCHAR:
2155
 
    /*
2156
 
      Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table
2157
 
      if they don't have a default value
2158
 
    */
2159
 
    max_field_charlength= MAX_FIELD_VARCHARLENGTH;
2160
 
    break;
2161
 
  case DRIZZLE_TYPE_BLOB:
2162
 
    if (fld_default_value)
2163
 
    {
2164
 
      /* Allow empty as default value. */
2165
 
      String str,*res;
2166
 
      res= fld_default_value->val_str(&str);
2167
 
      /*
2168
 
        A default other than '' is always an error, and any non-NULL
2169
 
        specified default is an error in strict mode.
2170
 
      */
2171
 
      if (res->length() || (thd->variables.sql_mode &
2172
 
                            (MODE_STRICT_TRANS_TABLES |
2173
 
                             MODE_STRICT_ALL_TABLES)))
2174
 
      {
2175
 
        my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
2176
 
                 fld_name); /* purecov: inspected */
2177
 
        return(true);
2178
 
      }
2179
 
      else
2180
 
      {
2181
 
        /*
2182
 
          Otherwise a default of '' is just a warning.
2183
 
        */
2184
 
        push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2185
 
                            ER_BLOB_CANT_HAVE_DEFAULT,
2186
 
                            ER(ER_BLOB_CANT_HAVE_DEFAULT),
2187
 
                            fld_name);
2188
 
      }
2189
 
      def= 0;
2190
 
    }
2191
 
    flags|= BLOB_FLAG;
2192
 
    break;
2193
 
  case DRIZZLE_TYPE_DOUBLE:
2194
 
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
2195
 
    if (!fld_length && !fld_decimals)
2196
 
    {
2197
 
      length= DBL_DIG+7;
2198
 
      decimals= NOT_FIXED_DEC;
2199
 
    }
2200
 
    if (length < decimals &&
2201
 
        decimals != NOT_FIXED_DEC)
2202
 
    {
2203
 
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
2204
 
      return(true);
2205
 
    }
2206
 
    break;
2207
 
  case DRIZZLE_TYPE_TIMESTAMP:
2208
 
    if (!fld_length)
2209
 
    {
2210
 
      /* Compressed date YYYYMMDDHHMMSS */
2211
 
      length= MAX_DATETIME_COMPRESSED_WIDTH;
2212
 
    }
2213
 
    else if (length != MAX_DATETIME_WIDTH)
2214
 
    {
2215
 
      /*
2216
 
        We support only even TIMESTAMP lengths less or equal than 14
2217
 
        and 19 as length of 4.1 compatible representation.
2218
 
      */
2219
 
      length= ((length+1)/2)*2; /* purecov: inspected */
2220
 
      length= min(length, (uint32_t)MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
2221
 
    }
2222
 
    flags|= UNSIGNED_FLAG;
2223
 
    if (fld_default_value)
2224
 
    {
2225
 
      /* Grammar allows only NOW() value for ON UPDATE clause */
2226
 
      if (fld_default_value->type() == Item::FUNC_ITEM && 
2227
 
          ((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
2228
 
      {
2229
 
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
2230
 
                                             Field::TIMESTAMP_DN_FIELD);
2231
 
        /*
2232
 
          We don't need default value any longer moreover it is dangerous.
2233
 
          Everything handled by unireg_check further.
2234
 
        */
2235
 
        def= 0;
2236
 
      }
2237
 
      else
2238
 
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
2239
 
                                             Field::NONE);
2240
 
    }
2241
 
    else
2242
 
    {
2243
 
      /*
2244
 
        If we have default TIMESTAMP NOT NULL column without explicit DEFAULT
2245
 
        or ON UPDATE values then for the sake of compatiblity we should treat
2246
 
        this column as having DEFAULT NOW() ON UPDATE NOW() (when we don't
2247
 
        have another TIMESTAMP column with auto-set option before this one)
2248
 
        or DEFAULT 0 (in other cases).
2249
 
        So here we are setting TIMESTAMP_OLD_FIELD only temporary, and will
2250
 
        replace this value by TIMESTAMP_DNUN_FIELD or NONE later when
2251
 
        information about all TIMESTAMP fields in table will be availiable.
2252
 
 
2253
 
        If we have TIMESTAMP NULL column without explicit DEFAULT value
2254
 
        we treat it as having DEFAULT NULL attribute.
2255
 
      */
2256
 
      unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD :
2257
 
                     (flags & NOT_NULL_FLAG ? Field::TIMESTAMP_OLD_FIELD :
2258
 
                                              Field::NONE));
2259
 
    }
2260
 
    break;
2261
 
  case DRIZZLE_TYPE_DATE:
2262
 
    /* Old date type. */
2263
 
    sql_type= DRIZZLE_TYPE_NEWDATE;
2264
 
    /* fall trough */
2265
 
  case DRIZZLE_TYPE_NEWDATE:
2266
 
    length= 10;
2267
 
    break;
2268
 
  case DRIZZLE_TYPE_TIME:
2269
 
    length= 10;
2270
 
    break;
2271
 
  case DRIZZLE_TYPE_DATETIME:
2272
 
    length= MAX_DATETIME_WIDTH;
2273
 
    break;
2274
 
  case DRIZZLE_TYPE_ENUM:
2275
 
    {
2276
 
      /* Should be safe. */
2277
 
      pack_length= get_enum_pack_length(fld_interval_list->elements);
2278
 
 
2279
 
      List_iterator<String> it(*fld_interval_list);
2280
 
      String *tmp;
2281
 
      while ((tmp= it++))
2282
 
        interval_list.push_back(tmp);
2283
 
      length= 1; /* See comment for DRIZZLE_TYPE_SET above. */
2284
 
      break;
2285
 
   }
2286
 
  }
2287
 
  /* Remember the value of length */
2288
 
  char_length= length;
2289
 
 
2290
 
  if (!(flags & BLOB_FLAG) &&
2291
 
      ((length > max_field_charlength &&
2292
 
        fld_type != DRIZZLE_TYPE_ENUM &&
2293
 
        (fld_type != DRIZZLE_TYPE_VARCHAR || fld_default_value)) ||
2294
 
       (!length && fld_type != DRIZZLE_TYPE_VARCHAR)))
2295
 
  {
2296
 
    my_error((fld_type == DRIZZLE_TYPE_VARCHAR) ?  ER_TOO_BIG_FIELDLENGTH : ER_TOO_BIG_DISPLAYWIDTH,
2297
 
              MYF(0),
2298
 
              fld_name, max_field_charlength); /* purecov: inspected */
2299
 
    return(true);
2300
 
  }
2301
 
  fld_type_modifier&= AUTO_INCREMENT_FLAG;
2302
 
  if ((~allowed_type_modifier) & fld_type_modifier)
2303
 
  {
2304
 
    my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
2305
 
    return(true);
2306
 
  }
2307
 
 
2308
 
  return(false); /* success */
2309
 
}
2310
 
 
2311
 
 
2312
 
enum_field_types get_blob_type_from_length(uint32_t length __attribute__((unused)))
2313
 
{
2314
 
  enum_field_types type;
2315
 
 
2316
 
  type= DRIZZLE_TYPE_BLOB;
2317
 
 
2318
 
  return type;
2319
 
}
2320
 
 
2321
 
 
2322
920
/*
2323
921
  Make a field from the .frm file info
2324
922
*/
2325
 
 
2326
923
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
2327
924
{
2328
925
  switch (type) {
2329
 
  case DRIZZLE_TYPE_VARCHAR:     return (length + (length < 256 ? 1: 2));
2330
 
  case DRIZZLE_TYPE_TINY        : return 1;
2331
 
  case DRIZZLE_TYPE_SHORT : return 2;
2332
 
  case DRIZZLE_TYPE_DATE:
2333
 
  case DRIZZLE_TYPE_NEWDATE:
2334
 
  case DRIZZLE_TYPE_TIME:   return 3;
 
926
  case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
 
927
  case DRIZZLE_TYPE_DATE: return 3;
2335
928
  case DRIZZLE_TYPE_TIMESTAMP:
2336
 
  case DRIZZLE_TYPE_LONG        : return 4;
 
929
  case DRIZZLE_TYPE_LONG: return 4;
2337
930
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
2338
931
  case DRIZZLE_TYPE_DATETIME:
2339
932
  case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
2340
 
  case DRIZZLE_TYPE_NULL        : return 0;
2341
 
  case DRIZZLE_TYPE_BLOB:               return 4+portable_sizeof_char_ptr;
 
933
  case DRIZZLE_TYPE_NULL: return 0;
 
934
  case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
2342
935
  case DRIZZLE_TYPE_ENUM:
2343
 
  case DRIZZLE_TYPE_NEWDECIMAL:
2344
 
    abort(); return 0;                          // This shouldn't happen
 
936
  case DRIZZLE_TYPE_DECIMAL:
 
937
    abort();
2345
938
  default:
2346
939
    return 0;
2347
940
  }
2348
941
}
2349
942
 
2350
 
 
2351
 
uint pack_length_to_packflag(uint type)
 
943
uint32_t pack_length_to_packflag(uint32_t type)
2352
944
{
2353
945
  switch (type) {
2354
 
    case 1: return f_settype((uint) DRIZZLE_TYPE_TINY);
2355
 
    case 2: return f_settype((uint) DRIZZLE_TYPE_SHORT);
 
946
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
 
947
    case 2: assert(1);
2356
948
    case 3: assert(1);
2357
 
    case 4: return f_settype((uint) DRIZZLE_TYPE_LONG);
2358
 
    case 8: return f_settype((uint) DRIZZLE_TYPE_LONGLONG);
 
949
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
 
950
    case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
2359
951
  }
2360
952
  return 0;                                     // This shouldn't happen
2361
953
}
2362
954
 
2363
 
 
2364
 
Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32_t field_length,
2365
 
                  uchar *null_pos, uchar null_bit,
2366
 
                  uint pack_flag,
2367
 
                  enum_field_types field_type,
2368
 
                  const CHARSET_INFO * field_charset,
2369
 
                  Field::utype unireg_check,
2370
 
                  TYPELIB *interval,
2371
 
                  const char *field_name)
 
955
Field *make_field(TableShare *share,
 
956
                  memory::Root *root,
 
957
                  unsigned char *ptr,
 
958
                  uint32_t field_length,
 
959
                  bool is_nullable,
 
960
                  unsigned char *null_pos,
 
961
                  unsigned char null_bit,
 
962
                  uint8_t decimals,
 
963
                  enum_field_types field_type,
 
964
                  const CHARSET_INFO * field_charset,
 
965
                  Field::utype unireg_check,
 
966
                  TYPELIB *interval,
 
967
                  const char *field_name)
2372
968
{
2373
 
  if (!f_maybe_null(pack_flag))
 
969
  if(! root)
 
970
    root= current_mem_root();
 
971
 
 
972
  if (! is_nullable)
2374
973
  {
2375
974
    null_pos=0;
2376
975
    null_bit=0;
2377
976
  }
2378
977
  else
2379
978
  {
2380
 
    null_bit= ((uchar) 1) << null_bit;
 
979
    null_bit= ((unsigned char) 1) << null_bit;
2381
980
  }
2382
981
 
2383
 
  switch (field_type) {
 
982
  switch (field_type) 
 
983
  {
2384
984
  case DRIZZLE_TYPE_DATE:
2385
 
  case DRIZZLE_TYPE_NEWDATE:
2386
 
  case DRIZZLE_TYPE_TIME:
2387
985
  case DRIZZLE_TYPE_DATETIME:
2388
986
  case DRIZZLE_TYPE_TIMESTAMP:
2389
987
    field_charset= &my_charset_bin;
2390
988
  default: break;
2391
989
  }
2392
990
 
2393
 
  if (f_is_alpha(pack_flag))
 
991
  if (field_type == DRIZZLE_TYPE_VARCHAR ||
 
992
      field_type == DRIZZLE_TYPE_BLOB ||
 
993
      field_type == DRIZZLE_TYPE_ENUM)
2394
994
  {
2395
 
    if (!f_is_packed(pack_flag))
 
995
    if (field_type == DRIZZLE_TYPE_VARCHAR)
 
996
      return new (root) Field_varstring(ptr,field_length,
 
997
                                  HA_VARCHAR_PACKLENGTH(field_length),
 
998
                                  null_pos,null_bit,
 
999
                                  field_name,
 
1000
                                  share,
 
1001
                                  field_charset);
 
1002
 
 
1003
    if (field_type == DRIZZLE_TYPE_BLOB)
2396
1004
    {
2397
 
      if (field_type == DRIZZLE_TYPE_VARCHAR)
2398
 
        return new Field_varstring(ptr,field_length,
2399
 
                                   HA_VARCHAR_PACKLENGTH(field_length),
2400
 
                                   null_pos,null_bit,
2401
 
                                   unireg_check, field_name,
 
1005
      return new (root) Field_blob(ptr,
 
1006
                                   null_pos,
 
1007
                                   null_bit,
 
1008
                                   field_name,
2402
1009
                                   share,
 
1010
                                   calc_pack_length(DRIZZLE_TYPE_LONG, 0),
2403
1011
                                   field_charset);
2404
 
      return 0;                                 // Error
2405
1012
    }
2406
1013
 
2407
 
    uint pack_length=calc_pack_length((enum_field_types)
2408
 
                                      f_packtype(pack_flag),
2409
 
                                      field_length);
2410
 
 
2411
 
    if (f_is_blob(pack_flag))
2412
 
      return new Field_blob(ptr,null_pos,null_bit,
2413
 
                            unireg_check, field_name, share,
2414
 
                            pack_length, field_charset);
2415
1014
    if (interval)
2416
1015
    {
2417
 
      if (f_is_enum(pack_flag))
2418
 
        return new Field_enum(ptr,field_length,null_pos,null_bit,
2419
 
                                  unireg_check, field_name,
2420
 
                                  pack_length, interval, field_charset);
 
1016
      return new (root) Field_enum(ptr,
 
1017
                                   field_length,
 
1018
                                   null_pos,
 
1019
                                   null_bit,
 
1020
                                   field_name,
 
1021
                                   get_enum_pack_length(interval->count),
 
1022
                                   interval,
 
1023
                                   field_charset);
2421
1024
    }
2422
1025
  }
2423
1026
 
2424
 
  switch (field_type) {
2425
 
  case DRIZZLE_TYPE_NEWDECIMAL:
2426
 
    return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
2427
 
                                 unireg_check, field_name,
2428
 
                                 f_decimals(pack_flag),
2429
 
                                 f_is_decimal_precision(pack_flag) != 0,
2430
 
                                 f_is_dec(pack_flag) == 0);
 
1027
  switch (field_type)
 
1028
  {
 
1029
  case DRIZZLE_TYPE_DECIMAL:
 
1030
    return new (root) Field_decimal(ptr,
 
1031
                                    field_length,
 
1032
                                    null_pos,
 
1033
                                    null_bit,
 
1034
                                    unireg_check,
 
1035
                                    field_name,
 
1036
                                    decimals,
 
1037
                                    false,
 
1038
                                    false /* is_unsigned */);
2431
1039
  case DRIZZLE_TYPE_DOUBLE:
2432
 
    return new Field_double(ptr,field_length,null_pos,null_bit,
2433
 
                            unireg_check, field_name,
2434
 
                            f_decimals(pack_flag),
2435
 
                            false,
2436
 
                            f_is_dec(pack_flag)== 0);
2437
 
  case DRIZZLE_TYPE_TINY:
2438
 
    return new Field_tiny(ptr,field_length,null_pos,null_bit,
2439
 
                          unireg_check, field_name,
2440
 
                          false,
2441
 
                          f_is_dec(pack_flag) == 0);
2442
 
  case DRIZZLE_TYPE_SHORT:
2443
 
    return new Field_short(ptr,field_length,null_pos,null_bit,
2444
 
                           unireg_check, field_name,
2445
 
                           false,
2446
 
                           f_is_dec(pack_flag) == 0);
 
1040
    return new (root) Field_double(ptr,
 
1041
                                   field_length,
 
1042
                                   null_pos,
 
1043
                                   null_bit,
 
1044
                                   unireg_check,
 
1045
                                   field_name,
 
1046
                                   decimals,
 
1047
                                   false,
 
1048
                                   false /* is_unsigned */);
2447
1049
  case DRIZZLE_TYPE_LONG:
2448
 
    return new Field_long(ptr,field_length,null_pos,null_bit,
2449
 
                           unireg_check, field_name,
2450
 
                           false,
2451
 
                           f_is_dec(pack_flag) == 0);
 
1050
    return new (root) Field_long(ptr,
 
1051
                                 field_length,
 
1052
                                 null_pos,
 
1053
                                 null_bit,
 
1054
                                 unireg_check,
 
1055
                                 field_name,
 
1056
                                 false,
 
1057
                                 false /* is_unsigned */);
2452
1058
  case DRIZZLE_TYPE_LONGLONG:
2453
 
    return new Field_int64_t(ptr,field_length,null_pos,null_bit,
2454
 
                              unireg_check, field_name,
2455
 
                              false,
2456
 
                              f_is_dec(pack_flag) == 0);
 
1059
    return new (root) Field_int64_t(ptr,
 
1060
                                    field_length,
 
1061
                                    null_pos,
 
1062
                                    null_bit,
 
1063
                                    unireg_check,
 
1064
                                    field_name,
 
1065
                                    false,
 
1066
                                    false /* is_unsigned */);
2457
1067
  case DRIZZLE_TYPE_TIMESTAMP:
2458
 
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,
2459
 
                               unireg_check, field_name, share,
2460
 
                               field_charset);
 
1068
    return new (root) Field_timestamp(ptr,
 
1069
                                      field_length,
 
1070
                                      null_pos,
 
1071
                                      null_bit,
 
1072
                                      unireg_check,
 
1073
                                      field_name,
 
1074
                                      share,
 
1075
                                      field_charset);
2461
1076
  case DRIZZLE_TYPE_DATE:
2462
 
  case DRIZZLE_TYPE_NEWDATE:
2463
 
    return new Field_newdate(ptr,null_pos,null_bit,
2464
 
                             unireg_check, field_name, field_charset);
2465
 
  case DRIZZLE_TYPE_TIME:
2466
 
    return new Field_time(ptr,null_pos,null_bit,
2467
 
                          unireg_check, field_name, field_charset);
 
1077
    return new (root) Field_date(ptr,
 
1078
                                 null_pos,
 
1079
                                 null_bit,
 
1080
                                 field_name,
 
1081
                                 field_charset);
2468
1082
  case DRIZZLE_TYPE_DATETIME:
2469
 
    return new Field_datetime(ptr,null_pos,null_bit,
2470
 
                              unireg_check, field_name, field_charset);
 
1083
    return new (root) Field_datetime(ptr,
 
1084
                                     null_pos,
 
1085
                                     null_bit,
 
1086
                                     field_name,
 
1087
                                     field_charset);
2471
1088
  case DRIZZLE_TYPE_NULL:
2472
 
    return new Field_null(ptr, field_length, unireg_check, field_name,
2473
 
                          field_charset);
2474
 
  default:                                      // Impossible (Wrong version)
 
1089
    return new (root) Field_null(ptr,
 
1090
                                 field_length,
 
1091
                                 field_name,
 
1092
                                 field_charset);
 
1093
  default: // Impossible (Wrong version)
2475
1094
    break;
2476
1095
  }
2477
1096
  return 0;
2478
1097
}
2479
1098
 
2480
 
 
2481
 
/** Create a field suitable for create of table. */
2482
 
 
2483
 
Create_field::Create_field(Field *old_field,Field *orig_field)
2484
 
{
2485
 
  field=      old_field;
2486
 
  field_name=change=old_field->field_name;
2487
 
  length=     old_field->field_length;
2488
 
  flags=      old_field->flags;
2489
 
  unireg_check=old_field->unireg_check;
2490
 
  pack_length=old_field->pack_length();
2491
 
  key_length= old_field->key_length();
2492
 
  sql_type=   old_field->real_type();
2493
 
  charset=    old_field->charset();             // May be NULL ptr
2494
 
  comment=    old_field->comment;
2495
 
  decimals=   old_field->decimals();
2496
 
 
2497
 
  /* Fix if the original table had 4 byte pointer blobs */
2498
 
  if (flags & BLOB_FLAG)
2499
 
    pack_length= (pack_length- old_field->table->s->blob_ptr_size +
2500
 
                  portable_sizeof_char_ptr);
2501
 
 
2502
 
  switch (sql_type) {
2503
 
  case DRIZZLE_TYPE_BLOB:
2504
 
    sql_type= DRIZZLE_TYPE_BLOB;
2505
 
    length/= charset->mbmaxlen;
2506
 
    key_length/= charset->mbmaxlen;
2507
 
    break;
2508
 
    /* Change CHAR -> VARCHAR if dynamic record length */
2509
 
  case DRIZZLE_TYPE_ENUM:
2510
 
  case DRIZZLE_TYPE_VARCHAR:
2511
 
    /* This is corrected in create_length_to_internal_length */
2512
 
    length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
2513
 
    break;
2514
 
  default:
2515
 
    break;
2516
 
  }
2517
 
 
2518
 
  if (flags & (ENUM_FLAG | SET_FLAG))
2519
 
    interval= ((Field_enum*) old_field)->typelib;
2520
 
  else
2521
 
    interval=0;
2522
 
  def=0;
2523
 
  char_length= length;
2524
 
 
2525
 
  if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
2526
 
      old_field->ptr && orig_field &&
2527
 
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
2528
 
       old_field->table->timestamp_field != old_field ||  /* timestamp field */ 
2529
 
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
2530
 
  {
2531
 
    char buff[MAX_FIELD_WIDTH];
2532
 
    String tmp(buff,sizeof(buff), charset);
2533
 
    my_ptrdiff_t diff;
2534
 
 
2535
 
    /* Get the value from default_values */
2536
 
    diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
2537
 
                          orig_field->table->record[0]);
2538
 
    orig_field->move_field_offset(diff);        // Points now at default_values
2539
 
    if (!orig_field->is_real_null())
2540
 
    {
2541
 
      char buff[MAX_FIELD_WIDTH], *pos;
2542
 
      String tmp(buff, sizeof(buff), charset), *res;
2543
 
      res= orig_field->val_str(&tmp);
2544
 
      pos= (char*) sql_strmake(res->ptr(), res->length());
2545
 
      def= new Item_string(pos, res->length(), charset);
2546
 
    }
2547
 
    orig_field->move_field_offset(-diff);       // Back to record[0]
2548
 
  }
2549
 
}
2550
 
 
2551
 
 
2552
1099
/*****************************************************************************
2553
1100
 Warning handling
2554
1101
*****************************************************************************/
2555
1102
 
2556
 
/**
2557
 
  Produce warning or note about data saved into field.
2558
 
 
2559
 
  @param level            - level of message (Note/Warning/Error)
2560
 
  @param code             - error code of message to be produced
2561
 
  @param cuted_increment  - whenever we should increase cut fields count or not
2562
 
 
2563
 
  @note
2564
 
    This function won't produce warning and increase cut fields counter
2565
 
    if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
2566
 
 
2567
 
    if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
2568
 
    This allows us to avoid notes in optimisation, like convert_constant_item().
2569
 
 
2570
 
  @retval
2571
 
    1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
2572
 
  @retval
2573
 
    0 otherwise
2574
 
*/
2575
 
 
2576
 
bool 
2577
 
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint code,
2578
 
                   int cuted_increment)
 
1103
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
 
1104
                        uint32_t code,
 
1105
                        int cuted_increment)
2579
1106
{
2580
1107
  /*
2581
1108
    If this field was created only for type conversion purposes it
2582
1109
    will have table == NULL.
2583
1110
  */
2584
 
  THD *thd= table ? table->in_use : current_thd;
2585
 
  if (thd->count_cuted_fields)
 
1111
  Session *session= table ? table->in_use : current_session;
 
1112
  if (session->count_cuted_fields)
2586
1113
  {
2587
 
    thd->cuted_fields+= cuted_increment;
2588
 
    push_warning_printf(thd, level, code, ER(code), field_name,
2589
 
                        thd->row_count);
 
1114
    session->cuted_fields+= cuted_increment;
 
1115
    push_warning_printf(session, level, code, ER(code), field_name,
 
1116
                        session->row_count);
2590
1117
    return 0;
2591
1118
  }
2592
1119
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
2593
1120
}
2594
1121
 
2595
1122
 
2596
 
/**
2597
 
  Produce warning or note about datetime string data saved into field.
2598
 
 
2599
 
  @param level            level of message (Note/Warning/Error)
2600
 
  @param code             error code of message to be produced
2601
 
  @param str              string value which we tried to save
2602
 
  @param str_length       length of string which we tried to save
2603
 
  @param ts_type          type of datetime value (datetime/date/time)
2604
 
  @param cuted_increment  whenever we should increase cut fields count or not
2605
 
 
2606
 
  @note
2607
 
    This function will always produce some warning but won't increase cut
2608
 
    fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
2609
 
    thread.
2610
 
*/
2611
 
 
2612
 
void 
2613
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
2614
 
                            unsigned int code, 
2615
 
                            const char *str, uint str_length, 
2616
 
                            timestamp_type ts_type, int cuted_increment)
 
1123
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
 
1124
                                 unsigned int code,
 
1125
                                 const char *str, 
 
1126
                                 uint32_t str_length,
 
1127
                                 enum enum_drizzle_timestamp_type ts_type, 
 
1128
                                 int cuted_increment)
2617
1129
{
2618
 
  THD *thd= table ? table->in_use : current_thd;
2619
 
  if ((thd->really_abort_on_warning() &&
 
1130
  Session *session= table ? table->in_use : current_session;
 
1131
  if ((session->really_abort_on_warning() &&
2620
1132
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
2621
1133
      set_warning(level, code, cuted_increment))
2622
 
    make_truncated_value_warning(thd, level, str, str_length, ts_type,
 
1134
    make_truncated_value_warning(session, level, str, str_length, ts_type,
2623
1135
                                 field_name);
2624
1136
}
2625
1137
 
2626
 
 
2627
 
/**
2628
 
  Produce warning or note about integer datetime value saved into field.
2629
 
 
2630
 
  @param level            level of message (Note/Warning/Error)
2631
 
  @param code             error code of message to be produced
2632
 
  @param nr               numeric value which we tried to save
2633
 
  @param ts_type          type of datetime value (datetime/date/time)
2634
 
  @param cuted_increment  whenever we should increase cut fields count or not
2635
 
 
2636
 
  @note
2637
 
    This function will always produce some warning but won't increase cut
2638
 
    fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
2639
 
    thread.
2640
 
*/
2641
 
 
2642
 
void 
2643
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint code, 
2644
 
                            int64_t nr, timestamp_type ts_type,
2645
 
                            int cuted_increment)
 
1138
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
 
1139
                                 uint32_t code,
 
1140
                                 int64_t nr, 
 
1141
                                 enum enum_drizzle_timestamp_type ts_type,
 
1142
                                 int cuted_increment)
2646
1143
{
2647
 
  THD *thd= table ? table->in_use : current_thd;
2648
 
  if (thd->really_abort_on_warning() ||
 
1144
  Session *session= table ? table->in_use : current_session;
 
1145
  if (session->really_abort_on_warning() ||
2649
1146
      set_warning(level, code, cuted_increment))
2650
1147
  {
2651
1148
    char str_nr[22];
2652
1149
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
2653
 
    make_truncated_value_warning(thd, level, str_nr, (uint) (str_end - str_nr), 
 
1150
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
2654
1151
                                 ts_type, field_name);
2655
1152
  }
2656
1153
}
2657
1154
 
2658
 
 
2659
 
/**
2660
 
  Produce warning or note about double datetime data saved into field.
2661
 
 
2662
 
  @param level            level of message (Note/Warning/Error)
2663
 
  @param code             error code of message to be produced
2664
 
  @param nr               double value which we tried to save
2665
 
  @param ts_type          type of datetime value (datetime/date/time)
2666
 
 
2667
 
  @note
2668
 
    This function will always produce some warning but won't increase cut
2669
 
    fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
2670
 
    thread.
2671
 
*/
2672
 
 
2673
 
void 
2674
 
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint code, 
2675
 
                            double nr, timestamp_type ts_type)
 
1155
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
 
1156
                                 const uint32_t code,
 
1157
                                 double nr, 
 
1158
                                 enum enum_drizzle_timestamp_type ts_type)
2676
1159
{
2677
 
  THD *thd= table ? table->in_use : current_thd;
2678
 
  if (thd->really_abort_on_warning() ||
 
1160
  Session *session= table ? table->in_use : current_session;
 
1161
  if (session->really_abort_on_warning() ||
2679
1162
      set_warning(level, code, 1))
2680
1163
  {
2681
1164
    /* DBL_DIG is enough to print '-[digits].E+###' */
2682
1165
    char str_nr[DBL_DIG + 8];
2683
 
    uint str_len= sprintf(str_nr, "%g", nr);
2684
 
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
 
1166
    uint32_t str_len= sprintf(str_nr, "%g", nr);
 
1167
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
2685
1168
                                 field_name);
2686
1169
  }
2687
1170
}
 
1171
 
 
1172
bool Field::isReadSet() 
 
1173
 
1174
  return table->isReadSet(field_index); 
 
1175
}
 
1176
 
 
1177
bool Field::isWriteSet()
 
1178
 
1179
  return table->isWriteSet(field_index); 
 
1180
}
 
1181
 
 
1182
void Field::setReadSet(bool arg)
 
1183
{
 
1184
  if (arg)
 
1185
    table->setReadSet(field_index);
 
1186
  else
 
1187
    table->clearReadSet(field_index);
 
1188
}
 
1189
 
 
1190
void Field::setWriteSet(bool arg)
 
1191
{
 
1192
  if (arg)
 
1193
    table->setWriteSet(field_index);
 
1194
  else
 
1195
    table->clearWriteSet(field_index);
 
1196
}