~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

MergeĀ fromĀ Nathan

Show diffs side-by-side

added added

removed removed

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