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.
13
# This file implements tests for the SQLITE_MISUSE detection logic.
14
# This test file leaks memory and file descriptors.
16
# $Id: misuse.test,v 1.11 2006/01/03 00:33:50 drh Exp $
18
set testdir [file dirname $argv0]
19
source $testdir/tester.tcl
21
proc catchsql2 {sql} {
27
foreach f $data(*) {lappend res $f}
29
foreach f $data(*) {lappend res $data($f)}
38
# Make sure the test logic works
42
catch {file delete -force test2.db}
43
catch {file delete -force test2.db-journal}
44
sqlite3 db test2.db; set ::DB [sqlite3_connection_pointer db]
47
INSERT INTO t1 VALUES(1,2);
55
SELECT x_coalesce(NULL,a) AS 'xyz' FROM t1
57
} {1 {no such function: x_coalesce}}
59
sqlite3_create_function $::DB
61
SELECT x_coalesce(NULL,a) AS 'xyz' FROM t1
65
# Use the x_sqlite_exec() SQL function to simulate the effect of two
66
# threads trying to use the same database at the same time.
68
# It used to be prohibited to invoke sqlite_exec() from within a function,
69
# but that has changed. The following tests used to cause errors but now
75
SELECT x_sqlite_exec('SELECT * FROM t1') AS xyz;
80
catchsql2 {SELECT * FROM t1}
88
# Attempt to register a new SQL function while an sqlite_exec() is active.
92
sqlite3 db test2.db; set ::DB [sqlite3_connection_pointer db]
98
catchsql2 {SELECT * FROM t1}
101
# We used to disallow creating new function from within an exec().
102
# But now this is acceptable.
105
db eval {SELECT * FROM t1} {} {
106
sqlite3_create_function $::DB
112
catchsql2 {SELECT * FROM t1}
120
# Attempt to register a new SQL aggregate while an sqlite_exec() is active.
124
sqlite3 db test2.db; set ::DB [sqlite3_connection_pointer db]
130
catchsql2 {SELECT * FROM t1}
133
# We used to disallow creating new function from within an exec().
134
# But now this is acceptable.
137
db eval {SELECT * FROM t1} {} {
138
sqlite3_create_aggregate $::DB
144
catchsql2 {SELECT * FROM t1}
152
# Attempt to close the database from an sqlite_exec callback.
154
# Update for v3: The db cannot be closed because there are active
155
# VMs. The sqlite3_close call would return SQLITE_BUSY.
158
sqlite3 db test2.db; set ::DB [sqlite3_connection_pointer db]
164
catchsql2 {SELECT * FROM t1}
168
db eval {SELECT * FROM t1} {} {
169
set r [sqlite3_close $::DB]
175
# Flush the TCL statement cache here, otherwise the sqlite3_close() will
176
# fail because there are still un-finalized() VDBEs.
179
catchsql2 {SELECT * FROM t1}
180
} {1 {library routine called out of sequence}}
185
} {1 {library routine called out of sequence}}
187
# Attempt to use a database after it has been closed.
191
sqlite3 db test2.db; set ::DB [sqlite3_connection_pointer db]
197
catchsql2 {SELECT * FROM t1}
202
sqlite3_prepare $::DB {SELECT * FROM t1} -1 TAIL
205
} {1 {(21) library routine called out of sequence}}