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.
12 # The focus of this script is testing the "eval.c" loadable extension.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
18 load_static_extension db eval
19 do_execsql_test misc8-1.0 {
20 CREATE TABLE t1(a,b,c);
21 INSERT INTO t1 VALUES(1,2,3),(4,5,6);
22 SELECT quote(eval('SELECT * FROM t1 ORDER BY a','-abc-'));
23 } {'1-abc-2-abc-3-abc-4-abc-5-abc-6'}
24 do_execsql_test misc8-1.1 {
25 SELECT quote(eval('SELECT * FROM t1 ORDER BY a'));
27 do_catchsql_test misc8-1.2 {
28 SELECT quote(eval('SELECT d FROM t1 ORDER BY a'));
29 } {1 {no such column: d}}
30 do_execsql_test misc8-1.3 {
31 INSERT INTO t1 VALUES(7,null,9);
32 SELECT eval('SELECT * FROM t1 ORDER BY a',',');
34 do_catchsql_test misc8-1.4 {
36 INSERT INTO t1 VALUES(10,11,12);
37 SELECT a, coalesce(b, eval('ROLLBACK; SELECT ''bam'';')), c
39 } {0 {1 2 3 4 5 6 7 bam 9}}
40 do_catchsql_test misc8-1.5 {
41 INSERT INTO t1 VALUES(10,11,12);
42 SELECT a, coalesce(b, eval('SELECT ''bam''')), c
45 } {0 {1 2 3 4 5 6 7 bam 9 10 11 12}}
46 do_catchsql_test misc8-1.6 {
47 SELECT a, coalesce(b, eval('DELETE FROM t1; SELECT ''bam''')), c
50 } {0 {1 2 3 4 5 6 7 bam {}}}
51 do_catchsql_test misc8-1.7 {
52 INSERT INTO t1 VALUES(1,2,3),(4,5,6),(7,null,9);
55 SELECT a, coalesce(b, eval('ROLLBACK; SELECT ''bam''')), c
58 } {1 {abort due to ROLLBACK}}
63 proc dbeval {sql} { db eval $sql }
66 do_execsql_test misc8-2.1 {
67 CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER) WITHOUT ROWID;
68 CREATE TABLE t2(c INTEGER PRIMARY KEY, d INTEGER, x BLOB);
69 INSERT INTO t1 VALUES(0,0);
70 INSERT INTO t1 VALUES(10,10);
71 INSERT INTO t2 VALUES(1,1,zeroblob(200));
72 INSERT INTO t2 VALUES(2,2,zeroblob(200));
73 INSERT INTO t2 VALUES(3,3,zeroblob(200));
74 INSERT INTO t2 VALUES(4,4,zeroblob(200));
75 INSERT INTO t2 VALUES(5,5,zeroblob(200));
76 INSERT INTO t2 VALUES(6,6,zeroblob(200));
77 INSERT INTO t2 VALUES(7,7,zeroblob(200));
78 INSERT INTO t2 VALUES(8,8,zeroblob(200));
79 INSERT INTO t2 VALUES(9,9,zeroblob(200));
80 INSERT INTO t2 VALUES(10,10,zeroblob(200));
82 printf('DELETE FROM t2 WHERE c=%d AND %d>5', a+c, a+c)
97 # 2016-02-26: An assertion fault found by the libFuzzer project
99 do_execsql_test misc8-3.0 {
103 (SELECT 0 AS i) AS x1,
106 (SELECT 6 AS j UNION ALL SELECT 7) AS x4
111 # The SQLITE_DBCONFIG_MAINDBNAME interface
114 forcedelete test.db test2.db
116 do_execsql_test misc8-4.0 {
117 CREATE TABLE t1(a,b,c);
118 INSERT INTO t1 VALUES(1,2,3);
119 ATTACH 'test2.db' AS aux2;
120 CREATE TABLE aux2.t2(c,d,e);
121 INSERT INTO t2 VALUES(4,5,6);
122 SELECT * FROM t1, t2;
124 do_execsql_test misc8-4.1 {
125 PRAGMA database_list;
126 } {/0 main .* 2 aux2/}
127 dbconfig_maindbname_icecube db
128 do_execsql_test misc8-4.2 {
129 SELECT name FROM icecube.sqlite_master;
131 do_execsql_test misc8-4.3 {
132 PRAGMA database_list;
133 } {/0 icecube .* 2 aux2/}