diff options
author | unknown <evgen@moonbone.local> | 2005-08-30 16:19:53 +0400 |
---|---|---|
committer | unknown <evgen@moonbone.local> | 2005-08-30 16:19:53 +0400 |
commit | f118f3ebaa587e4d81fc8bc622e071117a0501d4 (patch) | |
tree | 16edb78ed35954aaea1fb2952d968d34154e5c27 | |
parent | 5ea5fab40da420c19ab4a1f4b0c963c0ebb99b93 (diff) | |
download | mariadb-git-f118f3ebaa587e4d81fc8bc622e071117a0501d4.tar.gz |
Fix bug #12537 UNION produces longtext instead of varchar
Item::tmp_table_field_from_field_type() and create_tmp_field_from_item()
was converting string field to blob depending on byte-wise length instead of
character length, which results in converting valid varchar string with
length == 86 to longtext.
Made that functions above take into account max width of character when
converting string fields to blobs.
sql/item.cc:
Fix bug #12537 UNION produces longtext instead of varchar
Item::tmp_table_field_from_field_type() now taking into account max char width when creating tmp field for string fields.
sql/sql_select.cc:
Fix bug #12537 UNION produces longtext instead of varchar
create_tmp_field_from_item()now taking into account max char width when creating tmp field for string fields.
mysql-test/r/create.result:
Test case for bug #12537 UNION produces longtext instead of varchar
mysql-test/t/create.test:
Test case for bug #12537 UNION produces longtext instead of varchar
-rw-r--r-- | mysql-test/r/create.result | 7 | ||||
-rw-r--r-- | mysql-test/t/create.test | 9 | ||||
-rw-r--r-- | sql/item.cc | 6 | ||||
-rw-r--r-- | sql/sql_select.cc | 3 |
4 files changed, 22 insertions, 3 deletions
diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 00bc0320028..95757fbd7dc 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -580,6 +580,13 @@ ERROR 42000: Incorrect database name 'xyz' create table t1(t1.name int); create table t2(test.t2.name int); drop table t1,t2; +CREATE TABLE t1 (f1 VARCHAR(255) CHARACTER SET utf8); +CREATE TABLE t2 AS SELECT LEFT(f1,86) AS f2 FROM t1 UNION SELECT LEFT(f1,86) +AS f2 FROM t1; +DESC t2; +Field Type Null Key Default Extra +f2 varchar(86) YES NULL +DROP TABLE t1,t2; create database mysqltest; use mysqltest; drop database mysqltest; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 3b4b86a3df3..55321a81f5e 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -493,6 +493,15 @@ create table t2(test.t2.name int); drop table t1,t2; # +# Bug #12537: UNION produces longtext instead of varchar +# +CREATE TABLE t1 (f1 VARCHAR(255) CHARACTER SET utf8); +CREATE TABLE t2 AS SELECT LEFT(f1,86) AS f2 FROM t1 UNION SELECT LEFT(f1,86) +AS f2 FROM t1; +DESC t2; +DROP TABLE t1,t2; + +# # Bug#11028: Crash on create table like # create database mysqltest; diff --git a/sql/item.cc b/sql/item.cc index 79579eeeb67..ae95d76486b 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2022,12 +2022,14 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table) case MYSQL_TYPE_ENUM: case MYSQL_TYPE_SET: case MYSQL_TYPE_VAR_STRING: - if (max_length > 255) + DBUG_ASSERT(collation.collation); + if (max_length/collation.collation->mbmaxlen > 255) break; // If blob return new Field_varstring(max_length, maybe_null, name, table, collation.collation); case MYSQL_TYPE_STRING: - if (max_length > 255) // If blob + DBUG_ASSERT(collation.collation); + if (max_length/collation.collation->mbmaxlen > 255) // If blob break; return new Field_string(max_length, maybe_null, name, table, collation.collation); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9984cb4138f..d5890997295 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4899,7 +4899,8 @@ static Field* create_tmp_field_from_item(THD *thd, Item *item, TABLE *table, item->name, table, item->unsigned_flag); break; case STRING_RESULT: - if (item->max_length > 255) + DBUG_ASSERT(item->collation.collation); + if (item->max_length/item->collation.collation->mbmaxlen > 255) { if (convert_blob_length) new_field= new Field_varstring(convert_blob_length, maybe_null, |