1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

When resolving column names in the RETURNING clause, do not ignore an

incorrect table name qualifier.  Raise an error instead.
See [forum:forumpost/85aef8bc01|forum post 85aef8bc01] for context.

FossilOrigin-Name: 51d5c50b2fb373e4c7ddb7e26657c26ad39dc9c2fc629bba5c2522b4150d8fac
This commit is contained in:
drh
2021-03-31 17:42:24 +00:00
parent b3ad4e6118
commit d75aeee535
4 changed files with 52 additions and 12 deletions

View File

@@ -129,4 +129,42 @@ do_catchsql_test 6.1 {
SELECT * FROM t1 ORDER BY id;
} {0 {29 | 1 2 9 29}}
# Forum https://sqlite.org/forum/forumpost/85aef8bc01
# Do not silently ignore nonsense table names in the RETURNING clause.
# Raise an error.
#
reset_db
do_execsql_test 7.1 {
CREATE TABLE t1(a INT, b INT);
CREATE TABLE t2(x INT, y INT);
INSERT INTO t1(a,b) VALUES(1,2);
INSERT INTO t2(x,y) VALUES(1,30);
} {}
do_catchsql_test 7.2 {
UPDATE t1 SET b=b+1 RETURNING new.b;
} {1 {no such column: new.b}}
do_catchsql_test 7.3 {
UPDATE t1 SET b=b+1 RETURNING old.b;
} {1 {no such column: old.b}}
do_catchsql_test 7.4 {
UPDATE t1 SET b=b+1 RETURNING another.b;
} {1 {no such column: another.b}}
do_catchsql_test 7.5 {
UPDATE t1 SET b=b+y FROM t2 WHERE t2.x=t1.a RETURNING t2.x;
} {1 {no such column: t2.x}}
do_catchsql_test 7.6 {
UPDATE t1 SET b=b+y FROM t2 WHERE t2.x=t1.a RETURNING t1.b;
} {0 32}
# This is goofy: The RETURNING clause does not honor the alias
# for the table being modified. This might change in the future.
#
do_catchsql_test 7.7 {
UPDATE t1 AS alias SET b=123 RETURNING alias.b;
} {1 {no such column: alias.b}}
do_catchsql_test 7.8 {
UPDATE t1 AS alias SET b=alias.b+1000 RETURNING t1.b;
} {0 1032}
finish_test