2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library.
16 # This file implements tests for the SQLITE_MISUSE detection logic.
17 # This test file leaks memory and file descriptors.
19 # $Id: misuse.test,v 1.4 2004/01/07 19:24:48 drh Exp $
21 set testdir [file dirname $argv0]
22 source $testdir/tester.tcl
24 # Make sure the test logic works
28 catch {file delete -force test2.db}
29 set ::DB [sqlite db test2.db]
32 INSERT INTO t1 VALUES(1,2);
34 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
37 sqlite_exec_printf $::DB {SELECT x_coalesce(NULL,a) AS 'xyz' FROM t1} {}
38 } {1 {no such function: x_coalesce}}
40 sqlite_create_function $::DB
41 sqlite_exec_printf $::DB {SELECT x_coalesce(NULL,a) AS 'xyz' FROM t1} {}
44 # Use the x_sqlite_exec() SQL function to simulate the effect of two
45 # threads trying to use the same database at the same time.
47 # It used to be prohibited to invoke sqlite_exec() from within a function,
48 # but that has changed. The following tests used to cause errors but now
52 sqlite_exec_printf $::DB {
53 SELECT x_sqlite_exec('SELECT * FROM t1') AS xyz;
57 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
65 # Attempt to register a new SQL function while an sqlite_exec() is active.
69 set ::DB [sqlite db test2.db]
75 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
79 db eval {SELECT * FROM t1} {} {
80 sqlite_create_function $::DB
84 } {1 {library routine called out of sequence}}
86 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
87 } {21 {library routine called out of sequence}}
92 } {1 {library routine called out of sequence}}
94 # Attempt to register a new SQL aggregate while an sqlite_exec() is active.
98 set ::DB [sqlite db test2.db]
104 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
108 db eval {SELECT * FROM t1} {} {
109 sqlite_create_aggregate $::DB
113 } {1 {library routine called out of sequence}}
115 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
116 } {21 {library routine called out of sequence}}
121 } {1 {library routine called out of sequence}}
123 # Attempt to close the database from an sqlite_exec callback.
127 set ::DB [sqlite db test2.db]
133 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
137 db eval {SELECT * FROM t1} {} {
142 } {1 {library routine called out of sequence}}
144 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
145 } {21 {library routine called out of sequence}}
150 } {1 {library routine called out of sequence}}
152 # Attempt to use a database after it has been closed.
156 set ::DB [sqlite db test2.db]
162 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
166 sqlite_exec_printf $::DB {SELECT * FROM t1} {}
167 } {21 {library routine called out of sequence}}