Skip to content

Commit

Permalink
MDEV-29782 CONNECT YEAR type conversion fix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LinuxJedi committed Feb 21, 2023
1 parent 476b24d commit 358635b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions storage/connect/mysql-test/connect/r/mysql.result
Expand Up @@ -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
#
15 changes: 15 additions & 0 deletions storage/connect/mysql-test/connect/t/mysql.test
Expand Up @@ -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 #
2 changes: 1 addition & 1 deletion storage/connect/myutil.cpp
Expand Up @@ -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:
Expand All @@ -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;
Expand Down

0 comments on commit 358635b

Please sign in to comment.