~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2008-10-11 21:01:52 UTC
  • Revision ID: brian@tangent.org-20081011210152-8ipnqumvhtt1zcmj
Added back more tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 */
 
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
 
20
16
 
21
17
/**
22
 
 * @file This file implements the Field class and API
23
 
 */
 
18
  @file
24
19
 
25
 
#include "config.h"
26
 
#include <cstdio>
 
20
  @brief
 
21
  This file implements classes defined in field.h
 
22
*/
 
23
#include <drizzled/server_includes.h>
 
24
#include "sql_select.h"
27
25
#include <errno.h>
28
 
#include <float.h>
29
 
#include "drizzled/sql_select.h"
30
 
#include "drizzled/error.h"
31
 
#include "drizzled/field/str.h"
32
 
#include "drizzled/field/num.h"
33
 
#include "drizzled/field/blob.h"
34
 
#include "drizzled/field/enum.h"
35
 
#include "drizzled/field/null.h"
36
 
#include "drizzled/field/date.h"
37
 
#include "drizzled/field/decimal.h"
38
 
#include "drizzled/field/real.h"
39
 
#include "drizzled/field/double.h"
40
 
#include "drizzled/field/int32.h"
41
 
#include "drizzled/field/int64.h"
42
 
#include "drizzled/field/num.h"
43
 
#include "drizzled/field/timestamp.h"
44
 
#include "drizzled/field/datetime.h"
45
 
#include "drizzled/field/varstring.h"
46
 
#include "drizzled/field/uuid.h"
47
 
#include "drizzled/time_functions.h"
48
 
#include "drizzled/internal/m_string.h"
49
 
 
50
 
#include "drizzled/display.h"
51
 
 
52
 
namespace drizzled
53
 
