Skip to content

Commit

Permalink
Fix error when execute query contains escape parameters in parentheses
Browse files Browse the repository at this point in the history
…#62 (#63)

Example SQL: SELECT * FROM ftbl where title in ('Test''s', 'other tests');
  • Loading branch information
khieuvm authored Feb 22, 2023
1 parent 7518351 commit 9fd31f4
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 0 deletions.
3 changes: 3 additions & 0 deletions deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2940,6 +2940,9 @@ sqlite_deparse_scalar_array_op_expr(ScalarArrayOpExpr *node, deparse_expr_cxt *c
}
continue;
}

if (SQL_STR_DOUBLE(ch, true))
appendStringInfoChar(buf, ch);
appendStringInfoChar(buf, ch);
}

Expand Down
50 changes: 50 additions & 0 deletions expected/11.17/sqlite_fdw.out
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,56 @@ ALTER TABLE fts_table ALTER COLUMN name TYPE int;
--Testcase 160:
SELECT * FROM fts_table; -- should fail
ERROR: invalid input syntax for type =1, column type =3
-- issue #62 github
--Testcase 236:
INSERT INTO noprimary VALUES (4, 'Test''s');
--Testcase 237:
INSERT INTO noprimary VALUES (5, 'Test');
--Testcase 238:
SELECT * FROM noprimary;
a | b
---+--------
1 | 2
1 | 2
4 | Test's
5 | Test
(4 rows)

--Testcase 239:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b = 'Test''s';
QUERY PLAN
---------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..7.00 rows=7 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE ((`b` = 'Test''s'))
(3 rows)

--Testcase 240:
SELECT * FROM noprimary where b = 'Test''s';
a | b
---+--------
4 | Test's
(1 row)

--Testcase 241:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b in ('Test''s', 'Test');
QUERY PLAN
------------------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..14.00 rows=14 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE (`b` IN ('Test''s', 'Test'))
(3 rows)

--Testcase 242:
SELECT * FROM noprimary where b in ('Test''s', 'Test');
a | b
---+--------
4 | Test's
5 | Test
(2 rows)

-- Executable test case for pushdown CASE expressions (results)
--Testcase 224:
CREATE FOREIGN TABLE case_exp(c1 int OPTIONS (key 'true'), c3 text, c6 varchar(10)) SERVER sqlite_svr;
Expand Down
50 changes: 50 additions & 0 deletions expected/12.12/sqlite_fdw.out
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,56 @@ ALTER TABLE fts_table ALTER COLUMN name TYPE int;
--Testcase 160:
SELECT * FROM fts_table; -- should fail
ERROR: invalid input syntax for type =1, column type =3
-- issue #62 github
--Testcase 236:
INSERT INTO noprimary VALUES (4, 'Test''s');
--Testcase 237:
INSERT INTO noprimary VALUES (5, 'Test');
--Testcase 238:
SELECT * FROM noprimary;
a | b
---+--------
1 | 2
1 | 2
4 | Test's
5 | Test
(4 rows)

--Testcase 239:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b = 'Test''s';
QUERY PLAN
---------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..7.00 rows=7 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE ((`b` = 'Test''s'))
(3 rows)

--Testcase 240:
SELECT * FROM noprimary where b = 'Test''s';
a | b
---+--------
4 | Test's
(1 row)

--Testcase 241:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b in ('Test''s', 'Test');
QUERY PLAN
------------------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..14.00 rows=14 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE (`b` IN ('Test''s', 'Test'))
(3 rows)

--Testcase 242:
SELECT * FROM noprimary where b in ('Test''s', 'Test');
a | b
---+--------
4 | Test's
5 | Test
(2 rows)

-- Executable test case for pushdown CASE expressions (results)
--Testcase 224:
CREATE FOREIGN TABLE case_exp(c1 int OPTIONS (key 'true'), c3 text, c6 varchar(10)) SERVER sqlite_svr;
Expand Down
50 changes: 50 additions & 0 deletions expected/13.8/sqlite_fdw.out
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,56 @@ ALTER TABLE fts_table ALTER COLUMN name TYPE int;
--Testcase 160:
SELECT * FROM fts_table; -- should fail
ERROR: invalid input syntax for type =1, column type =3
-- issue #62 github
--Testcase 236:
INSERT INTO noprimary VALUES (4, 'Test''s');
--Testcase 237:
INSERT INTO noprimary VALUES (5, 'Test');
--Testcase 238:
SELECT * FROM noprimary;
a | b
---+--------
1 | 2
1 | 2
4 | Test's
5 | Test
(4 rows)

