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 # This test does not work on older PPC Macs due to problems in the
30 # pthreads library. So skip it.
32 if {$tcl_platform(machine)=="Power Macintosh" &&
33 $tcl_platform(byteOrder)=="bigEndian"} {
38 # The sample server implementation does not work right when memory
39 # management is enabled.
41 ifcapable (memorymanage||mutex_noop) {
46 # Create some data to work with
51 INSERT INTO t1 VALUES(1,'abcdefgh');
52 INSERT INTO t1 SELECT a+1, b||b FROM t1;
53 INSERT INTO t1 SELECT a+2, b||b FROM t1;
54 INSERT INTO t1 SELECT a+4, b||b FROM t1;
55 SELECT count(*), max(length(b)) FROM t1;
59 # Interleave two threads on read access. Then make sure a third
60 # thread can write the database. In other words:
69 client_create A test.db
70 client_create B test.db
71 client_create C test.db
72 client_compile A {SELECT a FROM t1}
83 client_compile B {SELECT b FROM t1}
101 do_test server1-1.10 {
102 client_compile C {CREATE TABLE t2(x,y)}
106 do_test server1-1.11 {
110 do_test server1-1.12 {
111 catchsql {SELECT name FROM sqlite_master}
112 execsql {SELECT name FROM sqlite_master}
116 # Read from table t1. Do not finalize the statement. This
117 # will leave the lock pending.
119 do_test server1-2.1 {
121 client_create A test.db
122 client_compile A {SELECT a FROM t1}
127 # Read from the same table from another thread. This is allows.
129 do_test server1-2.2 {
130 client_create B test.db
131 client_compile B {SELECT b FROM t1}
136 # Write to a different table from another thread. This is allowed
137 # because in server mode with a shared cache we have table-level locking.
139 do_test server1-2.3 {
140 client_create C test.db
141 client_compile C {INSERT INTO t2 VALUES(98,99)}
148 # But we cannot insert into table t1 because threads A and B have it locked.
150 do_test server1-2.4 {
151 client_compile C {INSERT INTO t1 VALUES(98,99)}
157 do_test server1-2.5 {
160 client_compile C {INSERT INTO t1 VALUES(98,99)}
167 # Insert into t1 is successful after finishing the other two threads.
168 do_test server1-2.6 {
171 client_compile C {INSERT INTO t1 VALUES(98,99)}
179 sqlite3_enable_shared_cache 0