{
 
26
#include <drizzled/drizzled_error_messages.h>
 
27
 
 
28
// Maximum allowed exponent value for converting string to decimal
 
29
#define MAX_EXPONENT 1024
54
30
 
55
31
/*****************************************************************************
56
32
  Instansiate templates and static variables
57
33
*****************************************************************************/
58
34
 
59
 
static enum_field_types
60
 
field_types_merge_rules [enum_field_types_size][enum_field_types_size]=
61
 
{
 
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_LONG
 
66
    DRIZZLE_TYPE_NEWDECIMAL,
 
67
  //DRIZZLE_TYPE_DOUBLE
 
68
    DRIZZLE_TYPE_DOUBLE,
 
69
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
70
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
 
71
  //DRIZZLE_TYPE_LONGLONG
 
72
    DRIZZLE_TYPE_NEWDECIMAL,
 
73
  //DRIZZLE_TYPE_TIME
 
74
    DRIZZLE_TYPE_VARCHAR,
 
75
  //DRIZZLE_TYPE_DATETIME
 
76
    DRIZZLE_TYPE_VARCHAR,
 
77
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
78
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
79
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
80
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
 
81
  //DRIZZLE_TYPE_BLOB
 
82
    DRIZZLE_TYPE_BLOB,
 
83
  },
 
84
  /* DRIZZLE_TYPE_TINY -> */
 
85
  {
 
86
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
87
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
 
88
  //DRIZZLE_TYPE_LONG
 
89
    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_TIME
 
97
    DRIZZLE_TYPE_VARCHAR,
 
98
  //DRIZZLE_TYPE_DATETIME
 
99
    DRIZZLE_TYPE_VARCHAR,
 
100
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
101
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
102
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
103
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
 
104
  //DRIZZLE_TYPE_BLOB
 
105
    DRIZZLE_TYPE_BLOB,
 
106
  },
62
107
  /* DRIZZLE_TYPE_LONG -> */
63
108
  {
64
 
    //DRIZZLE_TYPE_LONG
 
109
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
110
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONG,
 
111
  //DRIZZLE_TYPE_LONG
65
112
    DRIZZLE_TYPE_LONG,
66
 
    //DRIZZLE_TYPE_DOUBLE
 
113
  //DRIZZLE_TYPE_DOUBLE
67
114
    DRIZZLE_TYPE_DOUBLE,
68
 
    //DRIZZLE_TYPE_NULL
69
 
    DRIZZLE_TYPE_LONG,
70
 
    //DRIZZLE_TYPE_TIMESTAMP
71
 
    DRIZZLE_TYPE_VARCHAR,
72
 
    //DRIZZLE_TYPE_LONGLONG
 
115
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
116
    DRIZZLE_TYPE_LONG,         DRIZZLE_TYPE_VARCHAR,
 
117
  //DRIZZLE_TYPE_LONGLONG
73
118
    DRIZZLE_TYPE_LONGLONG,
74
 
    //DRIZZLE_TYPE_DATETIME
75
 
    DRIZZLE_TYPE_VARCHAR,
76
 
    //DRIZZLE_TYPE_DATE
77
 
    DRIZZLE_TYPE_VARCHAR,
78
 
    //DRIZZLE_TYPE_VARCHAR
79
 
    DRIZZLE_TYPE_VARCHAR,
80
 
    //DRIZZLE_TYPE_DECIMAL
81
 
    DRIZZLE_TYPE_DECIMAL,
82
 
    //DRIZZLE_TYPE_ENUM
83
 
    DRIZZLE_TYPE_VARCHAR,
84
 
    //DRIZZLE_TYPE_BLOB
 
119
  //DRIZZLE_TYPE_TIME
 
120
    DRIZZLE_TYPE_VARCHAR,
 
121
  //DRIZZLE_TYPE_DATETIME
 
122
    DRIZZLE_TYPE_VARCHAR,
 
123
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
124
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
125
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
126
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
 
127
  //DRIZZLE_TYPE_BLOB
85
128
    DRIZZLE_TYPE_BLOB,
86
 
    //DRIZZLE_TYPE_UUID
87
 
    DRIZZLE_TYPE_VARCHAR,
88
129
  },
89
130
  /* DRIZZLE_TYPE_DOUBLE -> */
90
131
  {
91
 
    //DRIZZLE_TYPE_LONG
92
 
    DRIZZLE_TYPE_DOUBLE,
93
 
    //DRIZZLE_TYPE_DOUBLE
94
 
    DRIZZLE_TYPE_DOUBLE,
95
 
    //DRIZZLE_TYPE_NULL
96
 
    DRIZZLE_TYPE_DOUBLE,
97
 
    //DRIZZLE_TYPE_TIMESTAMP
98
 
    DRIZZLE_TYPE_VARCHAR,
99
 
    //DRIZZLE_TYPE_LONGLONG
100
 
    DRIZZLE_TYPE_DOUBLE,
101
 
    //DRIZZLE_TYPE_DATETIME
102
 
    DRIZZLE_TYPE_VARCHAR,
103
 
    //DRIZZLE_TYPE_DATE
104
 
    DRIZZLE_TYPE_VARCHAR,
105
 
    //DRIZZLE_TYPE_VARCHAR
106
 
    DRIZZLE_TYPE_VARCHAR,
107
 
    //DRIZZLE_TYPE_DECIMAL
108
 
    DRIZZLE_TYPE_DOUBLE,
109
 
    //DRIZZLE_TYPE_ENUM
110
 
    DRIZZLE_TYPE_VARCHAR,
111
 
    //DRIZZLE_TYPE_BLOB
 
132
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
133
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_DOUBLE,
 
134
  //DRIZZLE_TYPE_LONG
 
135
    DRIZZLE_TYPE_DOUBLE,
 
136
  //DRIZZLE_TYPE_DOUBLE
 
137
    DRIZZLE_TYPE_DOUBLE,
 
138
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
139
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
 
140
  //DRIZZLE_TYPE_LONGLONG
 
141
    DRIZZLE_TYPE_DOUBLE,
 
142
  //DRIZZLE_TYPE_TIME
 
143
    DRIZZLE_TYPE_VARCHAR,
 
144
  //DRIZZLE_TYPE_DATETIME
 
145
    DRIZZLE_TYPE_VARCHAR,
 
146
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
147
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
148
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
149
    DRIZZLE_TYPE_DOUBLE,      DRIZZLE_TYPE_VARCHAR,
 
150
  //DRIZZLE_TYPE_BLOB
112
151
    DRIZZLE_TYPE_BLOB,
113
 
    //DRIZZLE_TYPE_UUID
114
 
    DRIZZLE_TYPE_VARCHAR,
115
152
  },
116
153
  /* DRIZZLE_TYPE_NULL -> */
117
154
  {
118
 
    //DRIZZLE_TYPE_LONG
 
155
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
156
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_TINY,
 
157
  //DRIZZLE_TYPE_LONG
119
158
    DRIZZLE_TYPE_LONG,
120
 
    //DRIZZLE_TYPE_DOUBLE
 
159
  //DRIZZLE_TYPE_DOUBLE
121
160
    DRIZZLE_TYPE_DOUBLE,
122
 
    //DRIZZLE_TYPE_NULL
123
 
    DRIZZLE_TYPE_NULL,
124
 
    //DRIZZLE_TYPE_TIMESTAMP
125
 
    DRIZZLE_TYPE_TIMESTAMP,
126
 
    //DRIZZLE_TYPE_LONGLONG
 
161
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
162
    DRIZZLE_TYPE_NULL,        DRIZZLE_TYPE_TIMESTAMP,
 
163
  //DRIZZLE_TYPE_LONGLONG
127
164
    DRIZZLE_TYPE_LONGLONG,
128
 
    //DRIZZLE_TYPE_DATETIME
 
165
  //DRIZZLE_TYPE_TIME
 
166
    DRIZZLE_TYPE_TIME,
 
167
  //DRIZZLE_TYPE_DATETIME
129
168
    DRIZZLE_TYPE_DATETIME,
130
 
    //DRIZZLE_TYPE_DATE
131
 
    DRIZZLE_TYPE_DATE,
132
 
    //DRIZZLE_TYPE_VARCHAR
133
 
    DRIZZLE_TYPE_VARCHAR,
134
 
    //DRIZZLE_TYPE_DECIMAL
135
 
    DRIZZLE_TYPE_DECIMAL,
136
 
    //DRIZZLE_TYPE_ENUM
137
 
    DRIZZLE_TYPE_ENUM,
138
 
    //DRIZZLE_TYPE_BLOB
 
169
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
170
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
 
171
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
172
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_ENUM,
 
173
  //DRIZZLE_TYPE_BLOB
139
174
    DRIZZLE_TYPE_BLOB,
140
 
    //DRIZZLE_TYPE_UUID
141
 
    DRIZZLE_TYPE_UUID,
142
175
  },
143
176
  /* DRIZZLE_TYPE_TIMESTAMP -> */
144
177
  {
145
 
    //DRIZZLE_TYPE_LONG
146
 
    DRIZZLE_TYPE_VARCHAR,
147
 
    //DRIZZLE_TYPE_DOUBLE
148
 
    DRIZZLE_TYPE_VARCHAR,
149
 
    //DRIZZLE_TYPE_NULL
150
 
    DRIZZLE_TYPE_TIMESTAMP,
151
 
    //DRIZZLE_TYPE_TIMESTAMP
152
 
    DRIZZLE_TYPE_TIMESTAMP,
153
 
    //DRIZZLE_TYPE_LONGLONG
154
 
    DRIZZLE_TYPE_VARCHAR,
155
 
    //DRIZZLE_TYPE_DATETIME
156
 
    DRIZZLE_TYPE_DATETIME,
157
 
    //DRIZZLE_TYPE_DATE
158
 
    DRIZZLE_TYPE_DATE,
159
 
    //DRIZZLE_TYPE_VARCHAR
160
 
    DRIZZLE_TYPE_VARCHAR,
161
 
    //DRIZZLE_TYPE_DECIMAL
162
 
    DRIZZLE_TYPE_VARCHAR,
163
 
    //DRIZZLE_TYPE_ENUM
164
 
    DRIZZLE_TYPE_VARCHAR,
165
 
    //DRIZZLE_TYPE_BLOB
 
178
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
179
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
180
  //DRIZZLE_TYPE_LONG
 
181
    DRIZZLE_TYPE_VARCHAR,
 
182
  //DRIZZLE_TYPE_DOUBLE
 
183
    DRIZZLE_TYPE_VARCHAR,
 
184
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
185
    DRIZZLE_TYPE_TIMESTAMP,   DRIZZLE_TYPE_TIMESTAMP,
 
186
  //DRIZZLE_TYPE_LONGLONG
 
187
    DRIZZLE_TYPE_VARCHAR,
 
188
  //DRIZZLE_TYPE_TIME
 
189
    DRIZZLE_TYPE_DATETIME,
 
190
  //DRIZZLE_TYPE_DATETIME
 
191
    DRIZZLE_TYPE_DATETIME,
 
192
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
193
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
 
194
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
195
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
196
  //DRIZZLE_TYPE_BLOB
166
197
    DRIZZLE_TYPE_BLOB,
167
 
    //DRIZZLE_TYPE_UUID
168
 
    DRIZZLE_TYPE_VARCHAR,
169
198
  },
170
199
  /* DRIZZLE_TYPE_LONGLONG -> */
171
200
  {
172
 
    //DRIZZLE_TYPE_LONG
 
201
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
202
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_LONGLONG,
 
203
  //DRIZZLE_TYPE_LONG
173
204
    DRIZZLE_TYPE_LONGLONG,
174
 
    //DRIZZLE_TYPE_DOUBLE
 
205
  //DRIZZLE_TYPE_DOUBLE
175
206
    DRIZZLE_TYPE_DOUBLE,
176
 
    //DRIZZLE_TYPE_NULL
177
 
    DRIZZLE_TYPE_LONGLONG,
178
 
    //DRIZZLE_TYPE_TIMESTAMP
179
 
    DRIZZLE_TYPE_VARCHAR,
180
 
    //DRIZZLE_TYPE_LONGLONG
181
 
    DRIZZLE_TYPE_LONGLONG,
182
 
    //DRIZZLE_TYPE_DATETIME
183
 
    DRIZZLE_TYPE_VARCHAR,
184
 
    //DRIZZLE_TYPE_DATE
185
 
    DRIZZLE_TYPE_DATE,
186
 
    //DRIZZLE_TYPE_VARCHAR
187
 
    DRIZZLE_TYPE_VARCHAR,
188
 
    //DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_ENUM
189
 
    DRIZZLE_TYPE_DECIMAL,
190
 
    DRIZZLE_TYPE_VARCHAR,
191
 
    //DRIZZLE_TYPE_BLOB
192
 
    DRIZZLE_TYPE_BLOB,
193
 
    //DRIZZLE_TYPE_UUID
194
 
    DRIZZLE_TYPE_VARCHAR,
 
207
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
208
    DRIZZLE_TYPE_LONGLONG,    DRIZZLE_TYPE_VARCHAR,
 
209
  //DRIZZLE_TYPE_LONGLONG
 
210
    DRIZZLE_TYPE_LONGLONG,
 
211
  //DRIZZLE_TYPE_TIME
 
212
    DRIZZLE_TYPE_VARCHAR,
 
213
  //DRIZZLE_TYPE_DATETIME
 
214
    DRIZZLE_TYPE_VARCHAR,
 
215
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
216
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
 
217
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
218
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
 
219
  //DRIZZLE_TYPE_BLOB
 
220
    DRIZZLE_TYPE_BLOB,
 
221
  },
 
222
  /* DRIZZLE_TYPE_TIME -> */
 
223
  {
 
224
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
225
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
226
  //DRIZZLE_TYPE_LONG
 
227
    DRIZZLE_TYPE_VARCHAR,
 
228
  //DRIZZLE_TYPE_DOUBLE
 
229
    DRIZZLE_TYPE_VARCHAR,
 
230
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
231
    DRIZZLE_TYPE_TIME,        DRIZZLE_TYPE_DATETIME,
 
232
  //DRIZZLE_TYPE_LONGLONG
 
233
    DRIZZLE_TYPE_VARCHAR,
 
234
  //DRIZZLE_TYPE_TIME
 
235
    DRIZZLE_TYPE_TIME,
 
236
  //DRIZZLE_TYPE_DATETIME
 
237
    DRIZZLE_TYPE_DATETIME,
 
238
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
239
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
 
240
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
241
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
242
  //DRIZZLE_TYPE_BLOB
 
243
    DRIZZLE_TYPE_BLOB,
195
244
  },
196
245
  /* DRIZZLE_TYPE_DATETIME -> */
197
246
  {
198
 
    //DRIZZLE_TYPE_LONG
199
 
    DRIZZLE_TYPE_VARCHAR,
200
 
    //DRIZZLE_TYPE_DOUBLE
201
 
    DRIZZLE_TYPE_VARCHAR,
202
 
    //DRIZZLE_TYPE_NULL
203
 
    DRIZZLE_TYPE_DATETIME,
204
 
    //DRIZZLE_TYPE_TIMESTAMP
205
 
    DRIZZLE_TYPE_DATETIME,
206
 
    //DRIZZLE_TYPE_LONGLONG
207
 
    DRIZZLE_TYPE_VARCHAR,
208
 
    //DRIZZLE_TYPE_DATETIME
209
 
    DRIZZLE_TYPE_DATETIME,
210
 
    //DRIZZLE_TYPE_DATE
211
 
    DRIZZLE_TYPE_DATE,
212
 
    //DRIZZLE_TYPE_VARCHAR
213
 
    DRIZZLE_TYPE_VARCHAR,
214
 
    //DRIZZLE_TYPE_DECIMAL
215
 
    DRIZZLE_TYPE_VARCHAR,
216
 
    //DRIZZLE_TYPE_ENUM
217
 
    DRIZZLE_TYPE_VARCHAR,
218
 
    //DRIZZLE_TYPE_BLOB
 
247
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
248
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
249
  //DRIZZLE_TYPE_LONG
 
250
    DRIZZLE_TYPE_VARCHAR,
 
251
  //DRIZZLE_TYPE_DOUBLE
 
252
    DRIZZLE_TYPE_VARCHAR,
 
253
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
254
    DRIZZLE_TYPE_DATETIME,    DRIZZLE_TYPE_DATETIME,
 
255
  //DRIZZLE_TYPE_LONGLONG
 
256
    DRIZZLE_TYPE_VARCHAR,
 
257
  //DRIZZLE_TYPE_TIME
 
258
    DRIZZLE_TYPE_DATETIME,
 
259
  //DRIZZLE_TYPE_DATETIME
 
260
    DRIZZLE_TYPE_DATETIME,
 
261
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
262
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
 
263
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
264
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
265
  //DRIZZLE_TYPE_BLOB
219
266
    DRIZZLE_TYPE_BLOB,
220
 
    //DRIZZLE_TYPE_UUID
221
 
    DRIZZLE_TYPE_VARCHAR,
222
267
  },
223
 
  /* DRIZZLE_TYPE_DATE -> */
 
268
  /* DRIZZLE_TYPE_NEWDATE -> */
224
269
  {
225
 
    //DRIZZLE_TYPE_LONG
226
 
    DRIZZLE_TYPE_VARCHAR,
227
 
    //DRIZZLE_TYPE_DOUBLE
228
 
    DRIZZLE_TYPE_VARCHAR,
229
 
    //DRIZZLE_TYPE_NULL
230
 
    DRIZZLE_TYPE_DATE,
231
 
    //DRIZZLE_TYPE_TIMESTAMP
232
 
    DRIZZLE_TYPE_DATETIME,
233
 
    //DRIZZLE_TYPE_LONGLONG
234
 
    DRIZZLE_TYPE_VARCHAR,
235
 
    //DRIZZLE_TYPE_DATETIME
236
 
    DRIZZLE_TYPE_DATETIME,
237
 
    //DRIZZLE_TYPE_DATE
238
 
    DRIZZLE_TYPE_DATE,
239
 
    //DRIZZLE_TYPE_VARCHAR
240
 
    DRIZZLE_TYPE_VARCHAR,
241
 
    //DRIZZLE_TYPE_DECIMAL
242
 
    DRIZZLE_TYPE_VARCHAR,
243
 
    //DRIZZLE_TYPE_ENUM
244
 
    DRIZZLE_TYPE_VARCHAR,
245
 
    //DRIZZLE_TYPE_BLOB
 
270
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
271
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
272
  //DRIZZLE_TYPE_LONG
 
273
    DRIZZLE_TYPE_VARCHAR,
 
274
  //DRIZZLE_TYPE_DOUBLE
 
275
    DRIZZLE_TYPE_VARCHAR,
 
276
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
277
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_DATETIME,
 
278
  //DRIZZLE_TYPE_LONGLONG
 
279
    DRIZZLE_TYPE_VARCHAR,
 
280
  //DRIZZLE_TYPE_TIME
 
281
    DRIZZLE_TYPE_DATETIME,
 
282
  //DRIZZLE_TYPE_DATETIME
 
283
    DRIZZLE_TYPE_DATETIME,
 
284
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
285
    DRIZZLE_TYPE_NEWDATE,     DRIZZLE_TYPE_VARCHAR,
 
286
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
287
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
288
  //DRIZZLE_TYPE_BLOB
246
289
    DRIZZLE_TYPE_BLOB,
247
 
    //DRIZZLE_TYPE_UUID
248
 
    DRIZZLE_TYPE_VARCHAR,
249
290
  },
250
291
  /* DRIZZLE_TYPE_VARCHAR -> */
251
292
  {
252
 
    //DRIZZLE_TYPE_LONG
253
 
    DRIZZLE_TYPE_VARCHAR,
254
 
    //DRIZZLE_TYPE_DOUBLE
255
 
    DRIZZLE_TYPE_VARCHAR,
256
 
    //DRIZZLE_TYPE_NULL
257
 
    DRIZZLE_TYPE_VARCHAR,
258
 
    //DRIZZLE_TYPE_TIMESTAMP
259
 
    DRIZZLE_TYPE_VARCHAR,
260
 
    //DRIZZLE_TYPE_LONGLONG
261
 
    DRIZZLE_TYPE_VARCHAR,
262
 
    //DRIZZLE_TYPE_DATETIME
263
 
    DRIZZLE_TYPE_VARCHAR,
264
 
    //DRIZZLE_TYPE_DATE
265
 
    DRIZZLE_TYPE_VARCHAR,
266
 
    //DRIZZLE_TYPE_VARCHAR
267
 
    DRIZZLE_TYPE_VARCHAR,
268
 
    //DRIZZLE_TYPE_DECIMAL
269
 
    DRIZZLE_TYPE_VARCHAR,
270
 
    //DRIZZLE_TYPE_ENUM
271
 
    DRIZZLE_TYPE_VARCHAR,
272
 
    //DRIZZLE_TYPE_BLOB
 
293
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
294
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
295
  //DRIZZLE_TYPE_LONG
 
296
    DRIZZLE_TYPE_VARCHAR,
 
297
  //DRIZZLE_TYPE_DOUBLE
 
298
    DRIZZLE_TYPE_VARCHAR,
 
299
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
300
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
301
  //DRIZZLE_TYPE_LONGLONG
 
302
    DRIZZLE_TYPE_VARCHAR,
 
303
  //DRIZZLE_TYPE_TIME
 
304
    DRIZZLE_TYPE_VARCHAR,
 
305
  //DRIZZLE_TYPE_DATETIME
 
306
    DRIZZLE_TYPE_VARCHAR,
 
307
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
308
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
309
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
310
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
311
  //DRIZZLE_TYPE_BLOB
273
312
    DRIZZLE_TYPE_BLOB,
274
 
    //DRIZZLE_TYPE_UUID
275
 
    DRIZZLE_TYPE_VARCHAR,
276
313
  },
277
 
  /* DRIZZLE_TYPE_DECIMAL -> */
 
314
  /* DRIZZLE_TYPE_NEWDECIMAL -> */
278
315
  {
279
 
    //DRIZZLE_TYPE_LONG
280
 
    DRIZZLE_TYPE_DECIMAL,
281
 
    //DRIZZLE_TYPE_DOUBLE
 
316
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
317
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_NEWDECIMAL,
 
318
  //DRIZZLE_TYPE_LONG
 
319
    DRIZZLE_TYPE_NEWDECIMAL,
 
320
  //DRIZZLE_TYPE_DOUBLE
282
321
    DRIZZLE_TYPE_DOUBLE,
283
 
    //DRIZZLE_TYPE_NULL
284
 
    DRIZZLE_TYPE_DECIMAL,
285
 
    //DRIZZLE_TYPE_TIMESTAMP
286
 
    DRIZZLE_TYPE_VARCHAR,
287
 
    //DRIZZLE_TYPE_LONGLONG
288
 
    DRIZZLE_TYPE_DECIMAL,
289
 
    //DRIZZLE_TYPE_DATETIME
290
 
    DRIZZLE_TYPE_VARCHAR,
291
 
    //DRIZZLE_TYPE_DATE
292
 
    DRIZZLE_TYPE_VARCHAR,
293
 
    //DRIZZLE_TYPE_VARCHAR
294
 
    DRIZZLE_TYPE_VARCHAR,
295
 
    //DRIZZLE_TYPE_DECIMAL
296
 
    DRIZZLE_TYPE_DECIMAL,
297
 
    //DRIZZLE_TYPE_ENUM
298
 
    DRIZZLE_TYPE_VARCHAR,
299
 
    //DRIZZLE_TYPE_BLOB
 
322
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
323
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
 
324
  //DRIZZLE_TYPE_LONGLONG
 
325
    DRIZZLE_TYPE_NEWDECIMAL,
 
326
  //DRIZZLE_TYPE_TIME
 
327
    DRIZZLE_TYPE_VARCHAR,
 
328
  //DRIZZLE_TYPE_DATETIME
 
329
    DRIZZLE_TYPE_VARCHAR,
 
330
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
331
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
332
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
333
    DRIZZLE_TYPE_NEWDECIMAL,  DRIZZLE_TYPE_VARCHAR,
 
334
  //DRIZZLE_TYPE_BLOB
300
335
    DRIZZLE_TYPE_BLOB,
301
 
    //DRIZZLE_TYPE_UUID
302
 
    DRIZZLE_TYPE_VARCHAR,
303
336
  },
304
337
  /* DRIZZLE_TYPE_ENUM -> */
305
338
  {
306
 
    //DRIZZLE_TYPE_LONG
307
 
    DRIZZLE_TYPE_VARCHAR,
308
 
    //DRIZZLE_TYPE_DOUBLE
309
 
    DRIZZLE_TYPE_VARCHAR,
310
 
    //DRIZZLE_TYPE_NULL
311
 
    DRIZZLE_TYPE_ENUM,
312
 
    //DRIZZLE_TYPE_TIMESTAMP
313
 
    DRIZZLE_TYPE_VARCHAR,
314
 
    //DRIZZLE_TYPE_LONGLONG
315
 
    DRIZZLE_TYPE_VARCHAR,
316
 
    //DRIZZLE_TYPE_DATETIME
317
 
    DRIZZLE_TYPE_VARCHAR,
318
 
    //DRIZZLE_TYPE_DATE
319
 
    DRIZZLE_TYPE_VARCHAR,
320
 
    //DRIZZLE_TYPE_VARCHAR
321
 
    DRIZZLE_TYPE_VARCHAR,
322
 
    //DRIZZLE_TYPE_DECIMAL
323
 
    DRIZZLE_TYPE_VARCHAR,
324
 
    //DRIZZLE_TYPE_ENUM
325
 
    DRIZZLE_TYPE_VARCHAR,
326
 
    //DRIZZLE_TYPE_BLOB
 
339
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
340
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
341
  //DRIZZLE_TYPE_LONG
 
342
    DRIZZLE_TYPE_VARCHAR,
 
343
  //DRIZZLE_TYPE_DOUBLE
 
344
    DRIZZLE_TYPE_VARCHAR,
 
345
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
346
    DRIZZLE_TYPE_ENUM,        DRIZZLE_TYPE_VARCHAR,
 
347
  //DRIZZLE_TYPE_LONGLONG
 
348
    DRIZZLE_TYPE_VARCHAR,
 
349
  //DRIZZLE_TYPE_TIME
 
350
    DRIZZLE_TYPE_VARCHAR,
 
351
  //DRIZZLE_TYPE_DATETIME
 
352
    DRIZZLE_TYPE_VARCHAR,
 
353
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
354
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
355
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
356
    DRIZZLE_TYPE_VARCHAR,     DRIZZLE_TYPE_VARCHAR,
 
357
  //DRIZZLE_TYPE_BLOB
327
358
    DRIZZLE_TYPE_BLOB,
328
 
    //DRIZZLE_TYPE_UUID
329
 
    DRIZZLE_TYPE_VARCHAR,
330
 
   },
 
359
  },
