124
124
if (field->table->in_use->count_cuted_fields == CHECK_FIELD_WARN)
126
field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
126
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
129
129
if (!field->table->in_use->no_errors)
180
180
if (field->table->in_use->count_cuted_fields == CHECK_FIELD_WARN)
182
field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
182
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
185
185
if (!field->table->in_use->no_errors)
229
229
if (*copy->from_null_ptr & copy->from_bit)
231
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
231
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
232
232
ER_WARN_DATA_TRUNCATED, 1);
233
233
copy->to_field->reset();
347
347
static void do_cut_string(Copy_field *copy)
349
const CHARSET_INFO * const cs= copy->from_field->charset();
349
CHARSET_INFO *cs= copy->from_field->charset();
350
350
memcpy(copy->to_ptr,copy->from_ptr,copy->to_length);
352
352
/* Check if we loosed any important characters */
355
355
(char*) copy->from_ptr + copy->from_length,
356
356
MY_SEQ_SPACES) < copy->from_length - copy->to_length)
358
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
358
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
359
359
ER_WARN_DATA_TRUNCATED, 1);
369
369
static void do_cut_string_complex(Copy_field *copy)
370
370
{ // Shorter string field
371
371
int well_formed_error;
372
const CHARSET_INFO * const cs= copy->from_field->charset();
373
const unsigned char *from_end= copy->from_ptr + copy->from_length;
374
uint32_t copy_length= cs->cset->well_formed_len(cs,
372
CHARSET_INFO *cs= copy->from_field->charset();
373
const uchar *from_end= copy->from_ptr + copy->from_length;
374
uint copy_length= cs->cset->well_formed_len(cs,
375
375
(char*) copy->from_ptr,
376
376
(char*) from_end,
377
377
copy->to_length / cs->mbmaxlen,
386
386
(char*) from_end,
387
387
MY_SEQ_SPACES) < (copy->from_length - copy_length))
389
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
389
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
390
390
ER_WARN_DATA_TRUNCATED, 1);
401
401
static void do_expand_binary(Copy_field *copy)
403
const CHARSET_INFO * const cs= copy->from_field->charset();
403
CHARSET_INFO *cs= copy->from_field->charset();
404
404
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
405
405
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
406
406
copy->to_length-copy->from_length, '\0');
411
411
static void do_expand_string(Copy_field *copy)
413
const CHARSET_INFO * const cs= copy->from_field->charset();
413
CHARSET_INFO *cs= copy->from_field->charset();
414
414
memcpy(copy->to_ptr,copy->from_ptr,copy->from_length);
415
415
cs->cset->fill(cs, (char*) copy->to_ptr+copy->from_length,
416
416
copy->to_length-copy->from_length, ' ');
420
420
static void do_varstring1(Copy_field *copy)
422
uint32_t length= (uint) *(unsigned char*) copy->from_ptr;
422
uint length= (uint) *(uchar*) copy->from_ptr;
423
423
if (length > copy->to_length- 1)
425
425
length=copy->to_length - 1;
426
426
if (copy->from_field->table->in_use->count_cuted_fields)
427
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
427
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
428
428
ER_WARN_DATA_TRUNCATED, 1);
430
*(unsigned char*) copy->to_ptr= (unsigned char) length;
430
*(uchar*) copy->to_ptr= (uchar) length;
431
431
memcpy(copy->to_ptr+1, copy->from_ptr + 1, length);
435
435
static void do_varstring1_mb(Copy_field *copy)
437
437
int well_formed_error;
438
const CHARSET_INFO * const cs= copy->from_field->charset();
439
uint32_t from_length= (uint) *(unsigned char*) copy->from_ptr;
440
const unsigned char *from_ptr= copy->from_ptr + 1;
441
uint32_t to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
442
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_ptr,
438
CHARSET_INFO *cs= copy->from_field->charset();
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,
443
443
(char*) from_ptr + from_length,
444
444
to_char_length, &well_formed_error);
445
445
if (length < from_length)
447
447
if (current_thd->count_cuted_fields)
448
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
448
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
449
449
ER_WARN_DATA_TRUNCATED, 1);
451
*copy->to_ptr= (unsigned char) length;
451
*copy->to_ptr= (uchar) length;
452
452
memcpy(copy->to_ptr + 1, from_ptr, length);
456
456
static void do_varstring2(Copy_field *copy)
458
uint32_t length=uint2korr(copy->from_ptr);
458
uint length=uint2korr(copy->from_ptr);
459
459
if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
461
461
length=copy->to_length-HA_KEY_BLOB_LENGTH;
462
462
if (copy->from_field->table->in_use->count_cuted_fields)
463
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
463
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
464
464
ER_WARN_DATA_TRUNCATED, 1);
466
466
int2store(copy->to_ptr,length);
472
472
static void do_varstring2_mb(Copy_field *copy)
474
474
int well_formed_error;
475
const CHARSET_INFO * const cs= copy->from_field->charset();
476
uint32_t char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
477
uint32_t from_length= uint2korr(copy->from_ptr);
478
const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
479
uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
475
CHARSET_INFO *cs= copy->from_field->charset();
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,
480
480
(char*) from_beg + from_length,
481
481
char_length, &well_formed_error);
482
482
if (length < from_length)
484
484
if (current_thd->count_cuted_fields)
485
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
485
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
486
486
ER_WARN_DATA_TRUNCATED, 1);
488
488
int2store(copy->to_ptr, length);
512
512
from_null_ptr=from->null_ptr;
513
513
from_bit= from->null_bit;
514
514
to_ptr[0]= 1; // Null as default value
515
to_null_ptr= (unsigned char*) to_ptr++;
515
to_null_ptr= (uchar*) to_ptr++;
517
517
if (from->table->maybe_null)
638
638
if (to->real_type() != from->real_type() ||
639
639
!compatible_db_low_byte_first ||
640
(((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))
642
if (from->real_type() == DRIZZLE_TYPE_ENUM)
642
if (from->real_type() == DRIZZLE_TYPE_ENUM ||
643
from->real_type() == DRIZZLE_TYPE_SET)
643
644
if (to->result_type() != STRING_RESULT)
644
645
return do_field_int; // Convert SET to number
645
646
return do_field_string;
647
if (to->real_type() == DRIZZLE_TYPE_ENUM)
648
if (to->real_type() == DRIZZLE_TYPE_ENUM ||
649
to->real_type() == DRIZZLE_TYPE_SET)
649
651
if (!to->eq_def(from))
726
728
if (to->pack_length() == from->pack_length() &&
727
729
!(to->flags & UNSIGNED_FLAG && !(from->flags & UNSIGNED_FLAG)) &&
728
730
to->real_type() != DRIZZLE_TYPE_ENUM &&
731
to->real_type() != DRIZZLE_TYPE_SET &&
729
732
(to->real_type() != DRIZZLE_TYPE_NEWDECIMAL || (to->field_length == from->field_length && (((Field_num*)to)->dec == ((Field_num*)from)->dec))) &&
730
733
from->charset() == to->charset() &&
731
734
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)) &&
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)) &&
733
736
(from->real_type() != DRIZZLE_TYPE_VARCHAR || ((Field_varstring*)from)->length_bytes == ((Field_varstring*)to)->length_bytes))
734
737
{ // Identical fields
735
738
#ifdef HAVE_purify
764
767
else if ((from->result_type() == STRING_RESULT &&
765
768
(to->result_type() == STRING_RESULT ||
766
(from->real_type() != DRIZZLE_TYPE_ENUM))))
769
(from->real_type() != DRIZZLE_TYPE_ENUM &&
770
from->real_type() != DRIZZLE_TYPE_SET))))
768
772
char buff[MAX_FIELD_WIDTH];
769
773
String result(buff,sizeof(buff),from->charset());