Add some tests with attached databases to savepoint.test. Also tests of creating and dropping tables in auto-vacuum mode inside of a savepoint. (CVS 6108)
FossilOrigin-Name: ca7f11d50d1a73443d18c79dfe4223c975c6e20b
This commit is contained in:
+190
-1
@@ -9,7 +9,7 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: savepoint.test,v 1.6 2009/01/01 14:06:13 danielk1977 Exp $
|
||||
# $Id: savepoint.test,v 1.7 2009/01/03 15:06:38 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -524,8 +524,197 @@ ifcapable auth {
|
||||
set res [catchsql { RELEASE sp1 }]
|
||||
concat $::authdata $res
|
||||
} {SQLITE_SAVEPOINT RELEASE sp1 {} {} 1 {not authorized}}
|
||||
|
||||
catch { db eval ROLLBACK }
|
||||
db auth ""
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# The following tests - savepoint-10.* - test the interaction of
|
||||
# savepoints and ATTACH statements.
|
||||
#
|
||||
|
||||
# First make sure it is not possible to attach or detach a database while
|
||||
# a savepoint is open (it is not possible if any transaction is open).
|
||||
#
|
||||
do_test savepoint-10.1.1 {
|
||||
catchsql {
|
||||
SAVEPOINT one;
|
||||
ATTACH 'test2.db' AS aux;
|
||||
}
|
||||
} {1 {cannot ATTACH database within transaction}}
|
||||
do_test savepoint-10.1.2 {
|
||||
execsql {
|
||||
RELEASE one;
|
||||
ATTACH 'test2.db' AS aux;
|
||||
}
|
||||
catchsql {
|
||||
SAVEPOINT one;
|
||||
DETACH aux;
|
||||
}
|
||||
} {1 {cannot DETACH database within transaction}}
|
||||
do_test savepoint-10.1.3 {
|
||||
execsql {
|
||||
RELEASE one;
|
||||
DETACH aux;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test savepoint-10.2.1 {
|
||||
file delete -force test3.db
|
||||
file delete -force test2.db
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS aux1;
|
||||
ATTACH 'test3.db' AS aux2;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE main.t1(x, y);
|
||||
CREATE TABLE aux1.t2(x, y);
|
||||
CREATE TABLE aux2.t3(x, y);
|
||||
SELECT name FROM sqlite_master
|
||||
UNION ALL
|
||||
SELECT name FROM aux1.sqlite_master
|
||||
UNION ALL
|
||||
SELECT name FROM aux2.sqlite_master;
|
||||
}
|
||||
} {t1 t2 t3}
|
||||
do_test savepoint-10.2.2 {
|
||||
execsql { PRAGMA lock_status }
|
||||
} {main unlocked temp unlocked aux1 unlocked aux2 unlocked}
|
||||
|
||||
do_test savepoint-10.2.3 {
|
||||
execsql {
|
||||
SAVEPOINT one;
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
PRAGMA lock_status;
|
||||
}
|
||||
} {main reserved temp unlocked aux1 unlocked aux2 unlocked}
|
||||
do_test savepoint-10.2.4 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES(3, 4);
|
||||
PRAGMA lock_status;
|
||||
}
|
||||
} {main reserved temp unlocked aux1 unlocked aux2 reserved}
|
||||
do_test savepoint-10.2.5 {
|
||||
execsql {
|
||||
SAVEPOINT two;
|
||||
INSERT INTO t2 VALUES(5, 6);
|
||||
PRAGMA lock_status;
|
||||
}
|
||||
} {main reserved temp unlocked aux1 reserved aux2 reserved}
|
||||
do_test savepoint-10.2.6 {
|
||||
execsql { SELECT * FROM t2 }
|
||||
} {5 6}
|
||||
do_test savepoint-10.2.7 {
|
||||
execsql { ROLLBACK TO two }
|
||||
execsql { SELECT * FROM t2 }
|
||||
} {}
|
||||
do_test savepoint-10.2.8 {
|
||||
execsql { PRAGMA lock_status }
|
||||
} {main reserved temp unlocked aux1 reserved aux2 reserved}
|
||||
do_test savepoint-10.2.9 {
|
||||
execsql { SELECT 'a', * FROM t1 UNION ALL SELECT 'b', * FROM t3 }
|
||||
} {a 1 2 b 3 4}
|
||||
do_test savepoint-10.2.9 {
|
||||
execsql {
|
||||
INSERT INTO t2 VALUES(5, 6);
|
||||
RELEASE one;
|
||||
}
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
SELECT * FROM t2;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 2 5 6 3 4}
|
||||
do_test savepoint-10.2.9 {
|
||||
execsql { PRAGMA lock_status }
|
||||
} {main unlocked temp unlocked aux1 unlocked aux2 unlocked}
|
||||
|
||||
do_test savepoint-10.2.10 {
|
||||
execsql {
|
||||
SAVEPOINT one;
|
||||
INSERT INTO t1 VALUES('a', 'b');
|
||||
SAVEPOINT two;
|
||||
INSERT INTO t2 VALUES('c', 'd');
|
||||
SAVEPOINT three;
|
||||
INSERT INTO t3 VALUES('e', 'f');
|
||||
}
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
SELECT * FROM t2;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 2 a b 5 6 c d 3 4 e f}
|
||||
do_test savepoint-10.2.11 {
|
||||
execsql { ROLLBACK TO two }
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
SELECT * FROM t2;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 2 a b 5 6 3 4}
|
||||
do_test savepoint-10.2.12 {
|
||||
execsql {
|
||||
INSERT INTO t3 VALUES('g', 'h');
|
||||
ROLLBACK TO two;
|
||||
}
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
SELECT * FROM t2;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 2 a b 5 6 3 4}
|
||||
do_test savepoint-10.2.13 {
|
||||
execsql { ROLLBACK }
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
SELECT * FROM t2;
|
||||
SELECT * FROM t3;
|
||||
}
|
||||
} {1 2 5 6 3 4}
|
||||
do_test savepoint-10.2.14 {
|
||||
execsql { PRAGMA lock_status }
|
||||
} {main unlocked temp unlocked aux1 unlocked aux2 unlocked}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# The following tests - savepoint-11.* - test the interaction of
|
||||
# savepoints and creating or dropping tables and indexes in
|
||||
# auto-vacuum mode.
|
||||
#
|
||||
do_test savepoint-11.1 {
|
||||
db close
|
||||
file delete -force test.db
|
||||
sqlite3 db test.db
|
||||
execsql {
|
||||
PRAGMA auto_vacuum = full;
|
||||
CREATE TABLE t1(a, b, UNIQUE(a, b));
|
||||
INSERT INTO t1 VALUES(1, randstr(1000,1000));
|
||||
INSERT INTO t1 VALUES(2, randstr(1000,1000));
|
||||
}
|
||||
} {}
|
||||
do_test savepoint-11.2 {
|
||||
execsql {
|
||||
SAVEPOINT one;
|
||||
CREATE TABLE t2(a, b, UNIQUE(a, b));
|
||||
SAVEPOINT two;
|
||||
CREATE TABLE t3(a, b, UNIQUE(a, b));
|
||||
}
|
||||
} {}
|
||||
integrity_check savepoint-11.3
|
||||
do_test savepoint-11.4 {
|
||||
execsql { ROLLBACK TO two }
|
||||
} {}
|
||||
integrity_check savepoint-11.5
|
||||
do_test savepoint-11.6 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a, b, UNIQUE(a, b));
|
||||
ROLLBACK TO one;
|
||||
}
|
||||
} {}
|
||||
integrity_check savepoint-11.7
|
||||
do_test savepoint-11.6 {
|
||||
execsql { ROLLBACK }
|
||||
file size test.db
|
||||
} {8192}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
Reference in New Issue
Block a user