331
360
  /* DRIZZLE_TYPE_BLOB -> */
332
361
  {
333
 
    //DRIZZLE_TYPE_LONG
334
 
    DRIZZLE_TYPE_BLOB,
335
 
    //DRIZZLE_TYPE_DOUBLE
336
 
    DRIZZLE_TYPE_BLOB,
337
 
    //DRIZZLE_TYPE_NULL
338
 
    DRIZZLE_TYPE_BLOB,
339
 
    //DRIZZLE_TYPE_TIMESTAMP
340
 
    DRIZZLE_TYPE_BLOB,
341
 
    //DRIZZLE_TYPE_LONGLONG
342
 
    DRIZZLE_TYPE_BLOB,
343
 
    //DRIZZLE_TYPE_DATETIME
344
 
    DRIZZLE_TYPE_BLOB,
345
 
    //DRIZZLE_TYPE_DATE
346
 
    DRIZZLE_TYPE_BLOB,
347
 
    //DRIZZLE_TYPE_VARCHAR
348
 
    DRIZZLE_TYPE_BLOB,
349
 
    //DRIZZLE_TYPE_DECIMAL
350
 
    DRIZZLE_TYPE_BLOB,
351
 
    //DRIZZLE_TYPE_ENUM
352
 
    DRIZZLE_TYPE_BLOB,
353
 
    //DRIZZLE_TYPE_BLOB
354
 
    DRIZZLE_TYPE_BLOB,
355
 
    //DRIZZLE_TYPE_UUID
356
 
    DRIZZLE_TYPE_VARCHAR,
357
 
  },
358
 
  /* DRIZZLE_TYPE_UUID -> */
359
 
  {
360
 
    //DRIZZLE_TYPE_LONG
361
 
    DRIZZLE_TYPE_VARCHAR,
362
 
    //DRIZZLE_TYPE_DOUBLE
363
 
    DRIZZLE_TYPE_VARCHAR,
364
 
    //DRIZZLE_TYPE_NULL
365
 
    DRIZZLE_TYPE_UUID,
366
 
    //DRIZZLE_TYPE_TIMESTAMP
367
 
    DRIZZLE_TYPE_VARCHAR,
368
 
    //DRIZZLE_TYPE_LONGLONG
369
 
    DRIZZLE_TYPE_VARCHAR,
370
 
    //DRIZZLE_TYPE_DATETIME
371
 
    DRIZZLE_TYPE_VARCHAR,
372
 
    //DRIZZLE_TYPE_DATE
373
 
    DRIZZLE_TYPE_VARCHAR,
374
 
    //DRIZZLE_TYPE_VARCHAR
375
 
    DRIZZLE_TYPE_VARCHAR,
376
 
    //DRIZZLE_TYPE_DECIMAL
377
 
    DRIZZLE_TYPE_VARCHAR,
378
 
    //DRIZZLE_TYPE_VARCHAR,
379
 
    DRIZZLE_TYPE_VARCHAR,
380
 
    //DRIZZLE_TYPE_BLOB
381
 
    DRIZZLE_TYPE_BLOB,
382
 
    //DRIZZLE_TYPE_UUID
383
 
    DRIZZLE_TYPE_UUID,
 
362
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
363
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
 
364
  //DRIZZLE_TYPE_LONG
 
365
    DRIZZLE_TYPE_BLOB,
 
366
  //DRIZZLE_TYPE_DOUBLE
 
367
    DRIZZLE_TYPE_BLOB,
 
368
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
369
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
 
370
  //DRIZZLE_TYPE_LONGLONG
 
371
    DRIZZLE_TYPE_BLOB,
 
372
  //DRIZZLE_TYPE_TIME
 
373
    DRIZZLE_TYPE_BLOB,
 
374
  //DRIZZLE_TYPE_DATETIME
 
375
    DRIZZLE_TYPE_BLOB,
 
376
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
377
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
 
378
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
379
    DRIZZLE_TYPE_BLOB,        DRIZZLE_TYPE_BLOB,
 
380
  //DRIZZLE_TYPE_BLOB
 
381
    DRIZZLE_TYPE_BLOB,
384
382
  },
385
383
};
386
384
 
387
 
static Item_result field_types_result_type [enum_field_types_size]=
388
 