--Testcase 239:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b = 'Test''s';
QUERY PLAN
---------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..7.00 rows=7 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE ((`b` = 'Test''s'))
(3 rows)

--Testcase 240:
SELECT * FROM noprimary where b = 'Test''s';
a | b
---+--------
4 | Test's
(1 row)

--Testcase 241:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b in ('Test''s', 'Test');
QUERY PLAN
------------------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..14.00 rows=14 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE (`b` IN ('Test''s', 'Test'))
(3 rows)

--Testcase 242:
SELECT * FROM noprimary where b in ('Test''s', 'Test');
a | b
---+--------
4 | Test's
5 | Test
(2 rows)

-- Executable test case for pushdown CASE expressions (results)
--Testcase 224:
CREATE FOREIGN TABLE case_exp(c1 int OPTIONS (key 'true'), c3 text, c6 varchar(10)) SERVER sqlite_svr;
Expand Down
50 changes: 50 additions & 0 deletions expected/14.5/sqlite_fdw.out
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,56 @@ ALTER TABLE fts_table ALTER COLUMN name TYPE int;
--Testcase 160:
SELECT * FROM fts_table; -- should fail
ERROR: invalid input syntax for type =1, column type =3
-- issue #62 github
--Testcase 236:
INSERT INTO noprimary VALUES (4, 'Test''s');
--Testcase 237:
INSERT INTO noprimary VALUES (5, 'Test');
--Testcase 238:
SELECT * FROM noprimary;
a | b
---+--------
1 | 2
1 | 2
4 | Test's
5 | Test
(4 rows)

--Testcase 239:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b = 'Test''s';
QUERY PLAN
---------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..7.00 rows=7 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE ((`b` = 'Test''s'))
(3 rows)

--Testcase 240:
SELECT * FROM noprimary where b = 'Test''s';
a | b
---+--------
4 | Test's
(1 row)

--Testcase 241:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b in ('Test''s', 'Test');
QUERY PLAN
------------------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..14.00 rows=14 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE (`b` IN ('Test''s', 'Test'))
(3 rows)

--Testcase 242:
SELECT * FROM noprimary where b in ('Test''s', 'Test');
a | b
---+--------
4 | Test's
5 | Test
(2 rows)

