sl@0
|
1 |
# 2008 July 11
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# This file experiments with recursion using the "test_eval()" SQL function
|
sl@0
|
14 |
# in order to make sure that SQLite is reentrant.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# $Id: eval.test,v 1.1 2008/07/11 21:02:54 drh Exp $
|
sl@0
|
17 |
|
sl@0
|
18 |
set testdir [file dirname $argv0]
|
sl@0
|
19 |
source $testdir/tester.tcl
|
sl@0
|
20 |
|
sl@0
|
21 |
# Create a table to work with.
|
sl@0
|
22 |
#
|
sl@0
|
23 |
do_test eval-1.1 {
|
sl@0
|
24 |
execsql {
|
sl@0
|
25 |
CREATE TABLE t1(x INTEGER PRIMARY KEY);
|
sl@0
|
26 |
INSERT INTO t1 VALUES(1);
|
sl@0
|
27 |
INSERT INTO t1 VALUES(2);
|
sl@0
|
28 |
INSERT INTO t1 SELECT x+2 FROM t1;
|
sl@0
|
29 |
INSERT INTO t1 SELECT x+4 FROM t1;
|
sl@0
|
30 |
INSERT INTO t1 SELECT x+8 FROM t1;
|
sl@0
|
31 |
INSERT INTO t1 SELECT x+16 FROM t1;
|
sl@0
|
32 |
INSERT INTO t1 SELECT x+32 FROM t1;
|
sl@0
|
33 |
INSERT INTO t1 SELECT x+64 FROM t1;
|
sl@0
|
34 |
INSERT INTO t1 SELECT x+128 FROM t1;
|
sl@0
|
35 |
INSERT INTO t1 SELECT x+256 FROM t1;
|
sl@0
|
36 |
SELECT count(*), max(x) FROM t1;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
} {512 512}
|
sl@0
|
39 |
do_test eval-1.2 {
|
sl@0
|
40 |
execsql {
|
sl@0
|
41 |
SELECT x, test_eval('SELECT max(x) FROM t1 WHERE x<' || x) FROM t1 LIMIT 5
|
sl@0
|
42 |
}
|
sl@0
|
43 |
} {1 {} 2 1 3 2 4 3 5 4}
|
sl@0
|
44 |
|
sl@0
|
45 |
# Delete a row out from under a read cursor in the middle of
|
sl@0
|
46 |
# collecting the arguments for a single row in a result set.
|
sl@0
|
47 |
# Verify that subsequent rows come out as NULL.
|
sl@0
|
48 |
#
|
sl@0
|
49 |
do_test eval-2.1 {
|
sl@0
|
50 |
execsql {
|
sl@0
|
51 |
CREATE TABLE t2(x,y);
|
sl@0
|
52 |
INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5;
|
sl@0
|
53 |
SELECT x, test_eval('DELETE FROM t2 WHERE x='||x), y FROM t2;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
} {1 {} {} 2 {} {} 3 {} {} 4 {} {}}
|
sl@0
|
56 |
do_test eval-2.2 {
|
sl@0
|
57 |
execsql {
|
sl@0
|
58 |
SELECT * FROM t2
|
sl@0
|
59 |
}
|
sl@0
|
60 |
} {}
|
sl@0
|
61 |
|
sl@0
|
62 |
# Modify a row while it is being read.
|
sl@0
|
63 |
#
|
sl@0
|
64 |
do_test eval-3.1 {
|
sl@0
|
65 |
execsql {
|
sl@0
|
66 |
INSERT INTO t2 SELECT x, x+1 FROM t1 WHERE x<5;
|
sl@0
|
67 |
SELECT x, test_eval('UPDATE t2 SET y=y+100 WHERE x='||x), y FROM t2;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
} {1 {} 102 2 {} 103 3 {} 104 4 {} 105}
|
sl@0
|
70 |
|
sl@0
|
71 |
finish_test
|