{
 
385
/**
 
386
  Return type of which can carry value of both given types in UNION result.
 
387
 
 
388
  @param a  type for merging
 
389
  @param b  type for merging
 
390
 
 
391
  @return
 
392
    type of field
 
393
*/
 
394
 
 
395
enum_field_types Field::field_type_merge(enum_field_types a,
 
396
                                         enum_field_types b)
 
397
{
 
398
  assert(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
 
399
  assert(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
 
400
  return field_types_merge_rules[field_type2index(a)]
 
401
                                [field_type2index(b)];
 
402
}
 
403
 
 
404
 
 
405
static Item_result field_types_result_type [FIELDTYPE_NUM]=
 
406
{
 
407
  //DRIZZLE_TYPE_DECIMAL      DRIZZLE_TYPE_TINY
 
408
  DECIMAL_RESULT,           INT_RESULT,
389
409
  //DRIZZLE_TYPE_LONG
390
410
  INT_RESULT,
391
411
  //DRIZZLE_TYPE_DOUBLE
392
412
  REAL_RESULT,
393
 
  //DRIZZLE_TYPE_NULL
394
 
  STRING_RESULT,
395
 
  //DRIZZLE_TYPE_TIMESTAMP
396
 
  STRING_RESULT,
 
413
  //DRIZZLE_TYPE_NULL         DRIZZLE_TYPE_TIMESTAMP
 
414
  STRING_RESULT,            STRING_RESULT,
397
415
  //DRIZZLE_TYPE_LONGLONG
398
416
  INT_RESULT,
 
417
  //DRIZZLE_TYPE_TIME
 
418
  STRING_RESULT,
399
419
  //DRIZZLE_TYPE_DATETIME
400
420
  STRING_RESULT,
401
 
  //DRIZZLE_TYPE_DATE
402
 
  STRING_RESULT,
403
 
  //DRIZZLE_TYPE_VARCHAR
404
 
  STRING_RESULT,
405
 
  //DRIZZLE_TYPE_DECIMAL   
406
 
  DECIMAL_RESULT,           
407
 
  //DRIZZLE_TYPE_ENUM
408
 
  STRING_RESULT,
 
421
  //DRIZZLE_TYPE_NEWDATE      DRIZZLE_TYPE_VARCHAR
 
422
  STRING_RESULT,            STRING_RESULT,
 
423
  //DRIZZLE_TYPE_NEWDECIMAL   DRIZZLE_TYPE_ENUM
 
424
  DECIMAL_RESULT,           STRING_RESULT,
409
425
  //DRIZZLE_TYPE_BLOB
410
426
  STRING_RESULT,
411
 
  //DRIZZLE_TYPE_UUID
412
 
  STRING_RESULT,
413
427
};
414
428
 
415
 
bool test_if_important_data(const CHARSET_INFO * const cs, 
416
 
                            const char *str,
417
 
                            const char *strend)
 
429
 
 
430
/*
 
431
  Test if the given string contains important data:
 
432
  not spaces for character string,
 
433
  or any data for binary string.
 
434
 
 
435
  SYNOPSIS
 
436
    test_if_important_data()
 
437
    cs          Character set
 
438
    str         String to test
 
439
    strend      String end
 
440
 
 
441
  RETURN
 
442
    false - If string does not have important data
 
443
    true  - If string has some important data
 
444
*/
 
445
 
 
446
bool
 
447
test_if_important_data(const CHARSET_INFO * const cs, const char *str,
 
448
                       const char *strend)
418
449
{
419
450
  if (cs != &my_charset_bin)
420
451
    str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
421
452
  return (str < strend);
422
453
}
423
454
 
424
 
void *Field::operator new(size_t size)
425
 
{
426
 
  return memory::sql_alloc(size);
427
 
}
428
 
 
429
 
void *Field::operator new(size_t size, memory::Root *mem_root)
430
 
{
431
 
  return mem_root->alloc_root(static_cast<uint32_t>(size));
432
 
}
433
 
 
434
 
enum_field_types Field::field_type_merge(enum_field_types a,
435
 
                                         enum_field_types b)
436
 
{
437
 
  assert(a < enum_field_types_size);
438
 
  assert(b < enum_field_types_size);
439
 
  return field_types_merge_rules[a][b];
440
 
}
 
455
 
 
456
/**
 
457
  Detect Item_result by given field type of UNION merge result.
 
458
 
 
459
  @param field_type  given field type
 
460
 
 
461
  @return
 
462
    Item_result (type of internal MySQL expression result)
 
463
*/
441
464
 
442
465
Item_result Field::result_merge_type(enum_field_types field_type)
443
466
{
444
 
  assert(field_type < enum_field_types_size);
445
 
  return field_types_result_type[field_type];
446
 
}
447
 
 
448
 
bool Field::eq(Field *field)
449
 
{
450
 
  return (ptr == field->ptr && null_ptr == field->null_ptr &&
451
 
          null_bit == field->null_bit);
452
 
}
453
 
 
454
 
uint32_t Field::pack_length() const
455
 
{
456
 
  return field_length;
457
 
}
458
 
 
459
 
uint32_t Field::pack_length_in_rec() const
460
 
{
461
 
  return pack_length();
462
 
}
463
 
 
464
 
uint32_t Field::data_length()
465
 
{
466
 
  return pack_length();
467
 
}
468
 
 
469
 
uint32_t Field::used_length()
470
 
{
471
 
  return pack_length();
472
 
}
473
 
 
474
 
uint32_t Field::sort_length() const
475
 
{
476
 
  return pack_length();
477
 
}
478
 
 
479
 
uint32_t Field::max_data_length() const
480
 
{
481
 
  return pack_length();
482
 
}
483
 
 
484
 
int Field::reset(void)
485
 
{
486
 
  memset(ptr, 0, pack_length());
487
 
  return 0;
488
 
}
489
 
 
490
 
void Field::reset_fields()
491
 
{}
492
 
 
493
 
void Field::set_default()
494
 
{
495
 
  ptrdiff_t l_offset= (ptrdiff_t) (table->getDefaultValues() - table->getInsertRecord());
496
 
  memcpy(ptr, ptr + l_offset, pack_length());
497
 
  if (null_ptr)
498
 
    *null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
499
 
 
500
 
  if (this == table->next_number_field)
501
 
    table->auto_increment_field_not_null= false;
502
 
}
503
 
 
504
 
bool Field::binary() const
505
 
{
506
 
  return true;
507
 
}
508
 
 
509
 
bool Field::zero_pack() const
510
 
{
511
 
  return true;
512
 
}
513
 
 
514
 
enum ha_base_keytype Field::key_type() const
515
 
{
516
 
  return HA_KEYTYPE_BINARY;
517
 
}
518
 
 
519
 
uint32_t Field::key_length() const
520
 
{
521
 
  return pack_length();
522
 
}
523
 
 
524
 
enum_field_types Field::real_type() const
525
 
{
526
 
  return type();
527
 
}
528
 
 
529
 
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
530
 
{
531
 
  return cmp(a, b);
532
 
}
533
 
 
534
 
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
535
 
{
536
 
  return memcmp(a,b,pack_length());
537
 
}
538
 
 
539
 
int Field::cmp_offset(uint32_t row_offset)
540
 
{
541
 
  return cmp(ptr,ptr+row_offset);
542
 
}
543
 
 
544
 
int Field::cmp_binary_offset(uint32_t row_offset)
545
 
{
546
 
  return cmp_binary(ptr, ptr+row_offset);
547
 
}
548
 
 
549
 
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
550
 
{
551
 
  return cmp(a, b);
552
 
}
553
 
 
554
 
int Field::key_cmp(const unsigned char *str, uint32_t)
555
 
{
556
 
  return cmp(ptr,str);
557
 
}
558
 
 
559
 
uint32_t Field::decimals() const
560
 
{
561
 
  return 0;
562
 
}
563
 
 
564
 
bool Field::is_null(ptrdiff_t row_offset)
565
 
{
566
 
  return null_ptr ?
567
 
    (null_ptr[row_offset] & null_bit ? true : false) :
568
 
    table->null_row;
569
 
}
570
 
 
571
 
bool Field::is_real_null(ptrdiff_t row_offset)
572
 
{
573
 
  return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
574
 
}
575
 
 
576
 
bool Field::is_null_in_record(const unsigned char *record)
577
 
{
578
 
  if (! null_ptr)
579
 
    return false;
580
 
  return test(record[(uint32_t) (null_ptr -table->getInsertRecord())] & null_bit);
581
 
}
582
 
 
583
 
bool Field::is_null_in_record_with_offset(ptrdiff_t with_offset)
584
 
{
585
 
  if (! null_ptr)
586
 
    return false;
587
 
  return test(null_ptr[with_offset] & null_bit);
588
 
}
589
 
 
590
 
void Field::set_null(ptrdiff_t row_offset)
591
 
{
592
 
  if (null_ptr)
593
 
    null_ptr[row_offset]|= null_bit;
594
 
}
595
 
 
596
 
void Field::set_notnull(ptrdiff_t row_offset)
597
 
{
598
 
  if (null_ptr)
599
 
    null_ptr[row_offset]&= (unsigned char) ~null_bit;
600
 
}
601
 
 
602
 
bool Field::maybe_null(void)
603
 
{
604
 
  return null_ptr != 0 || table->maybe_null;
605
 
}
606
 
 
607
 
bool Field::real_maybe_null(void)
608
 
{
609
 
  return null_ptr != 0;
610
 
}
 
467
  assert(field_type < FIELDTYPE_TEAR_FROM || field_type
 
468
              > FIELDTYPE_TEAR_TO);
 
469
  return field_types_result_type[field_type2index(field_type)];
 
470
}
 
471
 
 
472
/*****************************************************************************
 
473
  Static help functions
 
474
*****************************************************************************/
 
475
 
 
476
 
 
477
/**
 
478
  Check whether a field type can be partially indexed by a key.
 
479
 
 
480
  This is a static method, rather than a virtual function, because we need
 
481
  to check the type of a non-Field in mysql_alter_table().
 
482
 
 
483
  @param type  field type
 
484
 
 
485
  @retval
 
486
    true  Type can have a prefixed key
 
487
  @retval
 
488
    false Type can not have a prefixed key
 
489
*/
611
490
 
612
491
bool Field::type_can_have_key_part(enum enum_field_types type)
613
492
{
620
499
  }
621
500
}
622
501
 
 
502
 
 
503
/**
 
504
  Process decimal library return codes and issue warnings for overflow and
 
505
  truncation.
 
506
 
 
507
  @param op_result  decimal library return code (E_DEC_* see include/decimal.h)
 
508
 
 
509
  @retval
 
510
    1  there was overflow
 
511
  @retval
 
512
    0  no error or some other errors except overflow
 
513
*/
 
514
 
623
515
int Field::warn_if_overflow(int op_result)
624
516
{
625
517
  if (op_result == E_DEC_OVERFLOW)
626
518
  {
627
519
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
628
 
    return E_DEC_OVERFLOW;
 
520
    return 1;
629
521
  }
630
522
  if (op_result == E_DEC_TRUNCATED)
631
523
  {
632
 
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
633
 
    return E_DEC_TRUNCATED;
 
524
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
 
525
    /* We return 0 here as this is not a critical issue */
634
526
  }
635
527
  return 0;
636
528
}
637
529
 
638
 
void Field::init(Table *table_arg)
639
 
{
640
 
  orig_table= table= table_arg;
641
 
}
 
530
 
 
531
#ifdef NOT_USED
 
532
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
 
533
{
 
534
  cs= system_charset_info; // QQ move test_if_real into CHARSET_INFO struct
 
535
 
 
536
  while (length && my_isspace(cs,*str))
 
537
  {                                             // Allow start space
 
538
    length--; str++;
 
539
  }
 
540
  if (!length)
 
541
    return 0;
 
542
  if (*str == '+' || *str == '-')
 
543
  {
 
544
    length--; str++;
 
545
    if (!length || !(my_isdigit(cs,*str) || *str == '.'))
 
546
      return 0;
 
547
  }
 
548
  while (length && my_isdigit(cs,*str))
 
549
  {
 
550
    length--; str++;
 
551
  }
 
552
  if (!length)
 
553
    return 1;
 
554
  if (*str == '.')
 
555
  {
 
556
    length--; str++;
 
557
    while (length && my_isdigit(cs,*str))
 
558
    {
 
559
      length--; str++;
 
560
    }
 
561
  }
 
562
  if (!length)
 
563
    return 1;
 
564
  if (*str == 'E' || *str == 'e')
 
565
  {
 
566
    if (length < 3 || (str[1] != '+' && str[1] != '-') || 
 
567
        !my_isdigit(cs,str[2]))
 
568
      return 0;
 
569
    length-=3;
 
570
    str+=3;
 
571
    while (length && my_isdigit(cs,*str))
 
572
    {
 
573
      length--; str++;
 
574
    }
 
575
  }
 
576
  for (; length ; length--, str++)
 
577
  {                                             // Allow end space
 
578
    if (!my_isspace(cs,*str))
 
579
      return 0;
 
580
  }
 
581
  return 1;
 
582
}
 
583
#endif
 
584
 
 
585
 
 
586
/**
 
587
  Interpret field value as an integer but return the result as a string.
 
588
 
 
589
  This is used for printing bit_fields as numbers while debugging.
 
590
*/
 
591
 
 
592
String *Field::val_int_as_str(String *val_buffer, bool unsigned_val)
 
593
{
 
594
  const CHARSET_INFO * const cs= &my_charset_bin;
 
595
  uint32_t length;
 
596
  int64_t value= val_int();
 
597
 
 
598
  if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
 
599
    return 0;
 
600
  length= (uint32_t) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
 
601
                                                MY_INT64_NUM_DECIMAL_DIGITS,
 
602
                                                unsigned_val ? 10 : -10,
 
603
                                                value);
 
604
  val_buffer->length(length);
 
605
  return val_buffer;
 
606
}
 
607
 
642
608
 
643
609
/// This is used as a table name when the table structure is not set up
644
 
Field::Field(unsigned char *ptr_arg,
645
 
             uint32_t length_arg,
646
 
             unsigned char *null_ptr_arg,
647
 
             unsigned char null_bit_arg,
648
 
             utype unireg_check_arg, 
649
 
             const char *field_name_arg)
650
 
  :
651
 
    ptr(ptr_arg),
652
 
    null_ptr(null_ptr_arg),
653
 
    table(NULL),
654
 
    orig_table(NULL),
655
 
    field_name(field_name_arg),
656
 
    key_start(0),
657
 
    part_of_key(0),
658
 
    part_of_key_not_clustered(0),
659
 
    part_of_sortkey(0),
660
 
    unireg_check(unireg_check_arg),
661
 
    field_length(length_arg),
662
 
    null_bit(null_bit_arg),
663
 
    is_created_from_null_item(false)
 
610
Field::Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
 
611
             unsigned char null_bit_arg,
 
612
             utype unireg_check_arg, const char *field_name_arg)
 
613
  :ptr(ptr_arg), null_ptr(null_ptr_arg),
 
614
   table(0), orig_table(0), table_name(0),
 
615
   field_name(field_name_arg),
 
616
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
 
617
   part_of_sortkey(0), unireg_check(unireg_check_arg),
 
618
   field_length(length_arg), null_bit(null_bit_arg), 
 
619
   is_created_from_null_item(false)
664
620
{
665
 
  flags= null_ptr ? 0: NOT_NULL_FLAG;
 
621
  flags=null_ptr ? 0: NOT_NULL_FLAG;
666
622
  comment.str= (char*) "";
667
 
  comment.length= 0;
 
623
  comment.length=0;
668
624
  field_index= 0;
669
625
}
670
626
 
 
627
 
671
628
void Field::hash(uint32_t *nr, uint32_t *nr2)
672
629
{
673
630
  if (is_null())
682
639
  }
683
640
}
684
641
 
 
642
size_t
 
643
Field::do_last_null_byte() const
 
644
{
 
645
  assert(null_ptr == NULL || null_ptr >= table->record[0]);
 
646
  if (null_ptr)
 
647
    return (size_t) (null_ptr - table->record[0]) + 1;
 
648
  return LAST_NULL_BYTE_UNDEF;
 
649
}
 
650
 
 
651
 
685
652
void Field::copy_from_tmp(int row_offset)
686
653
{
687
654
  memcpy(ptr,ptr+row_offset,pack_length());
688
655
  if (null_ptr)
689
656
  {
690
 
    *null_ptr= (unsigned char) ((null_ptr[0] &
691
 
                                 (unsigned char) ~(uint32_t) null_bit) |
692
 
                                (null_ptr[row_offset] &
693
 
                                 (unsigned char) null_bit));
 
657
    *null_ptr= (unsigned char) ((null_ptr[0] & (unsigned char) ~(uint32_t) null_bit) | (null_ptr[row_offset] & (unsigned char) null_bit));
694
658
  }
695
659
}
696
660
 
697
 
int Field::store_and_check(enum_check_fields check_level,
698
 
                           const char *to, 
699
 
                           uint32_t length,
700
 
                           const CHARSET_INFO * const cs)
701
 
 
 
661
 
 
662
bool Field::send_binary(Protocol *protocol)
 
663
{
 
664
  char buff[MAX_FIELD_WIDTH];
 
665
  String tmp(buff,sizeof(buff),charset());
 
666
  val_str(&tmp);
 
667
  return protocol->store(tmp.ptr(), tmp.length(), tmp.charset());
 
668
}
 
669
 
 
670
 
 
671
/**
 
672
   Check to see if field size is compatible with destination.
 
673
 
 
674
   This method is used in row-based replication to verify that the slave's
 
675
   field size is less than or equal to the master's field size. The 
 
676
   encoded field metadata (from the master or source) is decoded and compared
 
677
   to the size of this field (the slave or destination). 
 
678
 
 
679
   @param   field_metadata   Encoded size in field metadata
 
680
 
 
681
   @retval 0 if this field's size is < the source field's size
 
682
   @retval 1 if this field's size is >= the source field's size
 
683
*/
 
684
int Field::compatible_field_size(uint32_t field_metadata)
 
685
{
 
686
  uint32_t const source_size= pack_length_from_metadata(field_metadata);
 
687
  uint32_t const destination_size= row_pack_length();
 
688
  return (source_size <= destination_size);
 
689
}
 
690
 
 
691
 
 
692
int Field::store(const char *to, uint32_t length, const CHARSET_INFO * const cs,
 
693
                 enum_check_fields check_level)
702
694
{
703
695
  int res;
704
696
  enum_check_fields old_check_level= table->in_use->count_cuted_fields;
708
700
  return res;
709
701
}
710
702
 
711
 
unsigned char *Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length, bool)
 
703
 
 
704
/**
 
705
   Pack the field into a format suitable for storage and transfer.
 
706
 
 
707
   To implement packing functionality, only the virtual function
 
708
   should be overridden. The other functions are just convenience
 
709
   functions and hence should not be overridden.
 
710
 
 
711
   The value of <code>low_byte_first</code> is dependent on how the
 
712
   packed data is going to be used: for local use, e.g., temporary
 
713
   store on disk or in memory, use the native format since that is
 
714
   faster. For data that is going to be transfered to other machines
 
715
   (e.g., when writing data to the binary log), data should always be
 
716
   stored in little-endian format.
 
717
 
 
718
   @note The default method for packing fields just copy the raw bytes
 
719
   of the record into the destination, but never more than
 
720
   <code>max_length</code> characters.
 
721
 
 
722
   @param to
 
723
   Pointer to memory area where representation of field should be put.
 
724
 
 
725
   @param from
 
726
   Pointer to memory area where record representation of field is
 
727
   stored.
 
728
 
 
729
   @param max_length
 
730
   Maximum length of the field, as given in the column definition. For
 
731
   example, for <code>CHAR(1000)</code>, the <code>max_length</code>
 
732
   is 1000. This information is sometimes needed to decide how to pack
 
733
   the data.
 
734
 
 
735
   @param low_byte_first
 
736
   @c true if integers should be stored little-endian, @c false if
 
737
   native format should be used. Note that for little-endian machines,
 
738
   the value of this flag is a moot point since the native format is
 
739
   little-endian.
 
740
*/
 
