diff options
author | Andrew Hutchings <andrew@mariadb.org> | 2022-09-23 14:02:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-23 14:02:41 +0100 |
commit | 66cd1c33f72d6781e1069efa93d2800c24215b11 (patch) | |
tree | 4061dd0f4e9fcad36984152400086f8c95ae6cca | |
parent | ce23802c0e4c85018f2141d2ebb0602dc0d3d6d8 (diff) | |
download | mariadb-git-66cd1c33f72d6781e1069efa93d2800c24215b11.tar.gz |
MDEV-25767 Fix CONNECT ODBC WHERE condition crash (#2243)
When an UPDATE or DELETE was executed with a WHERE condition it would
crash the MariaDB server. This is because the code expects the WHERE
condition to have generated a query string but it hasn't.
Also updates the ODBC test results for current MariaDB version.
4 files changed, 37 insertions, 14 deletions
diff --git a/storage/connect/mysql-test/connect/r/odbc_postgresql.result b/storage/connect/mysql-test/connect/r/odbc_postgresql.result index dc23dbdb990..fd23197c37f 100644 --- a/storage/connect/mysql-test/connect/r/odbc_postgresql.result +++ b/storage/connect/mysql-test/connect/r/odbc_postgresql.result @@ -17,6 +17,7 @@ mtr public t2 TABLE mtr public v1 VIEW mtr schema1 t1 TABLE mtr schema1 t2 TABLE +mtr schema1 t3 TABLE mtr schema1 v1 VIEW DROP TABLE t1; # All tables in all schemas @@ -28,6 +29,7 @@ mtr public t2 TABLE mtr public v1 VIEW mtr schema1 t1 TABLE mtr schema1 t2 TABLE +mtr schema1 t3 TABLE mtr schema1 v1 VIEW DROP TABLE t1; # All tables in all schemas @@ -39,6 +41,7 @@ mtr public t2 TABLE mtr public v1 VIEW mtr schema1 t1 TABLE mtr schema1 t2 TABLE +mtr schema1 t3 TABLE mtr schema1 v1 VIEW DROP TABLE t1; # All tables in the default schema ("public") @@ -101,6 +104,8 @@ mtr public t2 a 4 int4 10 4 0 10 0 mtr public v1 a 4 int4 10 4 0 10 1 mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0 mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0 +mtr schema1 t3 a 1 bpchar 10 40 NULL NULL 0 +mtr schema1 t3 b 1 bpchar 10 40 NULL NULL 0 mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1 DROP TABLE t1; # All columns in the schemas "public" and "schema1" @@ -112,6 +117,8 @@ mtr public t2 a 4 int4 10 4 0 10 0 mtr public v1 a 4 int4 10 4 0 10 1 mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0 mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0 +mtr schema1 t3 a 1 bpchar 10 40 NULL NULL 0 +mtr schema1 t3 b 1 bpchar 10 40 NULL NULL 0 mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1 DROP TABLE t1; # All tables "t1" in all schemas @@ -195,7 +202,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `a` char(10) NOT NULL -) ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.t1' `DATA_CHARSET`='utf8' +) ENGINE=CONNECT DEFAULT CHARSET=utf8mb3 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.t1' `DATA_CHARSET`='utf8' SELECT * FROM t1; a aaa @@ -206,7 +213,7 @@ CREATE TABLE t2 AS SELECT * FROM t1; SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( - `a` char(10) CHARACTER SET utf8 NOT NULL + `a` char(10) CHARACTER SET utf8mb3 NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM t2; a @@ -230,7 +237,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `a` char(10) DEFAULT NULL -) ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.v1' `DATA_CHARSET`='utf8' +) ENGINE=CONNECT DEFAULT CHARSET=utf8mb3 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.v1' `DATA_CHARSET`='utf8' SELECT * FROM t1; a aaa @@ -241,7 +248,7 @@ CREATE TABLE t2 AS SELECT * FROM t1; SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( - `a` char(10) CHARACTER SET utf8 DEFAULT NULL + `a` char(10) CHARACTER SET utf8mb3 DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM t2; a @@ -265,7 +272,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `a` char(10) NOT NULL -) ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.t2' `DATA_CHARSET`='utf8' +) ENGINE=CONNECT DEFAULT CHARSET=utf8mb3 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.t2' `DATA_CHARSET`='utf8' SELECT * FROM t1; a xxx @@ -276,7 +283,7 @@ CREATE TABLE t2 AS SELECT * FROM t1; SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( - `a` char(10) CHARACTER SET utf8 NOT NULL + `a` char(10) CHARACTER SET utf8mb3 NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM t2; a @@ -294,3 +301,8 @@ zzz ÄÖÜ DROP VIEW v1; DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(6), b VARCHAR(6), PRIMARY KEY(a, b)) ENGINE=CONNECT TABNAME='schema1.t3' CHARSET=utf8 DATA_CHARSET=utf8 TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr'; +DELETE FROM t1 WHERE a='20'; +Warnings: +Note 1105 schema1.t3: 0 affected rows +DROP TABLE t1; diff --git a/storage/connect/mysql-test/connect/t/odbc_postgresql.sql b/storage/connect/mysql-test/connect/t/odbc_postgresql.sql index 1c302294393..a795817a4d3 100644 --- a/storage/connect/mysql-test/connect/t/odbc_postgresql.sql +++ b/storage/connect/mysql-test/connect/t/odbc_postgresql.sql @@ -25,3 +25,6 @@ INSERT INTO schema1.t1 VALUES ('aaa'),('bbb'),('ccc'),('яяя'); CREATE VIEW schema1.v1 AS SELECT * FROM schema1.t1; CREATE TABLE schema1.t2 (a CHAR(10) NOT NULL); INSERT INTO schema1.t2 VALUES ('xxx'),('yyy'),('zzz'),('ÄÖÜ'); +CREATE TABLE schema1.t3 (a CHAR(10) NOT NULL, b CHAR(10) NOT NULL); +INSERT INTO schema1.t3 VALUES ('xxx', 'aaa'),('yyy', 'bbb'),('zzz', 'ccc'),('ÄÖÜ', 'яяя'); + diff --git a/storage/connect/mysql-test/connect/t/odbc_postgresql.test b/storage/connect/mysql-test/connect/t/odbc_postgresql.test index 7fc16130713..86597423d04 100644 --- a/storage/connect/mysql-test/connect/t/odbc_postgresql.test +++ b/storage/connect/mysql-test/connect/t/odbc_postgresql.test @@ -205,3 +205,9 @@ CREATE VIEW v1 AS SELECT * FROM t1; SELECT * FROM v1; DROP VIEW v1; DROP TABLE t1; + +# MDEV-25767 DELETE with WHERE condition crashes when two columns used for +# pkey +CREATE TABLE t1 (a VARCHAR(6), b VARCHAR(6), PRIMARY KEY(a, b)) ENGINE=CONNECT TABNAME='schema1.t3' CHARSET=utf8 DATA_CHARSET=utf8 TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr'; +DELETE FROM t1 WHERE a='20'; +DROP TABLE t1; diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp index 2a4ee89b235..140367bd954 100644 --- a/storage/connect/tabodbc.cpp +++ b/storage/connect/tabodbc.cpp @@ -557,15 +557,17 @@ bool TDBODBC::OpenDB(PGLOBAL g) if (Memory < 3) { // Method will depend on cursor type - if ((Rbuf = Ocp->Rewind(Query->GetStr(), (PODBCCOL)Columns)) < 0) - if (Mode != MODE_READX) { - Ocp->Close(); - return true; - } else - Rbuf = 0; - - } else + if (Query && (Rbuf = Ocp->Rewind(Query->GetStr(), (PODBCCOL)Columns)) < 0) { + if (Mode != MODE_READX) { + Ocp->Close(); + return true; + } else { + Rbuf = 0; + } + } + } else { Rbuf = Qrp->Nblin; + } CurNum = 0; Fpos = 0; |