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

Replace [0f0959c6f95046e8] with a new and better solution that also fixes the

CTE name resolution problem described in
[forum:/forumpost/8590e3f6dc|forum post 8590e3f6dc].
Test cases for both problems added.

FossilOrigin-Name: 5614279daff5007d6e047c5c1b3cc82ba80a5c91c529525b0fe68b79ee82dd2c
This commit is contained in:
drh
2021-05-20 00:44:04 +00:00
parent 5da5b71435
commit cd1499f47b
9 changed files with 74 additions and 26 deletions

View File

@@ -175,4 +175,20 @@ do_execsql_test 3.1 {
SELECT * FROM t0, t1;
} {}
# Problem described by forum post https://sqlite.org/forum/forumpost/a274248080
#
reset_db
do_execsql_test 4.1 {
CREATE TABLE t1(x INT); INSERT INTO t1 VALUES(1);
CREATE TABLE t2(y INT); INSERT INTO t2 VALUES(2);
WITH t1 AS (SELECT y+100 AS x FROM t2)
UPDATE t1 SET x=(SELECT x FROM t1);
SELECT x, y FROM t1, t2;
} {102 2}
do_execsql_test 4.2 {
WITH t1 AS (SELECT y+100 AS x FROM t2)
UPDATE t1 SET x=x+y FROM t2;
SELECT x, y FROM t1, t2;
} {104 2}
finish_test

View File

@@ -1207,4 +1207,28 @@ do_execsql_test 26.3 {
SELECT * FROM cte ORDER BY +label, +step;
} {a 1 a 2 a 3 b 1 b 2 b 3}
# 2021-05-20
# forum post https://sqlite.org/forum/forumpost/8590e3f6dc
#
reset_db
do_execsql_test 27.1 {
CREATE TABLE t1(k);
CREATE TABLE log(k, cte_map, main_map);
CREATE TABLE map(k, v);
INSERT INTO map VALUES(1, 'main1'), (2, 'main2');
CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
INSERT INTO log
WITH map(k,v) AS (VALUES(1,'cte1'),(2,'cte2'))
SELECT
new.k,
(SELECT v FROM map WHERE k=new.k),
(SELECT v FROM main.map WHERE k=new.k);
END;
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(2);
SELECT k, cte_map, main_map, '|' FROM log ORDER BY k;
} {1 cte1 main1 | 2 cte2 main2 |}
finish_test