741
unsigned char *
 
742
Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length,
 
743
            bool low_byte_first __attribute__((unused)))
712
744
{
713
745
  uint32_t length= pack_length();
714
746
  set_if_smaller(length, max_length);
716
748
  return to+length;
717
749
}
718
750
 
719
 
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
720
 
{
721
 
  unsigned char *result= this->pack(to, from, UINT32_MAX, table->getShare()->db_low_byte_first);
722
 
  return(result);
723
 
}
724
 
 
725
 
const unsigned char *Field::unpack(unsigned char* to,
726
 
                                   const unsigned char *from, 
727
 
                                   uint32_t param_data,
728
 
                                   bool)
 
751
/**
 
752
   Unpack a field from row data.
 
753
 
 
754
   This method is used to unpack a field from a master whose size of
 
755
   the field is less than that of the slave.
 
756
 
 
757
   The <code>param_data</code> parameter is a two-byte integer (stored
 
758
   in the least significant 16 bits of the unsigned integer) usually
 
759
   consisting of two parts: the real type in the most significant byte
 
760
   and a original pack length in the least significant byte.
 
761
 
 
762
   The exact layout of the <code>param_data</code> field is given by
 
763
   the <code>Table_map_log_event::save_field_metadata()</code>.
 
764
 
 
765
   This is the default method for unpacking a field. It just copies
 
766
   the memory block in byte order (of original pack length bytes or
 
767
   length of field, whichever is smaller).
 
768
 
 
769
   @param   to         Destination of the data
 
770
   @param   from       Source of the data
 
771
   @param   param_data Real type and original pack length of the field
 
772
                       data
 
773
 
 
774
   @param low_byte_first
 
775
   If this flag is @c true, all composite entities (e.g., lengths)
 
776
   should be unpacked in little-endian format; otherwise, the entities
 
777
   are unpacked in native order.
 
778
 
 
779
   @return  New pointer into memory based on from + length of the data
 
780
*/
 
781
const unsigned char *
 
782
Field::unpack(unsigned char* to, const unsigned char *from, uint32_t param_data,
 
783
              bool low_byte_first __attribute__((unused)))
729
784
{
730
785
  uint32_t length=pack_length();
731
786
  int from_type= 0;
751
806
            param_data : length;
752
807
 
753
808
  memcpy(to, from, param_data > length ? length : len);
754
 
  return (from + len);
755
 
}
756
 
 
757
 
const unsigned char *Field::unpack(unsigned char* to, const unsigned char *from)
758
 
{
759
 
  const unsigned char *result= unpack(to, from, 0U, table->getShare()->db_low_byte_first);
760
 
  return(result);
761
 
}
762
 
 
763
 
my_decimal *Field::val_decimal(my_decimal *)
 
809
  return from+len;
 
810
}
 
811
 
 
812
 
 
813
my_decimal *Field::val_decimal(my_decimal *decimal __attribute__((unused)))
764
814
{
765
815
  /* This never have to be called */
766
816
  assert(0);
768
818
}
769
819
 
770
820
 
771
 
void Field::make_field(SendField *field)
 
821
void Field::make_field(Send_field *field)
772
822
{
773
 
  if (orig_table && orig_table->getShare()->getSchemaName() && *orig_table->getShare()->getSchemaName())
 
823
  if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
774
824
  {
775
 
    field->db_name= orig_table->getShare()->getSchemaName();
776
 
    field->org_table_name= orig_table->getShare()->getTableName();
 
825
    field->db_name= orig_table->s->db.str;
 
826
    field->org_table_name= orig_table->s->table_name.str;
777
827
  }
778
828
  else
779
829
    field->org_table_name= field->db_name= "";
780
830
  if (orig_table)
781
831
  {
782
 
    field->table_name= orig_table->getAlias();
 
832
    field->table_name= orig_table->alias;
783
833
    field->org_col_name= field_name;
784
834
  }
785
835
  else
789
839
  }
790
840
  field->col_name= field_name;
791
841
  field->charsetnr= charset()->number;
792
 
  field->length= field_length;
793
 
  field->type= type();
794
 
  field->flags= table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
 
842
  field->length=field_length;
 
843
  field->type=type();
 
844
  field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
795
845
  field->decimals= 0;
796
846
}
797
847
 
798
 
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
 
848
 
 
849
/**
 
850
  Conversion from decimal to int64_t with checking overflow and
 
851
  setting correct value (min/max) in case of overflow.
 
852
 
 
853
  @param val             value which have to be converted
 
854
  @param unsigned_flag   type of integer in which we convert val
 
855
  @param err             variable to pass error code
 
856
 
 
857
  @return
 
858
    value converted from val
 
859
*/
 
860
int64_t Field::convert_decimal2int64_t(const my_decimal *val,
 
861
                                         bool unsigned_flag, int *err)
799
862
{
800
863
  int64_t i;
801
 
  if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
802
 
                                      ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
803
 
                                      val, false, &i)))
 
864
  if (unsigned_flag)
 
865
  {
 
866
    if (val->sign())
 
867
    {
 
868
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
869
      i= 0;
 
870
      *err= 1;
 
871
    }
 
872
    else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
873
                                           ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
 
874
                                           val, true, &i)))
 
875
    {
 
876
      i= ~(int64_t) 0;
 
877
      *err= 1;
 
878
    }
 
879
  }
 
880
  else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
 
881
                                         ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
 
882
                                         val, false, &i)))
804
883
  {
805
884
    i= (val->sign() ? INT64_MIN : INT64_MAX);
806
885
    *err= 1;
808
887
  return i;
809
888
}
810
889
 
811
 
uint32_t Field::fill_cache_field(CacheField *copy)
 
890
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
812
891
{
813
892
  uint32_t store_length;
814
893
  copy->str=ptr;
818
897
  {
819
898
    copy->blob_field=(Field_blob*) this;
820
899
    copy->strip=0;
821
 
    copy->length-= table->getShare()->blob_ptr_size;
 
900
    copy->length-= table->s->blob_ptr_size;
822
901
    return copy->length;
823
902
  }
824
903
  else
829
908
  return copy->length+ store_length;
830
909
}
831
910
 
 
911
 
