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}}
60 do_catchsql_test misc8-1.8 {
61 PRAGMA empty_result_callbacks = 1;
62 SELECT eval('SELECT * FROM t1 WHERE 1 = 0;');
67 proc dbeval {sql} { db eval $sql }
70 do_execsql_test misc8-2.1 {
71 CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER) WITHOUT ROWID;
72 CREATE TABLE t2(c INTEGER PRIMARY KEY, d INTEGER, x BLOB);
73 INSERT INTO t1 VALUES(0,0);
74 INSERT INTO t1 VALUES(10,10);
75 INSERT INTO t2 VALUES(1,1,zeroblob(200));
76 INSERT INTO t2 VALUES(2,2,zeroblob(200));
77 INSERT INTO t2 VALUES(3,3,zeroblob(200));
78 INSERT INTO t2 VALUES(4,4,zeroblob(200));
79 INSERT INTO t2 VALUES(5,5,zeroblob(200));
80 INSERT INTO t2 VALUES(6,6,zeroblob(200));
81 INSERT INTO t2 VALUES(7,7,zeroblob(200));
82 INSERT INTO t2 VALUES(8,8,zeroblob(200));
83 INSERT INTO t2 VALUES(9,9,zeroblob(200));
84 INSERT INTO t2 VALUES(10,10,zeroblob(200));
86 printf('DELETE FROM t2 WHERE c=%d AND %d>5', a+c, a+c)
101 # 2016-02-26: An assertion fault found by the libFuzzer project
103 do_catchsql_test misc8-3.0 {
107 (SELECT 0 AS i) AS x1,
110 (SELECT 6 AS j UNION ALL SELECT 7) AS x4
113 } {1 {no such column: rowid}}
115 # The SQLITE_DBCONFIG_MAINDBNAME interface
118 forcedelete test.db test2.db
120 do_execsql_test misc8-4.0 {
121 CREATE TABLE t1(a,b,c);
122 INSERT INTO t1 VALUES(1,2,3);
123 ATTACH 'test2.db' AS aux2;
124 CREATE TABLE aux2.t2(c,d,e);
125 INSERT INTO t2 VALUES(4,5,6);
126 SELECT * FROM t1, t2;
128 do_execsql_test misc8-4.1 {
129 PRAGMA database_list;
130 } {/0 main .* 2 aux2/}
131 dbconfig_maindbname_icecube db
132 do_execsql_test misc8-4.2 {
133 SELECT name FROM icecube.sqlite_master;
136 regexp {0 icecube .* 2 aux2} [db eval {PRAGMA database_list}]