summaryrefslogtreecommitdiff
path: root/sql/field_conv.cc
diff options
context:
space:
mode:
authorunknown <bar@mysql.com>2005-07-11 13:20:07 +0500
committerunknown <bar@mysql.com>2005-07-11 13:20:07 +0500
commitdce0304a42a7bcecc9db59a3ea7225bd8a56fe89 (patch)
tree463fbd2b1feb6bc3d505c84d6dc81866285efe01 /sql/field_conv.cc
parent8dce276058baa6ac41728d760e426c797d740f4e (diff)
downloadmariadb-git-dce0304a42a7bcecc9db59a3ea7225bd8a56fe89.tar.gz
field_conv.cc:
Bug#11591 CHAR column with utf8 does not work properly (more chars than expected) do_cut_string didn't call well_formed_length, and copied all data, which was wrong in the case of multibyte character set. ctype_utf8.result, ctype_utf8.test: adding test case sql/field_conv.cc: Bug#11591 CHAR column with utf8 does not work properly (more chars than expected) do_cut_string didn't call well_formed_length, and copied all data, which was wrong in the case of multibyte character set. mysql-test/t/ctype_utf8.test: adding test case mysql-test/r/ctype_utf8.result: adding test caser
Diffstat (limited to 'sql/field_conv.cc')
-rw-r--r--sql/field_conv.cc33
1 files changed, 20 insertions, 13 deletions
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 8b362bbf807..625586d8c9b 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -326,21 +326,28 @@ static void do_field_real(Copy_field *copy)
static void do_cut_string(Copy_field *copy)
{ // Shorter string field
- memcpy(copy->to_ptr,copy->from_ptr,copy->to_length);
-
- /* Check if we loosed any important characters */
- char *ptr,*end;
- for (ptr=copy->from_ptr+copy->to_length,end=copy->from_ptr+copy->from_length ;
- ptr != end ;
- ptr++)
+ int well_formed_error;
+ CHARSET_INFO *cs= copy->from_field->charset();
+ const char *from_end= copy->from_ptr + copy->from_length;
+ uint copy_length= cs->cset->well_formed_len(cs, copy->from_ptr, from_end,
+ copy->to_length / cs->mbmaxlen,
+ &well_formed_error);
+ if (copy->to_length < copy_length)
+ copy_length= copy->to_length;
+ memcpy(copy->to_ptr, copy->from_ptr, copy_length);
+
+ /* Check if we lost any important characters */
+ if (well_formed_error ||
+ cs->cset->scan(cs, copy->from_ptr + copy_length, from_end,
+ MY_SEQ_SPACES) < (copy->from_length - copy_length))
{
- if (!my_isspace(system_charset_info, *ptr)) // QQ: ucs incompatible
- {
- copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
- ER_WARN_DATA_TRUNCATED, 1);
- break;
- }
+ copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_WARN_DATA_TRUNCATED, 1);
}
+
+ if (copy_length < copy->to_length)
+ cs->cset->fill(cs, copy->to_ptr + copy_length,
+ copy->to_length - copy_length, ' ');
}