832
912
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
833
913
{
834
914
  char buff[40];
835
915
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
836
 
  if (!(res=val_str_internal(&tmp)) || str_to_datetime_with_warn(res->ptr(), res->length(),
837
 
                                                                 ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
838
 
  {
 
916
  if (!(res=val_str(&tmp)) ||
 
917
      str_to_datetime_with_warn(res->ptr(), res->length(),
 
918
                                ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
839
919
    return 1;
840
 
  }
841
 
 
842
920
  return 0;
843
921
}
844
922
 
846
924
{
847
925
  char buff[40];
848
926
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
849
 
 
850
 
  if (!(res=val_str_internal(&tmp)) || str_to_time_with_warn(res->ptr(), res->length(), ltime))
851
 
  {
 
927
  if (!(res=val_str(&tmp)) ||
 
928
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
852
929
    return 1;
853
 
  }
854
 
 
855
930
  return 0;
856
931
}
857
932
 
858
 
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
 
933
/**
 
934
  This is called when storing a date in a string.
 
935
 
 
936
  @note
 
937
    Needs to be changed if/when we want to support different time formats.
 
938
*/
 
939
 
 
940
int Field::store_time(DRIZZLE_TIME *ltime,
 
941
                      enum enum_drizzle_timestamp_type type_arg __attribute__((unused)))
859
942
{
860
943
  char buff[MAX_DATE_STRING_REP_LENGTH];
861
944
  uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
862
945
  return store(buff, length, &my_charset_bin);
863
946
}
864
947
 
865
 
bool Field::optimize_range(uint32_t idx, uint32_t)
 
948
 
 
949
bool Field::optimize_range(uint32_t idx, uint32_t part)
866
950
{
867
 
  return test(table->index_flags(idx) & HA_READ_RANGE);
 
951
  return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
868
952
}
869
953
 
870
 
Field *Field::new_field(memory::Root *root, Table *new_table, bool)
 
954
 
 
955
Field *Field::new_field(MEM_ROOT *root, Table *new_table,
 
956
                        bool keep_type __attribute__((unused)))
871
957
{
872
958
  Field *tmp;
873
 
  if (!(tmp= (Field*) root->memdup_root((char*) this,size_of())))
 
959
  if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
874
960
    return 0;
875
961
 
876
962
  if (tmp->table->maybe_null)
877
963
    tmp->flags&= ~NOT_NULL_FLAG;
878
964
  tmp->table= new_table;
879
 
  tmp->key_start.reset();
880
 
  tmp->part_of_key.reset();
881
 
  tmp->part_of_sortkey.reset();
 
965
  tmp->key_start.init(0);
 
966
  tmp->part_of_key.init(0);
 
967
  tmp->part_of_sortkey.init(0);
882
968
  tmp->unireg_check= Field::NONE;
883
 
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG);
 
969
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
884
970
  tmp->reset_fields();
885
971
  return tmp;
886
972
}
887
973
 
888
 
Field *Field::new_key_field(memory::Root *root, Table *new_table,
889
 
                            unsigned char *new_ptr,
890
 
                            unsigned char *new_null_ptr,
 
974
 
 
975
Field *Field::new_key_field(MEM_ROOT *root, Table *new_table,
 
976
                            unsigned char *new_ptr, unsigned char *new_null_ptr,
891
977
                            uint32_t new_null_bit)
892
978
{
893
979
  Field *tmp;
894
980
  if ((tmp= new_field(root, new_table, table == new_table)))
895
981
  {
896
 
    tmp->ptr= new_ptr;
 
982
    tmp->ptr=      new_ptr;
897
983
    tmp->null_ptr= new_null_ptr;
898
984
    tmp->null_bit= new_null_bit;
899
985
  }
900
986
  return tmp;
901
987
}
902
988
 
903
 
Field *Field::clone(memory::Root *root, Table *new_table)
 
989
 
 
990
/* This is used to generate a field in Table from TABLE_SHARE */
 
991
 
 
992
Field *Field::clone(MEM_ROOT *root, Table *new_table)
904
993
{
905
994
  Field *tmp;
906
 
  if ((tmp= (Field*) root->memdup_root((char*) this,size_of())))
 
995
  if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
907
996
  {
908
997
    tmp->init(new_table);
909
 
    tmp->move_field_offset((ptrdiff_t) (new_table->getInsertRecord() -
910
 
                                           new_table->getDefaultValues()));
 
998
    tmp->move_field_offset((my_ptrdiff_t) (new_table->record[0] -
 
999
                                           new_table->s->default_values));
911
1000
  }
912
1001
  return tmp;
913
1002
}
914
1003
 
915
1004
 
916
 
uint32_t Field::is_equal(CreateField *new_field_ptr)
917
 
{
918
 
  return (new_field_ptr->sql_type == real_type());
919
 
}
 
1005
/****************************************************************************
 
1006
** tiny int
 
1007
****************************************************************************/
 
1008
 
 
1009
int Field_tiny::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
 
1010
{
 
1011
  int error;
 
1012
  int64_t rnd;
 
1013
  
 
1014
  error= get_int(cs, from, len, &rnd, 255, -128, 127);
 
1015
  ptr[0]= unsigned_flag ? (char) (uint64_t) rnd : (char) rnd;
 
1016
  return error;
 
1017
}
 
1018
 
 
1019
 
 
1020
int Field_tiny::store(double nr)
 
1021
{
 
1022
  int error= 0;
 
1023
  nr=rint(nr);
 
1024
  if (unsigned_flag)
 
1025
  {
 
1026
    if (nr < 0.0)
 
1027
    {
 
1028
      *ptr=0;
 
1029
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1030
      error= 1;
 
1031
    }
 
1032
    else if (nr > 255.0)
 
1033
    {
 
1034
      *ptr=(char) 255;
 
1035
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1036
      error= 1;
 
1037
    }
 
1038
    else
 
1039
      *ptr=(char) nr;
 
1040
  }
 
1041
  else
 
1042
  {
 
1043
    if (nr < -128.0)
 
1044
    {
 
1045
      *ptr= (char) -128;
 
1046
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1047
      error= 1;
 
1048
    }
 
1049
    else if (nr > 127.0)
 
1050
    {
 
1051
      *ptr=127;
 
1052
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1053
      error= 1;
 
1054
    }
 
1055
    else
 
1056
      *ptr=(char) (int) nr;
 
1057
  }
 
1058
  return error;
 
1059
}
 
1060
 
 
1061
 
 
1062
int Field_tiny::store(int64_t nr, bool unsigned_val)
 
1063
{
 
1064
  int error= 0;
 
1065
 
 
1066
  if (unsigned_flag)
 
1067
  {
 
1068
    if (nr < 0 && !unsigned_val)
 
1069
    {
 
1070
      *ptr= 0;
 
1071
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1072
      error= 1;
 
1073
    }
 
1074
    else if ((uint64_t) nr > (uint64_t) 255)
 
1075
    {
 
1076
      *ptr= (char) 255;
 
1077
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1078
      error= 1;
 
1079
    }
 
1080
    else
 
1081
      *ptr=(char) nr;
 
1082
  }
 
1083
  else
 
1084
  {
 
1085
    if (nr < 0 && unsigned_val)
 
1086
      nr= 256;                                    // Generate overflow
 
1087
    if (nr < -128)
 
1088
    {
 
1089
      *ptr= (char) -128;
 
1090
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1091
      error= 1;
 
1092
    }
 
1093
    else if (nr > 127)
 
1094
    {
 
1095
      *ptr=127;
 
1096
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
 
1097
      error= 1;
 
1098
    }
 
1099
    else
 
1100
      *ptr=(char) nr;
 
1101
  }
 
1102
  return error;
 
1103
}
 
1104
 
 
1105
 
 
1106
double Field_tiny::val_real(void)
 
1107
{
 
1108
  int tmp= unsigned_flag ? (int) ptr[0] :
 
1109
    (int) ((signed char*) ptr)[0];
 
1110
  return (double) tmp;
 
1111
}
 
1112
 
 
1113
 
 
1114
int64_t Field_tiny::val_int(void)
 
1115
{
 
1116
  int tmp= unsigned_flag ? (int) ptr[0] :
 
1117
    (int) ((signed char*) ptr)[0];
 
1118
  return (int64_t) tmp;
 
1119
}
 
1120
 
 
1121
 
 
1122
String *Field_tiny::val_str(String *val_buffer,
 
1123
                            String *val_ptr __attribute__((unused)))
 
1124
{
 
1125
  const CHARSET_INFO * const cs= &my_charset_bin;
 
1126
  uint32_t length;
 
1127
  uint32_t mlength=cmax(field_length+1,5*cs->mbmaxlen);
 
1128
  val_buffer->alloc(mlength);
 
1129
  char *to=(char*) val_buffer->ptr();
 
1130
 
 
1131
  if (unsigned_flag)
 
1132
    length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength, 10,
 
1133
                                           (long) *ptr);
 
1134
  else
 
1135
    length= (uint32_t) cs->cset->long10_to_str(cs,to,mlength,-10,
 
1136
                                           (long) *((signed char*) ptr));
 
1137
  
 
1138
  val_buffer->length(length);
 
1139
 
 
1140
  return val_buffer;
 
1141
}
 
1142
 
 
1143
bool Field_tiny::send_binary(Protocol *protocol)
 
1144
{
 
1145
  return protocol->store_tiny((int64_t) (int8_t) ptr[0]);
 
1146
}
 
1147
 
 
1148
int Field_tiny::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
 
1149
{
 
1150
  signed char a,b;
 
1151
  a=(signed char) a_ptr[0]; b= (signed char) b_ptr[0];
 
1152
  if (unsigned_flag)
 
1153
    return ((unsigned char) a < (unsigned char) b) ? -1 : ((unsigned char) a > (unsigned char) b) ? 1 : 0;
 
1154
  return (a < b) ? -1 : (a > b) ? 1 : 0;
 
1155
}
 
1156
 
 
1157
void Field_tiny::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
 
1158
{
 
1159
  if (unsigned_flag)
 
1160
    *to= *ptr;
 
1161
  else
 
1162
    to[0] = (char) (ptr[0] ^ (unsigned char) 128);      /* Revers signbit */
 
1163
}
 
1164
 
 
1165
void Field_tiny::sql_type(String &res) const
 
1166
{
 
1167
  const CHARSET_INFO * const cs=res.charset();
 
1168
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
 
1169
                          "tinyint(%d)",(int) field_length));
 
1170
  add_unsigned(res);
 
1171
}
 
1172
 
 
1173
/*
 
1174
  Report "not well formed" or "cannot convert" error
 
1175
  after storing a character string info a field.
 
1176
 
 
1177
  SYNOPSIS
 
1178
    check_string_copy_error()
 
1179
    field                    - Field
 
1180
    well_formed_error_pos    - where not well formed data was first met
 
1181
    cannot_convert_error_pos - where a not-convertable character was first met
 
1182
    end                      - end of the string
 
1183
    cs                       - character set of the string
 
1184
 
 
1185
  NOTES
 
1186
    As of version 5.0 both cases return the same error:
 
1187
 
 
1188
      "Invalid string value: 'xxx' for column 't' at row 1"
 
1189
 
 
1190
  Future versions will possibly introduce a new error message:
 
1191
 
 
1192
      "Cannot convert character string: 'xxx' for column 't' at row 1"
 
1193
 
 
1194
  RETURN
 
1195
    false - If errors didn't happen
 
1196
    true  - If an error happened
 
1197
*/
 
1198
 
 
1199
bool
 
1200
check_string_copy_error(Field_str *field,
 
1201
                        const char *well_formed_error_pos,
 
1202
                        const char *cannot_convert_error_pos,
 
1203
                        const char *end,
 
1204
                        const CHARSET_INFO * const cs)
 
1205
{
 
1206
  const char *pos, *end_orig;
 
1207
  char tmp[64], *t;
 
1208
  
 
1209
  if (!(pos= well_formed_error_pos) &&
 
1210
      !(pos= cannot_convert_error_pos))
 
1211
    return false;
 
1212
 
 
1213
  end_orig= end;
 
1214
  set_if_smaller(end, pos + 6);
 
1215
 
 
1216
  for (t= tmp; pos < end; pos++)
 
1217
  {
 
1218
    /*
 
1219
      If the source string is ASCII compatible (mbminlen==1)
 
1220
      and the source character is in ASCII printable range (0x20..0x7F),
 
1221
      then display the character as is.
 
1222
      
 
1223
      Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
 
1224
      or the source character is not in the printable range,
 
1225
      then print the character using HEX notation.
 
1226
    */
 
1227
    if (((unsigned char) *pos) >= 0x20 &&
 
1228
        ((unsigned char) *pos) <= 0x7F &&
 
1229
        cs->mbminlen == 1)
 
1230
    {
 
1231
      *t++= *pos;
 
1232
    }
 
1233
    else
 
1234
    {
 
1235
      *t++= '\\';
 
1236
      *t++= 'x';
 
1237
      *t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
 
1238
      *t++= _dig_vec_upper[((unsigned char) *pos) & 15];
 
1239
    }
 
1240
  }
 
1241
  if (end_orig > end)
 
1242
  {
 
1243
    *t++= '.';
 
1244
    *t++= '.';
 
1245
    *t++= '.';
 
1246
  }
 
1247
  *t= '\0';
 
1248
  push_warning_printf(field->table->in_use, 
 
1249
                      field->table->in_use->abort_on_warning ?
 
1250
                      DRIZZLE_ERROR::WARN_LEVEL_ERROR :
 
1251
                      DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1252
                      ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, 
 
1253
                      ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
 
1254
                      "string", tmp, field->field_name,
 
1255
                      (uint32_t) field->table->in_use->row_count);
 
1256
  return true;
 
1257
}
 
1258
 
 
1259
uint32_t Field::is_equal(Create_field *new_field)
 
1260
{
 
1261
  return (new_field->sql_type == real_type());
 
1262
}
 
1263
 
 
1264
/**
 
1265
  @retval
 
1266
    1  if the fields are equally defined
 
1267
  @retval
 
1268
    0  if the fields are unequally defined
 
1269
*/
920
1270
 
921
1271
bool Field::eq_def(Field *field)
922
1272
{
926
1276
  return 1;
927
1277
}
928
1278
 
 
1279
/**
 
1280
  @return
 
1281
  returns 1 if the fields are equally defined
 
1282
*/
929
1283
bool Field_enum::eq_def(Field *field)
930
1284
{
931
1285
  if (!Field::eq_def(field))
944
1298
  return 1;
945
1299
}
946
1300
 
 
1301
/*****************************************************************************
 
1302
  Handling of field and Create_field
 
1303
*****************************************************************************/
 
1304
 
 
1305
/**
 
1306
  Convert create_field::length from number of characters to number of bytes.
 
1307
*/
 
1308
 
 
1309
void Create_field::create_length_to_internal_length(void)
 
1310
{
 
1311
  switch (sql_type) {
 
1312
  case DRIZZLE_TYPE_BLOB:
 
1313
  case DRIZZLE_TYPE_VARCHAR:
 
1314
    length*= charset->mbmaxlen;
 
1315
    key_length= length;
 
1316
    pack_length= calc_pack_length(sql_type, length);
 
1317
    break;
 
1318
  case DRIZZLE_TYPE_ENUM:
 
1319
    /* Pack_length already calculated in sql_parse.cc */
 
1320
    length*= charset->mbmaxlen;
 
1321
    key_length= pack_length;
 
1322
    break;
 
1323
  case DRIZZLE_TYPE_NEWDECIMAL:
 
1324
    key_length= pack_length=
 
1325
      my_decimal_get_binary_size(my_decimal_length_to_precision(length,
 
1326
                                                                decimals,
 
1327
                                                                flags &
 
1328
                                                                UNSIGNED_FLAG),
 
1329
                                 decimals);
 
1330
    break;
 
1331
  default:
 
1332
    key_length= pack_length= calc_pack_length(sql_type, length);
 
1333
    break;
 
1334
  }
 
1335
}
 
1336
 
 
1337
 
 
1338
/**
 
1339
  Init for a tmp table field. To be extended if need be.
 
1340
*/
 
1341
void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
 
1342
                                      uint32_t length_arg, uint32_t decimals_arg,
 
1343
                                      bool maybe_null, bool is_unsigned)
 
1344
{
 
1345
  field_name= "";
 
1346
  sql_type= sql_type_arg;
 
1347
  char_length= length= length_arg;;
 
1348
  unireg_check= Field::NONE;
 
1349
  interval= 0;
 
1350
  charset= &my_charset_bin;
 
1351
  pack_flag= (FIELDFLAG_NUMBER |
 
1352
              ((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
 
1353
              (maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
 
1354
              (is_unsigned ? 0 : FIELDFLAG_DECIMAL));
 
1355
}
 
1356
 
 
1357
 
 
1358
/**
 
1359
  Initialize field definition for create.
 
1360
 
 
1361
  @param thd                   Thread handle
 
1362
  @param fld_name              Field name
 
1363
  @param fld_type              Field type
 
1364
  @param fld_length            Field length
 
1365
  @param fld_decimals          Decimal (if any)
 
1366
  @param fld_type_modifier     Additional type information
 
1367
  @param fld_default_value     Field default value (if any)
 
1368
  @param fld_on_update_value   The value of ON UPDATE clause
 
1369
  @param fld_comment           Field comment
 
1370
  @param fld_change            Field change
 
1371
  @param fld_interval_list     Interval list (if any)
 
1372
  @param fld_charset           Field charset
 
1373
 
 
1374
  @retval
 
1375
    false on success
 
1376
  @retval
 
1377
    true  on error
 
1378
*/
 
1379
 
 
1380
bool Create_field::init(THD *thd __attribute__((unused)), char *fld_name, enum_field_types fld_type,
 
1381
                        char *fld_length, char *fld_decimals,
 
1382
                        uint32_t fld_type_modifier, Item *fld_default_value,
 
1383
                        Item *fld_on_update_value, LEX_STRING *fld_comment,
 
1384
                        char *fld_change, List<String> *fld_interval_list,
 
1385
                        const CHARSET_INFO * const fld_charset,
 
1386
                        uint32_t fld_geom_type __attribute__((unused)),
 
1387
                        enum column_format_type column_format)
 
1388
{
 
1389
  uint32_t sign_len, allowed_type_modifier= 0;
 
1390
  uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
 
1391
 
 
1392
  field= 0;
 
1393
  field_name= fld_name;
 
1394
  def= fld_default_value;
 
1395
  flags= fld_type_modifier;
 
1396
  flags|= (((uint32_t)column_format & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
 
1397
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
 
1398
                 Field::NEXT_NUMBER : Field::NONE);
 
1399
  decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
 
1400
  if (decimals >= NOT_FIXED_DEC)
 
1401
  {
 
1402
    my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
 
1403
             NOT_FIXED_DEC-1);
 
1404
    return(true);
 
1405
  }
 
1406
 
 
1407
  sql_type= fld_type;
 
1408
  length= 0;
 
1409
  change= fld_change;
 
1410
  interval= 0;
 
1411
  pack_length= key_length= 0;
 
1412
  charset= fld_charset;
 
1413
  interval_list.empty();
 
1414
 
 
1415
  comment= *fld_comment;
 
1416
  /*
 
1417
    Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
 
1418
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
 
1419
  */
 
1420
  if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
 
1421
      (fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
 
1422
    flags|= NO_DEFAULT_VALUE_FLAG;
 
1423
 
 
1424
  if (fld_length && !(length= (uint32_t) atoi(fld_length)))
 
1425
    fld_length= 0; /* purecov: inspected */
 
1426
  sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
 
1427
 
 
1428
  switch (fld_type) {
 
1429
  case DRIZZLE_TYPE_TINY:
 
1430
    if (!fld_length)
 
1431
      length= MAX_TINYINT_WIDTH+sign_len;
 
1432
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
 
1433
    break;
 
1434
  case DRIZZLE_TYPE_LONG:
 
1435
    if (!fld_length)
 
1436
      length= MAX_INT_WIDTH+sign_len;
 
1437
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
 
1438
    break;
 
1439
  case DRIZZLE_TYPE_LONGLONG:
 
1440
    if (!fld_length)
 
1441
      length= MAX_BIGINT_WIDTH;
 
1442
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
 
1443
    break;
 
1444
  case DRIZZLE_TYPE_NULL:
 
1445
    break;
 
1446
  case DRIZZLE_TYPE_NEWDECIMAL:
 
1447
    my_decimal_trim(&length, &decimals);
 
1448
    if (length > DECIMAL_MAX_PRECISION)
 
1449
    {
 
1450
      my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
 
1451
               DECIMAL_MAX_PRECISION);
 
1452
      return(true);
 
1453
    }
 
1454
    if (length < decimals)
 
1455
    {
 
1456
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
 
1457
      return(true);
 
1458
    }
 
1459
    length=
 
1460
      my_decimal_precision_to_length(length, decimals,
 
1461
                                     fld_type_modifier & UNSIGNED_FLAG);
 
1462
    pack_length=
 
1463
      my_decimal_get_binary_size(length, decimals);
 
1464
    break;
 
1465
  case DRIZZLE_TYPE_VARCHAR:
 
1466
    /*
 
1467
      Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table
 
1468
      if they don't have a default value
 
1469
    */
 
1470
    max_field_charlength= MAX_FIELD_VARCHARLENGTH;
 
1471
    break;
 
1472
  case DRIZZLE_TYPE_BLOB:
 
1473
    if (fld_default_value)
 
1474
    {
 
1475
      /* Allow empty as default value. */
 
1476
      String str,*res;
 
1477
      res= fld_default_value->val_str(&str);
 
1478
    }
 
1479
    flags|= BLOB_FLAG;
 
1480
    break;
 
1481
  case DRIZZLE_TYPE_DOUBLE:
 
1482
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
 
1483
    if (!fld_length && !fld_decimals)
 
1484
    {
 
1485
      length= DBL_DIG+7;
 
1486
      decimals= NOT_FIXED_DEC;
 
1487
    }
 
1488
    if (length < decimals &&
 
1489
        decimals != NOT_FIXED_DEC)
 
1490
    {
 
1491
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
 
1492
      return(true);
 
1493
    }
 
1494
    break;
 
1495
  case DRIZZLE_TYPE_TIMESTAMP:
 
1496
    if (!fld_length)
 
1497
    {
 
1498
      /* Compressed date YYYYMMDDHHMMSS */
 
1499
      length= MAX_DATETIME_COMPRESSED_WIDTH;
 
1500
    }
 
1501
    else if (length != MAX_DATETIME_WIDTH)
 
1502
    {
 
1503
      /*
 
1504
        We support only even TIMESTAMP lengths less or equal than 14
 
1505
        and 19 as length of 4.1 compatible representation.
 
1506
      */
 
1507
      length= ((length+1)/2)*2; /* purecov: inspected */
 
1508
      length= cmin(length, (uint32_t)MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
 
1509
    }
 
1510
    flags|= UNSIGNED_FLAG;
 
1511
    if (fld_default_value)
 
1512
    {
 
1513
      /* Grammar allows only NOW() value for ON UPDATE clause */
 
1514
      if (fld_default_value->type() == Item::FUNC_ITEM && 
 
1515
          ((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
 
1516
      {
 
1517
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
 
1518
                                             Field::TIMESTAMP_DN_FIELD);
 
1519
        /*
 
1520
          We don't need default value any longer moreover it is dangerous.
 
1521
          Everything handled by unireg_check further.
 
1522
        */
 
1523
        def= 0;
 
1524
      }
 
1525
      else
 
1526
        unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
 
1527
                                             Field::NONE);
 
1528
    }
 
1529
    else
 
1530
    {
 
1531
      /*
 
1532
        If we have default TIMESTAMP NOT NULL column without explicit DEFAULT
 
1533
        or ON UPDATE values then for the sake of compatiblity we should treat
 
1534
        this column as having DEFAULT NOW() ON UPDATE NOW() (when we don't
 
1535
        have another TIMESTAMP column with auto-set option before this one)
 
1536
        or DEFAULT 0 (in other cases).
 
1537
        So here we are setting TIMESTAMP_OLD_FIELD only temporary, and will
 
1538
        replace this value by TIMESTAMP_DNUN_FIELD or NONE later when
 
1539
        information about all TIMESTAMP fields in table will be availiable.
 
1540
 
 
1541
        If we have TIMESTAMP NULL column without explicit DEFAULT value
 
1542
        we treat it as having DEFAULT NULL attribute.
 
1543
      */
 
1544
      unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD :
 
1545
                     (flags & NOT_NULL_FLAG ? Field::TIMESTAMP_OLD_FIELD :
 
1546
                                              Field::NONE));
 
1547
    }
 
1548
    break;
 
1549
  case DRIZZLE_TYPE_NEWDATE:
 
1550
    length= 10;
 
1551
    break;
 
1552
  case DRIZZLE_TYPE_TIME:
 
1553
    length= 10;
 
1554
    break;
 
1555
  case DRIZZLE_TYPE_DATETIME:
 
1556
    length= MAX_DATETIME_WIDTH;
 
1557
    break;
 
1558
  case DRIZZLE_TYPE_ENUM:
 
1559
    {
 
1560
      /* Should be safe. */
 
1561
      pack_length= get_enum_pack_length(fld_interval_list->elements);
 
1562
 
 
1563
      List_iterator<String> it(*fld_interval_list);
 
1564
      String *tmp;
 
1565
      while ((tmp= it++))
 
1566
        interval_list.push_back(tmp);
 
1567
      length= 1; /* See comment for DRIZZLE_TYPE_SET above. */
 
1568
      break;
 
1569
   }
 
1570
  }
 
1571
  /* Remember the value of length */
 
1572
  char_length= length;
 
1573
 
 
1574
  if (!(flags & BLOB_FLAG) &&
 
1575
      ((length > max_field_charlength &&
 
1576
        fld_type != DRIZZLE_TYPE_ENUM &&
 
1577
        (fld_type != DRIZZLE_TYPE_VARCHAR || fld_default_value)) ||
 
1578
       (!length && fld_type != DRIZZLE_TYPE_VARCHAR)))
 
1579
  {
 
1580
    my_error((fld_type == DRIZZLE_TYPE_VARCHAR) ?  ER_TOO_BIG_FIELDLENGTH : ER_TOO_BIG_DISPLAYWIDTH,
 
1581
              MYF(0),
 
1582
              fld_name, max_field_charlength); /* purecov: inspected */
 
1583
    return(true);
 
1584
  }
 
1585
  fld_type_modifier&= AUTO_INCREMENT_FLAG;
 
1586
  if ((~allowed_type_modifier) & fld_type_modifier)
 
1587
  {
 
1588
    my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
 
1589
    return(true);
 
1590
  }
 
1591
 
 
1592
  return(false); /* success */
 
1593
}
 
1594
 
 
1595
 
 
1596
enum_field_types get_blob_type_from_length(uint32_t length __attribute__((unused)))
 
1597
{
 
1598
  enum_field_types type;
 
1599
 
 
1600
  type= DRIZZLE_TYPE_BLOB;
 
1601
 
 
1602
  return type;
 
1603
}
 
1604
 
 
1605
 
 
1606
/*
 
1607
  Make a field from the .frm file info
 
1608
*/
 
1609
 
947
1610
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
948
1611
{
949
1612
  switch (type) {
950
 
  case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
951
 
  case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
952
 
  case DRIZZLE_TYPE_DATE:
953
 
  case DRIZZLE_TYPE_ENUM:
954
 
  case DRIZZLE_TYPE_LONG: return 4;
 
1613
  case DRIZZLE_TYPE_VARCHAR:     return (length + (length < 256 ? 1: 2));
 
1614
  case DRIZZLE_TYPE_TINY        : return 1;
 
1615
  case DRIZZLE_TYPE_NEWDATE:
 
1616
  case DRIZZLE_TYPE_TIME:   return 3;
 
1617
  case DRIZZLE_TYPE_TIMESTAMP:
 
1618
  case DRIZZLE_TYPE_LONG        : return 4;
955
1619
  case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
956
1620
  case DRIZZLE_TYPE_DATETIME:
957
 
  case DRIZZLE_TYPE_TIMESTAMP:
958
1621
  case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
959
 
  case DRIZZLE_TYPE_NULL: return 0;
960
 
  case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
961
 
  case DRIZZLE_TYPE_DECIMAL:
962
 
                          assert(0);
963
 
                          abort();
 
1622
  case DRIZZLE_TYPE_NULL        : return 0;
 
1623
  case DRIZZLE_TYPE_BLOB:               return 4+portable_sizeof_char_ptr;
 
1624
  case DRIZZLE_TYPE_ENUM:
 
1625
  case DRIZZLE_TYPE_NEWDECIMAL:
 
1626
    abort(); return 0;                          // This shouldn't happen
 
1627
  default:
 
1628
    return 0;
964
1629
  }
965
 
 
966
 
  assert(0);
967
 
  abort();
968
1630
}
969
1631
 
 
1632
 
970
1633
uint32_t pack_length_to_packflag(uint32_t type)
971
1634
{
972
1635
  switch (type) {
973
 
    case 1: return 1 << FIELDFLAG_PACK_SHIFT;
 
1636
    case 1: return f_settype((uint32_t) DRIZZLE_TYPE_TINY);
974
1637
    case 2: assert(1);
975
1638
    case 3: assert(1);
976
 
    case 4: return f_settype(DRIZZLE_TYPE_LONG);
977
 
    case 8: return f_settype(DRIZZLE_TYPE_LONGLONG);
 
1639
    case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
 
1640
    case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
978
1641
  }
979
1642
  return 0;                                     // This shouldn't happen
980
1643
}
981
1644
 
 
1645
 
 
1646
Field *make_field(TABLE_SHARE *share, unsigned char *ptr, uint32_t field_length,
 
1647
                  unsigned char *null_pos, unsigned char null_bit,
 
1648
                  uint32_t pack_flag,
 
1649
                  enum_field_types field_type,
 
1650
                  const CHARSET_INFO * field_charset,
 
1651
                  Field::utype unireg_check,
 
1652
                  TYPELIB *interval,
 
1653
                  const char *field_name)
 
1654
{
 
1655
  if (!f_maybe_null(pack_flag))
 
1656
  {
 
1657
    null_pos=0;
 
1658
    null_bit=0;
 
1659
  }
 
1660
  else
 
1661
  {
 
1662
    null_bit= ((unsigned char) 1) << null_bit;
 
1663
  }
 
1664
 
 
1665
  switch (field_type) {
 
1666
  case DRIZZLE_TYPE_NEWDATE:
 
1667
  case DRIZZLE_TYPE_TIME:
 
1668
  case DRIZZLE_TYPE_DATETIME:
 
1669
  case DRIZZLE_TYPE_TIMESTAMP:
 
1670
    field_charset= &my_charset_bin;
 
1671
  default: break;
 
1672
  }
 
1673
 
 
1674
  if (f_is_alpha(pack_flag))
 
1675
  {
 
1676
    if (!f_is_packed(pack_flag))
 
1677
    {
 
1678
      if (field_type == DRIZZLE_TYPE_VARCHAR)
 
1679
        return new Field_varstring(ptr,field_length,
 
1680
                                   HA_VARCHAR_PACKLENGTH(field_length),
 
1681
                                   null_pos,null_bit,
 
1682
                                   unireg_check, field_name,
 
1683
                                   share,
 
1684
                                   field_charset);
 
1685
      return 0;                                 // Error
 
1686
    }
 
1687
 
 
1688
    uint32_t pack_length=calc_pack_length((enum_field_types)
 
1689
                                      f_packtype(pack_flag),
 
1690
                                      field_length);
 
1691
 
 
1692
    if (f_is_blob(pack_flag))
 
1693
      return new Field_blob(ptr,null_pos,null_bit,
 
1694
                            unireg_check, field_name, share,
 
1695
                            pack_length, field_charset);
 
1696
    if (interval)
 
1697
    {
 
1698
      if (f_is_enum(pack_flag))
 
1699
        return new Field_enum(ptr,field_length,null_pos,null_bit,
 
1700
                                  unireg_check, field_name,
 
1701
                                  pack_length, interval, field_charset);
 
1702
    }
 
1703
  }
 
1704
 
 
1705
  switch (field_type) {
 
1706
  case DRIZZLE_TYPE_NEWDECIMAL:
 
1707
    return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
 
1708
                                 unireg_check, field_name,
 
1709
                                 f_decimals(pack_flag),
 
1710
                                 f_is_decimal_precision(pack_flag) != 0,
 
1711
                                 f_is_dec(pack_flag) == 0);
 
1712
  case DRIZZLE_TYPE_DOUBLE:
 
1713
    return new Field_double(ptr,field_length,null_pos,null_bit,
 
1714
                            unireg_check, field_name,
 
1715
                            f_decimals(pack_flag),
 
1716
                            false,
 
1717
                            f_is_dec(pack_flag)== 0);
 
1718
  case DRIZZLE_TYPE_TINY:
 
1719
    return new Field_tiny(ptr,field_length,null_pos,null_bit,
 
1720
                          unireg_check, field_name,
 
1721
                          false,
 
1722
                          f_is_dec(pack_flag) == 0);
 
1723
  case DRIZZLE_TYPE_LONG:
 
1724
    return new Field_long(ptr,field_length,null_pos,null_bit,
 
1725
                           unireg_check, field_name,
 
1726
                           false,
 
1727
                           f_is_dec(pack_flag) == 0);
 
1728
  case DRIZZLE_TYPE_LONGLONG:
 
1729
    return new Field_int64_t(ptr,field_length,null_pos,null_bit,
 
1730
                              unireg_check, field_name,
 
1731
                              false,
 
1732
                              f_is_dec(pack_flag) == 0);
 
1733
  case DRIZZLE_TYPE_TIMESTAMP:
 
1734
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,
 
1735
                               unireg_check, field_name, share,
 
1736
                               field_charset);
 
1737
  case DRIZZLE_TYPE_NEWDATE:
 
1738
    return new Field_newdate(ptr,null_pos,null_bit,
 
1739
                             unireg_check, field_name, field_charset);
 
1740
  case DRIZZLE_TYPE_TIME:
 
1741
    return new Field_time(ptr,null_pos,null_bit,
 
1742
                          unireg_check, field_name, field_charset);
 
1743
  case DRIZZLE_TYPE_DATETIME:
 
1744
    return new Field_datetime(ptr,null_pos,null_bit,
 
1745
                              unireg_check, field_name, field_charset);
 
1746
  case DRIZZLE_TYPE_NULL:
 
1747
    return new Field_null(ptr, field_length, unireg_check, field_name,
 
1748
                          field_charset);
 
1749
  default:                                      // Impossible (Wrong version)
 
1750
    break;
 
1751
  }
 
1752
  return 0;
 
1753
}
 
1754
 
 
1755
 
 
1756
/** Create a field suitable for create of table. */
 
1757
 
 
1758
Create_field::Create_field(Field *old_field,Field *orig_field)
 
1759
{
 
1760
  field=      old_field;
 
1761
  field_name=change=old_field->field_name;
 
1762
  length=     old_field->field_length;
 
1763
  flags=      old_field->flags;
 
1764
  unireg_check=old_field->unireg_check;
 
1765
  pack_length=old_field->pack_length();
 
1766
  key_length= old_field->key_length();
 
1767
  sql_type=   old_field->real_type();
 
1768
  charset=    old_field->charset();             // May be NULL ptr
 
1769
  comment=    old_field->comment;
 
1770
  decimals=   old_field->decimals();
 
1771
 
 
1772
  /* Fix if the original table had 4 byte pointer blobs */
 
1773
  if (flags & BLOB_FLAG)
 
1774
    pack_length= (pack_length- old_field->table->s->blob_ptr_size +
 
1775
                  portable_sizeof_char_ptr);
 
1776
 
 
1777
  switch (sql_type) {
 
1778
  case DRIZZLE_TYPE_BLOB:
 
1779
    sql_type= DRIZZLE_TYPE_BLOB;
 
1780
    length/= charset->mbmaxlen;
 
1781
    key_length/= charset->mbmaxlen;
 
1782
    break;
 
1783
    /* Change CHAR -> VARCHAR if dynamic record length */
 
1784
  case DRIZZLE_TYPE_ENUM:
 
1785
  case DRIZZLE_TYPE_VARCHAR:
 
1786
    /* This is corrected in create_length_to_internal_length */
 
1787
    length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
 
1788
    break;
 
1789
  default:
 
1790
    break;
 
1791
  }
 
1792
 
 
1793
  if (flags & (ENUM_FLAG | SET_FLAG))
 
1794
    interval= ((Field_enum*) old_field)->typelib;
 
1795
  else
 
1796
    interval=0;
 
1797
  def=0;
 
1798
  char_length= length;
 
1799
 
 
1800
  if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
 
1801
      old_field->ptr && orig_field &&
 
1802
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
 
1803
       old_field->table->timestamp_field != old_field ||  /* timestamp field */ 
 
1804
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
 
1805
  {
 
1806
    char buff[MAX_FIELD_WIDTH];
 
1807
    String tmp(buff,sizeof(buff), charset);
 
1808
    my_ptrdiff_t diff;
 
1809
 
 
1810
    /* Get the value from default_values */
 
1811
    diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
 
1812
                          orig_field->table->record[0]);
 
1813
    orig_field->move_field_offset(diff);        // Points now at default_values
 
1814
    if (!orig_field->is_real_null())
 
1815
    {
 
1816
      char buff[MAX_FIELD_WIDTH], *pos;
 
1817
      String tmp(buff, sizeof(buff), charset), *res;
 
1818
      res= orig_field->val_str(&tmp);
 
1819
      pos= (char*) sql_strmake(res->ptr(), res->length());
 
1820
      def= new Item_string(pos, res->length(), charset);
 
1821
    }
 
1822
    orig_field->move_field_offset(-diff);       // Back to record[0]
 
1823
  }
 
1824
}
 
1825
 
 
1826
 
982
1827
/*****************************************************************************
983
1828
 Warning handling
984
1829
*****************************************************************************/
985
1830
 
986
 
bool Field::set_warning(DRIZZLE_ERROR::enum_warning_level level,
987
 
                        uint32_t code,
988
 
                        int cuted_increment)
 
1831
/**
 
1832
  Produce warning or note about data saved into field.
 
1833
 
 
1834
  @param level            - level of message (Note/Warning/Error)
 
1835
  @param code             - error code of message to be produced
 
1836
  @param cuted_increment  - whenever we should increase cut fields count or not
 
1837
 
 
1838
  @note
 
1839
    This function won't produce warning and increase cut fields counter
 
1840
    if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
 
1841
 
 
1842
    if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
 
1843
    This allows us to avoid notes in optimisation, like convert_constant_item().
 
1844
 
 
1845
  @retval
 
1846
    1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
 
1847
  @retval
 
1848
    0 otherwise
 
1849
*/
 
1850
 
 
1851
bool 
 
1852
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
 
1853
                   int cuted_increment)
989
1854
{
990
1855
  /*
991
1856
    If this field was created only for type conversion purposes it
992
1857
    will have table == NULL.
993
1858
  */
994
 
  Session *session= table ? table->in_use : current_session;
995
 
  if (session->count_cuted_fields)
 
1859
  THD *thd= table ? table->in_use : current_thd;
 
1860
  if (thd->count_cuted_fields)
996
1861
  {
997
 
    session->cuted_fields+= cuted_increment;
998
 
    push_warning_printf(session, level, code, ER(code), field_name,
999
 
                        session->row_count);
 
1862
    thd->cuted_fields+= cuted_increment;
 
1863
    push_warning_printf(thd, level, code, ER(code), field_name,
 
1864
                        thd->row_count);
1000
1865
    return 0;
1001
1866
  }
1002
1867
  return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
1003
1868
}
1004
1869
 
1005
1870
 
1006
 
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1007
 
                                 unsigned int code,
1008
 
                                 const char *str, 
1009
 
                                 uint32_t str_length,
1010
 
                                 enum enum_drizzle_timestamp_type ts_type, 
1011
 
                                 int cuted_increment)
 
