46
45
#include <drizzled/field/datetime.h>
47
46
#include <drizzled/field/varstring.h>
50
static void do_field_eq(Copy_field *copy)
52
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
55
static void do_field_1(Copy_field *copy)
57
copy->to_ptr[0]=copy->from_ptr[0];
60
static void do_field_2(Copy_field *copy)
62
copy->to_ptr[0]=copy->from_ptr[0];
63
copy->to_ptr[1]=copy->from_ptr[1];
66
static void do_field_3(Copy_field *copy)
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];
73
static void do_field_4(Copy_field *copy)
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];
81
static void do_field_6(Copy_field *copy)
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];
91
static void do_field_8(Copy_field *copy)
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];
104
static void do_field_to_null_str(Copy_field *copy)
51
static void do_field_eq(CopyField *copy)
53
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
56
static void do_field_1(CopyField *copy)
58
copy->to_ptr[0]= copy->from_ptr[0];
61
static void do_field_2(CopyField *copy)
63
copy->to_ptr[0]= copy->from_ptr[0];
64
copy->to_ptr[1]= copy->from_ptr[1];
67
static void do_field_3(CopyField *copy)
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];
74
static void do_field_4(CopyField *copy)
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];
82
static void do_field_6(CopyField *copy)
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];
92
static void do_field_8(CopyField *copy)
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];
105
static void do_field_to_null_str(CopyField *copy)
106
107
if (*copy->from_null_ptr & copy->from_bit)
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
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);
119
static void do_outer_field_to_null_str(Copy_field *copy)
120
static void do_outer_field_to_null_str(CopyField *copy)
121
122
if (*copy->null_row ||
122
123
(copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
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
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);
294
static void do_copy_blob(Copy_field *copy)
295
static void do_copy_blob(CopyField *copy)
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*));
301
static void do_conv_blob(Copy_field *copy)
302
static void do_conv_blob(CopyField *copy)
303
304
copy->from_field->val_str(©->tmp);
304
305
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
306
copy->tmp.charset());
307
copy->tmp.charset());
309
310
/** Save blob in copy->tmp for GROUP BY. */
311
static void do_save_blob(Copy_field *copy)
312
static void do_save_blob(CopyField *copy)
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(),
319
copy->tmp.charset());
320
copy->tmp.charset());
323
static void do_field_string(Copy_field *copy)
324
static void do_field_string(CopyField *copy)
325
326
char buff[MAX_FIELD_WIDTH];
326
327
copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
422
static void do_expand_binary(Copy_field *copy)
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');
432
static void do_expand_string(Copy_field *copy)
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, ' ');
441
static void do_varstring1(Copy_field *copy)
423
static void do_expand_binary(CopyField *copy)
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');
433
static void do_expand_string(CopyField *copy)
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, ' ');
442
static void do_varstring1(CopyField *copy)
443
444
uint32_t length= (uint32_t) *(unsigned char*) copy->from_ptr;
444
445
if (length > copy->to_length- 1)
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);
523
524
The 'to' buffer should have a size of field->pack_length()+1
526
void Copy_field::set(unsigned char *to,Field *from)
527
void CopyField::set(unsigned char *to,Field *from)
530
from_length=from->pack_length();
531
from_length= from->pack_length();
531
532
if (from->maybe_null())
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++;
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
539
if (from->table->maybe_null)
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;
544
do_copy= do_field_to_null_str;
545
do_copy= do_field_to_null_str;
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;
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.
569
void Copy_field::set(Field *to,Field *from,bool save)
570
void CopyField::set(Field *to,Field *from,bool save)
571
572
if (to->type() == DRIZZLE_TYPE_NULL)
573
to_null_ptr=0; // For easy debugging
574
to_null_ptr= 0; // For easy debugging
581
from_length=from->pack_length();
583
to_length=to_field->pack_length();
582
from_length= from->pack_length();
584
to_length= to_field->pack_length();
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())
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())
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;
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;