Commit 66cd1c33 authored by Andrew Hutchings's avatar Andrew Hutchings Committed by GitHub

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.
parent ce23802c
...@@ -17,6 +17,7 @@ mtr public t2 TABLE ...@@ -17,6 +17,7 @@ mtr public t2 TABLE
mtr public v1 VIEW mtr public v1 VIEW
mtr schema1 t1 TABLE mtr schema1 t1 TABLE
mtr schema1 t2 TABLE mtr schema1 t2 TABLE
mtr schema1 t3 TABLE
mtr schema1 v1 VIEW mtr schema1 v1 VIEW
DROP TABLE t1; DROP TABLE t1;
# All tables in all schemas # All tables in all schemas
...@@ -28,6 +29,7 @@ mtr public t2 TABLE ...@@ -28,6 +29,7 @@ mtr public t2 TABLE
mtr public v1 VIEW mtr public v1 VIEW
mtr schema1 t1 TABLE mtr schema1 t1 TABLE
mtr schema1 t2 TABLE mtr schema1 t2 TABLE
mtr schema1 t3 TABLE
mtr schema1 v1 VIEW mtr schema1 v1 VIEW
DROP TABLE t1; DROP TABLE t1;
# All tables in all schemas # All tables in all schemas
...@@ -39,6 +41,7 @@ mtr public t2 TABLE ...@@ -39,6 +41,7 @@ mtr public t2 TABLE
mtr public v1 VIEW mtr public v1 VIEW
mtr schema1 t1 TABLE mtr schema1 t1 TABLE
mtr schema1 t2 TABLE mtr schema1 t2 TABLE
mtr schema1 t3 TABLE
mtr schema1 v1 VIEW mtr schema1 v1 VIEW
DROP TABLE t1; DROP TABLE t1;
# All tables in the default schema ("public") # All tables in the default schema ("public")
...@@ -101,6 +104,8 @@ mtr public t2 a 4 int4 10 4 0 10 0 ...@@ -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 public v1 a 4 int4 10 4 0 10 1
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0 mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
mtr schema1 t2 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 mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1
DROP TABLE t1; DROP TABLE t1;
# All columns in the schemas "public" and "schema1" # All columns in the schemas "public" and "schema1"
...@@ -112,6 +117,8 @@ mtr public t2 a 4 int4 10 4 0 10 0 ...@@ -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 public v1 a 4 int4 10 4 0 10 1
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0 mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
mtr schema1 t2 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 mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1
DROP TABLE t1; DROP TABLE t1;
# All tables "t1" in all schemas # All tables "t1" in all schemas
...@@ -195,7 +202,7 @@ SHOW CREATE TABLE t1; ...@@ -195,7 +202,7 @@ SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` char(10) NOT NULL `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; SELECT * FROM t1;
a a
aaa aaa
...@@ -206,7 +213,7 @@ CREATE TABLE t2 AS SELECT * FROM t1; ...@@ -206,7 +213,7 @@ CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2; SHOW CREATE TABLE t2;
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( 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 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2; SELECT * FROM t2;
a a
...@@ -230,7 +237,7 @@ SHOW CREATE TABLE t1; ...@@ -230,7 +237,7 @@ SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` char(10) DEFAULT NULL `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; SELECT * FROM t1;
a a
aaa aaa
...@@ -241,7 +248,7 @@ CREATE TABLE t2 AS SELECT * FROM t1; ...@@ -241,7 +248,7 @@ CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2; SHOW CREATE TABLE t2;
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( 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 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2; SELECT * FROM t2;
a a
...@@ -265,7 +272,7 @@ SHOW CREATE TABLE t1; ...@@ -265,7 +272,7 @@ SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` char(10) NOT NULL `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; SELECT * FROM t1;
a a
xxx xxx
...@@ -276,7 +283,7 @@ CREATE TABLE t2 AS SELECT * FROM t1; ...@@ -276,7 +283,7 @@ CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2; SHOW CREATE TABLE t2;
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( 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 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2; SELECT * FROM t2;
a a
...@@ -294,3 +301,8 @@ zzz ...@@ -294,3 +301,8 @@ zzz
ÄÖÜ ÄÖÜ
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; 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;
...@@ -25,3 +25,6 @@ INSERT INTO schema1.t1 VALUES ('aaa'),('bbb'),('ccc'),('яяя'); ...@@ -25,3 +25,6 @@ INSERT INTO schema1.t1 VALUES ('aaa'),('bbb'),('ccc'),('яяя');
CREATE VIEW schema1.v1 AS SELECT * FROM schema1.t1; CREATE VIEW schema1.v1 AS SELECT * FROM schema1.t1;
CREATE TABLE schema1.t2 (a CHAR(10) NOT NULL); CREATE TABLE schema1.t2 (a CHAR(10) NOT NULL);
INSERT INTO schema1.t2 VALUES ('xxx'),('yyy'),('zzz'),('ÄÖÜ'); 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'),('ÄÖÜ', 'яяя');
...@@ -205,3 +205,9 @@ CREATE VIEW v1 AS SELECT * FROM t1; ...@@ -205,3 +205,9 @@ CREATE VIEW v1 AS SELECT * FROM t1;
SELECT * FROM v1; SELECT * FROM v1;
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; 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;
...@@ -557,15 +557,17 @@ bool TDBODBC::OpenDB(PGLOBAL g) ...@@ -557,15 +557,17 @@ bool TDBODBC::OpenDB(PGLOBAL g)
if (Memory < 3) { if (Memory < 3) {
// Method will depend on cursor type // Method will depend on cursor type
if ((Rbuf = Ocp->Rewind(Query->GetStr(), (PODBCCOL)Columns)) < 0) if (Query && (Rbuf = Ocp->Rewind(Query->GetStr(), (PODBCCOL)Columns)) < 0) {
if (Mode != MODE_READX) { if (Mode != MODE_READX) {
Ocp->Close(); Ocp->Close();
return true; return true;
} else } else {
Rbuf = 0; Rbuf = 0;
}
} else }
} else {
Rbuf = Qrp->Nblin; Rbuf = Qrp->Nblin;
}
CurNum = 0; CurNum = 0;
Fpos = 0; Fpos = 0;
......
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