49
49
static void do_field_eq(CopyField *copy)
51
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
51
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
54
54
static void do_field_1(CopyField *copy)
56
copy->to_ptr[0]=copy->from_ptr[0];
56
copy->to_ptr[0]= copy->from_ptr[0];
59
59
static void do_field_2(CopyField *copy)
61
copy->to_ptr[0]=copy->from_ptr[0];
62
copy->to_ptr[1]=copy->from_ptr[1];
61
copy->to_ptr[0]= copy->from_ptr[0];
62
copy->to_ptr[1]= copy->from_ptr[1];
65
65
static void do_field_3(CopyField *copy)
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];
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];
72
72
static void do_field_4(CopyField *copy)
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];
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];
80
80
static void do_field_6(CopyField *copy)
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];
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];
90
90
static void do_field_8(CopyField *copy)
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];
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];
105
105
if (*copy->from_null_ptr & copy->from_bit)
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
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);
121
121
(copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
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
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);
293
293
static void do_copy_blob(CopyField *copy)
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*));
300
300
static void do_conv_blob(CopyField *copy)
302
302
copy->from_field->val_str(©->tmp);
303
303
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
305
copy->tmp.charset());
305
copy->tmp.charset());
308
308
/** Save blob in copy->tmp for GROUP BY. */
421
421
static void do_expand_binary(CopyField *copy)
423
423
const CHARSET_INFO * const cs= copy->from_field->charset();
424
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
424
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
425
425
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
426
copy->to_length-copy->from_length, '\0');
426
copy->to_length-copy->from_length, '\0');
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)
504
504
if (current_session->count_cuted_fields)
525
525
void CopyField::set(unsigned char *to,Field *from)
529
from_length=from->pack_length();
529
from_length= from->pack_length();
530
530
if (from->maybe_null())
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++;
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++;
537
537
if (from->table->maybe_null)
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;
543
do_copy= do_field_to_null_str;
543
do_copy= do_field_to_null_str;
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;
570
570
if (to->type() == DRIZZLE_TYPE_NULL)
572
to_null_ptr=0; // For easy debugging
572
to_null_ptr= 0; // For easy debugging
580
from_length=from->pack_length();
582
to_length=to_field->pack_length();
580
from_length= from->pack_length();
582
to_length= to_field->pack_length();
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())
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())
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;
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;
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))
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)
665
if (to->result_type() != STRING_RESULT)
667
return do_field_int; // Convert SET to number
670
return do_field_string;
667
674
if (to->real_type() == DRIZZLE_TYPE_ENUM)
669
if (!to->eq_def(from))
676
if (!to->eq_def(from))
671
678
if (from->real_type() == DRIZZLE_TYPE_ENUM &&
672
679
to->real_type() == DRIZZLE_TYPE_ENUM)
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)
682
689
if (((Field_varstring*) to)->length_bytes !=
683
690
((Field_varstring*) from)->length_bytes)
684
692
return do_field_string;
685
695
if (to_length != from_length)
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));
692
704
else if (to_length < from_length)
693
return (from->charset()->mbmaxlen == 1 ?
706
return (from->charset()->mbmaxlen == 1 ?
694
707
do_cut_string : do_cut_string_complex);
695
709
else if (to_length > from_length)
697
711
if (to->charset() == &my_charset_bin)
700
714
return do_expand_string;
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)
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)
712
726
return do_field_real;
716
730
if (!to->eq_def(from) || !compatible_db_low_byte_first)
718
if (to->result_type() == INT_RESULT)
721
return do_field_real;
732
if (to->result_type() == INT_RESULT)
735
return do_field_real;
727
743
case 1: return do_field_1;
728
744
case 2: return do_field_2;
729
745
case 3: return do_field_3;