-- INSERT/UPDATE whole row with generated column
--Testcase 216:
CREATE FOREIGN TABLE grem1_1 (
Expand Down
50 changes: 50 additions & 0 deletions expected/15.0/sqlite_fdw.out
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,56 @@ ALTER TABLE fts_table ALTER COLUMN name TYPE int;
--Testcase 160:
SELECT * FROM fts_table; -- should fail
ERROR: invalid input syntax for type =1, column type =3
-- issue #62 github
--Testcase 236:
INSERT INTO noprimary VALUES (4, 'Test''s');
--Testcase 237:
INSERT INTO noprimary VALUES (5, 'Test');
--Testcase 238:
SELECT * FROM noprimary;
a | b
---+--------
1 | 2
1 | 2
4 | Test's
5 | Test
(4 rows)

--Testcase 239:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b = 'Test''s';
QUERY PLAN
---------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..7.00 rows=7 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE ((`b` = 'Test''s'))
(3 rows)

--Testcase 240:
SELECT * FROM noprimary where b = 'Test''s';
a | b
---+--------
4 | Test's
(1 row)

--Testcase 241:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b in ('Test''s', 'Test');
QUERY PLAN
------------------------------------------------------------------------------------------
Foreign Scan on public.noprimary (cost=10.00..14.00 rows=14 width=36)
Output: a, b
SQLite query: SELECT `a`, `b` FROM main."noprimary" WHERE (`b` IN ('Test''s', 'Test'))
(3 rows)

--Testcase 242:
SELECT * FROM noprimary where b in ('Test''s', 'Test');
a | b
---+--------
4 | Test's
5 | Test
(2 rows)

-- INSERT/UPDATE whole row with generated column
--Testcase 216:
CREATE FOREIGN TABLE grem1_1 (
Expand Down
20 changes: 20 additions & 0 deletions sql/11.17/sqlite_fdw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,26 @@ ALTER TABLE fts_table ALTER COLUMN name TYPE int;
--Testcase 160:
SELECT * FROM fts_table; -- should fail

-- issue #62 github
--Testcase 236:
INSERT INTO noprimary VALUES (4, 'Test''s');
--Testcase 237:
INSERT INTO noprimary VALUES (5, 'Test');

--Testcase 238:
SELECT * FROM noprimary;
--Testcase 239:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b = 'Test''s';
--Testcase 240:
SELECT * FROM noprimary where b = 'Test''s';

--Testcase 241:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b in ('Test''s', 'Test');
--Testcase 242:
SELECT * FROM noprimary where b in ('Test''s', 'Test');

-- Executable test case for pushdown CASE expressions (results)
--Testcase 224:
CREATE FOREIGN TABLE case_exp(c1 int OPTIONS (key 'true'), c3 text, c6 varchar(10)) SERVER sqlite_svr;
Expand Down
20 changes: 20 additions & 0 deletions sql/12.12/sqlite_fdw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,26 @@ ALTER TABLE fts_table ALTER COLUMN name TYPE int;
--Testcase 160:
SELECT * FROM fts_table; -- should fail

-- issue #62 github
--Testcase 236:
INSERT INTO noprimary VALUES (4, 'Test''s');
--Testcase 237:
INSERT INTO noprimary VALUES (5, 'Test');

--Testcase 238:
SELECT * FROM noprimary;
--Testcase 239:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b = 'Test''s';
--Testcase 240:
SELECT * FROM noprimary where b = 'Test''s';

--Testcase 241:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b in ('Test''s', 'Test');
--Testcase 242:
SELECT * FROM noprimary where b in ('Test''s', 'Test');

-- Executable test case for pushdown CASE expressions (results)
--Testcase 224:
CREATE FOREIGN TABLE case_exp(c1 int OPTIONS (key 'true'), c3 text, c6 varchar(10)) SERVER sqlite_svr;
Expand Down
10 changes: 10 additions & 0 deletions sql/13.8/sqlite_fdw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,16 @@ ALTER TABLE fts_table ALTER COLUMN name TYPE int;
--Testcase 160:
SELECT * FROM fts_table; -- should fail

-- issue #62 github
--Testcase 236:
SELECT * FROM noprimary;

--Testcase 237:
SELECT * FROM noprimary where b = 'Test''s';

--Testcase 238:
SELECT * FROM noprimary where b in ('Test''s', '2');

-- Executable test case for pushdown CASE expressions (results)
--Testcase 224:
CREATE FOREIGN TABLE case_exp(c1 int OPTIONS (key 'true'), c3 text, c6 varchar(10)) SERVER sqlite_svr;
Expand Down
20 changes: 20 additions & 0 deletions sql/14.5/sqlite_fdw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,26 @@ ALTER TABLE fts_table ALTER COLUMN name TYPE int;
--Testcase 160:
SELECT * FROM fts_table; -- should fail

-- issue #62 github
--Testcase 236:
INSERT INTO noprimary VALUES (4, 'Test''s');
--Testcase 237:
INSERT INTO noprimary VALUES (5, 'Test');

--Testcase 238:
SELECT * FROM noprimary;
--Testcase 239:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b = 'Test''s';
--Testcase 240:
SELECT * FROM noprimary where b = 'Test''s';

--Testcase 241:
EXPLAIN VERBOSE
SELECT * FROM noprimary where b in ('Test''s', 'Test');
--Testcase 242:
SELECT * FROM noprimary where b in ('Test''s', 'Test');

-- INSERT/UPDATE whole row with generated column
--Testcase 216:
CREATE FOREIGN TABLE grem1_1 (
Expand Down
Loading

0 comments on commit 9fd31f4

Please sign in to comment.