diff options
-rw-r--r-- | mysql-test/r/type_enum.result | 6 | ||||
-rw-r--r-- | sql/item.h | 2 | ||||
-rw-r--r-- | sql/protocol.cc | 12 | ||||
-rw-r--r-- | tests/client_test.c | 29 |
4 files changed, 32 insertions, 17 deletions
diff --git a/mysql-test/r/type_enum.result b/mysql-test/r/type_enum.result index e5239dcf769..14d3443bda9 100644 --- a/mysql-test/r/type_enum.result +++ b/mysql-test/r/type_enum.result @@ -1731,9 +1731,9 @@ alter table t1 add b set ('Y','N') CHARACTER SET utf8 COLLATE utf8_bin; alter table t1 add c enum ('Y','N') CHARACTER SET utf8 COLLATE utf8_bin; select * from t1; Catalog Database Table Table_alias Column Column_alias Name Type Length Max length Is_null Flags Decimals Charsetnr -def test t1 t1 a a 254 3 1 Y 384 0 8 -def test t1 t1 b b 254 9 0 Y 2176 0 8 -def test t1 t1 c c 254 3 0 Y 384 0 8 +def test t1 t1 a a 254 1 1 Y 384 0 8 +def test t1 t1 b b 254 3 0 Y 2176 0 8 +def test t1 t1 c c 254 1 0 Y 384 0 8 a b c Y NULL NULL drop table t1; diff --git a/sql/item.h b/sql/item.h index 71b92cd1efc..1024251793e 100644 --- a/sql/item.h +++ b/sql/item.h @@ -765,7 +765,7 @@ class Item_empty_string :public Item_string public: Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) : Item_string("",0, cs ? cs : &my_charset_bin) - { name=(char*) header; max_length=length;} + { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; } void make_field(Send_field *field); }; diff --git a/sql/protocol.cc b/sql/protocol.cc index eaa0fd55b25..95cd8415c85 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -549,10 +549,18 @@ bool Protocol::send_fields(List<Item> *list, uint flag) pos= (char*) local_packet->ptr()+local_packet->length(); *pos++= 12; // Length of packed fields if (item->collation.collation == &my_charset_bin || thd_charset == NULL) + { + /* No conversion */ int2store(pos, field.charsetnr); + int4store(pos+2, field.length); + } else - int2store(pos, thd_charset->number); - int4store(pos+2, field.length); + { + /* With conversion */ + int2store(pos, thd_charset->number); + uint char_len= field.length / item->collation.collation->mbmaxlen; + int4store(pos+2, char_len * thd_charset->mbmaxlen); + } pos[6]= field.type; int2store(pos+7,field.flags); pos[9]= (char) field.decimals; diff --git a/tests/client_test.c b/tests/client_test.c index b0bf40799da..b78339cc9bb 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -1101,7 +1101,8 @@ static void test_prepare_simple() mysql_stmt_close(stmt); /* update */ - strmov(query, "UPDATE test_prepare_simple SET id=? WHERE id=? AND name= ?"); + strmov(query, "UPDATE test_prepare_simple SET id=? " + "WHERE id=? AND CONVERT(name USING utf8)= ?"); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -1129,7 +1130,8 @@ static void test_prepare_simple() mysql_stmt_close(stmt); /* select */ - strmov(query, "SELECT * FROM test_prepare_simple WHERE id=? AND name= ?"); + strmov(query, "SELECT * FROM test_prepare_simple WHERE id=? " + "AND CONVERT(name USING utf8)= ?"); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -1158,7 +1160,7 @@ static void test_prepare_field_result() rc= mysql_query(mysql, "CREATE TABLE test_prepare_field_result(int_c int, " "var_c varchar(50), ts_c timestamp(14), " - "char_c char(3), date_c date, extra tinyint)"); + "char_c char(4), date_c date, extra tinyint)"); myquery(rc); /* insert */ @@ -1184,8 +1186,8 @@ static void test_prepare_field_result() "t1", "test_prepare_field_result", current_db, 10, 0); verify_prepare_field(result, 3, "ts_c", "ts_c", MYSQL_TYPE_TIMESTAMP, "t1", "test_prepare_field_result", current_db, 19, 0); - verify_prepare_field(result, 4, "char_c", "char_c", MYSQL_TYPE_STRING, - "t1", "test_prepare_field_result", current_db, 3, 0); + verify_prepare_field(result, 4, "char_c", "char_c", MYSQL_TYPE_VAR_STRING, + "t1", "test_prepare_field_result", current_db, 4, 0); verify_field_count(result, 5); mysql_free_result(result); @@ -1921,7 +1923,8 @@ static void test_select() rc= mysql_commit(mysql); myquery(rc); - strmov(query, "SELECT * FROM test_select WHERE id= ? AND name=?"); + strmov(query, "SELECT * FROM test_select WHERE id= ? " + "AND CONVERT(name USING utf8) =?"); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -1981,7 +1984,8 @@ static void test_ps_conj_select() "(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')"); myquery(rc); - strmov(query, "select id1, value1 from t1 where id1= ? or value1= ?"); + strmov(query, "select id1, value1 from t1 where id1= ? or " + "CONVERT(value1 USING utf8)= ?"); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -2060,7 +2064,8 @@ session_id char(9) NOT NULL, \ "(\"abx\", 1, 2, 3, 2003-08-30)"); myquery(rc); - strmov(query, "SELECT * FROM test_select WHERE session_id= ?"); + strmov(query, "SELECT * FROM test_select WHERE " + "CONVERT(session_id USING utf8)= ?"); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -2898,7 +2903,8 @@ static void test_simple_delete() myquery(rc); /* insert by prepare */ - strmov(query, "DELETE FROM test_simple_delete WHERE col1= ? AND col2= ? AND col3= 100"); + strmov(query, "DELETE FROM test_simple_delete WHERE col1= ? AND " + "CONVERT(col2 USING utf8)= ? AND col3= 100"); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -4866,7 +4872,8 @@ static void test_multi_stmt() /* alter the table schema now */ stmt1= mysql_simple_prepare(mysql, "DELETE FROM test_multi_table " - "WHERE id= ? AND name=?"); + "WHERE id= ? AND " + "CONVERT(name USING utf8)=?"); check_stmt(stmt1); verify_param_count(stmt1, 2); @@ -6632,7 +6639,7 @@ static void test_field_misc() "@@table_type", "", /* field and its org name */ MYSQL_TYPE_STRING, /* field type */ "", "", /* table and its org name */ - "", type_length*3, 0); /* db name, length */ + "", type_length, 0); /* db name, length */ mysql_free_result(result); mysql_stmt_close(stmt); |