1871
/**
 
1872
  Produce warning or note about datetime string data saved into field.
 
1873
 
 
1874
  @param level            level of message (Note/Warning/Error)
 
1875
  @param code             error code of message to be produced
 
1876
  @param str              string value which we tried to save
 
1877
  @param str_length       length of string which we tried to save
 
1878
  @param ts_type          type of datetime value (datetime/date/time)
 
1879
  @param cuted_increment  whenever we should increase cut fields count or not
 
1880
 
 
1881
  @note
 
1882
    This function will always produce some warning but won't increase cut
 
1883
    fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
 
1884
    thread.
 
1885
*/
 
1886
 
 
1887
void 
 
1888
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
 
1889
                            unsigned int code, 
 
1890
                            const char *str, uint32_t str_length, 
 
1891
                            enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
1012
1892
{
1013
 
  Session *session= table ? table->in_use : current_session;
1014
 
  if ((session->really_abort_on_warning() &&
 
1893
  THD *thd= table ? table->in_use : current_thd;
 
1894
  if ((thd->really_abort_on_warning() &&
1015
1895
       level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
1016
1896
      set_warning(level, code, cuted_increment))
1017
 
    make_truncated_value_warning(session, level, str, str_length, ts_type,
 
1897
    make_truncated_value_warning(thd, level, str, str_length, ts_type,
1018
1898
                                 field_name);
1019
1899
}
1020
1900
 
1021
 
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, 
1022
 
                                 uint32_t code,
1023
 
                                 int64_t nr, 
1024
 
                                 enum enum_drizzle_timestamp_type ts_type,
1025
 
                                 int cuted_increment)
 
1901
 
 
1902
/**
 
1903
  Produce warning or note about integer datetime value saved into field.
 
1904
 
 
1905
  @param level            level of message (Note/Warning/Error)
 
1906
  @param code             error code of message to be produced
 
1907
  @param nr               numeric value which we tried to save
 
1908
  @param ts_type          type of datetime value (datetime/date/time)
 
1909
  @param cuted_increment  whenever we should increase cut fields count or not
 
1910
 
 
1911
  @note
 
1912
    This function will always produce some warning but won't increase cut
 
1913
    fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
 
1914
    thread.
 
1915
*/
 
1916
 
 
1917
void 
 
1918
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
1919
                            int64_t nr, enum enum_drizzle_timestamp_type ts_type,
 
1920
                            int cuted_increment)
1026
1921
{
1027
 
  Session *session= table ? table->in_use : current_session;
1028
 
  if (session->really_abort_on_warning() ||
 
1922
  THD *thd= table ? table->in_use : current_thd;
 
1923
  if (thd->really_abort_on_warning() ||
1029
1924
      set_warning(level, code, cuted_increment))
1030
1925
  {
1031
1926
    char str_nr[22];
1032
 
    char *str_end= internal::int64_t10_to_str(nr, str_nr, -10);
1033
 
    make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
 
1927
    char *str_end= int64_t10_to_str(nr, str_nr, -10);
 
1928
    make_truncated_value_warning(thd, level, str_nr, (uint32_t) (str_end - str_nr), 
1034
1929
                                 ts_type, field_name);
1035
1930
  }
1036
1931
}
1037
1932
 
1038
 
void Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
1039
 
                                 const uint32_t code,
1040
 
                                 double nr, 
1041
 
                                 enum enum_drizzle_timestamp_type ts_type)
 
1933
 
 
1934
/**
 
1935
  Produce warning or note about double datetime data saved into field.
 
1936
 
 
1937
  @param level            level of message (Note/Warning/Error)
 
1938
  @param code             error code of message to be produced
 
1939
  @param nr               double value which we tried to save
 
1940
  @param ts_type          type of datetime value (datetime/date/time)
 
1941
 
 
1942
  @note
 
1943
    This function will always produce some warning but won't increase cut
 
1944
    fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
 
1945
    thread.
 
1946
*/
 
1947
 
 
1948
void 
 
1949
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code, 
 
1950
                            double nr, enum enum_drizzle_timestamp_type ts_type)
1042
1951
{
1043
 
  Session *session= table ? table->in_use : current_session;
1044
 
  if (session->really_abort_on_warning() ||
 
1952
  THD *thd= table ? table->in_use : current_thd;
 
1953
  if (thd->really_abort_on_warning() ||
1045
1954
      set_warning(level, code, 1))
1046
1955
  {
1047
1956
    /* DBL_DIG is enough to print '-[digits].E+###' */
1048
1957
    char str_nr[DBL_DIG + 8];
1049
 
    uint32_t str_len= snprintf(str_nr, sizeof(str_nr), "%g", nr);
1050
 
    make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
 
1958
    uint32_t str_len= sprintf(str_nr, "%g", nr);
 
1959
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
1051
1960
                                 field_name);
1052
1961
  }
1053
1962
}
1054
 
 
1055
 
bool Field::isReadSet() 
1056
 
1057
 
  return table->isReadSet(field_index); 
1058
 
}
1059
 
 
1060
 
bool Field::isWriteSet()
1061
 
1062
 
  return table->isWriteSet(field_index); 
1063
 
}
1064
 
 
1065
 
void Field::setReadSet(bool arg)
1066
 
{
1067
 
  if (arg)
1068
 
    table->setReadSet(field_index);
1069
 
  else
1070
 
    table->clearReadSet(field_index);
1071
 
}
1072
 
 
1073
 
void Field::setWriteSet(bool arg)
1074
 
{
1075
 
  if (arg)
1076
 
    table->setWriteSet(field_index);
1077
 
  else
1078
 
    table->clearWriteSet(field_index);
1079
 
}
1080
 
 
1081
 
std::ostream& operator<<(std::ostream& output, const Field &field)
1082
 
{
1083
 
  output << "Field:(";
1084
 
  output <<  field.field_name;
1085
 
  output << ", ";
1086
 
  output << drizzled::display::type(field.real_type());
1087
 
  output << ")";
1088
 
 
1089
 
  return output;  // for multiple << operators.
1090
 
}
1091
 
 
1092
 
} /* namespace drizzled */