24
24
gives much more speed.
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)
27
#include <drizzled/server_includes.h>
29
static void do_field_eq(Copy_field *copy)
31
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
34
static void do_field_1(Copy_field *copy)
36
copy->to_ptr[0]=copy->from_ptr[0];
39
static void do_field_2(Copy_field *copy)
41
copy->to_ptr[0]=copy->from_ptr[0];
42
copy->to_ptr[1]=copy->from_ptr[1];
45
static void do_field_3(Copy_field *copy)
47
copy->to_ptr[0]=copy->from_ptr[0];
48
copy->to_ptr[1]=copy->from_ptr[1];
49
copy->to_ptr[2]=copy->from_ptr[2];
52
static void do_field_4(Copy_field *copy)
54
copy->to_ptr[0]=copy->from_ptr[0];
55
copy->to_ptr[1]=copy->from_ptr[1];
56
copy->to_ptr[2]=copy->from_ptr[2];
57
copy->to_ptr[3]=copy->from_ptr[3];
60
static void do_field_6(Copy_field *copy)
62
copy->to_ptr[0]=copy->from_ptr[0];
63
copy->to_ptr[1]=copy->from_ptr[1];
64
copy->to_ptr[2]=copy->from_ptr[2];
65
copy->to_ptr[3]=copy->from_ptr[3];
66
copy->to_ptr[4]=copy->from_ptr[4];
67
copy->to_ptr[5]=copy->from_ptr[5];
70
static void do_field_8(Copy_field *copy)
72
copy->to_ptr[0]=copy->from_ptr[0];
73
copy->to_ptr[1]=copy->from_ptr[1];
74
copy->to_ptr[2]=copy->from_ptr[2];
75
copy->to_ptr[3]=copy->from_ptr[3];
76
copy->to_ptr[4]=copy->from_ptr[4];
77
copy->to_ptr[5]=copy->from_ptr[5];
78
copy->to_ptr[6]=copy->from_ptr[6];
79
copy->to_ptr[7]=copy->from_ptr[7];
83
static void do_field_to_null_str(Copy_field *copy)
107
85
if (*copy->from_null_ptr & copy->from_bit)
109
87
memset(copy->to_ptr, 0, copy->from_length);
110
copy->to_null_ptr[0]= 1; // Always bit 1
88
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);
92
copy->to_null_ptr[0]=0;
93
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
120
static void do_outer_field_to_null_str(CopyField *copy)
98
static void do_outer_field_to_null_str(Copy_field *copy)
122
100
if (*copy->null_row ||
123
101
(copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
125
103
memset(copy->to_ptr, 0, copy->from_length);
126
copy->to_null_ptr[0]= 1; // Always bit 1
104
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);
108
copy->to_null_ptr[0]=0;
109
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
295
static void do_copy_blob(CopyField *copy)
273
static void do_copy_blob(Copy_field *copy)
297
ulong length= ((Field_blob*) copy->from_field)->get_length();
275
ulong length=((Field_blob*) copy->from_field)->get_length();
298
276
((Field_blob*) copy->to_field)->store_length(length);
299
memcpy(copy->to_ptr, copy->from_ptr, sizeof(char*));
277
memcpy(copy->to_ptr,copy->from_ptr,sizeof(char*));
302
static void do_conv_blob(CopyField *copy)
280
static void do_conv_blob(Copy_field *copy)
304
282
copy->from_field->val_str(©->tmp);
305
283
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
307
copy->tmp.charset());
285
copy->tmp.charset());
310
288
/** Save blob in copy->tmp for GROUP BY. */
312
static void do_save_blob(CopyField *copy)
290
static void do_save_blob(Copy_field *copy)
314
292
char buff[MAX_FIELD_WIDTH];
315
String res(buff, sizeof(buff), copy->tmp.charset());
293
String res(buff,sizeof(buff),copy->tmp.charset());
316
294
copy->from_field->val_str(&res);
317
295
copy->tmp.copy(res);
318
296
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
320
copy->tmp.charset());
298
copy->tmp.charset());
324
static void do_field_string(CopyField *copy)
302
static void do_field_string(Copy_field *copy)
326
304
char buff[MAX_FIELD_WIDTH];
327
305
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;
401
static void do_expand_binary(Copy_field *copy)
403
const CHARSET_INFO * const cs= copy->from_field->charset();
404
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
405
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
406
copy->to_length-copy->from_length, '\0');
411
static void do_expand_string(Copy_field *copy)
413
const CHARSET_INFO * const cs= copy->from_field->charset();
414
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
415
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
416
copy->to_length-copy->from_length, ' ');
420
static void do_varstring1(Copy_field *copy)
422
uint32_t length= (uint) *(unsigned char*) copy->from_ptr;
445
423
if (length > copy->to_length- 1)
447
length= copy->to_length - 1;
425
length=copy->to_length - 1;
448
426
if (copy->from_field->table->in_use->count_cuted_fields)
449
427
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
428
ER_WARN_DATA_TRUNCATED, 1);
499
477
uint32_t from_length= uint2korr(copy->from_ptr);
500
478
const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
501
479
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
502
(char*) from_beg + from_length,
503
char_length, &well_formed_error);
480
(char*) from_beg + from_length,
481
char_length, &well_formed_error);
504
482
if (length < from_length)
506
if (current_session->count_cuted_fields)
484
if (current_thd->count_cuted_fields)
507
485
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
508
486
ER_WARN_DATA_TRUNCATED, 1);
510
488
int2store(copy->to_ptr, length);
511
489
memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
515
493
/***************************************************************************
516
** The different functions that fills in a CopyField class
494
** The different functions that fills in a Copy_field class
517
495
***************************************************************************/
524
502
The 'to' buffer should have a size of field->pack_length()+1
527
void CopyField::set(unsigned char *to,Field *from)
505
void Copy_field::set(unsigned char *to,Field *from)
531
from_length= from->pack_length();
509
from_length=from->pack_length();
532
510
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++;
512
from_null_ptr=from->null_ptr;
513
from_bit= from->null_bit;
514
to_ptr[0]= 1; // Null as default value
515
to_null_ptr= (unsigned char*) to_ptr++;
539
517
if (from->table->maybe_null)
541
null_row= &from->table->null_row;
542
do_copy= do_outer_field_to_null_str;
519
null_row= &from->table->null_row;
520
do_copy= do_outer_field_to_null_str;
545
do_copy= do_field_to_null_str;
523
do_copy= do_field_to_null_str;
549
to_null_ptr= 0; // For easy debugging
550
do_copy= do_field_eq;
527
to_null_ptr= 0; // For easy debugging
528
do_copy= do_field_eq;
558
536
If 'save\ is set to true and the 'from' is a blob field, do_copy is set to
559
537
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
540
- do_save_blob allocates and uses an intermediate buffer before calling
541
Field_blob::store. Is this in order to trigger the call to
564
542
well_formed_copy_nchars, by changing the pointer copy->tmp.ptr()?
565
543
That call will take place anyway in all known cases.
567
- The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended
545
- The above causes a truncation to MAX_FIELD_WIDTH. Is this the intended
568
546
effect? Truncation is handled by well_formed_copy_nchars anyway.
570
void CopyField::set(Field *to,Field *from,bool save)
548
void Copy_field::set(Field *to,Field *from,bool save)
572
550
if (to->type() == DRIZZLE_TYPE_NULL)
574
to_null_ptr= 0; // For easy debugging
552
to_null_ptr=0; // For easy debugging
582
from_length= from->pack_length();
584
to_length= to_field->pack_length();
560
from_length=from->pack_length();
562
to_length=to_field->pack_length();
586
564
// set up null handling
587
from_null_ptr= to_null_ptr= 0;
565
from_null_ptr=to_null_ptr=0;
588
566
if (from->maybe_null())
590
from_null_ptr= from->null_ptr;
591
from_bit= from->null_bit;
568
from_null_ptr= from->null_ptr;
569
from_bit= from->null_bit;
592
570
if (to_field->real_maybe_null())
594
to_null_ptr= to->null_ptr;
595
to_bit= to->null_bit;
572
to_null_ptr= to->null_ptr;
573
to_bit= to->null_bit;
596
574
if (from_null_ptr)
597
do_copy= do_copy_null;
575
do_copy= do_copy_null;
600
null_row= &from->table->null_row;
601
do_copy= do_outer_field_null;
578
null_row= &from->table->null_row;
579
do_copy= do_outer_field_null;
762
723
!(to->type() == DRIZZLE_TYPE_BLOB && to->table->copy_blobs))
764
725
/* 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))) &&
726
if (to->pack_length() == from->pack_length() &&
727
!(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
728
to->real_type() != DRIZZLE_TYPE_ENUM &&
729
(to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
769
730
from->charset() == to->charset() &&
770
731
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)) &&
732
(!(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
733
(from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
773
734
{ // Identical fields
774
736
/* This may happen if one does 'UPDATE ... SET x=x' */
775
737
if (to->ptr != from->ptr)
776
739
memcpy(to->ptr,from->ptr,to->pack_length());