371
370
{ // Shorter string field
372
371
int well_formed_error;
373
372
const CHARSET_INFO * const cs= copy->from_field->charset();
374
const unsigned char *from_end= copy->from_ptr + copy->from_length;
375
uint32_t copy_length= cs->cset->well_formed_len(cs,
373
const uchar *from_end= copy->from_ptr + copy->from_length;
374
uint copy_length= cs->cset->well_formed_len(cs,
376
375
(char*) copy->from_ptr,
377
376
(char*) from_end,
378
377
copy->to_length / cs->mbmaxlen,
421
420
static void do_varstring1(Copy_field *copy)
423
uint32_t length= (uint) *(unsigned char*) copy->from_ptr;
422
uint length= (uint) *(uchar*) copy->from_ptr;
424
423
if (length > copy->to_length- 1)
426
425
length=copy->to_length - 1;
428
427
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
429
428
ER_WARN_DATA_TRUNCATED, 1);
431
*(unsigned char*) copy->to_ptr= (unsigned char) length;
430
*(uchar*) copy->to_ptr= (uchar) length;
432
431
memcpy(copy->to_ptr+1, copy->from_ptr + 1, length);
438
437
int well_formed_error;
439
438
const CHARSET_INFO * const cs= copy->from_field->charset();
440
uint32_t from_length= (uint) *(unsigned char*) copy->from_ptr;
441
const unsigned char *from_ptr= copy->from_ptr + 1;
442
uint32_t to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
443
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_ptr,
439
uint from_length= (uint) *(uchar*) copy->from_ptr;
440
const uchar *from_ptr= copy->from_ptr + 1;
441
uint to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
442
uint length= cs->cset->well_formed_len(cs, (char*) from_ptr,
444
443
(char*) from_ptr + from_length,
445
444
to_char_length, &well_formed_error);
446
445
if (length < from_length)
448
if (current_session->count_cuted_fields)
447
if (current_thd->count_cuted_fields)
449
448
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
450
449
ER_WARN_DATA_TRUNCATED, 1);
452
*copy->to_ptr= (unsigned char) length;
451
*copy->to_ptr= (uchar) length;
453
452
memcpy(copy->to_ptr + 1, from_ptr, length);
457
456
static void do_varstring2(Copy_field *copy)
459
uint32_t length=uint2korr(copy->from_ptr);
458
uint length=uint2korr(copy->from_ptr);
460
459
if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
462
461
length=copy->to_length-HA_KEY_BLOB_LENGTH;
475
474
int well_formed_error;
476
475
const CHARSET_INFO * const cs= copy->from_field->charset();
477
uint32_t char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
478
uint32_t from_length= uint2korr(copy->from_ptr);
479
const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
480
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
476
uint char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
477
uint from_length= uint2korr(copy->from_ptr);
478
const uchar *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
479
uint length= cs->cset->well_formed_len(cs, (char*) from_beg,
481
480
(char*) from_beg + from_length,
482
481
char_length, &well_formed_error);
483
482
if (length < from_length)
485
if (current_session->count_cuted_fields)
484
if (current_thd->count_cuted_fields)
486
485
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
487
486
ER_WARN_DATA_TRUNCATED, 1);
513
512
from_null_ptr=from->null_ptr;
514
513
from_bit= from->null_bit;
515
514
to_ptr[0]= 1; // Null as default value
516
to_null_ptr= (unsigned char*) to_ptr++;
515
to_null_ptr= (uchar*) to_ptr++;
518
517
if (from->table->maybe_null)
639
638
if (to->real_type() != from->real_type() ||
640
639
!compatible_db_low_byte_first ||
641
(((to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_NEWDATE) || to->type() == DRIZZLE_TYPE_DATETIME))
640
(((to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) && to->type() == DRIZZLE_TYPE_NEWDATE) || to->type() == DRIZZLE_TYPE_DATETIME))
643
if (from->real_type() == DRIZZLE_TYPE_ENUM)
642
if (from->real_type() == DRIZZLE_TYPE_ENUM ||
643
from->real_type() == DRIZZLE_TYPE_SET)
644
644
if (to->result_type() != STRING_RESULT)
645
645
return do_field_int; // Convert SET to number
646
646
return do_field_string;
648
if (to->real_type() == DRIZZLE_TYPE_ENUM)
648
if (to->real_type() == DRIZZLE_TYPE_ENUM ||
649
to->real_type() == DRIZZLE_TYPE_SET)
650
651
if (!to->eq_def(from))
727
728
if (to->pack_length() == from->pack_length() &&
728
729
!(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
729
730
to->real_type() != DRIZZLE_TYPE_ENUM &&
731
to->real_type() != DRIZZLE_TYPE_SET &&
730
732
(to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
731
733
from->charset() == to->charset() &&
732
734
to->table->s->db_low_byte_first == from->table->s->db_low_byte_first &&
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)) &&
735
(!(to->table->in_use->variables.sql_mode & (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | MODE_INVALID_DATES)) || (to->type() != DRIZZLE_TYPE_NEWDATE && to->type() != DRIZZLE_TYPE_DATETIME)) &&
734
736
(from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
735
737
{ // Identical fields
736
738
#ifdef HAVE_purify
765
767
else if ((from->result_type() == STRING_RESULT &&
766
768
(to->result_type() == STRING_RESULT ||
767
(from->real_type() != DRIZZLE_TYPE_ENUM))))
769
(from->real_type() != DRIZZLE_TYPE_ENUM &&
770
from->real_type() != DRIZZLE_TYPE_SET))))
769
772
char buff[MAX_FIELD_WIDTH];
770
773
String result(buff,sizeof(buff),from->charset());