From f7cbe9a2cc973d73967c1628f7716487f2f174f1 Mon Sep 17 00:00:00 2001 From: "serg@mysql.com" <> Date: Tue, 22 Mar 2005 20:13:49 +0100 Subject: [PATCH] BUG#9339 - Updating a column does not work if the table has a UTF-8 VARCHAR primary key fixed my_charpos() call in Field_varstring::get_key_image --- mysql-test/r/type_varchar.result | 7 +++++++ mysql-test/t/type_varchar.test | 9 +++++++++ sql/field.cc | 6 +++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/type_varchar.result b/mysql-test/r/type_varchar.result index 1c2653bd225..d2fe843a68b 100644 --- a/mysql-test/r/type_varchar.result +++ b/mysql-test/r/type_varchar.result @@ -376,3 +376,10 @@ explain select * from t1 where v like 'S%' order by v; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range v v 13 NULL 2 Using where; Using filesort drop table t1; +create table t1 (pkcol varchar(16), othercol varchar(16), primary key (pkcol)); +insert into t1 values ('test', 'something'); +update t1 set othercol='somethingelse' where pkcol='test'; +select * from t1; +pkcol othercol +test somethingelse +drop table t1; diff --git a/mysql-test/t/type_varchar.test b/mysql-test/t/type_varchar.test index 0168128d513..9867cf4c057 100644 --- a/mysql-test/t/type_varchar.test +++ b/mysql-test/t/type_varchar.test @@ -97,3 +97,12 @@ explain select * from t1 where v like 'This is a test' order by v; explain select * from t1 where v='This is a test' order by v; explain select * from t1 where v like 'S%' order by v; drop table t1; + +# +# bug#9339 - meaningless Field_varstring::get_key_image +# +create table t1 (pkcol varchar(16), othercol varchar(16), primary key (pkcol)); +insert into t1 values ('test', 'something'); +update t1 set othercol='somethingelse' where pkcol='test'; +select * from t1; +drop table t1; diff --git a/sql/field.cc b/sql/field.cc index 84024a63266..b96a2cbdf4d 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5725,12 +5725,12 @@ void Field_varstring::get_key_image(char *buff, uint length, imagetype type) { uint f_length= length_bytes == 1 ? (uint) (uchar) *ptr : uint2korr(ptr); uint char_length= length / field_charset->mbmaxlen; - char_length= my_charpos(field_charset, ptr, ptr + length_bytes, - char_length); + char *pos= ptr+length_bytes; + char_length= my_charpos(field_charset, pos, pos + f_length, char_length); set_if_smaller(f_length, char_length); /* Key is always stored with 2 bytes */ int2store(buff,f_length); - memcpy(buff+HA_KEY_BLOB_LENGTH, ptr+length_bytes, f_length); + memcpy(buff+HA_KEY_BLOB_LENGTH, pos, f_length); if (f_length < length) { /*