1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2003 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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
16 |
||
17 |
/**
|
|
18 |
@file
|
|
19 |
||
20 |
@brief
|
|
21 |
Functions to copy data to or from fields
|
|
22 |
||
23 |
This could be done with a single short function but opencoding this
|
|
24 |
gives much more speed.
|
|
25 |
*/
|
|
26 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
27 |
#include <config.h> |
2154.2.11
by Brian Aker
Further strip out includes. |
28 |
|
550
by Monty Taylor
Moved error.h into just the files that need it. |
29 |
#include <drizzled/error.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
30 |
#include <drizzled/table.h> |
31 |
#include <drizzled/session.h> |
|
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
32 |
#include <drizzled/current_session.h> |
1
by brian
clean slate |
33 |
|
2154.2.11
by Brian Aker
Further strip out includes. |
34 |
#include <drizzled/copy_field.h> |
584.5.1
by Monty Taylor
Removed field includes from field.h. |
35 |
#include <drizzled/field/blob.h> |
36 |
#include <drizzled/field/date.h> |
|
2154.2.11
by Brian Aker
Further strip out includes. |
37 |
#include <drizzled/field/datetime.h> |
670.1.1
by Monty Taylor
Renamed fdecimal.* to decimal.*. Let's see how many things we can break! |
38 |
#include <drizzled/field/decimal.h> |
584.5.1
by Monty Taylor
Removed field includes from field.h. |
39 |
#include <drizzled/field/double.h> |
2154.2.11
by Brian Aker
Further strip out includes. |
40 |
#include <drizzled/field/enum.h> |
41 |
#include <drizzled/field/epoch.h> |
|
2007
by Brian Aker
Refactor naming for integers. |
42 |
#include <drizzled/field/int32.h> |
43 |
#include <drizzled/field/int64.h> |
|
2154.2.11
by Brian Aker
Further strip out includes. |
44 |
#include <drizzled/field/null.h> |
45 |
#include <drizzled/field/num.h> |
|
46 |
#include <drizzled/field/num.h> |
|
47 |
#include <drizzled/field/real.h> |
|
48 |
#include <drizzled/field/str.h> |
|
584.5.1
by Monty Taylor
Removed field includes from field.h. |
49 |
#include <drizzled/field/varstring.h> |
2239.1.9
by Olaf van der Spek
Refactor includes |
50 |
#include <drizzled/util/test.h> |
2241.3.2
by Olaf van der Spek
Refactor Session::variables |
51 |
#include <drizzled/system_variables.h> |
584.5.1
by Monty Taylor
Removed field includes from field.h. |
52 |
|
2239.1.9
by Olaf van der Spek
Refactor includes |
53 |
namespace drizzled { |
584.5.1
by Monty Taylor
Removed field includes from field.h. |
54 |
|
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
55 |
static void do_field_eq(CopyField *copy) |
1
by brian
clean slate |
56 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
57 |
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length); |
1
by brian
clean slate |
58 |
}
|
59 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
60 |
static void do_field_1(CopyField *copy) |
1
by brian
clean slate |
61 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
62 |
copy->to_ptr[0]= copy->from_ptr[0]; |
1
by brian
clean slate |
63 |
}
|
64 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
65 |
static void do_field_2(CopyField *copy) |
1
by brian
clean slate |
66 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
67 |
copy->to_ptr[0]= copy->from_ptr[0]; |
68 |
copy->to_ptr[1]= copy->from_ptr[1]; |
|
1
by brian
clean slate |
69 |
}
|
70 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
71 |
static void do_field_3(CopyField *copy) |
1
by brian
clean slate |
72 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
73 |
copy->to_ptr[0]= copy->from_ptr[0]; |
74 |
copy->to_ptr[1]= copy->from_ptr[1]; |
|
75 |
copy->to_ptr[2]= copy->from_ptr[2]; |
|
1
by brian
clean slate |
76 |
}
|
77 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
78 |
static void do_field_4(CopyField *copy) |
1
by brian
clean slate |
79 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
80 |
copy->to_ptr[0]= copy->from_ptr[0]; |
81 |
copy->to_ptr[1]= copy->from_ptr[1]; |
|
82 |
copy->to_ptr[2]= copy->from_ptr[2]; |
|
83 |
copy->to_ptr[3]= copy->from_ptr[3]; |
|
1
by brian
clean slate |
84 |
}
|
85 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
86 |
static void do_field_6(CopyField *copy) |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
87 |
{ // For blob field |
88 |
copy->to_ptr[0]= copy->from_ptr[0]; |
|
89 |
copy->to_ptr[1]= copy->from_ptr[1]; |
|
90 |
copy->to_ptr[2]= copy->from_ptr[2]; |
|
91 |
copy->to_ptr[3]= copy->from_ptr[3]; |
|
92 |
copy->to_ptr[4]= copy->from_ptr[4]; |
|
93 |
copy->to_ptr[5]= copy->from_ptr[5]; |
|
1
by brian
clean slate |
94 |
}
|
95 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
96 |
static void do_field_8(CopyField *copy) |
1
by brian
clean slate |
97 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
98 |
copy->to_ptr[0]= copy->from_ptr[0]; |
99 |
copy->to_ptr[1]= copy->from_ptr[1]; |
|
100 |
copy->to_ptr[2]= copy->from_ptr[2]; |
|
101 |
copy->to_ptr[3]= copy->from_ptr[3]; |
|
102 |
copy->to_ptr[4]= copy->from_ptr[4]; |
|
103 |
copy->to_ptr[5]= copy->from_ptr[5]; |
|
104 |
copy->to_ptr[6]= copy->from_ptr[6]; |
|
105 |
copy->to_ptr[7]= copy->from_ptr[7]; |
|
1
by brian
clean slate |
106 |
}
|
107 |
||
108 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
109 |
static void do_field_to_null_str(CopyField *copy) |
1
by brian
clean slate |
110 |
{
|
111 |
if (*copy->from_null_ptr & copy->from_bit) |
|
112 |
{
|
|
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
113 |
memset(copy->to_ptr, 0, copy->from_length); |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
114 |
copy->to_null_ptr[0]= 1; // Always bit 1 |
1
by brian
clean slate |
115 |
}
|
116 |
else
|
|
117 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
118 |
copy->to_null_ptr[0]= 0; |
119 |
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length); |
|
1
by brian
clean slate |
120 |
}
|
121 |
}
|
|
122 |
||
123 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
124 |
static void do_outer_field_to_null_str(CopyField *copy) |
1
by brian
clean slate |
125 |
{
|
126 |
if (*copy->null_row || |
|
127 |
(copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit))) |
|
128 |
{
|
|
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
129 |
memset(copy->to_ptr, 0, copy->from_length); |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
130 |
copy->to_null_ptr[0]= 1; // Always bit 1 |
1
by brian
clean slate |
131 |
}
|
132 |
else
|
|
133 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
134 |
copy->to_null_ptr[0]= 0; |
135 |
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length); |
|
1
by brian
clean slate |
136 |
}
|
137 |
}
|
|
138 |
||
139 |
||
140 |
int
|
|
141 |
set_field_to_null(Field *field) |
|
142 |
{
|
|
143 |
if (field->real_maybe_null()) |
|
144 |
{
|
|
145 |
field->set_null(); |
|
146 |
field->reset(); |
|
147 |
return 0; |
|
148 |
}
|
|
149 |
field->reset(); |
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
150 |
if (field->getTable()->in_use->count_cuted_fields == CHECK_FIELD_WARN) |
685.4.2
by Jay Pipes
Added back truncation warnings. The NULL error is triggered from: session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL, not CHECK_FIELD_WARN |
151 |
{
|
152 |
field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); |
|
153 |
return 0; |
|
154 |
}
|
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
155 |
if (!field->getTable()->in_use->no_errors) |
1
by brian
clean slate |
156 |
my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name); |
157 |
return -1; |
|
158 |
}
|
|
159 |
||
160 |
||
161 |
/**
|
|
162 |
Set field to NULL or TIMESTAMP or to next auto_increment number.
|
|
163 |
||
164 |
@param field Field to update
|
|
165 |
@param no_conversions Set to 1 if we should return 1 if field can't
|
|
166 |
take null values.
|
|
167 |
If set to 0 we will do store the 'default value'
|
|
168 |
if the field is a special field. If not we will
|
|
169 |
give an error.
|
|
170 |
||
171 |
@retval
|
|
172 |
0 Field could take 0 or an automatic conversion was used
|
|
173 |
@retval
|
|
174 |
-1 Field could not take NULL and no conversion was used.
|
|
175 |
If no_conversion was not set, an error message is printed
|
|
176 |
*/
|
|
177 |
||
178 |
int
|
|
179 |
set_field_to_null_with_conversions(Field *field, bool no_conversions) |
|
180 |
{
|
|
181 |
if (field->real_maybe_null()) |
|
182 |
{
|
|
183 |
field->set_null(); |
|
184 |
field->reset(); |
|
185 |
return 0; |
|
186 |
}
|
|
1999.4.9
by Brian Aker
Created EPOCH |
187 |
|
1
by brian
clean slate |
188 |
if (no_conversions) |
189 |
return -1; |
|
190 |
||
191 |
/*
|
|
192 |
Check if this is a special type, which will get a special walue
|
|
193 |
when set to NULL (TIMESTAMP fields which allow setting to NULL
|
|
194 |
are handled by first check).
|
|
195 |
*/
|
|
2046.2.1
by Brian Aker
First pass on micro timestamp. |
196 |
if (field->is_timestamp()) |
1
by brian
clean slate |
197 |
{
|
1999.4.9
by Brian Aker
Created EPOCH |
198 |
((field::Epoch::pointer) field)->set_time(); |
1
by brian
clean slate |
199 |
return 0; // Ok to set time to NULL |
200 |
}
|
|
1999.4.9
by Brian Aker
Created EPOCH |
201 |
|
1
by brian
clean slate |
202 |
field->reset(); |
1660.1.3
by Brian Aker
Encapsulate Table in field |
203 |
if (field == field->getTable()->next_number_field) |
1
by brian
clean slate |
204 |
{
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
205 |
field->getTable()->auto_increment_field_not_null= false; |
1
by brian
clean slate |
206 |
return 0; // field is set in fill_record() |
207 |
}
|
|
1999.4.9
by Brian Aker
Created EPOCH |
208 |
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
209 |
if (field->getTable()->in_use->count_cuted_fields == CHECK_FIELD_WARN) |
685.4.2
by Jay Pipes
Added back truncation warnings. The NULL error is triggered from: session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL, not CHECK_FIELD_WARN |
210 |
{
|
211 |
field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1); |
|
212 |
return 0; |
|
213 |
}
|
|
1999.4.9
by Brian Aker
Created EPOCH |
214 |
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
215 |
if (!field->getTable()->in_use->no_errors) |
1
by brian
clean slate |
216 |
my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name); |
1999.4.9
by Brian Aker
Created EPOCH |
217 |
|
1
by brian
clean slate |
218 |
return -1; |
219 |
}
|
|
220 |
||
221 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
222 |
static void do_skip(CopyField *) |
1
by brian
clean slate |
223 |
{
|
224 |
}
|
|
225 |
||
226 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
227 |
static void do_copy_null(CopyField *copy) |
1
by brian
clean slate |
228 |
{
|
229 |
if (*copy->from_null_ptr & copy->from_bit) |
|
230 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
231 |
*copy->to_null_ptr|= copy->to_bit; |
1
by brian
clean slate |
232 |
copy->to_field->reset(); |
233 |
}
|
|
234 |
else
|
|
235 |
{
|
|
236 |
*copy->to_null_ptr&= ~copy->to_bit; |
|
237 |
(copy->do_copy2)(copy); |
|
238 |
}
|
|
239 |
}
|
|
240 |
||
241 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
242 |
static void do_outer_field_null(CopyField *copy) |
1
by brian
clean slate |
243 |
{
|
244 |
if (*copy->null_row || |
|
245 |
(copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit))) |
|
246 |
{
|
|
247 |
*copy->to_null_ptr|=copy->to_bit; |
|
248 |
copy->to_field->reset(); |
|
249 |
}
|
|
250 |
else
|
|
251 |
{
|
|
252 |
*copy->to_null_ptr&= ~copy->to_bit; |
|
253 |
(copy->do_copy2)(copy); |
|
254 |
}
|
|
255 |
}
|
|
256 |
||
257 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
258 |
static void do_copy_not_null(CopyField *copy) |
1
by brian
clean slate |
259 |
{
|
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
260 |
if (copy->to_field->hasDefault() and *copy->from_null_ptr & copy->from_bit) |
261 |
{
|
|
262 |
copy->to_field->set_default(); |
|
263 |
}
|
|
264 |
else if (*copy->from_null_ptr & copy->from_bit) |
|
1
by brian
clean slate |
265 |
{
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
266 |
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
212.5.42
by Monty Taylor
Ding dong include is dead. |
267 |
ER_WARN_DATA_TRUNCATED, 1); |
1
by brian
clean slate |
268 |
copy->to_field->reset(); |
269 |
}
|
|
270 |
else
|
|
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
271 |
{
|
1
by brian
clean slate |
272 |
(copy->do_copy2)(copy); |
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
273 |
}
|
1
by brian
clean slate |
274 |
}
|
275 |
||
276 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
277 |
static void do_copy_maybe_null(CopyField *copy) |
1
by brian
clean slate |
278 |
{
|
279 |
*copy->to_null_ptr&= ~copy->to_bit; |
|
280 |
(copy->do_copy2)(copy); |
|
281 |
}
|
|
282 |
||
283 |
/* timestamp and next_number has special handling in case of NULL values */
|
|
284 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
285 |
static void do_copy_timestamp(CopyField *copy) |
1
by brian
clean slate |
286 |
{
|
287 |
if (*copy->from_null_ptr & copy->from_bit) |
|
288 |
{
|
|
289 |
/* Same as in set_field_to_null_with_conversions() */
|
|
1999.4.9
by Brian Aker
Created EPOCH |
290 |
((field::Epoch::pointer) copy->to_field)->set_time(); |
1
by brian
clean slate |
291 |
}
|
292 |
else
|
|
1999.4.9
by Brian Aker
Created EPOCH |
293 |
{
|
1
by brian
clean slate |
294 |
(copy->do_copy2)(copy); |
1999.4.9
by Brian Aker
Created EPOCH |
295 |
}
|
1
by brian
clean slate |
296 |
}
|
297 |
||
298 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
299 |
static void do_copy_next_number(CopyField *copy) |
1
by brian
clean slate |
300 |
{
|
301 |
if (*copy->from_null_ptr & copy->from_bit) |
|
302 |
{
|
|
303 |
/* Same as in set_field_to_null_with_conversions() */
|
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
304 |
copy->to_field->getTable()->auto_increment_field_not_null= false; |
1
by brian
clean slate |
305 |
copy->to_field->reset(); |
306 |
}
|
|
307 |
else
|
|
1999.4.9
by Brian Aker
Created EPOCH |
308 |
{
|
1
by brian
clean slate |
309 |
(copy->do_copy2)(copy); |
1999.4.9
by Brian Aker
Created EPOCH |
310 |
}
|
1
by brian
clean slate |
311 |
}
|
312 |
||
313 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
314 |
static void do_copy_blob(CopyField *copy) |
1
by brian
clean slate |
315 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
316 |
ulong length= ((Field_blob*) copy->from_field)->get_length(); |
1
by brian
clean slate |
317 |
((Field_blob*) copy->to_field)->store_length(length); |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
318 |
memcpy(copy->to_ptr, copy->from_ptr, sizeof(char*)); |
1
by brian
clean slate |
319 |
}
|
320 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
321 |
static void do_conv_blob(CopyField *copy) |
1
by brian
clean slate |
322 |
{
|
1996.2.1
by Brian Aker
uuid type code. |
323 |
copy->from_field->val_str_internal(©->tmp); |
1
by brian
clean slate |
324 |
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(), |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
325 |
copy->tmp.length(), |
326 |
copy->tmp.charset()); |
|
1
by brian
clean slate |
327 |
}
|
328 |
||
329 |
/** Save blob in copy->tmp for GROUP BY. */
|
|
330 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
331 |
static void do_save_blob(CopyField *copy) |
1
by brian
clean slate |
332 |
{
|
333 |
char buff[MAX_FIELD_WIDTH]; |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
334 |
String res(buff, sizeof(buff), copy->tmp.charset()); |
1996.2.1
by Brian Aker
uuid type code. |
335 |
copy->from_field->val_str_internal(&res); |
1
by brian
clean slate |
336 |
copy->tmp.copy(res); |
337 |
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(), |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
338 |
copy->tmp.length(), |
339 |
copy->tmp.charset()); |
|
1
by brian
clean slate |
340 |
}
|
341 |
||
342 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
343 |
static void do_field_string(CopyField *copy) |
1
by brian
clean slate |
344 |
{
|
345 |
char buff[MAX_FIELD_WIDTH]; |
|
346 |
copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset()); |
|
1996.2.1
by Brian Aker
uuid type code. |
347 |
copy->from_field->val_str_internal(©->tmp); |
1
by brian
clean slate |
348 |
copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length(), |
349 |
copy->tmp.charset()); |
|
350 |
}
|
|
351 |
||
352 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
353 |
static void do_field_enum(CopyField *copy) |
1
by brian
clean slate |
354 |
{
|
355 |
if (copy->from_field->val_int() == 0) |
|
151
by Brian Aker
Ulonglong to uint64_t |
356 |
((Field_enum *) copy->to_field)->store_type((uint64_t) 0); |
1
by brian
clean slate |
357 |
else
|
358 |
do_field_string(copy); |
|
359 |
}
|
|
360 |
||
361 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
362 |
static void do_field_int(CopyField *copy) |
1
by brian
clean slate |
363 |
{
|
152
by Brian Aker
longlong replacement |
364 |
int64_t value= copy->from_field->val_int(); |
1
by brian
clean slate |
365 |
copy->to_field->store(value, |
366 |
test(copy->from_field->flags & UNSIGNED_FLAG)); |
|
367 |
}
|
|
368 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
369 |
static void do_field_real(CopyField *copy) |
1
by brian
clean slate |
370 |
{
|
371 |
double value=copy->from_field->val_real(); |
|
372 |
copy->to_field->store(value); |
|
373 |
}
|
|
374 |
||
375 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
376 |
static void do_field_decimal(CopyField *copy) |
1
by brian
clean slate |
377 |
{
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
378 |
type::Decimal value; |
1
by brian
clean slate |
379 |
copy->to_field->store_decimal(copy->from_field->val_decimal(&value)); |
380 |
}
|
|
381 |
||
382 |
||
383 |
/**
|
|
384 |
string copy for single byte characters set when to string is shorter than
|
|
385 |
from string.
|
|
386 |
*/
|
|
387 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
388 |
static void do_cut_string(CopyField *copy) |
1
by brian
clean slate |
389 |
{
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
390 |
const charset_info_st * const cs= copy->from_field->charset(); |
2046.2.3
by Brian Aker
Add basic tests for microtime. |
391 |
memcpy(copy->to_ptr, copy->from_ptr, copy->to_length); |
1
by brian
clean slate |
392 |
|
393 |
/* Check if we loosed any important characters */
|
|
394 |
if (cs->cset->scan(cs, |
|
395 |
(char*) copy->from_ptr + copy->to_length, |
|
396 |
(char*) copy->from_ptr + copy->from_length, |
|
397 |
MY_SEQ_SPACES) < copy->from_length - copy->to_length) |
|
398 |
{
|
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
399 |
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
212.5.42
by Monty Taylor
Ding dong include is dead. |
400 |
ER_WARN_DATA_TRUNCATED, 1); |
1
by brian
clean slate |
401 |
}
|
402 |
}
|
|
403 |
||
404 |
||
405 |
/**
|
|
406 |
string copy for multi byte characters set when to string is shorter than
|
|
407 |
from string.
|
|
408 |
*/
|
|
409 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
410 |
static void do_cut_string_complex(CopyField *copy) |
1
by brian
clean slate |
411 |
{ // Shorter string field |
412 |
int well_formed_error; |
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
413 |
const charset_info_st * const cs= copy->from_field->charset(); |
481
by Brian Aker
Remove all of uchar. |
414 |
const unsigned char *from_end= copy->from_ptr + copy->from_length; |
482
by Brian Aker
Remove uint. |
415 |
uint32_t copy_length= cs->cset->well_formed_len(cs, |
1
by brian
clean slate |
416 |
(char*) copy->from_ptr, |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
417 |
(char*) from_end, |
1
by brian
clean slate |
418 |
copy->to_length / cs->mbmaxlen, |
419 |
&well_formed_error); |
|
420 |
if (copy->to_length < copy_length) |
|
421 |
copy_length= copy->to_length; |
|
422 |
memcpy(copy->to_ptr, copy->from_ptr, copy_length); |
|
423 |
||
424 |
/* Check if we lost any important characters */
|
|
425 |
if (well_formed_error || |
|
426 |
cs->cset->scan(cs, (char*) copy->from_ptr + copy_length, |
|
427 |
(char*) from_end, |
|
428 |
MY_SEQ_SPACES) < (copy->from_length - copy_length)) |
|
429 |
{
|
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
430 |
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
212.5.42
by Monty Taylor
Ding dong include is dead. |
431 |
ER_WARN_DATA_TRUNCATED, 1); |
1
by brian
clean slate |
432 |
}
|
433 |
||
434 |
if (copy_length < copy->to_length) |
|
435 |
cs->cset->fill(cs, (char*) copy->to_ptr + copy_length, |
|
436 |
copy->to_length - copy_length, ' '); |
|
437 |
}
|
|
438 |
||
439 |
||
440 |
||
441 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
442 |
static void do_expand_binary(CopyField *copy) |
1
by brian
clean slate |
443 |
{
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
444 |
const charset_info_st * const cs= copy->from_field->charset(); |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
445 |
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length); |
1
by brian
clean slate |
446 |
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length, |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
447 |
copy->to_length-copy->from_length, '\0'); |
1
by brian
clean slate |
448 |
}
|
449 |
||
450 |
||
451 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
452 |
static void do_expand_string(CopyField *copy) |
1
by brian
clean slate |
453 |
{
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
454 |
const charset_info_st * const cs= copy->from_field->charset(); |
1
by brian
clean slate |
455 |
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length); |
456 |
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length, |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
457 |
copy->to_length-copy->from_length, ' '); |
1
by brian
clean slate |
458 |
}
|
459 |
||
460 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
461 |
static void do_varstring1(CopyField *copy) |
1
by brian
clean slate |
462 |
{
|
895
by Brian Aker
Completion (?) of uint conversion. |
463 |
uint32_t length= (uint32_t) *(unsigned char*) copy->from_ptr; |
1
by brian
clean slate |
464 |
if (length > copy->to_length- 1) |
465 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
466 |
length= copy->to_length - 1; |
1660.1.3
by Brian Aker
Encapsulate Table in field |
467 |
if (copy->from_field->getTable()->in_use->count_cuted_fields) |
2046.2.3
by Brian Aker
Add basic tests for microtime. |
468 |
{
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
469 |
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
212.5.42
by Monty Taylor
Ding dong include is dead. |
470 |
ER_WARN_DATA_TRUNCATED, 1); |
2046.2.3
by Brian Aker
Add basic tests for microtime. |
471 |
}
|
1
by brian
clean slate |
472 |
}
|
481
by Brian Aker
Remove all of uchar. |
473 |
*(unsigned char*) copy->to_ptr= (unsigned char) length; |
1
by brian
clean slate |
474 |
memcpy(copy->to_ptr+1, copy->from_ptr + 1, length); |
475 |
}
|
|
476 |
||
477 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
478 |
static void do_varstring1_mb(CopyField *copy) |
1
by brian
clean slate |
479 |
{
|
480 |
int well_formed_error; |
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
481 |
const charset_info_st * const cs= copy->from_field->charset(); |
895
by Brian Aker
Completion (?) of uint conversion. |
482 |
uint32_t from_length= (uint32_t) *(unsigned char*) copy->from_ptr; |
481
by Brian Aker
Remove all of uchar. |
483 |
const unsigned char *from_ptr= copy->from_ptr + 1; |
482
by Brian Aker
Remove uint. |
484 |
uint32_t to_char_length= (copy->to_length - 1) / cs->mbmaxlen; |
485 |
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_ptr, |
|
1
by brian
clean slate |
486 |
(char*) from_ptr + from_length, |
487 |
to_char_length, &well_formed_error); |
|
488 |
if (length < from_length) |
|
489 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
490 |
if (current_session->count_cuted_fields) |
2046.2.3
by Brian Aker
Add basic tests for microtime. |
491 |
{
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
492 |
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
212.5.42
by Monty Taylor
Ding dong include is dead. |
493 |
ER_WARN_DATA_TRUNCATED, 1); |
2046.2.3
by Brian Aker
Add basic tests for microtime. |
494 |
}
|
1
by brian
clean slate |
495 |
}
|
481
by Brian Aker
Remove all of uchar. |
496 |
*copy->to_ptr= (unsigned char) length; |
1
by brian
clean slate |
497 |
memcpy(copy->to_ptr + 1, from_ptr, length); |
498 |
}
|
|
499 |
||
500 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
501 |
static void do_varstring2(CopyField *copy) |
1
by brian
clean slate |
502 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
503 |
uint32_t length= uint2korr(copy->from_ptr); |
1
by brian
clean slate |
504 |
if (length > copy->to_length- HA_KEY_BLOB_LENGTH) |
505 |
{
|
|
506 |
length=copy->to_length-HA_KEY_BLOB_LENGTH; |
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
507 |
if (copy->from_field->getTable()->in_use->count_cuted_fields) |
2046.2.3
by Brian Aker
Add basic tests for microtime. |
508 |
{
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
509 |
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
212.5.42
by Monty Taylor
Ding dong include is dead. |
510 |
ER_WARN_DATA_TRUNCATED, 1); |
2046.2.3
by Brian Aker
Add basic tests for microtime. |
511 |
}
|
1
by brian
clean slate |
512 |
}
|
513 |
int2store(copy->to_ptr,length); |
|
514 |
memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, copy->from_ptr + HA_KEY_BLOB_LENGTH, |
|
515 |
length); |
|
516 |
}
|
|
517 |
||
518 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
519 |
static void do_varstring2_mb(CopyField *copy) |
1
by brian
clean slate |
520 |
{
|
521 |
int well_formed_error; |
|
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
522 |
const charset_info_st * const cs= copy->from_field->charset(); |
482
by Brian Aker
Remove uint. |
523 |
uint32_t char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen; |
524 |
uint32_t from_length= uint2korr(copy->from_ptr); |
|
481
by Brian Aker
Remove all of uchar. |
525 |
const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH; |
482
by Brian Aker
Remove uint. |
526 |
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg, |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
527 |
(char*) from_beg + from_length, |
528 |
char_length, &well_formed_error); |
|
1
by brian
clean slate |
529 |
if (length < from_length) |
530 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
531 |
if (current_session->count_cuted_fields) |
2046.2.3
by Brian Aker
Add basic tests for microtime. |
532 |
{
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
533 |
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
212.5.42
by Monty Taylor
Ding dong include is dead. |
534 |
ER_WARN_DATA_TRUNCATED, 1); |
2046.2.3
by Brian Aker
Add basic tests for microtime. |
535 |
}
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
536 |
}
|
1
by brian
clean slate |
537 |
int2store(copy->to_ptr, length); |
538 |
memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length); |
|
539 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
540 |
|
1
by brian
clean slate |
541 |
|
542 |
/***************************************************************************
|
|
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
543 |
** The different functions that fills in a CopyField class
|
1
by brian
clean slate |
544 |
***************************************************************************/
|
545 |
||
546 |
/**
|
|
547 |
copy of field to maybe null string.
|
|
548 |
If field is null then the all bytes are set to 0.
|
|
549 |
if field is not null then the first byte is set to 1 and the rest of the
|
|
550 |
string is the field value.
|
|
551 |
The 'to' buffer should have a size of field->pack_length()+1
|
|
552 |
*/
|
|
553 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
554 |
void CopyField::set(unsigned char *to,Field *from) |
1
by brian
clean slate |
555 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
556 |
from_ptr= from->ptr; |
557 |
to_ptr= to; |
|
558 |
from_length= from->pack_length(); |
|
1
by brian
clean slate |
559 |
if (from->maybe_null()) |
560 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
561 |
from_null_ptr= from->null_ptr; |
562 |
from_bit= from->null_bit; |
|
563 |
to_ptr[0]= 1; // Null as default value |
|
564 |
to_null_ptr= (unsigned char*) to_ptr++; |
|
565 |
to_bit= 1; |
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
566 |
if (from->getTable()->maybe_null) |
1
by brian
clean slate |
567 |
{
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
568 |
null_row= &from->getTable()->null_row; |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
569 |
do_copy= do_outer_field_to_null_str; |
1
by brian
clean slate |
570 |
}
|
571 |
else
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
572 |
do_copy= do_field_to_null_str; |
1
by brian
clean slate |
573 |
}
|
574 |
else
|
|
575 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
576 |
to_null_ptr= 0; // For easy debugging |
577 |
do_copy= do_field_eq; |
|
1
by brian
clean slate |
578 |
}
|
579 |
}
|
|
580 |
||
581 |
||
582 |
/*
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
583 |
To do:
|
1
by brian
clean slate |
584 |
|
585 |
If 'save\ is set to true and the 'from' is a blob field, do_copy is set to
|
|
586 |
do_save_blob rather than do_conv_blob. The only differences between them
|
|
587 |
appears to be:
|
|
588 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
589 |
- do_save_blob allocates and uses an intermediate buffer before calling
|
590 |
Field_blob::store. Is this in order to trigger the call to
|
|
1
by brian
clean slate |
591 |
well_formed_copy_nchars, by changing the pointer copy->tmp.ptr()?
|
592 |
That call will take place anyway in all known cases.
|
|
593 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
594 |
- The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended
|
1
by brian
clean slate |
595 |
effect? Truncation is handled by well_formed_copy_nchars anyway.
|
596 |
*/
|
|
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
597 |
void CopyField::set(Field *to,Field *from,bool save) |
1
by brian
clean slate |
598 |
{
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
599 |
if (to->type() == DRIZZLE_TYPE_NULL) |
1
by brian
clean slate |
600 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
601 |
to_null_ptr= 0; // For easy debugging |
602 |
to_ptr= 0; |
|
603 |
do_copy= do_skip; |
|
1
by brian
clean slate |
604 |
return; |
605 |
}
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
606 |
from_field= from; |
607 |
to_field= to; |
|
608 |
from_ptr= from->ptr; |
|
609 |
from_length= from->pack_length(); |
|
610 |
to_ptr= to->ptr; |
|
611 |
to_length= to_field->pack_length(); |
|
1
by brian
clean slate |
612 |
|
613 |
// set up null handling
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
614 |
from_null_ptr= to_null_ptr= 0; |
1
by brian
clean slate |
615 |
if (from->maybe_null()) |
616 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
617 |
from_null_ptr= from->null_ptr; |
618 |
from_bit= from->null_bit; |
|
1
by brian
clean slate |
619 |
if (to_field->real_maybe_null()) |
620 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
621 |
to_null_ptr= to->null_ptr; |
622 |
to_bit= to->null_bit; |
|
1
by brian
clean slate |
623 |
if (from_null_ptr) |
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
624 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
625 |
do_copy= do_copy_null; |
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
626 |
}
|
1
by brian
clean slate |
627 |
else
|
628 |
{
|
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
629 |
null_row= &from->getTable()->null_row; |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
630 |
do_copy= do_outer_field_null; |
1
by brian
clean slate |
631 |
}
|
632 |
}
|
|
633 |
else
|
|
634 |
{
|
|
2046.2.1
by Brian Aker
First pass on micro timestamp. |
635 |
if (to_field->is_timestamp()) |
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
636 |
{
|
1
by brian
clean slate |
637 |
do_copy= do_copy_timestamp; // Automatic timestamp |
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
638 |
}
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
639 |
else if (to_field == to_field->getTable()->next_number_field) |
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
640 |
{
|
1
by brian
clean slate |
641 |
do_copy= do_copy_next_number; |
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
642 |
}
|
1
by brian
clean slate |
643 |
else
|
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
644 |
{
|
1
by brian
clean slate |
645 |
do_copy= do_copy_not_null; |
1976.6.1
by Brian Aker
This is a fix for bug lp:686197 |
646 |
}
|
1
by brian
clean slate |
647 |
}
|
648 |
}
|
|
649 |
else if (to_field->real_maybe_null()) |
|
650 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
651 |
to_null_ptr= to->null_ptr; |
652 |
to_bit= to->null_bit; |
|
1
by brian
clean slate |
653 |
do_copy= do_copy_maybe_null; |
654 |
}
|
|
655 |
else
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
656 |
do_copy= 0; |
1
by brian
clean slate |
657 |
|
658 |
if ((to->flags & BLOB_FLAG) && save) |
|
659 |
do_copy2= do_save_blob; |
|
660 |
else
|
|
661 |
do_copy2= get_copy_func(to,from); |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
662 |
if (!do_copy) // Not null |
663 |
do_copy= do_copy2; |
|
1
by brian
clean slate |
664 |
}
|
665 |
||
666 |
||
1052.2.2
by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards. |
667 |
CopyField::Copy_func * |
668 |
CopyField::get_copy_func(Field *to,Field *from) |
|
1
by brian
clean slate |
669 |
{
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
670 |
bool compatible_db_low_byte_first= (to->getTable()->getShare()->db_low_byte_first == |
671 |
from->getTable()->getShare()->db_low_byte_first); |
|
1
by brian
clean slate |
672 |
if (to->flags & BLOB_FLAG) |
673 |
{
|
|
674 |
if (!(from->flags & BLOB_FLAG) || from->charset() != to->charset()) |
|
675 |
return do_conv_blob; |
|
676 |
if (from_length != to_length || !compatible_db_low_byte_first) |
|
677 |
{
|
|
678 |
// Correct pointer to point at char pointer
|
|
2134.1.4
by Brian Aker
Simple encapsulation for table. |
679 |
to_ptr+= to_length - to->getTable()->getShare()->sizeBlobPtr(); |
680 |
from_ptr+= from_length- from->getTable()->getShare()->sizeBlobPtr(); |
|
1
by brian
clean slate |
681 |
return do_copy_blob; |
682 |
}
|
|
683 |
}
|
|
684 |
else
|
|
685 |
{
|
|
686 |
if (to->result_type() == DECIMAL_RESULT) |
|
687 |
return do_field_decimal; |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
688 |
|
1
by brian
clean slate |
689 |
// Check if identical fields
|
690 |
if (from->result_type() == STRING_RESULT) |
|
691 |
{
|
|
692 |
/*
|
|
693 |
If we are copying date or datetime's we have to check the dates
|
|
694 |
if we don't allow 'all' dates.
|
|
695 |
*/
|
|
696 |
if (to->real_type() != from->real_type() || |
|
697 |
!compatible_db_low_byte_first || |
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
698 |
(((to->getTable()->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_DATE) || to->type() == DRIZZLE_TYPE_DATETIME)) |
1
by brian
clean slate |
699 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
700 |
if (from->real_type() == DRIZZLE_TYPE_ENUM) |
701 |
{
|
|
702 |
if (to->result_type() != STRING_RESULT) |
|
703 |
{
|
|
704 |
return do_field_int; // Convert SET to number |
|
705 |
}
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
706 |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
707 |
return do_field_string; |
708 |
}
|
|
1
by brian
clean slate |
709 |
}
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
710 |
|
325
by Brian Aker
Remove SET |
711 |
if (to->real_type() == DRIZZLE_TYPE_ENUM) |
1
by brian
clean slate |
712 |
{
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
713 |
if (!to->eq_def(from)) |
1
by brian
clean slate |
714 |
{
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
715 |
if (from->real_type() == DRIZZLE_TYPE_ENUM && |
716 |
to->real_type() == DRIZZLE_TYPE_ENUM) |
|
1
by brian
clean slate |
717 |
return do_field_enum; |
718 |
else
|
|
719 |
return do_field_string; |
|
720 |
}
|
|
721 |
}
|
|
722 |
else if (to->charset() != from->charset()) |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
723 |
return do_field_string; |
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
724 |
else if (to->real_type() == DRIZZLE_TYPE_VARCHAR) |
1
by brian
clean slate |
725 |
{
|
1267.1.7
by Stewart Smith
in field_conv.cc, get_copy_func should not try to cast Field_blob to Field_varstring as Field_ blob does not inherit from field_varstring. Previously this kinda worked out due to the first member of field_blob kinda making sense in this comparison. Instead, we just shortcut to that decision if we are converting from BLOB. |
726 |
/* Field_blob is not part of the Field_varstring hierarchy,
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
727 |
and casting to varstring for calling pack_length_no_ptr()
|
728 |
is always incorrect. Previously the below comparison has
|
|
729 |
always evaluated to false as pack_length_no_ptr() for BLOB
|
|
730 |
will return 4 and varstring can only be <= 2.
|
|
731 |
If your brain slightly bleeds as to why this worked for
|
|
732 |
so many years, you are in no way alone.
|
|
1267.1.7
by Stewart Smith
in field_conv.cc, get_copy_func should not try to cast Field_blob to Field_varstring as Field_ blob does not inherit from field_varstring. Previously this kinda worked out due to the first member of field_blob kinda making sense in this comparison. Instead, we just shortcut to that decision if we are converting from BLOB. |
733 |
*/
|
734 |
if (from->flags & BLOB_FLAG) |
|
735 |
return do_field_string; |
|
736 |
||
1267.1.8
by Stewart Smith
change dynamic_cast in field_conv.cc back to static_cast for runtime performance |
737 |
if ((static_cast<Field_varstring*>(to))->pack_length_no_ptr() != |
738 |
(static_cast<Field_varstring*>(from))->pack_length_no_ptr()) |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
739 |
{
|
1
by brian
clean slate |
740 |
return do_field_string; |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
741 |
}
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
742 |
|
1
by brian
clean slate |
743 |
if (to_length != from_length) |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
744 |
{
|
1782.4.5
by Brian Aker
Encapsulate the length of the bytes in the varchar header. |
745 |
return (((Field_varstring*) to)->pack_length_no_ptr() == 1 ? |
1
by brian
clean slate |
746 |
(from->charset()->mbmaxlen == 1 ? do_varstring1 : |
2008
by Brian Aker
Formatting + remove default from switch/case. |
747 |
do_varstring1_mb) : |
1
by brian
clean slate |
748 |
(from->charset()->mbmaxlen == 1 ? do_varstring2 : |
2008
by Brian Aker
Formatting + remove default from switch/case. |
749 |
do_varstring2_mb)); |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
750 |
}
|
1
by brian
clean slate |
751 |
}
|
752 |
else if (to_length < from_length) |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
753 |
{
|
754 |
return (from->charset()->mbmaxlen == 1 ? |
|
1
by brian
clean slate |
755 |
do_cut_string : do_cut_string_complex); |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
756 |
}
|
1
by brian
clean slate |
757 |
else if (to_length > from_length) |
758 |
{
|
|
759 |
if (to->charset() == &my_charset_bin) |
|
760 |
return do_expand_binary; |
|
761 |
else
|
|
762 |
return do_expand_string; |
|
763 |
}
|
|
764 |
}
|
|
765 |
else if (to->real_type() != from->real_type() || |
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
766 |
to_length != from_length || |
1
by brian
clean slate |
767 |
!compatible_db_low_byte_first) |
768 |
{
|
|
80
by Brian Aker
Most of the removal of dead DECIMAL type |
769 |
if (to->result_type() == STRING_RESULT) |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
770 |
return do_field_string; |
1
by brian
clean slate |
771 |
if (to->result_type() == INT_RESULT) |
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
772 |
return do_field_int; |
773 |
||
1
by brian
clean slate |
774 |
return do_field_real; |
775 |
}
|
|
776 |
else
|
|
777 |
{
|
|
778 |
if (!to->eq_def(from) || !compatible_db_low_byte_first) |
|
779 |
{
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
780 |
if (to->result_type() == INT_RESULT) |
781 |
return do_field_int; |
|
782 |
else
|
|
783 |
return do_field_real; |
|
1
by brian
clean slate |
784 |
}
|
785 |
}
|
|
786 |
}
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
787 |
|
1
by brian
clean slate |
788 |
/* Eq fields */
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
789 |
switch (to_length) |
790 |
{
|
|
1
by brian
clean slate |
791 |
case 1: return do_field_1; |
792 |
case 2: return do_field_2; |
|
793 |
case 3: return do_field_3; |
|
794 |
case 4: return do_field_4; |
|
795 |
case 6: return do_field_6; |
|
796 |
case 8: return do_field_8; |
|
797 |
}
|
|
1052.2.6
by Nathan Williams
More style cleanup in files associated with Copy_field to CopyField change. Primarily spacing after = operator. |
798 |
|
1
by brian
clean slate |
799 |
return do_field_eq; |
800 |
}
|
|
801 |
||
802 |
||
803 |
/** Simple quick field convert that is called on insert. */
|
|
804 |
||
805 |
int field_conv(Field *to,Field *from) |
|
806 |
{
|
|
807 |
if (to->real_type() == from->real_type() && |
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
808 |
!(to->type() == DRIZZLE_TYPE_BLOB && to->getTable()->copy_blobs)) |
1
by brian
clean slate |
809 |
{
|
810 |
/* Please god, will someone rewrite this to be readable :( */
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
811 |
if (to->pack_length() == from->pack_length() && |
812 |
!(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) && |
|
813 |
to->real_type() != DRIZZLE_TYPE_ENUM && |
|
1211.1.1
by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update |
814 |
(to->real_type() != DRIZZLE_TYPE_DECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) && |
1
by brian
clean slate |
815 |
from->charset() == to->charset() && |
1660.1.3
by Brian Aker
Encapsulate Table in field |
816 |
to->getTable()->getShare()->db_low_byte_first == from->getTable()->getShare()->db_low_byte_first && |
817 |
(!(to->getTable()->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_DATE && to->type() != DRIZZLE_TYPE_DATETIME)) && |
|
1782.4.5
by Brian Aker
Encapsulate the length of the bytes in the varchar header. |
818 |
(from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->pack_length_no_ptr() == ((Field_varstring*)to)->pack_length_no_ptr())) |
1
by brian
clean slate |
819 |
{ // Identical fields |
820 |
/* This may happen if one does 'UPDATE ... SET x=x' */
|
|
821 |
if (to->ptr != from->ptr) |
|
822 |
memcpy(to->ptr,from->ptr,to->pack_length()); |
|
823 |
return 0; |
|
824 |
}
|
|
825 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
826 |
if (to->type() == DRIZZLE_TYPE_BLOB) |
1
by brian
clean slate |
827 |
{ // Be sure the value is stored |
828 |
Field_blob *blob=(Field_blob*) to; |
|
1996.2.1
by Brian Aker
uuid type code. |
829 |
from->val_str_internal(&blob->value); |
1
by brian
clean slate |
830 |
/*
|
831 |
Copy value if copy_blobs is set, or source is not a string and
|
|
832 |
we have a pointer to its internal string conversion buffer.
|
|
833 |
*/
|
|
1660.1.3
by Brian Aker
Encapsulate Table in field |
834 |
if (to->getTable()->copy_blobs || |
1
by brian
clean slate |
835 |
(!blob->value.is_alloced() && |
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
836 |
from->real_type() != DRIZZLE_TYPE_VARCHAR)) |
1
by brian
clean slate |
837 |
blob->value.copy(); |
838 |
return blob->store(blob->value.ptr(),blob->value.length(),from->charset()); |
|
839 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
840 |
if (from->real_type() == DRIZZLE_TYPE_ENUM && |
841 |
to->real_type() == DRIZZLE_TYPE_ENUM && |
|
1
by brian
clean slate |
842 |
from->val_int() == 0) |
843 |
{
|
|
844 |
((Field_enum *)(to))->store_type(0); |
|
845 |
return 0; |
|
846 |
}
|
|
847 |
else if ((from->result_type() == STRING_RESULT && |
|
848 |
(to->result_type() == STRING_RESULT || |
|
325
by Brian Aker
Remove SET |
849 |
(from->real_type() != DRIZZLE_TYPE_ENUM)))) |
1
by brian
clean slate |
850 |
{
|
851 |
char buff[MAX_FIELD_WIDTH]; |
|
852 |
String result(buff,sizeof(buff),from->charset()); |
|
1996.2.1
by Brian Aker
uuid type code. |
853 |
from->val_str_internal(&result); |
1
by brian
clean slate |
854 |
/*
|
855 |
We use c_ptr_quick() here to make it easier if to is a float/double
|
|
856 |
as the conversion routines will do a copy of the result doesn't
|
|
857 |
end with \0. Can be replaced with .ptr() when we have our own
|
|
858 |
string->double conversion.
|
|
859 |
*/
|
|
860 |
return to->store(result.c_ptr_quick(),result.length(),from->charset()); |
|
861 |
}
|
|
862 |
else if (from->result_type() == REAL_RESULT) |
|
2057.2.4
by Brian Aker
We no longer look at the sign of a timestamp. |
863 |
{
|
1
by brian
clean slate |
864 |
return to->store(from->val_real()); |
2057.2.4
by Brian Aker
We no longer look at the sign of a timestamp. |
865 |
}
|
1
by brian
clean slate |
866 |
else if (from->result_type() == DECIMAL_RESULT) |
867 |
{
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
868 |
type::Decimal buff; |
1
by brian
clean slate |
869 |
return to->store_decimal(from->val_decimal(&buff)); |
870 |
}
|
|
871 |
else
|
|
2057.2.4
by Brian Aker
We no longer look at the sign of a timestamp. |
872 |
{
|
1
by brian
clean slate |
873 |
return to->store(from->val_int(), test(from->flags & UNSIGNED_FLAG)); |
2057.2.4
by Brian Aker
We no longer look at the sign of a timestamp. |
874 |
}
|
1
by brian
clean slate |
875 |
}
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
876 |
|
877 |
} /* namespace drizzled */ |