interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / busy.test

139 lines · 2659 bytes Raw Blame History
1# 2005 july 8
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file test the busy handler
12#
13
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17set testprefix busy
18
19do_test busy-1.1 {
20 sqlite3 db2 test.db
21 execsql {
22 CREATE TABLE t1(x);
23 INSERT INTO t1 VALUES(1);
24 SELECT * FROM t1
25 }
26} 1
27proc busy x {
28 lappend ::busyargs $x
29 if {$x>2} {return 1}
30 return 0
31}
32set busyargs {}
33do_test busy-1.2 {
34 db busy busy
35 db2 eval {BEGIN EXCLUSIVE}
36 catchsql {BEGIN IMMEDIATE}
37} {1 {database is locked}}
38do_test busy-1.3 {
39 set busyargs
40} {0 1 2 3}
41do_test busy-1.4 {
42 set busyargs {}
43 catchsql {BEGIN IMMEDIATE}
44 set busyargs
45} {0 1 2 3}
46
47do_test busy-2.1 {
48 db2 eval {COMMIT}
49 db eval {BEGIN; INSERT INTO t1 VALUES(5)}
50 db2 eval {BEGIN; SELECT * FROM t1}
51 set busyargs {}
52 catchsql COMMIT
53} {1 {database is locked}}
54do_test busy-2.2 {
55 set busyargs
56} {0 1 2 3}
57
58db2 close
59
60#-------------------------------------------------------------------------
61# Test that the busy-handler is invoked correctly for "PRAGMA optimize"
62# and ANALYZE commnds.
63ifcapable pragma&&analyze&&!stat4 {
64
65reset_db
66
67do_execsql_test 3.1 {
68 CREATE TABLE t1(x);
69 CREATE TABLE t2(y);
70 CREATE TABLE t3(z);
71
72 CREATE INDEX i1 ON t1(x);
73 CREATE INDEX i2 ON t2(y);
74
75 INSERT INTO t1 VALUES(1);
76 INSERT INTO t2 VALUES(1);
77 ANALYZE;
78
79 SELECT * FROM t1 WHERE x=1;
80 SELECT * FROM t2 WHERE y=1;
81} {1 1}
82
83do_test 3.2 {
84 sqlite3 db2 test.db
85 execsql { BEGIN EXCLUSIVE } db2
86 catchsql { PRAGMA optimize }
87} {1 {database is locked}}
88
89proc busy_handler {n} {
90 if {$n>1000} { execsql { COMMIT } db2 }
91 return 0
92}
93db busy busy_handler
94
95do_test 3.3 {
96 catchsql { PRAGMA optimize }
97} {0 {}}
98
99do_test 3.4 {
100 execsql {
101 BEGIN;
102 SELECT count(*) FROM sqlite_master;
103 } db2
104} {6}
105
106proc busy_handler {n} { return 1 }
107do_test 3.5 {
108 catchsql { PRAGMA optimize }
109} {1 {database is locked}}
110
111do_test 3.6 {
112 execsql { COMMIT } db2
113 execsql {
114 WITH s(i) AS (
115 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
116 )
117 INSERT INTO t1 SELECT i FROM s;
118 }
119 execsql {
120 BEGIN;
121 SELECT count(*) FROM sqlite_master;
122 } db2
123} {6}
124
125do_test 3.7 {
126 catchsql { PRAGMA optimize }
127} {1 {database is locked}}
128
129proc busy_handler {n} {
130 if {$n>1000} { execsql { COMMIT } db2 }
131 return 0
132}
133do_test 3.8 {
134 catchsql { PRAGMA optimize }
135} {0 {}}
136
137}
138
139finish_test