Commit b3e06ce3 authored by Anel's avatar Anel Committed by GitHub

MDEV-28533: CONNECT engine does not quote columns involved in WHERE clause (#2263)

parent 66cd1c33
......@@ -3073,6 +3073,8 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
if ((iscol= args[i]->type() == COND::FIELD_ITEM)) {
const char *fnm;
char buf[MAX_FIELD_WIDTH];
String strColumn(buf, sizeof(buf), system_charset_info);
ha_field_option_struct *fop;
Item_field *pField= (Item_field *)args[i];
......@@ -3098,8 +3100,14 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
return NULL;
} else {
bool h;
fnm= filp->Chk(pField->field->field_name.str, &h);
if (tty == TYPE_AM_MYSQL && !(x || ismul))
{
strColumn.length(0);
strColumn.qs_append(STRING_WITH_LEN("`"));
strColumn.qs_append(fnm);
strColumn.append(STRING_WITH_LEN("`"));
}
if (h && i && !ishav)
return NULL; // Having should be col VOP arg
......@@ -3113,9 +3121,11 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
htrc("Field name=%s\n", pField->field->field_name.str);
htrc("Field type=%d\n", pField->field->type());
htrc("Field_type=%d\n", args[i]->field_type());
} // endif trace
strcat((ishav ? havg : body), fnm);
} // endif trace
if (tty == TYPE_AM_MYSQL && !(x || ismul))
strcat((ishav ? havg : body), strColumn.ptr());
else
strcat((ishav ? havg : body), fnm);
} else if (args[i]->type() == COND::FUNC_ITEM) {
if (tty == TYPE_AM_MYSQL) {
if (!CheckCond(g, filp, args[i]))
......
......@@ -304,5 +304,27 @@ INSERT INTO t2 VALUES (10),(20),(30),(40);
DROP TABLE t2;
DROP TABLE t1;
#
# MDEV-28533 CONNECT engine does not quote columns involved in WHERE clause
#
CREATE TABLE t1 (id int, `spaced col` varchar(10),`nospace` varchar(10));
insert into t1 values (1,1,'x1'),(2,'C-003','x2');
SELECT * from t1;
id spaced col nospace
1 1 x1
2 C-003 x2
CREATE TABLE t2 (id int, `spaced col` varchar(10), `nospace` varchar(10)) ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=PORT';
SELECT * from t2;
id spaced col nospace
1 1 x1
2 C-003 x2
SELECT `id` FROM t2 WHERE t2.`nospace` = 'x1';
id
1
SELECT `id` FROM t2 WHERE t2.`spaced col` = 'C-003';
id
2
DROP TABLE t1;
DROP TABLE t2;
#
# End of 10.3 tests
#
......@@ -483,6 +483,26 @@ INSERT INTO t2 VALUES (10),(20),(30),(40);
DROP TABLE t2;
DROP TABLE t1;
--echo #
--echo # MDEV-28533 CONNECT engine does not quote columns involved in WHERE clause
--echo #
CREATE TABLE t1 (id int, `spaced col` varchar(10),`nospace` varchar(10));
insert into t1 values (1,1,'x1'),(2,'C-003','x2');
SELECT * from t1;
--replace_result $PORT PORT
--eval CREATE TABLE t2 (id int, `spaced col` varchar(10), `nospace` varchar(10)) ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=$PORT'
SELECT * from t2;
SELECT `id` FROM t2 WHERE t2.`nospace` = 'x1';
SELECT `id` FROM t2 WHERE t2.`spaced col` = 'C-003';
DROP TABLE t1;
DROP TABLE t2;
--echo #
--echo # End of 10.3 tests
--echo #
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