Commit 043c1d18 authored by Andrew Hutchings's avatar Andrew Hutchings Committed by Daniel Black

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.
parent dc6a0171
......@@ -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;
......
......@@ -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
#
......@@ -503,6 +503,36 @@ SELECT `id` FROM t2 WHERE t2.`spaced col` = 'C-003';
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 #
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment