xref: /sqlite-3.40.0/test/eval.test (revision 7d44b22d)
1a3460585Sdrh# 2008 July 11
2a3460585Sdrh#
3a3460585Sdrh# The author disclaims copyright to this source code.  In place of
4a3460585Sdrh# a legal notice, here is a blessing:
5a3460585Sdrh#
6a3460585Sdrh#    May you do good and not evil.
7a3460585Sdrh#    May you find forgiveness for yourself and forgive others.
8a3460585Sdrh#    May you share freely, never taking more than you give.
9a3460585Sdrh#
10a3460585Sdrh#***********************************************************************
11a3460585Sdrh# This file implements regression tests for SQLite library.
12a3460585Sdrh#
13a3460585Sdrh# This file experiments with recursion using the "test_eval()" SQL function
14a3460585Sdrh# in order to make sure that SQLite is reentrant.
15a3460585Sdrh#
16d0ffa1e8Sdanielk1977# $Id: eval.test,v 1.2 2008/10/13 10:37:50 danielk1977 Exp $
17a3460585Sdrh
18a3460585Sdrhset testdir [file dirname $argv0]
19a3460585Sdrhsource $testdir/tester.tcl
20a3460585Sdrh
21a3460585Sdrh# Create a table to work with.
22a3460585Sdrh#
23a3460585Sdrhdo_test eval-1.1 {
24a3460585Sdrh  execsql {
25a3460585Sdrh    CREATE TABLE t1(x INTEGER PRIMARY KEY);
26a3460585Sdrh    INSERT INTO t1 VALUES(1);
27a3460585Sdrh    INSERT INTO t1 VALUES(2);
28a3460585Sdrh    INSERT INTO t1 SELECT x+2 FROM t1;
29a3460585Sdrh    INSERT INTO t1 SELECT x+4 FROM t1;
30a3460585Sdrh    INSERT INTO t1 SELECT x+8 FROM t1;
31a3460585Sdrh    INSERT INTO t1 SELECT x+16 FROM t1;
32a3460585Sdrh    INSERT INTO t1 SELECT x+32 FROM t1;
33a3460585Sdrh    INSERT INTO t1 SELECT x+64 FROM t1;
34a3460585Sdrh    INSERT INTO t1 SELECT x+128 FROM t1;
35a3460585Sdrh    INSERT INTO t1 SELECT x+256 FROM t1;
36a3460585Sdrh    SELECT count(*), max(x) FROM t1;
37a3460585Sdrh  }
38a3460585Sdrh} {512 512}
39a3460585Sdrhdo_test eval-1.2 {
40a3460585Sdrh  execsql {
41a3460585Sdrh    SELECT x, test_eval('SELECT max(x) FROM t1 WHERE x<' || x) FROM t1 LIMIT 5
42a3460585Sdrh  }
43a3460585Sdrh} {1 {} 2 1 3 2 4 3 5 4}
44a3460585Sdrh
45a3460585Sdrh# Delete a row out from under a read cursor in the middle of
46a3460585Sdrh# collecting the arguments for a single row in a result set.
47a3460585Sdrh# Verify that subsequent rows come out as NULL.
48a3460585Sdrh#
49a3460585Sdrhdo_test eval-2.1 {
50a3460585Sdrh  execsql {
51a3460585Sdrh    CREATE TABLE t2(x,y);
52a3460585Sdrh    INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5;
53a3460585Sdrh    SELECT x, test_eval('DELETE FROM t2 WHERE x='||x), y FROM t2;
54a3460585Sdrh  }
55a3460585Sdrh} {1 {} {} 2 {} {} 3 {} {} 4 {} {}}
56a3460585Sdrhdo_test eval-2.2 {
57a3460585Sdrh  execsql {
58a3460585Sdrh    SELECT * FROM t2
59a3460585Sdrh  }
60a3460585Sdrh} {}
617682a476Sdrhdo_test eval-2.3 {
627682a476Sdrh  execsql {
637682a476Sdrh    INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5;
647682a476Sdrh    SELECT x, test_eval('DELETE FROM t2 WHERE x='||x), y FROM t2
657682a476Sdrh     ORDER BY rowid DESC;
667682a476Sdrh  }
677682a476Sdrh} {4 {} {} 3 {} {} 2 {} {} 1 {} {}}
687682a476Sdrhdo_test eval-2.4 {
697682a476Sdrh  execsql {
707682a476Sdrh    SELECT * FROM t2
717682a476Sdrh  }
727682a476Sdrh} {}
73a3460585Sdrh
74a3460585Sdrh# Modify a row while it is being read.
75a3460585Sdrh#
76a3460585Sdrhdo_test eval-3.1 {
77a3460585Sdrh  execsql {
78a3460585Sdrh    INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5;
79a3460585Sdrh    SELECT x, test_eval('UPDATE t2 SET y=y+100 WHERE x='||x), y FROM t2;
80a3460585Sdrh  }
81a3460585Sdrh} {1 {} 102 2 {} 103 3 {} 104 4 {} 105}
82a3460585Sdrh
83d0ffa1e8Sdanielk1977do_test eval-4.1 {
84*7d44b22dSdrh  execsql { SELECT test_eval('SELECT ''abcdefghij''') }
85d0ffa1e8Sdanielk1977} {abcdefghij}
86d0ffa1e8Sdanielk1977
87a3460585Sdrhfinish_test
88