~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Brian Aker
  • Date: 2010-02-24 00:19:06 UTC
  • mto: (1273.13.98 build)
  • mto: This revision was merged to the branch mainline in revision 1309.
  • Revision ID: brian@gaz-20100224001906-zuykji0jmbtx07al
Added binary to ignore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    gives much more speed.
25
25
*/
26
26
 
27
 
#include <drizzled/server_includes.h>
 
27
#include "config.h"
28
28
#include <drizzled/error.h>
29
29
#include <drizzled/table.h>
30
30
#include <drizzled/session.h>
31
31
 
32
32
#include <drizzled/field/str.h>
33
 
#include <drizzled/field/longstr.h>
34
33
#include <drizzled/field/num.h>
35
34
#include <drizzled/field/blob.h>
36
35
#include <drizzled/field/enum.h>
46
45
#include <drizzled/field/datetime.h>
47
46
#include <drizzled/field/varstring.h>
48
47
 
49
 
 
50
 
static void do_field_eq(Copy_field *copy)
51
 
{
52
 
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
53
 
}
54
 
 
55
 
static void do_field_1(Copy_field *copy)
56
 
{
57
 
  copy->to_ptr[0]=copy->from_ptr[0];
58
 
}
59
 
 
60
 
static void do_field_2(Copy_field *copy)
61
 
{
62
 
  copy->to_ptr[0]=copy->from_ptr[0];
63
 
  copy->to_ptr[1]=copy->from_ptr[1];
64
 
}
65
 
 
66
 
static void do_field_3(Copy_field *copy)
67
 
{
68
 
  copy->to_ptr[0]=copy->from_ptr[0];
69
 
  copy->to_ptr[1]=copy->from_ptr[1];
70
 
  copy->to_ptr[2]=copy->from_ptr[2];
71
 
}
72
 
 
73
 
static void do_field_4(Copy_field *copy)
74
 
{
75
 
  copy->to_ptr[0]=copy->from_ptr[0];
76
 
  copy->to_ptr[1]=copy->from_ptr[1];
77
 
  copy->to_ptr[2]=copy->from_ptr[2];
78
 
  copy->to_ptr[3]=copy->from_ptr[3];
79
 
}
80
 
 
81
 
static void do_field_6(Copy_field *copy)
82
 
{                                               // For blob field
83
 
  copy->to_ptr[0]=copy->from_ptr[0];
84
 
  copy->to_ptr[1]=copy->from_ptr[1];
85
 
  copy->to_ptr[2]=copy->from_ptr[2];
86
 
  copy->to_ptr[3]=copy->from_ptr[3];
87
 
  copy->to_ptr[4]=copy->from_ptr[4];
88
 
  copy->to_ptr[5]=copy->from_ptr[5];
89
 
}
90
 
 
91
 
static void do_field_8(Copy_field *copy)
92
 
{
93
 
  copy->to_ptr[0]=copy->from_ptr[0];
94
 
  copy->to_ptr[1]=copy->from_ptr[1];
95
 
  copy->to_ptr[2]=copy->from_ptr[2];
96
 
  copy->to_ptr[3]=copy->from_ptr[3];
97
 
  copy->to_ptr[4]=copy->from_ptr[4];
98
 
  copy->to_ptr[5]=copy->from_ptr[5];
99
 
  copy->to_ptr[6]=copy->from_ptr[6];
100
 
  copy->to_ptr[7]=copy->from_ptr[7];
101
 
}
102
 
 
103
 
 
104
 
static void do_field_to_null_str(Copy_field *copy)
 
48
namespace drizzled
 
