xref: /sqlite-3.40.0/test/misc8.test (revision 6e5020e8)
11728bcb0Sdrh# 2014-11-10
21728bcb0Sdrh#
31728bcb0Sdrh# The author disclaims copyright to this source code.  In place of
41728bcb0Sdrh# a legal notice, here is a blessing:
51728bcb0Sdrh#
61728bcb0Sdrh#    May you do good and not evil.
71728bcb0Sdrh#    May you find forgiveness for yourself and forgive others.
81728bcb0Sdrh#    May you share freely, never taking more than you give.
91728bcb0Sdrh#
101728bcb0Sdrh#***********************************************************************
111728bcb0Sdrh# This file implements regression tests for SQLite library.
121728bcb0Sdrh# The focus of this script is testing the "eval.c" loadable extension.
131728bcb0Sdrh#
141728bcb0Sdrh
151728bcb0Sdrhset testdir [file dirname $argv0]
161728bcb0Sdrhsource $testdir/tester.tcl
171728bcb0Sdrh
181728bcb0Sdrhload_static_extension db eval
191728bcb0Sdrhdo_execsql_test misc8-1.0 {
201728bcb0Sdrh  CREATE TABLE t1(a,b,c);
211728bcb0Sdrh  INSERT INTO t1 VALUES(1,2,3),(4,5,6);
221728bcb0Sdrh  SELECT quote(eval('SELECT * FROM t1 ORDER BY a','-abc-'));
231728bcb0Sdrh} {'1-abc-2-abc-3-abc-4-abc-5-abc-6'}
241728bcb0Sdrhdo_execsql_test misc8-1.1 {
251728bcb0Sdrh  SELECT quote(eval('SELECT * FROM t1 ORDER BY a'));
261728bcb0Sdrh} {{'1 2 3 4 5 6'}}
271728bcb0Sdrhdo_catchsql_test misc8-1.2 {
281728bcb0Sdrh  SELECT quote(eval('SELECT d FROM t1 ORDER BY a'));
291728bcb0Sdrh} {1 {no such column: d}}
301728bcb0Sdrhdo_execsql_test misc8-1.3 {
311728bcb0Sdrh  INSERT INTO t1 VALUES(7,null,9);
321728bcb0Sdrh  SELECT eval('SELECT * FROM t1 ORDER BY a',',');
331728bcb0Sdrh} {1,2,3,4,5,6,7,,9}
341728bcb0Sdrhdo_catchsql_test misc8-1.4 {
351728bcb0Sdrh  BEGIN;
361728bcb0Sdrh  INSERT INTO t1 VALUES(10,11,12);
3747b7fc78Sdrh  SELECT a, coalesce(b, eval('ROLLBACK; SELECT ''bam'';')), c
3847b7fc78Sdrh   FROM t1 ORDER BY a;
3947b7fc78Sdrh} {0 {1 2 3 4 5 6 7 bam 9}}
40de58f4feSdrhdo_catchsql_test misc8-1.5 {
41de58f4feSdrh  INSERT INTO t1 VALUES(10,11,12);
42de58f4feSdrh  SELECT a, coalesce(b, eval('SELECT ''bam''')), c
43de58f4feSdrh    FROM t1
44de58f4feSdrh   ORDER BY rowid;
45de58f4feSdrh} {0 {1 2 3 4 5 6 7 bam 9 10 11 12}}
46de58f4feSdrhdo_catchsql_test misc8-1.6 {
47de58f4feSdrh  SELECT a, coalesce(b, eval('DELETE FROM t1; SELECT ''bam''')), c
48de58f4feSdrh    FROM t1
49de58f4feSdrh   ORDER BY rowid;
50de58f4feSdrh} {0 {1 2 3 4 5 6 7 bam {}}}
5147b7fc78Sdrhdo_catchsql_test misc8-1.7 {
5247b7fc78Sdrh  INSERT INTO t1 VALUES(1,2,3),(4,5,6),(7,null,9);
5347b7fc78Sdrh  BEGIN;
5447b7fc78Sdrh  CREATE TABLE t2(x);
5547b7fc78Sdrh  SELECT a, coalesce(b, eval('ROLLBACK; SELECT ''bam''')), c
5647b7fc78Sdrh    FROM t1
5747b7fc78Sdrh   ORDER BY rowid;
5847b7fc78Sdrh} {1 {abort due to ROLLBACK}}
591728bcb0Sdrh
6033fc2779Smistachkindo_catchsql_test misc8-1.8 {
6133fc2779Smistachkin  PRAGMA empty_result_callbacks = 1;
6233fc2779Smistachkin  SELECT eval('SELECT * FROM t1 WHERE 1 = 0;');
6333fc2779Smistachkin} {0 {{}}}
641728bcb0Sdrh
652b8669a9Sdanreset_db
662b8669a9Sdan
672b8669a9Sdanproc dbeval {sql} { db eval $sql }
682b8669a9Sdandb func eval dbeval
692b8669a9Sdan
702b8669a9Sdando_execsql_test misc8-2.1 {
712b8669a9Sdan  CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER) WITHOUT ROWID;
722b8669a9Sdan  CREATE TABLE t2(c INTEGER PRIMARY KEY, d INTEGER, x BLOB);
732b8669a9Sdan  INSERT INTO t1 VALUES(0,0);
742b8669a9Sdan  INSERT INTO t1 VALUES(10,10);
752b8669a9Sdan  INSERT INTO t2 VALUES(1,1,zeroblob(200));
762b8669a9Sdan  INSERT INTO t2 VALUES(2,2,zeroblob(200));
772b8669a9Sdan  INSERT INTO t2 VALUES(3,3,zeroblob(200));
782b8669a9Sdan  INSERT INTO t2 VALUES(4,4,zeroblob(200));
792b8669a9Sdan  INSERT INTO t2 VALUES(5,5,zeroblob(200));
802b8669a9Sdan  INSERT INTO t2 VALUES(6,6,zeroblob(200));
812b8669a9Sdan  INSERT INTO t2 VALUES(7,7,zeroblob(200));
822b8669a9Sdan  INSERT INTO t2 VALUES(8,8,zeroblob(200));
832b8669a9Sdan  INSERT INTO t2 VALUES(9,9,zeroblob(200));
842b8669a9Sdan  INSERT INTO t2 VALUES(10,10,zeroblob(200));
852b8669a9Sdan  SELECT a, c, eval(
862b8669a9Sdan      printf('DELETE FROM t2 WHERE c=%d AND %d>5', a+c, a+c)
872b8669a9Sdan  ) FROM t1, t2;
882b8669a9Sdan} {
892b8669a9Sdan  0 1 {} 10 1 {}
902b8669a9Sdan  0 2 {} 10 2 {}
912b8669a9Sdan  0 3 {} 10 3 {}
922b8669a9Sdan  0 4 {} 10 4 {}
932b8669a9Sdan  0 5 {} 10 5 {}
942b8669a9Sdan  0 6 {} 10 {} {}
952b8669a9Sdan  0 7 {} 10 {} {}
962b8669a9Sdan  0 8 {} 10 {} {}
972b8669a9Sdan  0 9 {} 10 {} {}
982b8669a9Sdan  0 10 {} 10 {} {}
992b8669a9Sdan}
1002b8669a9Sdan
10126bcc7cfSdrh# 2016-02-26: An assertion fault found by the libFuzzer project
10226bcc7cfSdrh#
103*6e5020e8Sdrhdo_catchsql_test misc8-3.0 {
10426bcc7cfSdrh  SELECT *
10526bcc7cfSdrh    FROM
10626bcc7cfSdrh         (
10726bcc7cfSdrh           (SELECT 0 AS i) AS x1,
10826bcc7cfSdrh           (SELECT 1) AS x2
10926bcc7cfSdrh         ) AS x3,
11026bcc7cfSdrh         (SELECT 6 AS j UNION ALL SELECT 7) AS x4
11126bcc7cfSdrh   WHERE i<rowid
11226bcc7cfSdrh   ORDER BY 1;
113*6e5020e8Sdrh} {1 {no such column: rowid}}
1142b8669a9Sdan
115da84dcaeSdrh# The SQLITE_DBCONFIG_MAINDBNAME interface
116da84dcaeSdrh#
117da84dcaeSdrhdb close
118da84dcaeSdrhforcedelete test.db test2.db
119da84dcaeSdrhsqlite3 db test.db
120da84dcaeSdrhdo_execsql_test misc8-4.0 {
121da84dcaeSdrh  CREATE TABLE t1(a,b,c);
122da84dcaeSdrh  INSERT INTO t1 VALUES(1,2,3);
123da84dcaeSdrh  ATTACH 'test2.db' AS aux2;
124da84dcaeSdrh  CREATE TABLE aux2.t2(c,d,e);
125da84dcaeSdrh  INSERT INTO t2 VALUES(4,5,6);
126da84dcaeSdrh  SELECT * FROM t1, t2;
127da84dcaeSdrh} {1 2 3 4 5 6}
128da84dcaeSdrhdo_execsql_test misc8-4.1 {
129da84dcaeSdrh  PRAGMA database_list;
130da84dcaeSdrh} {/0 main .* 2 aux2/}
131da84dcaeSdrhdbconfig_maindbname_icecube db
132da84dcaeSdrhdo_execsql_test misc8-4.2 {
133da84dcaeSdrh  SELECT name FROM icecube.sqlite_master;
134da84dcaeSdrh} {t1}
13500bd55e1Sdando_test misc8-4.3 {
13600bd55e1Sdan  regexp {0 icecube .* 2 aux2} [db eval {PRAGMA database_list}]
13700bd55e1Sdan} 1
138da84dcaeSdrh
139da84dcaeSdrh
140da84dcaeSdrh
1411728bcb0Sdrhfinish_test
142