123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- # 2002 May 10
- #
- # The author disclaims copyright to this source code. In place of
- # a legal notice, here is a blessing:
- #
- # May you do good and not evil.
- # May you find forgiveness for yourself and forgive others.
- # May you share freely, never taking more than you give.
- #
- #***********************************************************************
- # This file implements regression tests for SQLite library.
- #
- # This file implements tests for the SQLITE_MISUSE detection logic.
- # This test file leaks memory and file descriptors.
- #
- # $Id: misuse.test,v 1.3 2002/05/21 11:38:12 drh Exp $
- set testdir [file dirname $argv0]
- source $testdir/tester.tcl
- # Make sure the test logic works
- #
- do_test misuse-1.1 {
- db close
- catch {file delete -force test2.db}
- set ::DB [sqlite db test2.db]
- execsql {
- CREATE TABLE t1(a,b);
- INSERT INTO t1 VALUES(1,2);
- }
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {0 {a b 1 2}}
- do_test misuse-1.2 {
- sqlite_exec_printf $::DB {SELECT x_coalesce(NULL,a) AS 'xyz' FROM t1} {}
- } {1 {no such function: x_coalesce}}
- do_test misuse-1.3 {
- sqlite_create_function $::DB
- sqlite_exec_printf $::DB {SELECT x_coalesce(NULL,a) AS 'xyz' FROM t1} {}
- } {0 {xyz 1}}
- # Use the x_sqlite_exec() SQL function to simulate the effect of two
- # threads trying to use the same database at the same time.
- #
- do_test misuse-1.4 {
- sqlite_exec_printf $::DB {
- SELECT x_sqlite_exec('SELECT * FROM t1');
- } {}
- } {21 {library routine called out of sequence}}
- do_test misuse-1.5 {
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {21 {library routine called out of sequence}}
- do_test misuse-1.6 {
- catchsql {
- SELECT * FROM t1
- }
- } {1 {library routine called out of sequence}}
- # Attempt to register a new SQL function while an sqlite_exec() is active.
- #
- do_test misuse-2.1 {
- db close
- set ::DB [sqlite db test2.db]
- execsql {
- SELECT * FROM t1
- }
- } {1 2}
- do_test misuse-2.2 {
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {0 {a b 1 2}}
- do_test misuse-2.3 {
- set v [catch {
- db eval {SELECT * FROM t1} {} {
- sqlite_create_function $::DB
- }
- } msg]
- lappend v $msg
- } {1 {library routine called out of sequence}}
- do_test misuse-2.4 {
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {21 {library routine called out of sequence}}
- do_test misuse-2.5 {
- catchsql {
- SELECT * FROM t1
- }
- } {1 {library routine called out of sequence}}
- # Attempt to register a new SQL aggregate while an sqlite_exec() is active.
- #
- do_test misuse-3.1 {
- db close
- set ::DB [sqlite db test2.db]
- execsql {
- SELECT * FROM t1
- }
- } {1 2}
- do_test misuse-3.2 {
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {0 {a b 1 2}}
- do_test misuse-3.3 {
- set v [catch {
- db eval {SELECT * FROM t1} {} {
- sqlite_create_aggregate $::DB
- }
- } msg]
- lappend v $msg
- } {1 {library routine called out of sequence}}
- do_test misuse-3.4 {
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {21 {library routine called out of sequence}}
- do_test misuse-3.5 {
- catchsql {
- SELECT * FROM t1
- }
- } {1 {library routine called out of sequence}}
- # Attempt to close the database from an sqlite_exec callback.
- #
- do_test misuse-4.1 {
- db close
- set ::DB [sqlite db test2.db]
- execsql {
- SELECT * FROM t1
- }
- } {1 2}
- do_test misuse-4.2 {
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {0 {a b 1 2}}
- do_test misuse-4.3 {
- set v [catch {
- db eval {SELECT * FROM t1} {} {
- sqlite_close $::DB
- }
- } msg]
- lappend v $msg
- } {1 {library routine called out of sequence}}
- do_test misuse-4.4 {
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {21 {library routine called out of sequence}}
- do_test misuse-4.5 {
- catchsql {
- SELECT * FROM t1
- }
- } {1 {library routine called out of sequence}}
- # Attempt to use a database after it has been closed.
- #
- do_test misuse-5.1 {
- db close
- set ::DB [sqlite db test2.db]
- execsql {
- SELECT * FROM t1
- }
- } {1 2}
- do_test misuse-5.2 {
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {0 {a b 1 2}}
- do_test misuse-5.3 {
- db close
- sqlite_exec_printf $::DB {SELECT * FROM t1} {}
- } {21 {library routine called out of sequence}}
- finish_test
|