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. This
12 # script focuses on testing internal function sqlite_rename_quotefix().
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix alterqf
20 # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
21 ifcapable !altertable {
27 sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db
28 sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1
29 sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1
32 CREATE TABLE t1(a, b, c);
35 foreach {tn before after} {
36 1 {CREATE VIEW v1 AS SELECT "a", "b", "notacolumn!", "c" FROM t1}
37 {CREATE VIEW v1 AS SELECT "a", "b", 'notacolumn!', "c" FROM t1}
39 2 {CREATE VIEW v1 AS SELECT "a", "b", "not'a'column!", "c" FROM t1}
40 {CREATE VIEW v1 AS SELECT "a", "b", 'not''a''column!', "c" FROM t1}
42 3 {CREATE VIEW v1 AS SELECT "a", "b", "not""a""column!", "c" FROM t1}
43 {CREATE VIEW v1 AS SELECT "a", "b", 'not"a"column!', "c" FROM t1}
45 4 {CREATE VIEW v1 AS SELECT "val", count("b") FROM t1 GROUP BY "abc"}
46 {CREATE VIEW v1 AS SELECT 'val', count("b") FROM t1 GROUP BY 'abc'}
48 5 {CREATE TABLE xyz(a CHECK (a!="str"), b AS (a||"str"))}
49 {CREATE TABLE xyz(a CHECK (a!='str'), b AS (a||'str'))}
51 6 {CREATE INDEX i1 ON t1(a || "str", "b", "val")}
52 {CREATE INDEX i1 ON t1(a || 'str', "b", 'val')}
54 7 {CREATE TRIGGER tr AFTER INSERT ON t1 BEGIN SELECT "abcd"; END}
55 {CREATE TRIGGER tr AFTER INSERT ON t1 BEGIN SELECT 'abcd'; END}
57 8 {CREATE VIEW v1 AS SELECT "string"'alias' FROM t1}
58 {CREATE VIEW v1 AS SELECT 'string' 'alias' FROM t1}
60 9 {CREATE INDEX i1 ON t1(a) WHERE "b"="bb"}
61 {CREATE INDEX i1 ON t1(a) WHERE "b"='bb'}
63 10 {CREATE TABLE t2(abc, xyz CHECK (xyz != "123"))}
64 {CREATE TABLE t2(abc, xyz CHECK (xyz != '123'))}
66 11 {CREATE TRIGGER ott AFTER UPDATE ON t1 BEGIN
67 SELECT max("str", new."a") FROM t1
68 WHERE string_agg("b", ",") OVER (ORDER BY c||"str");
69 UPDATE t1 SET c= b + "str";
70 DELETE FROM t1 WHERE EXISTS (
71 SELECT 1 FROM t1 AS o WHERE o."a" = "o.a" AND t1.b IN("t1.b")
74 } {CREATE TRIGGER ott AFTER UPDATE ON t1 BEGIN
75 SELECT max('str', new."a") FROM t1
76 WHERE string_agg("b", ',') OVER (ORDER BY c||'str');
77 UPDATE t1 SET c= b + 'str';
78 DELETE FROM t1 WHERE EXISTS (
79 SELECT 1 FROM t1 AS o WHERE o."a" = 'o.a' AND t1.b IN('t1.b')
85 do_execsql_test 1.$tn {
86 SELECT sqlite_rename_quotefix('main', $before)
90 #-------------------------------------------------------------------------
92 sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1
93 sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1
96 one, two, three, PRIMARY KEY(one),
97 CHECK (three!="xyz"), CHECK (two!="one")
99 CREATE INDEX x1i ON x1(one+"two"+"four") WHERE "five";
100 CREATE TEMP TRIGGER AFTER INSERT ON x1 BEGIN
101 UPDATE x1 SET two=new.three || "new" WHERE one=new.one||"";
105 do_execsql_test 2.1 {
106 ALTER TABLE x1 RENAME two TO 'four';
107 SELECT sql FROM sqlite_schema;
108 SELECT sql FROM sqlite_temp_schema;
110 one, "four", three, PRIMARY KEY(one),
111 CHECK (three!='xyz'), CHECK ("four"!="one")
113 {CREATE INDEX x1i ON x1(one+"four"+'four') WHERE 'five'}
114 {CREATE TRIGGER AFTER INSERT ON x1 BEGIN
115 UPDATE x1 SET "four"=new.three || 'new' WHERE one=new.one||'';