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 test the busy handler
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
23 INSERT INTO t1 VALUES(1);
35 db2 eval {BEGIN EXCLUSIVE}
36 catchsql {BEGIN IMMEDIATE}
37 } {1 {database is locked}}
43 catchsql {BEGIN IMMEDIATE}
49 db eval {BEGIN; INSERT INTO t1 VALUES(5)}
50 db2 eval {BEGIN; SELECT * FROM t1}
53 } {1 {database is locked}}
60 #-------------------------------------------------------------------------
61 # Test that the busy-handler is invoked correctly for "PRAGMA optimize"
62 # and ANALYZE commnds.
63 ifcapable pragma&&analyze&&!stat4 {
72 CREATE INDEX i1 ON t1(x);
73 CREATE INDEX i2 ON t2(y);
75 INSERT INTO t1 VALUES(1);
76 INSERT INTO t2 VALUES(1);
79 SELECT * FROM t1 WHERE x=1;
80 SELECT * FROM t2 WHERE y=1;
85 execsql { BEGIN EXCLUSIVE } db2
86 catchsql { PRAGMA optimize }
87 } {1 {database is locked}}
89 proc busy_handler {n} {
90 if {$n>1000} { execsql { COMMIT } db2 }
96 catchsql { PRAGMA optimize }
102 SELECT count(*) FROM sqlite_master;
106 proc busy_handler {n} { return 1 }
108 catchsql { PRAGMA optimize }
112 execsql { COMMIT } db2
115 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
117 INSERT INTO t1 SELECT i FROM s;
121 SELECT count(*) FROM sqlite_master;
126 catchsql { PRAGMA optimize }
127 } {1 {database is locked}}
129 proc busy_handler {n} {
130 if {$n>1000} { execsql { COMMIT } db2 }
134 catchsql { PRAGMA optimize }