3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #*************************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing UPDATE statements with FROM clauses
13 # against FTS4 tables.
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set testprefix fts4upfrom
21 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
27 foreach {tn create_table} {
28 0 { CREATE VIRTUAL TABLE ft USING fts5(a, b, c) }
29 1 { CREATE VIRTUAL TABLE ft USING fts3(a, b, c) }
30 2 { CREATE TABLE ft(a, b, c) }
32 CREATE TABLE real(a, b, c);
33 CREATE INDEX i1 ON real(a);
34 CREATE VIEW ft AS SELECT rowid, a, b, c FROM real;
35 CREATE TRIGGER tr1 INSTEAD OF INSERT ON ft BEGIN
36 INSERT INTO real(rowid, a, b, c) VALUES(new.rowid, new.a, new.b, new.c);
38 CREATE TRIGGER tr2 INSTEAD OF UPDATE ON ft BEGIN
39 UPDATE real SET rowid=new.rowid, a=new.a, b=new.b, c=new.c
40 WHERE rowid=old.rowid;
44 if {$tn==0} { ifcapable !fts5 { continue } }
45 catchsql { DROP VIEW IF EXISTS changes }
46 catchsql { DROP TABLE IF EXISTS ft }
47 catchsql { DROP VIEW IF EXISTS ft }
50 do_execsql_test 1.$tn.0 {
51 INSERT INTO ft(a, b, c) VALUES('a', NULL, 'apple');
52 INSERT INTO ft(a, b, c) VALUES('b', NULL, 'banana');
53 INSERT INTO ft(a, b, c) VALUES('c', NULL, 'cherry');
54 INSERT INTO ft(a, b, c) VALUES('d', NULL, 'damson plum');
57 do_execsql_test 1.$tn.1 {
58 SELECT a, b, c FROM ft ORDER BY rowid;
66 do_execsql_test 1.$tn.2 {
67 UPDATE ft SET b=o.c FROM ft AS o WHERE (ft.a == char(unicode(o.a)+1))
70 do_execsql_test 1.$tn.3 {
71 SELECT a, b, c FROM ft ORDER BY rowid;
76 d cherry {damson plum}
79 do_catchsql_test 1.$tn.4 {
80 UPDATE ft SET c=v FROM changes WHERE a=k;
81 } {1 {no such table: changes}}
83 do_execsql_test 1.$tn.5 {
84 create view changes(k, v) AS
85 VALUES( 'd', 'dewberry' ) UNION ALL
86 VALUES( 'c', 'clementine' ) UNION ALL
87 VALUES( 'b', 'blueberry' ) UNION ALL
88 VALUES( 'a', 'apricot' )
92 do_execsql_test 1.$tn.6 {
93 UPDATE ft SET c=v FROM changes WHERE a=k;
96 do_execsql_test 1.$tn.7 {
97 SELECT rowid, a, b, c FROM ft ORDER BY rowid;
101 3 c banana clementine
105 do_execsql_test 1.$tn.8 "
107 VALUES(1, 11) UNION ALL
108 VALUES(2, 12) UNION ALL
109 VALUES(3, 13) UNION ALL
112 SELECT ft.rowid, a, b, c, o, n FROM ft, x1 WHERE ft.rowid = o;
115 2 b apple blueberry 2 12
116 3 c banana clementine 3 13
117 4 d cherry dewberry 4 14
121 if {$tn==1} { set ROWID docid }
122 do_execsql_test 1.$tn.9 "
124 VALUES(1, 11) UNION ALL
125 VALUES(2, 12) UNION ALL
126 VALUES(3, 13) UNION ALL
129 UPDATE ft SET $ROWID = n FROM x1 WHERE ft.rowid = o;
130 SELECT rowid, a, b, c FROM ft ORDER BY rowid;
134 13 c banana clementine