~drizzle-trunk/drizzle/development

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