1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Fix the locking protocol. (CVS 280)

FossilOrigin-Name: 484b82d8a1c84f3d9725a509de93276b9fa9b294
This commit is contained in:
drh
2001-10-09 04:19:46 +00:00
parent f57b339988
commit ad75e9874b
13 changed files with 413 additions and 134 deletions

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is database locks.
#
# $Id: lock.test,v 1.12 2001/09/23 19:46:52 drh Exp $
# $Id: lock.test,v 1.13 2001/10/09 04:19:47 drh Exp $
set testdir [file dirname $argv0]
@ -33,16 +33,14 @@ do_test lock-1.3 {
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
} {t1}
do_test lock-1.4 {
set r [catch {execsql {
SELECT name FROM sqlite_master WHERE type='table' ORDER BY name
} db2} msg]
lappend r $msg
catchsql {
SELECT name FROM sqlite_master WHERE type='table' ORDER BY name
} db2
} {1 {database schema has changed}}
do_test lock-1.5 {
set r [catch {execsql {
catchsql {
SELECT name FROM sqlite_master WHERE type='table' ORDER BY name
} db2} msg]
lappend r $msg
} db2
} {0 t1}
do_test lock-1.6 {
@ -59,19 +57,16 @@ do_test lock-1.8 {
do_test lock-1.9 {
execsql {SELECT * FROM t1}
} {2 1}
do_test lock-1.10 {
execsql {BEGIN TRANSACTION}
execsql {SELECT * FROM t1}
} {2 1}
do_test lock-1.11 {
set r [catch {execsql {SELECT * FROM t1} db2} msg]
lappend r $msg
catchsql {SELECT * FROM t1} db2
} {1 {database is locked}}
do_test lock-1.12 {
execsql {ROLLBACK}
set r [catch {execsql {SELECT * FROM t1} db2} msg]
lappend r $msg
catchsql {SELECT * FROM t1}
} {0 {2 1}}
do_test lock-1.13 {
@ -80,12 +75,10 @@ do_test lock-1.13 {
execsql {SELECT * FROM t2}
} {8 9}
do_test lock-1.14 {
set r [catch {execsql {SELECT * FROM t1} db2} msg]
lappend r $msg
catchsql {SELECT * FROM t1} db2
} {1 {database schema has changed}}
do_test lock-1.15 {
set r [catch {execsql {SELECT * FROM t2} db2} msg]
lappend r $msg
catchsql {SELECT * FROM t2} db2
} {0 {8 9}}
do_test lock-1.16 {

View File

@ -12,7 +12,7 @@
#
# This file implements tests for temporary tables and indices.
#
# $Id: temptable.test,v 1.1 2001/10/08 13:22:33 drh Exp $
# $Id: temptable.test,v 1.2 2001/10/09 04:19:47 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -34,50 +34,50 @@ do_test temptable-1.2 {
catch {db2 eval {SELECT * FROM sqlite_master}}
db2 eval {SELECT * FROM t1}
} {1 2 3}
do_test testtable-1.3 {
do_test temptable-1.3 {
execsql {SELECT name FROM sqlite_master}
} {t1}
do_test testtable-1.4 {
do_test temptable-1.4 {
db2 eval {SELECT name FROM sqlite_master}
} {t1}
# Create a temporary table. Verify that only one of the two
# processes can see it.
#
do_test testtable-1.5 {
do_test temptable-1.5 {
db2 eval {
CREATE TEMP TABLE t2(x,y,z);
INSERT INTO t2 VALUES(4,5,6);
}
db2 eval {SELECT * FROM t2}
} {4 5 6}
do_test testtable-1.6 {
do_test temptable-1.6 {
catch {execsql {SELECT * FROM sqlite_master}}
catchsql {SELECT * FROM t2}
} {1 {no such table: t2}}
do_test testtable-1.7 {
do_test temptable-1.7 {
catchsql {INSERT INTO t2 VALUES(8,9,0);}
} {1 {no such table: t2}}
do_test testtable-1.8 {
do_test temptable-1.8 {
db2 eval {INSERT INTO t2 VALUES(8,9,0);}
db2 eval {SELECT * FROM t2 ORDER BY x}
} {4 5 6 8 9 0}
do_test testtable-1.9 {
do_test temptable-1.9 {
db2 eval {DELETE FROM t2 WHERE x==8}
db2 eval {SELECT * FROM t2 ORDER BY x}
} {4 5 6}
do_test testtable-1.10 {
do_test temptable-1.10 {
db2 eval {DELETE FROM t2}
db2 eval {SELECT * FROM t2}
} {}
do_test testtable-1.11 {
do_test temptable-1.11 {
db2 eval {
INSERT INTO t2 VALUES(7,6,5);
INSERT INTO t2 VALUES(4,3,2);
SELECT * FROM t2 ORDER BY x;
}
} {4 3 2 7 6 5}
do_test testtable-1.12 {
do_test temptable-1.12 {
db2 eval {DROP TABLE t2;}
set r [catch {db2 eval {SELECT * FROM t2}} msg]
lappend r $msg
@ -85,7 +85,7 @@ do_test testtable-1.12 {
# Make sure temporary tables work with transactions
#
do_test testtable-2.1 {
do_test temptable-2.1 {
execsql {
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t2(x,y);
@ -93,11 +93,11 @@ do_test testtable-2.1 {
SELECT * FROM t2;
}
} {1 2}
do_test testtable-2.2 {
do_test temptable-2.2 {
execsql {ROLLBACK}
catchsql {SELECT * FROM t2}
} {1 {no such table: t2}}
do_test testtable-2.3 {
do_test temptable-2.3 {
execsql {
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t2(x,y);
@ -105,20 +105,124 @@ do_test testtable-2.3 {
SELECT * FROM t2;
}
} {1 2}
do_test testtable-2.4 {
do_test temptable-2.4 {
execsql {COMMIT}
catchsql {SELECT * FROM t2}
} {0 {1 2}}
do_test testtable-2.5 {
do_test temptable-2.5 {
set r [catch {db2 eval {SELECT * FROM t2}} msg]
lappend r $msg
} {1 {no such table: t2}}
# Make sure indices on temporary tables are also temporary.
#
do_test temptable-3.1 {
execsql {
CREATE INDEX i2 ON t2(x);
SELECT name FROM sqlite_master WHERE type='index';
}
} {}
do_test temptable-3.2 {
execsql {
SELECT y FROM t2 WHERE x=1;
}
} {2}
do_test temptable-3.3 {
execsql {
DROP INDEX i2;
SELECT y FROM t2 WHERE x=1;
}
} {2}
do_test temptable-3.4 {
execsql {
CREATE INDEX i2 ON t2(x);
DROP TABLE t2;
}
catchsql {DROP INDEX i2}
} {1 {no such index: i2}}
# Check for correct name collision processing. A name collision can
# occur when process A creates a temporary table T then process B
# creates a permanent table also named T. The temp table in process A
# hides the existance of the permanent table.
#
do_test temptable-4.1 {
db2 eval {
CREATE TEMP TABLE t2(x,y);
INSERT INTO t2 VALUES(10,20);
SELECT * FROM t2;
}
} {10 20}
do_test temptable-4.2 {
execsql {
CREATE TABLE t2(x,y,z);
INSERT INTO t2 VALUES(9,8,7);
SELECT * FROM t2;
}
} {9 8 7}
do_test temptable-4.3 {
set r [catch {db2 eval {SELECT * FROM t2}} msg]
lappend r $msg
} {1 {database schema has changed}}
do_test temptable-4.4 {
set r [catch {db2 eval {SELECT * FROM t2}} msg]
lappend r $msg
} {0 {10 20}}
do_test temptable-4.5 {
db2 eval {DROP TABLE t2}
set r [catch {db2 eval {SELECT * FROM t2}} msg]
lappend r $msg
} {1 {no such table: t2}}
do_test temptable-4.6 {
db2 close
sqlite db2 ./test.db
set r [catch {db2 eval {SELECT * FROM t2}} msg]
lappend r $msg
} {0 {9 8 7}}
# Now create a temporary table in db2 and a permanent index in db. The
# temporary table in db2 should mask the name of the permanent index,
# but the permanent index should still be accessible and should still
# be updated when its correspnding table changes.
#
do_test temptable-5.1 {
db2 eval {CREATE TEMP TABLE mask(a,b,c)}
execsql {
CREATE INDEX mask ON t2(x);
SELECT * FROM t2;
}
} {9 8 7}
do_test temptable-5.2 {
set r [catch {db2 eval {SELECT * FROM t2}} msg]
lappend r $msg
} {1 {database schema has changed}}
do_test temptable-5.3 {
set r [catch {db2 eval {SELECT * FROM t2}} msg]
lappend r $msg
} {0 {9 8 7}}
do_test temptable-5.4 {
execsql {SELECT y FROM t2 WHERE x=9}
} {8}
do_test temptable-5.5 {
db2 eval {SELECT y FROM t2 WHERE x=9}
} {8}
do_test temptable-5.6 {
db2 eval {
INSERT INTO t2 VALUES(1,2,3);
SELECT y FROM t2 WHERE x=1;
}
} {2}
do_test temptable-5.7 {
db2 eval {SELECT y FROM t2 WHERE x=9}
} {8}
do_test temptable-5.8 {
execsql {
SELECT y FROM t2 WHERE x=1;
}
} {2}
do_test temptable-5.9 {
execsql {SELECT y FROM t2 WHERE x=9}
} {8}
finish_test