~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

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