46
46
#include <drizzled/field/varstring.h>
49
static void do_field_eq(Copy_field *copy)
51
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
54
static void do_field_1(Copy_field *copy)
56
copy->to_ptr[0]=copy->from_ptr[0];
59
static void do_field_2(Copy_field *copy)
61
copy->to_ptr[0]=copy->from_ptr[0];
62
copy->to_ptr[1]=copy->from_ptr[1];
65
static void do_field_3(Copy_field *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];
72
static void do_field_4(Copy_field *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];
80
static void do_field_6(Copy_field *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];
90
static void do_field_8(Copy_field *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];
103
static void do_field_to_null_str(Copy_field *copy)
49
static void do_field_eq(CopyField *copy)
51
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
54
static void do_field_1(CopyField *copy)
56
copy->to_ptr[0]= copy->from_ptr[0];
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];
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];
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];
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];
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];
103
static void do_field_to_null_str(CopyField *copy)
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);
118
static void do_outer_field_to_null_str(Copy_field *copy)
118
static void do_outer_field_to_null_str(CopyField *copy)
120
120
if (*copy->null_row ||
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
static void do_copy_blob(Copy_field *copy)
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
static void do_conv_blob(Copy_field *copy)
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. */
310
static void do_save_blob(Copy_field *copy)
310
static void do_save_blob(CopyField *copy)
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(),
318
copy->tmp.charset());
318
copy->tmp.charset());
322
static void do_field_string(Copy_field *copy)
322
static void do_field_string(CopyField *copy)
324
324
char buff[MAX_FIELD_WIDTH];
325
325
copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
421
static void do_expand_binary(Copy_field *copy)
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');
431
static void do_expand_string(Copy_field *copy)
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, ' ');
440
static void do_varstring1(Copy_field *copy)
421
static void do_expand_binary(CopyField *copy)
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');
431
static void do_expand_string(CopyField *copy)
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, ' ');
440
static void do_varstring1(CopyField *copy)
442
442
uint32_t length= (uint32_t) *(unsigned char*) copy->from_ptr;
443
443
if (length > copy->to_length- 1)
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);
522
522
The 'to' buffer should have a size of field->pack_length()+1
525
void Copy_field::set(unsigned char *to,Field *from)
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;
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.
568
void Copy_field::set(Field *to,Field *from,bool save)
568
void CopyField::set(Field *to,Field *from,bool save)
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;