24
24
gives much more speed.
29
#include <drizzled/error.h>
30
#include <drizzled/table.h>
31
#include <drizzled/session.h>
32
#include <drizzled/current_session.h>
34
#include <drizzled/copy_field.h>
35
#include <drizzled/field/blob.h>
36
#include <drizzled/field/date.h>
37
#include <drizzled/field/datetime.h>
38
#include <drizzled/field/decimal.h>
39
#include <drizzled/field/double.h>
40
#include <drizzled/field/enum.h>
41
#include <drizzled/field/epoch.h>
42
#include <drizzled/field/int32.h>
43
#include <drizzled/field/int64.h>
44
#include <drizzled/field/null.h>
45
#include <drizzled/field/num.h>
46
#include <drizzled/field/num.h>
47
#include <drizzled/field/real.h>
48
#include <drizzled/field/str.h>
49
#include <drizzled/field/varstring.h>
54
static void do_field_eq(CopyField *copy)
56
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
59
static void do_field_1(CopyField *copy)
61
copy->to_ptr[0]= copy->from_ptr[0];
64
static void do_field_2(CopyField *copy)
66
copy->to_ptr[0]= copy->from_ptr[0];
67
copy->to_ptr[1]= copy->from_ptr[1];
70
static void do_field_3(CopyField *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];
77
static void do_field_4(CopyField *copy)
79
copy->to_ptr[0]= copy->from_ptr[0];
80
copy->to_ptr[1]= copy->from_ptr[1];
81
copy->to_ptr[2]= copy->from_ptr[2];
82
copy->to_ptr[3]= copy->from_ptr[3];
85
static void do_field_6(CopyField *copy)
87
copy->to_ptr[0]= copy->from_ptr[0];
88
copy->to_ptr[1]= copy->from_ptr[1];
89
copy->to_ptr[2]= copy->from_ptr[2];
90
copy->to_ptr[3]= copy->from_ptr[3];
91
copy->to_ptr[4]= copy->from_ptr[4];
92
copy->to_ptr[5]= copy->from_ptr[5];
95
static void do_field_8(CopyField *copy)
97
copy->to_ptr[0]= copy->from_ptr[0];
98
copy->to_ptr[1]= copy->from_ptr[1];
99
copy->to_ptr[2]= copy->from_ptr[2];
100
copy->to_ptr[3]= copy->from_ptr[3];
101
copy->to_ptr[4]= copy->from_ptr[4];
102
copy->to_ptr[5]= copy->from_ptr[5];
103
copy->to_ptr[6]= copy->from_ptr[6];
104
copy->to_ptr[7]= copy->from_ptr[7];
108
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)
110
85
if (*copy->from_null_ptr & copy->from_bit)
112
87
memset(copy->to_ptr, 0, copy->from_length);
113
copy->to_null_ptr[0]= 1; // Always bit 1
88
copy->to_null_ptr[0]=1; // Always bit 1
117
copy->to_null_ptr[0]= 0;
118
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);
123
static void do_outer_field_to_null_str(CopyField *copy)
98
static void do_outer_field_to_null_str(Copy_field *copy)
125
100
if (*copy->null_row ||
126
101
(copy->from_null_ptr && (*copy->from_null_ptr & copy->from_bit)))
128
103
memset(copy->to_ptr, 0, copy->from_length);
129
copy->to_null_ptr[0]= 1; // Always bit 1
104
copy->to_null_ptr[0]=1; // Always bit 1
133
copy->to_null_ptr[0]= 0;
134
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);
192
166
when set to NULL (TIMESTAMP fields which allow setting to NULL
193
167
are handled by first check).
195
if (field->is_timestamp())
169
if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
197
((field::Epoch::pointer) field)->set_time();
171
((Field_timestamp*) field)->set_time();
198
172
return 0; // Ok to set time to NULL
202
if (field == field->getTable()->next_number_field)
175
if (field == field->table->next_number_field)
204
field->getTable()->auto_increment_field_not_null= false;
177
field->table->auto_increment_field_not_null= false;
205
178
return 0; // field is set in fill_record()
208
if (field->getTable()->in_use->count_cuted_fields == CHECK_FIELD_WARN)
180
if (field->table->in_use->count_cuted_fields == CHECK_FIELD_WARN)
210
182
field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
214
if (!field->getTable()->in_use->no_errors)
185
if (!field->table->in_use->no_errors)
215
186
my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
221
static void do_skip(CopyField *)
191
static void do_skip(Copy_field *copy __attribute__((unused)))
226
static void do_copy_null(CopyField *copy)
196
static void do_copy_null(Copy_field *copy)
228
198
if (*copy->from_null_ptr & copy->from_bit)
230
*copy->to_null_ptr|= copy->to_bit;
200
*copy->to_null_ptr|=copy->to_bit;
231
201
copy->to_field->reset();
282
246
/* timestamp and next_number has special handling in case of NULL values */
284
static void do_copy_timestamp(CopyField *copy)
248
static void do_copy_timestamp(Copy_field *copy)
286
250
if (*copy->from_null_ptr & copy->from_bit)
288
252
/* Same as in set_field_to_null_with_conversions() */
289
((field::Epoch::pointer) copy->to_field)->set_time();
253
((Field_timestamp*) copy->to_field)->set_time();
293
256
(copy->do_copy2)(copy);
298
static void do_copy_next_number(CopyField *copy)
260
static void do_copy_next_number(Copy_field *copy)
300
262
if (*copy->from_null_ptr & copy->from_bit)
302
264
/* Same as in set_field_to_null_with_conversions() */
303
copy->to_field->getTable()->auto_increment_field_not_null= false;
265
copy->to_field->table->auto_increment_field_not_null= false;
304
266
copy->to_field->reset();
308
269
(copy->do_copy2)(copy);
313
static void do_copy_blob(CopyField *copy)
273
static void do_copy_blob(Copy_field *copy)
315
ulong length= ((Field_blob*) copy->from_field)->get_length();
275
ulong length=((Field_blob*) copy->from_field)->get_length();
316
276
((Field_blob*) copy->to_field)->store_length(length);
317
memcpy(copy->to_ptr, copy->from_ptr, sizeof(char*));
277
memcpy(copy->to_ptr,copy->from_ptr,sizeof(char*));
320
static void do_conv_blob(CopyField *copy)
280
static void do_conv_blob(Copy_field *copy)
322
copy->from_field->val_str_internal(©->tmp);
282
copy->from_field->val_str(©->tmp);
323
283
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
325
copy->tmp.charset());
285
copy->tmp.charset());
328
288
/** Save blob in copy->tmp for GROUP BY. */
330
static void do_save_blob(CopyField *copy)
290
static void do_save_blob(Copy_field *copy)
332
292
char buff[MAX_FIELD_WIDTH];
333
String res(buff, sizeof(buff), copy->tmp.charset());
334
copy->from_field->val_str_internal(&res);
293
String res(buff,sizeof(buff),copy->tmp.charset());
294
copy->from_field->val_str(&res);
335
295
copy->tmp.copy(res);
336
296
((Field_blob *) copy->to_field)->store(copy->tmp.ptr(),
338
copy->tmp.charset());
298
copy->tmp.charset());
342
static void do_field_string(CopyField *copy)
302
static void do_field_string(Copy_field *copy)
344
304
char buff[MAX_FIELD_WIDTH];
345
305
copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset());
346
copy->from_field->val_str_internal(©->tmp);
306
copy->from_field->val_str(©->tmp);
347
307
copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length(),
348
308
copy->tmp.charset());
352
static void do_field_enum(CopyField *copy)
312
static void do_field_enum(Copy_field *copy)
354
314
if (copy->from_field->val_int() == 0)
355
315
((Field_enum *) copy->to_field)->store_type((uint64_t) 0);
441
static void do_expand_binary(CopyField *copy)
443
const CHARSET_INFO * const cs= copy->from_field->charset();
444
memcpy(copy->to_ptr, copy->from_ptr, copy->from_length);
445
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
446
copy->to_length-copy->from_length, '\0');
451
static void do_expand_string(CopyField *copy)
453
const CHARSET_INFO * const cs= copy->from_field->charset();
454
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
455
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
456
copy->to_length-copy->from_length, ' ');
460
static void do_varstring1(CopyField *copy)
462
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;
463
423
if (length > copy->to_length- 1)
465
length= copy->to_length - 1;
466
if (copy->from_field->getTable()->in_use->count_cuted_fields)
425
length=copy->to_length - 1;
426
if (copy->from_field->table->in_use->count_cuted_fields)
468
427
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
469
428
ER_WARN_DATA_TRUNCATED, 1);
472
430
*(unsigned char*) copy->to_ptr= (unsigned char) length;
473
431
memcpy(copy->to_ptr+1, copy->from_ptr + 1, length);
477
static void do_varstring1_mb(CopyField *copy)
435
static void do_varstring1_mb(Copy_field *copy)
479
437
int well_formed_error;
480
438
const CHARSET_INFO * const cs= copy->from_field->charset();
481
uint32_t from_length= (uint32_t) *(unsigned char*) copy->from_ptr;
439
uint32_t from_length= (uint) *(unsigned char*) copy->from_ptr;
482
440
const unsigned char *from_ptr= copy->from_ptr + 1;
483
441
uint32_t to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
484
442
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_ptr,
486
444
to_char_length, &well_formed_error);
487
445
if (length < from_length)
489
if (current_session->count_cuted_fields)
447
if (current_thd->count_cuted_fields)
491
448
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
492
449
ER_WARN_DATA_TRUNCATED, 1);
495
451
*copy->to_ptr= (unsigned char) length;
496
452
memcpy(copy->to_ptr + 1, from_ptr, length);
500
static void do_varstring2(CopyField *copy)
456
static void do_varstring2(Copy_field *copy)
502
uint32_t length= uint2korr(copy->from_ptr);
458
uint32_t length=uint2korr(copy->from_ptr);
503
459
if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
505
461
length=copy->to_length-HA_KEY_BLOB_LENGTH;
506
if (copy->from_field->getTable()->in_use->count_cuted_fields)
462
if (copy->from_field->table->in_use->count_cuted_fields)
508
463
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
509
464
ER_WARN_DATA_TRUNCATED, 1);
512
466
int2store(copy->to_ptr,length);
513
467
memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, copy->from_ptr + HA_KEY_BLOB_LENGTH,
523
477
uint32_t from_length= uint2korr(copy->from_ptr);
524
478
const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
525
479
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
526
(char*) from_beg + from_length,
527
char_length, &well_formed_error);
480
(char*) from_beg + from_length,
481
char_length, &well_formed_error);
528
482
if (length < from_length)
530
if (current_session->count_cuted_fields)
484
if (current_thd->count_cuted_fields)
532
485
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
533
486
ER_WARN_DATA_TRUNCATED, 1);
536
488
int2store(copy->to_ptr, length);
537
489
memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
541
493
/***************************************************************************
542
** The different functions that fills in a CopyField class
494
** The different functions that fills in a Copy_field class
543
495
***************************************************************************/
550
502
The 'to' buffer should have a size of field->pack_length()+1
553
void CopyField::set(unsigned char *to,Field *from)
505
void Copy_field::set(unsigned char *to,Field *from)
557
from_length= from->pack_length();
509
from_length=from->pack_length();
558
510
if (from->maybe_null())
560
from_null_ptr= from->null_ptr;
561
from_bit= from->null_bit;
562
to_ptr[0]= 1; // Null as default value
563
to_null_ptr= (unsigned char*) to_ptr++;
565
if (from->getTable()->maybe_null)
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++;
517
if (from->table->maybe_null)
567
null_row= &from->getTable()->null_row;
568
do_copy= do_outer_field_to_null_str;
519
null_row= &from->table->null_row;
520
do_copy= do_outer_field_to_null_str;
571
do_copy= do_field_to_null_str;
523
do_copy= do_field_to_null_str;
575
to_null_ptr= 0; // For easy debugging
576
do_copy= do_field_eq;
527
to_null_ptr= 0; // For easy debugging
528
do_copy= do_field_eq;
584
536
If 'save\ is set to true and the 'from' is a blob field, do_copy is set to
585
537
do_save_blob rather than do_conv_blob. The only differences between them
588
- do_save_blob allocates and uses an intermediate buffer before calling
589
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
590
542
well_formed_copy_nchars, by changing the pointer copy->tmp.ptr()?
591
543
That call will take place anyway in all known cases.
593
- 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
594
546
effect? Truncation is handled by well_formed_copy_nchars anyway.
596
void CopyField::set(Field *to,Field *from,bool save)
548
void Copy_field::set(Field *to,Field *from,bool save)
598
550
if (to->type() == DRIZZLE_TYPE_NULL)
600
to_null_ptr= 0; // For easy debugging
552
to_null_ptr=0; // For easy debugging
608
from_length= from->pack_length();
610
to_length= to_field->pack_length();
560
from_length=from->pack_length();
562
to_length=to_field->pack_length();
612
564
// set up null handling
613
from_null_ptr= to_null_ptr= 0;
565
from_null_ptr=to_null_ptr=0;
614
566
if (from->maybe_null())
616
from_null_ptr= from->null_ptr;
617
from_bit= from->null_bit;
568
from_null_ptr= from->null_ptr;
569
from_bit= from->null_bit;
618
570
if (to_field->real_maybe_null())
620
to_null_ptr= to->null_ptr;
621
to_bit= to->null_bit;
572
to_null_ptr= to->null_ptr;
573
to_bit= to->null_bit;
622
574
if (from_null_ptr)
624
do_copy= do_copy_null;
575
do_copy= do_copy_null;
628
null_row= &from->getTable()->null_row;
629
do_copy= do_outer_field_null;
578
null_row= &from->table->null_row;
579
do_copy= do_outer_field_null;
634
if (to_field->is_timestamp())
584
if (to_field->type() == DRIZZLE_TYPE_TIMESTAMP)
636
585
do_copy= do_copy_timestamp; // Automatic timestamp
638
else if (to_field == to_field->getTable()->next_number_field)
586
else if (to_field == to_field->table->next_number_field)
640
587
do_copy= do_copy_next_number;
644
589
do_copy= do_copy_not_null;
648
592
else if (to_field->real_maybe_null())
650
to_null_ptr= to->null_ptr;
651
to_bit= to->null_bit;
594
to_null_ptr= to->null_ptr;
595
to_bit= to->null_bit;
652
596
do_copy= do_copy_maybe_null;
657
601
if ((to->flags & BLOB_FLAG) && save)
658
602
do_copy2= do_save_blob;
660
604
do_copy2= get_copy_func(to,from);
661
if (!do_copy) // Not null
605
if (!do_copy) // Not null
666
CopyField::Copy_func *
667
CopyField::get_copy_func(Field *to,Field *from)
610
Copy_field::Copy_func *
611
Copy_field::get_copy_func(Field *to,Field *from)
669
bool compatible_db_low_byte_first= (to->getTable()->getShare()->db_low_byte_first ==
670
from->getTable()->getShare()->db_low_byte_first);
613
bool compatible_db_low_byte_first= (to->table->s->db_low_byte_first ==
614
from->table->s->db_low_byte_first);
671
615
if (to->flags & BLOB_FLAG)
673
617
if (!(from->flags & BLOB_FLAG) || from->charset() != to->charset())
721
658
else if (to->charset() != from->charset())
722
return do_field_string;
659
return do_field_string;
723
660
else if (to->real_type() == DRIZZLE_TYPE_VARCHAR)
725
/* Field_blob is not part of the Field_varstring hierarchy,
726
and casting to varstring for calling pack_length_no_ptr()
727
is always incorrect. Previously the below comparison has
728
always evaluated to false as pack_length_no_ptr() for BLOB
729
will return 4 and varstring can only be <= 2.
730
If your brain slightly bleeds as to why this worked for
731
so many years, you are in no way alone.
733
if (from->flags & BLOB_FLAG)
734
return do_field_string;
736
if ((static_cast<Field_varstring*>(to))->pack_length_no_ptr() !=
737
(static_cast<Field_varstring*>(from))->pack_length_no_ptr())
739
return do_field_string;
662
if (((Field_varstring*) to)->length_bytes !=
663
((Field_varstring*) from)->length_bytes)
664
return do_field_string;
742
665
if (to_length != from_length)
744
return (((Field_varstring*) to)->pack_length_no_ptr() == 1 ?
666
return (((Field_varstring*) to)->length_bytes == 1 ?
745
667
(from->charset()->mbmaxlen == 1 ? do_varstring1 :
747
669
(from->charset()->mbmaxlen == 1 ? do_varstring2 :
751
672
else if (to_length < from_length)
753
return (from->charset()->mbmaxlen == 1 ?
673
return (from->charset()->mbmaxlen == 1 ?
754
674
do_cut_string : do_cut_string_complex);
756
675
else if (to_length > from_length)
758
677
if (to->charset() == &my_charset_bin)
804
720
int field_conv(Field *to,Field *from)
806
722
if (to->real_type() == from->real_type() &&
807
!(to->type() == DRIZZLE_TYPE_BLOB && to->getTable()->copy_blobs))
723
!(to->type() == DRIZZLE_TYPE_BLOB && to->table->copy_blobs))
809
725
/* Please god, will someone rewrite this to be readable :( */
810
if (to->pack_length() == from->pack_length() &&
811
!(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
812
to->real_type() != DRIZZLE_TYPE_ENUM &&
813
(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))) &&
814
730
from->charset() == to->charset() &&
815
to->getTable()->getShare()->db_low_byte_first == from->getTable()->getShare()->db_low_byte_first &&
816
(!(to->getTable()->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_DATE && to->type() != DRIZZLE_TYPE_DATETIME)) &&
817
(from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->pack_length_no_ptr() == ((Field_varstring*)to)->pack_length_no_ptr()))
731
to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
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)) &&
733
(from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
818
734
{ // Identical fields
819
736
/* This may happen if one does 'UPDATE ... SET x=x' */
820
737
if (to->ptr != from->ptr)
821
739
memcpy(to->ptr,from->ptr,to->pack_length());