24
24
gives much more speed.
27
#include <drizzled/server_includes.h>
28
28
#include <drizzled/error.h>
29
#include <drizzled/table.h>
30
#include <drizzled/session.h>
32
#include <drizzled/field/str.h>
33
#include <drizzled/field/num.h>
34
#include <drizzled/field/blob.h>
35
#include <drizzled/field/enum.h>
36
#include <drizzled/field/null.h>
37
#include <drizzled/field/date.h>
38
#include <drizzled/field/decimal.h>
39
#include <drizzled/field/real.h>
40
#include <drizzled/field/double.h>
41
#include <drizzled/field/long.h>
42
#include <drizzled/field/int64_t.h>
43
#include <drizzled/field/num.h>
44
#include <drizzled/field/timestamp.h>
45
#include <drizzled/field/datetime.h>
46
#include <drizzled/field/varstring.h>
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)
30
static void do_field_eq(Copy_field *copy)
32
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
35
static void do_field_1(Copy_field *copy)
37
copy->to_ptr[0]=copy->from_ptr[0];
40
static void do_field_2(Copy_field *copy)
42
copy->to_ptr[0]=copy->from_ptr[0];
43
copy->to_ptr[1]=copy->from_ptr[1];
46
static void do_field_3(Copy_field *copy)
48
copy->to_ptr[0]=copy->from_ptr[0];
49
copy->to_ptr[1]=copy->from_ptr[1];
50
copy->to_ptr[2]=copy->from_ptr[2];
53
static void do_field_4(Copy_field *copy)
55
copy->to_ptr[0]=copy->from_ptr[0];
56
copy->to_ptr[1]=copy->from_ptr[1];
57
copy->to_ptr[2]=copy->from_ptr[2];
58
copy->to_ptr[3]=copy->from_ptr[3];
61
static void do_field_6(Copy_field *copy)
63
copy->to_ptr[0]=copy->from_ptr[0];
64
copy->to_ptr[1]=copy->from_ptr[1];
65
copy->to_ptr[2]=copy->from_ptr[2];
66
copy->to_ptr[3]=copy->from_ptr[3];
67
copy->to_ptr[4]=copy->from_ptr[4];
68
copy->to_ptr[5]=copy->from_ptr[5];
71
static void do_field_8(Copy_field *copy)
73
copy->to_ptr[0]=copy->from_ptr[0];
74
copy->to_ptr[1]=copy->from_ptr[1];
75
copy->to_ptr[2]=copy->from_ptr[2];
76
copy->to_ptr[3]=copy->from_ptr[3];
77
copy->to_ptr[4]=copy->from_ptr[4];
78
copy->to_ptr[5]=copy->from_ptr[5];
79
copy->to_ptr[6]=copy->from_ptr[6];
80
copy->to_ptr[7]=copy->from_ptr[7];
84
static void do_field_to_null_str(Copy_field *copy)
107
86
if (*copy->from_null_ptr & copy->from_bit)
109
88
memset(copy->to_ptr, 0, copy->from_length);
110
copy->to_null_ptr[0]= 1; // Always bit 1
89
copy->to_null_ptr[0]=1; // Always bit 1
114
copy->to_null_ptr[0]= 0;
115
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
93
copy->to_null_ptr[0]=0;
94
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
120
static void do_outer_field_to_null_str(CopyField *copy)
99
static void do_outer_field_to_null_str(Copy_field *copy)
122
101
if (*copy->null_row ||
123
102
(copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
125
104
memset(copy->to_ptr, 0, copy->from_length);
126
copy->to_null_ptr[0]= 1; // Always bit 1
105
copy->to_null_ptr[0]=1; // Always bit 1
130
copy->to_null_ptr[0]= 0;
131
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
109
copy->to_null_ptr[0]=0;
110
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
295
static void do_copy_blob(CopyField *copy)
274
static void do_copy_blob(Copy_field *copy)
297
ulong length= ((Field_blob*) copy->from_field)->get_length();
276
ulong length=((Field_blob*) copy->from_field)->get_length();
298
277
((Field_blob*) copy->to_field)->store_length(length);
299
memcpy(copy->to_ptr, copy->from_ptr, sizeof(char*));
278
memcpy(copy->to_ptr,copy->from_ptr,sizeof(char*));
302
static void do_conv_blob(CopyField *copy)
281
static void do_conv_blob(Copy_field *copy)
304
283
copy->from_field->val_str(©->tmp);
305
284
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
307
copy->tmp.charset());
286
copy->tmp.charset());
310
289
/** Save blob in copy->tmp for GROUP BY. */
312
static void do_save_blob(CopyField *copy)
291
static void do_save_blob(Copy_field *copy)
314
293
char buff[MAX_FIELD_WIDTH];
315
String res(buff, sizeof(buff), copy->tmp.charset());
294
String res(buff,sizeof(buff),copy->tmp.charset());
316
295
copy->from_field->val_str(&res);
317
296
copy->tmp.copy(res);
318
297
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
320
copy->tmp.charset());
299
copy->tmp.charset());
324
static void do_field_string(CopyField *copy)
303
static void do_field_string(Copy_field *copy)
326
305
char buff[MAX_FIELD_WIDTH];
327
306
copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
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)
444
uint32_t length= (uint32_t) *(unsigned char*) copy->from_ptr;
402
static void do_expand_binary(Copy_field *copy)
404
const CHARSET_INFO * const cs= copy->from_field->charset();
405
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
406
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
407
copy->to_length-copy->from_length, '\0');
412
static void do_expand_string(Copy_field *copy)
414
const CHARSET_INFO * const cs= copy->from_field->charset();
415
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
416
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
417
copy->to_length-copy->from_length, ' ');
421
static void do_varstring1(Copy_field *copy)
423
uint32_t length= (uint) *(unsigned char*) copy->from_ptr;
445
424
if (length > copy->to_length- 1)
447
length= copy->to_length - 1;
426
length=copy->to_length - 1;
448
427
if (copy->from_field->table->in_use->count_cuted_fields)
449
428
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
429
ER_WARN_DATA_TRUNCATED, 1);
499
478
uint32_t from_length= uint2korr(copy->from_ptr);
500
479
const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
501
480
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
502
(char*) from_beg + from_length,
503
char_length, &well_formed_error);
481
(char*) from_beg + from_length,
482
char_length, &well_formed_error);
504
483
if (length < from_length)
506
485
if (current_session->count_cuted_fields)
507
486
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
508
487
ER_WARN_DATA_TRUNCATED, 1);
510
489
int2store(copy->to_ptr, length);
511
490
memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
515
494
/***************************************************************************
516
** The different functions that fills in a CopyField class
495
** The different functions that fills in a Copy_field class
517
496
***************************************************************************/
524
503
The 'to' buffer should have a size of field->pack_length()+1
527
void CopyField::set(unsigned char *to,Field *from)
506
void Copy_field::set(unsigned char *to,Field *from)
531
from_length= from->pack_length();
510
from_length=from->pack_length();
532
511
if (from->maybe_null())
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++;
513
from_null_ptr=from->null_ptr;
514
from_bit= from->null_bit;
515
to_ptr[0]= 1; // Null as default value
516
to_null_ptr= (unsigned char*) to_ptr++;
539
518
if (from->table->maybe_null)
541
null_row= &from->table->null_row;
542
do_copy= do_outer_field_to_null_str;
520
null_row= &from->table->null_row;
521
do_copy= do_outer_field_to_null_str;
545
do_copy= do_field_to_null_str;
524
do_copy= do_field_to_null_str;
549
to_null_ptr= 0; // For easy debugging
550
do_copy= do_field_eq;
528
to_null_ptr= 0; // For easy debugging
529
do_copy= do_field_eq;
558
537
If 'save\ is set to true and the 'from' is a blob field, do_copy is set to
559
538
do_save_blob rather than do_conv_blob. The only differences between them
562
- do_save_blob allocates and uses an intermediate buffer before calling
563
Field_blob::store. Is this in order to trigger the call to
541
- do_save_blob allocates and uses an intermediate buffer before calling
542
Field_blob::store. Is this in order to trigger the call to
564
543
well_formed_copy_nchars, by changing the pointer copy->tmp.ptr()?
565
544
That call will take place anyway in all known cases.
567
- The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended
546
- The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended
568
547
effect? Truncation is handled by well_formed_copy_nchars anyway.
570
void CopyField::set(Field *to,Field *from,bool save)
549
void Copy_field::set(Field *to,Field *from,bool save)
572
551
if (to->type() == DRIZZLE_TYPE_NULL)
574
to_null_ptr= 0; // For easy debugging
553
to_null_ptr=0; // For easy debugging
582
from_length= from->pack_length();
584
to_length= to_field->pack_length();
561
from_length=from->pack_length();
563
to_length=to_field->pack_length();
586
565
// set up null handling
587
from_null_ptr= to_null_ptr= 0;
566
from_null_ptr=to_null_ptr=0;
588
567
if (from->maybe_null())
590
from_null_ptr= from->null_ptr;
591
from_bit= from->null_bit;
569
from_null_ptr= from->null_ptr;
570
from_bit= from->null_bit;
592
571
if (to_field->real_maybe_null())
594
to_null_ptr= to->null_ptr;
595
to_bit= to->null_bit;
573
to_null_ptr= to->null_ptr;
574
to_bit= to->null_bit;
596
575
if (from_null_ptr)
597
do_copy= do_copy_null;
576
do_copy= do_copy_null;
600
null_row= &from->table->null_row;
601
do_copy= do_outer_field_null;
579
null_row= &from->table->null_row;
580
do_copy= do_outer_field_null;
762
724
!(to->type() == DRIZZLE_TYPE_BLOB && to->table->copy_blobs))
764
726
/* Please god, will someone rewrite this to be readable :( */
765
if (to->pack_length() == from->pack_length() &&
766
!(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
767
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))) &&
727
if (to->pack_length() == from->pack_length() &&
728
!(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
729
to->real_type() != DRIZZLE_TYPE_ENUM &&
730
(to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
769
731
from->charset() == to->charset() &&
770
732
to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
771
(!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_DATE && to->type() != DRIZZLE_TYPE_DATETIME)) &&
733
(!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_NEWDATE && to->type() != DRIZZLE_TYPE_DATETIME)) &&
772
734
(from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
773
735
{ // Identical fields
774
737
/* This may happen if one does 'UPDATE ... SET x=x' */
775
738
if (to->ptr != from->ptr)
776
740
memcpy(to->ptr,from->ptr,to->pack_length());