diff options
author | Andrew Hutchings <andrew@mariadb.org> | 2022-10-31 17:02:58 +0000 |
---|---|---|
committer | Daniel Black <daniel@mariadb.org> | 2022-11-11 11:30:09 +1100 |
commit | 043c1d183088c7179037bb562d1715848fdf9d7e (patch) | |
tree | 0f9f16773a4c7700b1ece289d0a50ccb68bf04d3 | |
parent | dc6a0171110741d633cef7877013d8e29d5e6def (diff) | |
download | mariadb-git-043c1d183088c7179037bb562d1715848fdf9d7e.tar.gz |
MDEV-28489 CONNECT used incorrect CHAR length
CONNECT engine was using dividing UTF8 columns by 3 to get the length,
but in reality it did need the byte length.
This fixes MDEV-26722 too.
-rw-r--r-- | storage/connect/ha_connect.cc | 9 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/r/mysql.result | 38 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/t/mysql.test | 30 |
3 files changed, 70 insertions, 7 deletions
diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 5af952afcd4..0071aed69c2 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -1618,14 +1618,9 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) pcf->Scale= 0; pcf->Opt= (fop) ? (int)fop->opt : 0; - if (fp->field_length >= 0) { + if (fp->field_length >= 0) pcf->Length= fp->field_length; - - // length is bytes for Connect, not characters - if (!strnicmp(chset, "utf8", 4)) - pcf->Length /= 3; - - } else + else pcf->Length= 256; // BLOB? pcf->Precision= pcf->Length; diff --git a/storage/connect/mysql-test/connect/r/mysql.result b/storage/connect/mysql-test/connect/r/mysql.result index 918256ac395..d3c244b277a 100644 --- a/storage/connect/mysql-test/connect/r/mysql.result +++ b/storage/connect/mysql-test/connect/r/mysql.result @@ -326,5 +326,43 @@ id DROP TABLE t1; DROP TABLE t2; # +# MDEV-28489 / MDEV-26722 UTF8 bytes calculated incorrectly +# +CREATE TABLE t1 (name varchar(20)) CHARSET=utf8; +INSERT INTO t1 (name) VALUES ('Иванова'), ('Ivanova'); +CREATE TABLE t2 (name varchar(1)) ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=PORT' CHARSET=utf8; +SELECT hex(name) from t1; +hex(name) +C390CB9CC390C2B2C390C2B0C390C2BDC390C2BEC390C2B2C390C2B0 +4976616E6F7661 +SELECT hex(name) from t2; +hex(name) +C390 +49 +Warnings: +Warning 1105 Out of range value for column name at row 1 +Warning 1265 Data truncated for column 'name' at row 1 +Warning 1105 Out of range value Ð? for column 'name' at row 1 +Warning 1105 Out of range value for column name at row 2 +Warning 1265 Data truncated for column 'name' at row 2 +Warning 1105 Out of range value Iva for column 'name' at row 2 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (col char(5)) CHARSET=utf8; +INSERT INTO t1 (col) VALUES ('glace'), ('glacé'); +Warnings: +Warning 1406 Data too long for column 'col' at row 2 +CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=PORT' CHARSET=utf8; +SELECT hex(col) from t1; +hex(col) +676C616365 +676C6163C383 +SELECT hex(col) from t2; +hex(col) +676C616365 +676C6163C383 +DROP TABLE t2; +DROP TABLE t1; +# # End of 10.3 tests # diff --git a/storage/connect/mysql-test/connect/t/mysql.test b/storage/connect/mysql-test/connect/t/mysql.test index ce76a4665d5..a50db4a6457 100644 --- a/storage/connect/mysql-test/connect/t/mysql.test +++ b/storage/connect/mysql-test/connect/t/mysql.test @@ -504,5 +504,35 @@ DROP TABLE t1; DROP TABLE t2; --echo # +--echo # MDEV-28489 / MDEV-26722 UTF8 bytes calculated incorrectly +--echo # + +CREATE TABLE t1 (name varchar(20)) CHARSET=utf8; +INSERT INTO t1 (name) VALUES ('Иванова'), ('Ivanova'); + +--replace_result $PORT PORT +--eval CREATE TABLE t2 (name varchar(1)) ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=$PORT' CHARSET=utf8 + +SELECT hex(name) from t1; +# This will warn as we are truncating data +SELECT hex(name) from t2; + +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (col char(5)) CHARSET=utf8; +INSERT INTO t1 (col) VALUES ('glace'), ('glacé'); + +--replace_result $PORT PORT +--eval CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=$PORT' CHARSET=utf8 + +SELECT hex(col) from t1; +SELECT hex(col) from t2; + +DROP TABLE t2; +DROP TABLE t1; + + +--echo # --echo # End of 10.3 tests --echo # |