49
{
 
50
 
 
51
static void do_field_eq(CopyField *copy)
 
52
{
 
53
  memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
 
54
}
 
55
 
 
56
static void do_field_1(CopyField *copy)
 
57
{
 
58
  copy->to_ptr[0]= copy->from_ptr[0];
 
59
}
 
60
 
 
61
static void do_field_2(CopyField *copy)
 
62
{
 
63
  copy->to_ptr[0]= copy->from_ptr[0];
 
64
  copy->to_ptr[1]= copy->from_ptr[1];
 
65
}
 
66
 
 
67
static void do_field_3(CopyField *copy)
 
68
{
 
69
  copy->to_ptr[0]= copy->from_ptr[0];
 
70
  copy->to_ptr[1]= copy->from_ptr[1];
 
71
  copy->to_ptr[2]= copy->from_ptr[2];
 
72
}
 
73
 
 
74
static void do_field_4(CopyField *copy)
 
75
{
 
76
  copy->to_ptr[0]= copy->from_ptr[0];
 
77
  copy->to_ptr[1]= copy->from_ptr[1];
 
78
  copy->to_ptr[2]= copy->from_ptr[2];
 
79
  copy->to_ptr[3]= copy->from_ptr[3];
 
80
}
 
81
 
 
82
static void do_field_6(CopyField *copy)
 
83
{                  // For blob field
 
84
  copy->to_ptr[0]= copy->from_ptr[0];
 
85
  copy->to_ptr[1]= copy->from_ptr[1];
 
86
  copy->to_ptr[2]= copy->from_ptr[2];
 
87
  copy->to_ptr[3]= copy->from_ptr[3];
 
88
  copy->to_ptr[4]= copy->from_ptr[4];
 
89
  copy->to_ptr[5]= copy->from_ptr[5];
 
90
}
 
91
 
 
92
static void do_field_8(CopyField *copy)
 
93
{
 
94
  copy->to_ptr[0]= copy->from_ptr[0];
 
95
  copy->to_ptr[1]= copy->from_ptr[1];
 
96
  copy->to_ptr[2]= copy->from_ptr[2];
 
97
  copy->to_ptr[3]= copy->from_ptr[3];
 
98
  copy->to_ptr[4]= copy->from_ptr[4];
 
99
  copy->to_ptr[5]= copy->from_ptr[5];
 
100
  copy->to_ptr[6]= copy->from_ptr[6];
 
101
  copy->to_ptr[7]= copy->from_ptr[7];
 
102
}
 
103
 
 
104
 
 
105
static void do_field_to_null_str(CopyField *copy)
105
106
{
106
107
  if (*copy->from_null_ptr & copy->from_bit)
107
108
  {
108
109
    memset(copy->to_ptr, 0, copy->from_length);
109
 
    copy->to_null_ptr[0]=1;                     // Always bit 1
 
110
    copy->to_null_ptr[0]= 1;  // Always bit 1
110
111
  }
111
112
  else
112
113
  {
113
 
    copy->to_null_ptr[0]=0;
114
 
    memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
 
114
    copy->to_null_ptr[0]= 0;
 
115
    memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
115
116
  }
116
117
}
117
118
 
118
119
 
119
 
static void do_outer_field_to_null_str(Copy_field *copy)
 
120
static void do_outer_field_to_null_str(CopyField *copy)
120
121
{
121
122
  if (*copy->null_row ||
122
123
      (copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
123
124
  {
124
125
    memset(copy->to_ptr, 0, copy->from_length);
125
 
    copy->to_null_ptr[0]=1;                     // Always bit 1
 
126
    copy->to_null_ptr[0]= 1;  // Always bit 1
126
127
  }
127
128
  else
128
129
  {
129
 
    copy->to_null_ptr[0]=0;
130
 
    memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
 
130
    copy->to_null_ptr[0]= 0;
 
131
    memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
131
132
  }
132
133
}
133
134
 
209
210
}
210
211
 
211
212
 
212
 
static void do_skip(Copy_field *)
 
213
static void do_skip(CopyField *)
213
214
{
214
215
}
215
216
 
216
217
 
217
 
static void do_copy_null(Copy_field *copy)
 
218
static void do_copy_null(CopyField *copy)
218
219
{
219
220
  if (*copy->from_null_ptr & copy->from_bit)
220
221
  {
221
 
    *copy->to_null_ptr|=copy->to_bit;
 
222
    *copy->to_null_ptr|= copy->to_bit;
222
223
    copy->to_field->reset();
223
224
  }
224
225
  else
229
230
}
230
231
 
231
232
 
232
 
static void do_outer_field_null(Copy_field *copy)
 
233
static void do_outer_field_null(CopyField *copy)
233
234
{
234
235
  if (*copy->null_row ||
235
236
      (copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
245
246
}
246
247
 
247
248
 
248
 
static void do_copy_not_null(Copy_field *copy)
 
249
static void do_copy_not_null(CopyField *copy)
249
250
{
250
251
  if (*copy->from_null_ptr & copy->from_bit)
251
252
  {
258
259
}
259
260
 
260
261
 
261
 
static void do_copy_maybe_null(Copy_field *copy)
 
262
static void do_copy_maybe_null(CopyField *copy)
262
263
{
263
264
  *copy->to_null_ptr&= ~copy->to_bit;
264
265
  (copy->do_copy2)(copy);
266
267
 
267
268
/* timestamp and next_number has special handling in case of NULL values */
268
269
 
269
 
static void do_copy_timestamp(Copy_field *copy)
 
270
static void do_copy_timestamp(CopyField *copy)
270
271
{
271
272
  if (*copy->from_null_ptr & copy->from_bit)
272
273
  {
278
279
}
279
280
 
280
281
 
281
 
static void do_copy_next_number(Copy_field *copy)
 
282
static void do_copy_next_number(CopyField *copy)
282
283
{
283
284
  if (*copy->from_null_ptr & copy->from_bit)
284
285
  {
291
292
}
292
293
 
293
294
 
294
 
static void do_copy_blob(Copy_field *copy)
 
295
static void do_copy_blob(CopyField *copy)
295
296
{
296
 
  ulong length=((Field_blob*) copy->from_field)->get_length();
 
297
  ulong length= ((Field_blob*) copy->from_field)->get_length();
297
298
  ((Field_blob*) copy->to_field)->store_length(length);
298
 
  memcpy(copy->to_ptr,copy->from_ptr,sizeof(char*));
 
299
  memcpy(copy->to_ptr, copy->from_ptr, sizeof(char*));
299
300
}
300
301
 
301
 
static void do_conv_blob(Copy_field *copy)
 
302
static void do_conv_blob(CopyField *copy)
302
303
{
303
304
  copy->from_field->val_str(&copy->tmp);
304
305
  ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
305
 
                                         copy->tmp.length(),
306
 
                                         copy->tmp.charset());
 
306
                                         copy->tmp.length(),
 
307
                                         copy->tmp.charset());
307
308
}
308
309
 
309
310
/** Save blob in copy->tmp for GROUP BY. */
310
311
 
311
 
static void do_save_blob(Copy_field *copy)
 
312
static void do_save_blob(CopyField *copy)
312
313
{
313
314
  char buff[MAX_FIELD_WIDTH];
314
 
  String res(buff,sizeof(buff),copy->tmp.charset());
 
315
  String res(buff, sizeof(buff), copy->tmp.charset());
315
316
  copy->from_field->val_str(&res);
316
317
  copy->tmp.copy(res);
317
318
  ((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
318
 
                                         copy->tmp.length(),
319
 
                                         copy->tmp.charset());
 
319
                                         copy->tmp.length(),
 
320
                                         copy->tmp.charset());
320
321
}
321
322
 
322
323
 
323
 
static void do_field_string(Copy_field *copy)
 
324
static void do_field_string(CopyField *copy)
324
325
{
325
326
  char buff[MAX_FIELD_WIDTH];
326
327
  copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
330
331
}
331
332
 
332
333
 
333
 
static void do_field_enum(Copy_field *copy)
 
334
static void do_field_enum(CopyField *copy)
334
335
{
335
336
  if (copy->from_field->val_int() == 0)
336
337
    ((Field_enum *) copy->to_field)->store_type((uint64_t) 0);
339
340
}
340
341
 
341
342
 
342
 
static void do_field_int(Copy_field *copy)
 
343
static void do_field_int(CopyField *copy)
343
344
{
344
345
  int64_t value= copy->from_field->val_int();
345
346
  copy->to_field->store(value,
346
347
                        test(copy->from_field->flags & UNSIGNED_FLAG));
347
348
}
348
349
 
349
 
static void do_field_real(Copy_field *copy)
 
350
static void do_field_real(CopyField *copy)
350
351
{
351
352
  double value=copy->from_field->val_real();
352
353
  copy->to_field->store(value);
353
354
}
354
355
 
355
356
 
356
 
static void do_field_decimal(Copy_field *copy)
 
357
static void do_field_decimal(CopyField *copy)
357
358
{
358
359
  my_decimal value;
359
360
  copy->to_field->store_decimal(copy->from_field->val_decimal(&value));
365
366
  from string.
366
367
*/
367
368
 
368
 
static void do_cut_string(Copy_field *copy)
 
369
static void do_cut_string(CopyField *copy)
369
370
{
370
371
  const CHARSET_INFO * const cs= copy->from_field->charset();
371
372
  memcpy(copy->to_ptr,copy->from_ptr,copy->to_length);
387
388
  from string.
388
389
*/
389
390
 
390
 
static void do_cut_string_complex(Copy_field *copy)
 
391
static void do_cut_string_complex(CopyField *copy)
391
392
{                                               // Shorter string field
392
393
  int well_formed_error;
393
394
  const CHARSET_INFO * const cs= copy->from_field->charset();
419
420
 
420
421
 
421
422
 
422
 
static void do_expand_binary(Copy_field *copy)
423
 
{
424
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
425
 
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
426
 
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
427
 
                     copy->to_length-copy->from_length, '\0');
428
 
}
429
 
 
430
 
 
431
 
 
432
 
static void do_expand_string(Copy_field *copy)
433
 
{
434
 
  const CHARSET_INFO * const cs= copy->from_field->charset();
435
 
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
436
 
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
437
 
                     copy->to_length-copy->from_length, ' ');
438
 
}
439
 
 
440
 
 
441
 
static void do_varstring1(Copy_field *copy)
 
423
static void do_expand_binary(CopyField *copy)
 
424
{
 
425
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
426
  memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
 
427
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
 
428
                 copy->to_length-copy->from_length, '\0');
 
429
}
 
430
 
 
431
 
 
432
 
 
433
static void do_expand_string(CopyField *copy)
 
434
{
 
435
  const CHARSET_INFO * const cs= copy->from_field->charset();
 
436
  memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
 
437
  cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
 
438
                 copy->to_length-copy->from_length, ' ');
 
439
}
 
440
 
 
441
 
 
442
static void do_varstring1(CopyField *copy)
442
443
{
443
444
  uint32_t length= (uint32_t) *(unsigned char*) copy->from_ptr;
444
445
  if (length > copy->to_length- 1)
445
446
  {
446
 
    length=copy->to_length - 1;
 
447
    length= copy->to_length - 1;
447
448
    if (copy->from_field->table->in_use->count_cuted_fields)
448
449
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
449
450
                                  ER_WARN_DATA_TRUNCATED, 1);
453
454
}
454
455
 
455
456
 
456
 
static void do_varstring1_mb(Copy_field *copy)
 
457
static void do_varstring1_mb(CopyField *copy)
457
458
{
458
459
  int well_formed_error;
459
460
  const CHARSET_INFO * const cs= copy->from_field->charset();
474
475
}
475
476
 
476
477
 
477
 
static void do_varstring2(Copy_field *copy)
 
478
static void do_varstring2(CopyField *copy)
478
479
{
479
 
  uint32_t length=uint2korr(copy->from_ptr);
 
480
  uint32_t length= uint2korr(copy->from_ptr);
480
481
  if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
481
482
  {
482
483
    length=copy->to_length-HA_KEY_BLOB_LENGTH;
490
491
}
491
492
 
492
493
 
493
 
static void do_varstring2_mb(Copy_field *copy)
 
494
static void do_varstring2_mb(CopyField *copy)
494
495
{
495
496
  int well_formed_error;
496
497
  const CHARSET_INFO * const cs= copy->from_field->charset();
498
499
  uint32_t from_length= uint2korr(copy->from_ptr);
499
500
  const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
500
501
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
501
 
                                         (char*) from_beg + from_length,
502
 
                                         char_length, &well_formed_error);
 
502
                                             (char*) from_beg + from_length,
 
503
                                             char_length, &well_formed_error);
503
504
  if (length < from_length)
504
505
  {
505
506
    if (current_session->count_cuted_fields)
512
513
 
513
514
 
514
515
/***************************************************************************
515
 
** The different functions that fills in a Copy_field class
 
516
** The different functions that fills in a CopyField class
516
517
***************************************************************************/
517
518
 
518
519
/**
523
524
  The 'to' buffer should have a size of field->pack_length()+1
524
525
*/
525
526
 
526
 
void Copy_field::set(unsigned char *to,Field *from)
 
527
void CopyField::set(unsigned char *to,Field *from)
527
528
{
528
 
  from_ptr=from->ptr;
529
 
  to_ptr=to;
530
 
  from_length=from->pack_length();
 
529
  from_ptr= from->ptr;
 
530
  to_ptr= to;
 
531
  from_length= from->pack_length();
531
532
  if (from->maybe_null())
532
533
  {
533
 
    from_null_ptr=from->null_ptr;
534
 
    from_bit=     from->null_bit;
535
 
    to_ptr[0]=    1;                            // Null as default value
536
 
    to_null_ptr=  (unsigned char*) to_ptr++;
537
 
    to_bit=       1;
 
534
    from_null_ptr= from->null_ptr;
 
535
    from_bit= from->null_bit;
 
536
    to_ptr[0]= 1;                             // Null as default value
 
537
    to_null_ptr= (unsigned char*) to_ptr++;
 
538
    to_bit= 1;
538
539
    if (from->table->maybe_null)
539
540
    {
540
 
      null_row=   &from->table->null_row;
541
 
      do_copy=    do_outer_field_to_null_str;
 
541
      null_row= &from->table->null_row;
 
542
      do_copy= do_outer_field_to_null_str;
542
543
    }
543
544
    else
544
 
      do_copy=    do_field_to_null_str;
 
545
      do_copy= do_field_to_null_str;
545
546
  }
546
547
  else
547
548
  {
548
 
    to_null_ptr=  0;                            // For easy debugging
549
 
    do_copy=      do_field_eq;
 
549
    to_null_ptr= 0;                           // For easy debugging
 
550
    do_copy= do_field_eq;
550
551
  }
551
552
}
552
553
 
566
567
  - The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended
567
568
    effect? Truncation is handled by well_formed_copy_nchars anyway.
568
569
 */
569
 
void Copy_field::set(Field *to,Field *from,bool save)
 
570
void CopyField::set(Field *to,Field *from,bool save)
570
571
{
571
572
  if (to->type() == DRIZZLE_TYPE_NULL)
572
573
  {
573
 
    to_null_ptr=0;                              // For easy debugging
574
 
    to_ptr=0;
575
 
    do_copy=do_skip;
 
574
    to_null_ptr= 0;           // For easy debugging
 
575
    to_ptr= 0;
 
576
    do_copy= do_skip;
576
577
    return;
577
578
  }
578
 
  from_field=from;
579
 
  to_field=to;
580
 
  from_ptr=from->ptr;
581
 
  from_length=from->pack_length();
582
 
  to_ptr=  to->ptr;
583
 
  to_length=to_field->pack_length();
 
579
  from_field= from;
 
580
  to_field= to;
 
581
  from_ptr= from->ptr;
 
582
  from_length= from->pack_length();
 
583
  to_ptr= to->ptr;
 
584
  to_length= to_field->pack_length();
584
585
 
585
586
  // set up null handling
586
 
  from_null_ptr=to_null_ptr=0;
 
587
  from_null_ptr= to_null_ptr= 0;
587
588
  if (from->maybe_null())
588
589
  {
589
 
    from_null_ptr=      from->null_ptr;
590
 
    from_bit=           from->null_bit;
 
590
    from_null_ptr= from->null_ptr;
 
591
    from_bit= from->null_bit;
591
592
    if (to_field->real_maybe_null())
592
593
    {
593
 
      to_null_ptr=      to->null_ptr;
594
 
      to_bit=           to->null_bit;
 
594
      to_null_ptr= to->null_ptr;
 
595
      to_bit= to->null_bit;
595
596
      if (from_null_ptr)
596
 
        do_copy=        do_copy_null;
 
597
        do_copy= do_copy_null;
597
598
      else
598
599
      {
599
 
        null_row=       &from->table->null_row;
600
 
        do_copy=        do_outer_field_null;
 
600
        null_row= &from->table->null_row;
 
601
        do_copy= do_outer_field_null;
601
602
      }
602
603
    }
603
604
    else
612
613
  }
613
614
  else if (to_field->real_maybe_null())
614
615
  {
615
 
    to_null_ptr=        to->null_ptr;
616
 
    to_bit=             to->null_bit;
 
616
    to_null_ptr= to->null_ptr;
 
617
    to_bit= to->null_bit;
617
618
    do_copy= do_copy_maybe_null;
618
619
  }
619
620
  else
620
 
   do_copy=0;
 
621
   do_copy= 0;
621
622
 
622
623
  if ((to->flags & BLOB_FLAG) && save)
623
624
    do_copy2= do_save_blob;
624
625
  else
625
626
    do_copy2= get_copy_func(to,from);
626
 
  if (!do_copy)                                 // Not null
627
 
    do_copy=do_copy2;
 
627
  if (!do_copy)         // Not null
 
628
    do_copy= do_copy2;
628
629
}
629
630
 
630
631
 
631
 
Copy_field::Copy_func *
632
 
Copy_field::get_copy_func(Field *to,Field *from)
 
632
CopyField::Copy_func *
 
633
CopyField::get_copy_func(Field *to,Field *from)
633
634
{
634
635
  bool compatible_db_low_byte_first= (to->table->s->db_low_byte_first ==
635
636
                                     from->table->s->db_low_byte_first);
640
641
    if (from_length != to_length || !compatible_db_low_byte_first)
641
642
    {
642
643
      // Correct pointer to point at char pointer
643
 
      to_ptr+=   to_length - to->table->s->blob_ptr_size;
 
644
      to_ptr+= to_length - to->table->s->blob_ptr_size;
644
645
      from_ptr+= from_length- from->table->s->blob_ptr_size;
645
646
      return do_copy_blob;
646
647
    }
649
650
  {
650
651
    if (to->result_type() == DECIMAL_RESULT)
651
652
      return do_field_decimal;
 
653
      
652
654
    // Check if identical fields
653
655
    if (from->result_type() == STRING_RESULT)
654
656
    {
660
662
          !compatible_db_low_byte_first ||
661
663
          (((to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_DATE) || to->type() == DRIZZLE_TYPE_DATETIME))
662
664
      {
663
 
        if (from->real_type() == DRIZZLE_TYPE_ENUM)
664
 
          if (to->result_type() != STRING_RESULT)
665
 
            return do_field_int;                // Convert SET to number
666
 
        return do_field_string;
 
665
        if (from->real_type() == DRIZZLE_TYPE_ENUM)
 
666
        {
 
667
          if (to->result_type() != STRING_RESULT)
 
668
          {
 
669
            return do_field_int;  // Convert SET to number
 
670
          }
 
671
          
 
672
          return do_field_string;
 
673
        }
667
674
      }
 
675
      
668
676
      if (to->real_type() == DRIZZLE_TYPE_ENUM)
669
677
      {
670
 
        if (!to->eq_def(from))
 
678
        if (!to->eq_def(from))
671
679
        {
672
680
          if (from->real_type() == DRIZZLE_TYPE_ENUM &&
673
681
              to->real_type() == DRIZZLE_TYPE_ENUM)
677
685
        }
678
686
      }
679
687
      else if (to->charset() != from->charset())
680
 
        return do_field_string;
 
688
        return do_field_string;
681
689
      else if (to->real_type() == DRIZZLE_TYPE_VARCHAR)
682
690
      {
683
691
        if (((Field_varstring*) to)->length_bytes !=
684
692
            ((Field_varstring*) from)->length_bytes)
 
693
        {
685
694
          return do_field_string;
 
695
        }
 
696
        
686
697
        if (to_length != from_length)
 
698
        {
687
699
          return (((Field_varstring*) to)->length_bytes == 1 ?
688
700
                  (from->charset()->mbmaxlen == 1 ? do_varstring1 :
689
701
                                                    do_varstring1_mb) :
690
702
                  (from->charset()->mbmaxlen == 1 ? do_varstring2 :
691
703
                                                    do_varstring2_mb));
 
704
        }
692
705
      }
693
706
      else if (to_length < from_length)
694
 
        return (from->charset()->mbmaxlen == 1 ?
 
707
      {
 
708
        return (from->charset()->mbmaxlen == 1 ?
695
709
                do_cut_string : do_cut_string_complex);
 
710
      }
696
711
      else if (to_length > from_length)
697
712
      {
698
713
        if (to->charset() == &my_charset_bin)
700
715
        else
701
716
          return do_expand_string;
702
717
      }
703
 
 
704
718
    }
705
719
    else if (to->real_type() != from->real_type() ||
706
 
             to_length != from_length ||
 
720
             to_length != from_length ||
707
721
             !compatible_db_low_byte_first)
708
722
    {
709
723
      if (to->result_type() == STRING_RESULT)
710
 
        return do_field_string;
 
724
        return do_field_string;
711
725
      if (to->result_type() == INT_RESULT)
712
 
        return do_field_int;
 
726
        return do_field_int;
 
727
 
713
728
      return do_field_real;
714
729
    }
715
730
    else
716
731
    {
717
732
      if (!to->eq_def(from) || !compatible_db_low_byte_first)
718
733
      {
719
 
        if (to->result_type() == INT_RESULT)
720
 
          return do_field_int;
721
 
        else
722
 
          return do_field_real;
 
734
        if (to->result_type() == INT_RESULT)
 
735
          return do_field_int;
 
736
        else
 
737
          return do_field_real;
723
738
      }
724
739
    }
725
740
  }
 
741
  
726
742
    /* Eq fields */
727
 
  switch (to_length) {
 
743
  switch (to_length)
 
744
  {
728
745
  case 1: return do_field_1;
729
746
  case 2: return do_field_2;
730
747
  case 3: return do_field_3;
732
749
  case 6: return do_field_6;
733
750
  case 8: return do_field_8;
734
751
  }
 
752
  
735
753
  return do_field_eq;
736
754
}
737
755
 
747
765
    if (to->pack_length() == from->pack_length() &&
748
766
        !(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
749
767
        to->real_type() != DRIZZLE_TYPE_ENUM &&
750
 
        (to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
 
768
        (to->real_type() != DRIZZLE_TYPE_DECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
751
769
        from->charset() == to->charset() &&
752
770
        to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
753
771
        (!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_DATE && to->type() != DRIZZLE_TYPE_DATETIME)) &&
805
823
  else
806
824
    return to->store(from->val_int(), test(from->flags & UNSIGNED_FLAG));
807
825
}
 
826
 
 
827
} /* namespace drizzled */