MDEV-29782 CONNECT YEAR type conversion fix

When using the MySQL table type the CONNECT engine converted the YEAR
datatype to DATETIME for INSERT queries. This is incorrect, causing an
error on the INSERT. It should be SHORT instead.
This commit is contained in:
Andrew Hutchings 2022-10-31 15:51:00 +00:00 committed by Andrew Hutchings
parent 476b24d084
commit 358635bbad
3 changed files with 27 additions and 1 deletions

View file

@ -364,5 +364,16 @@ hex(col)
DROP TABLE t2;
DROP TABLE t1;
#
# MDEV-29782 CONNECT engine converted YEAR to DATETIME, causing INSERT to fail
#
CREATE TABLE t1 (id year);
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=PORT';
INSERT INTO t2 VALUES (1999);
SELECT * FROM t2;
id
1999
DROP TABLE t2;
DROP TABLE t1;
#
# End of 10.3 tests
#

View file

@ -533,6 +533,21 @@ DROP TABLE t2;
DROP TABLE t1;
--echo #
--echo # MDEV-29782 CONNECT engine converted YEAR to DATETIME, causing INSERT to fail
--echo #
CREATE TABLE t1 (id year);
--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'
INSERT INTO t2 VALUES (1999);
SELECT * FROM t2;
DROP TABLE t2;
DROP TABLE t1;
--echo #
--echo # End of 10.3 tests
--echo #

View file

@ -183,6 +183,7 @@ int MYSQLtoPLG(int mytype, char *var)
switch (mytype) {
case MYSQL_TYPE_SHORT:
case MYSQL_TYPE_YEAR:
type = TYPE_SHORT;
break;
case MYSQL_TYPE_LONG:
@ -209,7 +210,6 @@ int MYSQLtoPLG(int mytype, char *var)
case MYSQL_TYPE_TIMESTAMP:
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_YEAR:
case MYSQL_TYPE_TIME:
type = TYPE_DATE;
break;