Skip to content

Commit

Permalink
MDEV-25767 Fix CONNECT ODBC WHERE condition crash (#2243)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LinuxJedi committed Sep 23, 2022
1 parent ce23802 commit 66cd1c3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
24 changes: 18 additions & 6 deletions storage/connect/mysql-test/connect/r/odbc_postgresql.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
3 changes: 3 additions & 0 deletions storage/connect/mysql-test/connect/t/odbc_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'),('ÄÖÜ', 'яяя');

6 changes: 6 additions & 0 deletions storage/connect/mysql-test/connect/t/odbc_postgresql.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;
18 changes: 10 additions & 8 deletions storage/connect/tabodbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 66cd1c3

Please sign in to comment.