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. The
12 # focus of this script is testing the server mode of SQLite.
14 # This file is derived from thread1.test
16 # $Id: server1.test,v 1.5 2007/08/29 18:20:17 drh Exp $
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
22 # Skip this whole file if the server testing code is not enabled
24 if {[llength [info command client_step]]==0 || [sqlite3 -has-codec]} {
29 # The sample server implementation does not work right when memory
30 # management is enabled.
32 ifcapable (memorymanage||mutex_noop) {
37 # Create some data to work with
42 INSERT INTO t1 VALUES(1,'abcdefgh');
43 INSERT INTO t1 SELECT a+1, b||b FROM t1;
44 INSERT INTO t1 SELECT a+2, b||b FROM t1;
45 INSERT INTO t1 SELECT a+4, b||b FROM t1;
46 SELECT count(*), max(length(b)) FROM t1;
50 # Interleave two threads on read access. Then make sure a third
51 # thread can write the database. In other words:
60 client_create A test.db
61 client_create B test.db
62 client_create C test.db
63 client_compile A {SELECT a FROM t1}
74 client_compile B {SELECT b FROM t1}
92 do_test server1-1.10 {
93 client_compile C {CREATE TABLE t2(x,y)}
97 do_test server1-1.11 {
101 do_test server1-1.12 {
102 catchsql {SELECT name FROM sqlite_master}
103 execsql {SELECT name FROM sqlite_master}
107 # Read from table t1. Do not finalize the statement. This
108 # will leave the lock pending.
110 do_test server1-2.1 {
112 client_create A test.db
113 client_compile A {SELECT a FROM t1}
118 # Read from the same table from another thread. This is allows.
120 do_test server1-2.2 {
121 client_create B test.db
122 client_compile B {SELECT b FROM t1}
127 # Write to a different table from another thread. This is allowed
128 # because in server mode with a shared cache we have table-level locking.
130 do_test server1-2.3 {
131 client_create C test.db
132 client_compile C {INSERT INTO t2 VALUES(98,99)}
139 # But we cannot insert into table t1 because threads A and B have it locked.
141 do_test server1-2.4 {
142 client_compile C {INSERT INTO t1 VALUES(98,99)}
148 do_test server1-2.5 {
151 client_compile C {INSERT INTO t1 VALUES(98,99)}
158 # Insert into t1 is successful after finishing the other two threads.
159 do_test server1-2.6 {
162 client_compile C {INSERT INTO t1 VALUES(98,99)}
170 sqlite3_enable_shared_cache 0