mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add the experimental sqlite3_transaction_hook() API.
FossilOrigin-Name: 093d8cd8e2f3a6af5d40cf810e396f4919eb5cef
This commit is contained in:
137
test/hook.test
137
test/hook.test
@ -616,16 +616,151 @@ do_execsql_test 7.5.2.0 {
|
||||
ALTER TABLE t8 ADD COLUMN c DEFAULT 'xxx';
|
||||
}
|
||||
|
||||
# At time of writing, these two are broken. They demonstraight that the
|
||||
# sqlite3_preupdate_old() method does not handle the case where ALTER TABLE
|
||||
# has been used to add a column with a default value other than NULL.
|
||||
#
|
||||
do_preupdate_test 7.5.2.1 {
|
||||
DELETE FROM t8 WHERE a = 'one'
|
||||
} {
|
||||
DELETE main t8 1 1 one two xxx
|
||||
}
|
||||
|
||||
do_preupdate_test 7.5.2.2 {
|
||||
UPDATE t8 SET b = 'five'
|
||||
} {
|
||||
UPDATE main t8 2 2 three four xxx
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# The following tests - hook-8.* - test the transaction hook.
|
||||
#
|
||||
db close
|
||||
forcedelete test.db
|
||||
sqlite3 db test.db
|
||||
|
||||
proc transaction_hook {op iLevel} {
|
||||
lappend ::transaction_hook $op $iLevel
|
||||
}
|
||||
db transaction_hook transaction_hook
|
||||
|
||||
proc do_transaction_test {tn sql x} {
|
||||
set X [list]
|
||||
foreach elem $x {lappend X $elem}
|
||||
|
||||
uplevel do_test $tn [list "
|
||||
set ::transaction_hook \[list\]
|
||||
catchsql { $sql }
|
||||
set ::transaction_hook
|
||||
"] [list $X]
|
||||
}
|
||||
|
||||
do_transaction_test 8.1.1 "CREATE TABLE t1(x)" {BEGIN 0 COMMIT 0}
|
||||
do_transaction_test 8.1.2 "BEGIN" {BEGIN 0}
|
||||
do_transaction_test 8.1.3 "COMMIT" {COMMIT 0}
|
||||
do_transaction_test 8.1.4 "BEGIN ; ROLLBACK" {BEGIN 0 ROLLBACK 0}
|
||||
|
||||
do_execsql_test 8.2.0 {
|
||||
CREATE TABLE t2(a PRIMARY KEY, b);
|
||||
INSERT INTO t2 VALUES(1, 'one');
|
||||
INSERT INTO t2 VALUES(2, 'two');
|
||||
INSERT INTO t2 VALUES(3, 'three');
|
||||
}
|
||||
do_transaction_test 8.2.1 {
|
||||
INSERT INTO t2 VALUES(2, 'xxx')
|
||||
} {BEGIN 0 ROLLBACK 0}
|
||||
|
||||
do_transaction_test 8.2.2 {
|
||||
BEGIN; INSERT INTO t2 SELECT a-2, b FROM t2;
|
||||
} {BEGIN 0 BEGIN 1 ROLLBACK 1}
|
||||
|
||||
do_transaction_test 8.2.3 {
|
||||
INSERT OR ROLLBACK INTO t2 SELECT a-2, b FROM t2;
|
||||
} {ROLLBACK 0}
|
||||
|
||||
do_transaction_test 8.2.4 {
|
||||
BEGIN; INSERT INTO t2 SELECT a+3, b FROM t2;
|
||||
} {BEGIN 0 BEGIN 1 COMMIT 1}
|
||||
|
||||
do_transaction_test 8.2.5 "COMMIT" {COMMIT 0}
|
||||
|
||||
do_transaction_test 8.3.1 {SELECT * FROM t2} {}
|
||||
|
||||
do_transaction_test 8.4.1 {
|
||||
SAVEPOINT top;
|
||||
RELEASE top;
|
||||
} {BEGIN 0 COMMIT 0}
|
||||
|
||||
do_transaction_test 8.4.2 {
|
||||
SAVEPOINT top;
|
||||
ROLLBACK TO top;
|
||||
RELEASE top;
|
||||
} {BEGIN 0 ROLLBACK 0 BEGIN 0 COMMIT 0}
|
||||
|
||||
do_transaction_test 8.4.3 {
|
||||
SAVEPOINT zero;
|
||||
SAVEPOINT one;
|
||||
SAVEPOINT two;
|
||||
SAVEPOINT three;
|
||||
ROLLBACK TO zero;
|
||||
SAVEPOINT one;
|
||||
SAVEPOINT two;
|
||||
SAVEPOINT three;
|
||||
ROLLBACK TO one;
|
||||
SAVEPOINT two;
|
||||
RELEASE zero;
|
||||
|
||||
SAVEPOINT zero;
|
||||
SAVEPOINT one;
|
||||
SAVEPOINT two;
|
||||
RELEASE two;
|
||||
SAVEPOINT two;
|
||||
SAVEPOINT three;
|
||||
RELEASE one;
|
||||
ROLLBACK TO zero;
|
||||
RELEASE zero;
|
||||
} {
|
||||
BEGIN 0 BEGIN 1 BEGIN 2 BEGIN 3 ROLLBACK 0 BEGIN 0
|
||||
BEGIN 1 BEGIN 2 BEGIN 3 ROLLBACK 1 BEGIN 1 BEGIN 2
|
||||
COMMIT 0
|
||||
|
||||
BEGIN 0 BEGIN 1 BEGIN 2 COMMIT 2 BEGIN 2 BEGIN 3 COMMIT 1
|
||||
ROLLBACK 0 BEGIN 0 COMMIT 0
|
||||
}
|
||||
|
||||
do_transaction_test 8.4.4 {
|
||||
BEGIN;
|
||||
SAVEPOINT zero;
|
||||
SAVEPOINT one;
|
||||
SAVEPOINT two;
|
||||
SAVEPOINT three;
|
||||
ROLLBACK TO zero;
|
||||
SAVEPOINT one;
|
||||
SAVEPOINT two;
|
||||
SAVEPOINT three;
|
||||
ROLLBACK TO one;
|
||||
SAVEPOINT two;
|
||||
RELEASE zero;
|
||||
|
||||
SAVEPOINT zero;
|
||||
SAVEPOINT one;
|
||||
SAVEPOINT two;
|
||||
RELEASE two;
|
||||
SAVEPOINT two;
|
||||
SAVEPOINT three;
|
||||
RELEASE one;
|
||||
ROLLBACK TO zero;
|
||||
RELEASE zero;
|
||||
COMMIT;
|
||||
} {
|
||||
BEGIN 0
|
||||
BEGIN 1 BEGIN 2 BEGIN 3 BEGIN 4 ROLLBACK 1 BEGIN 1
|
||||
BEGIN 2 BEGIN 3 BEGIN 4 ROLLBACK 2 BEGIN 2 BEGIN 3
|
||||
COMMIT 1
|
||||
|
||||
BEGIN 1 BEGIN 2 BEGIN 3 COMMIT 3 BEGIN 3 BEGIN 4 COMMIT 2
|
||||
ROLLBACK 1 BEGIN 1 COMMIT 1
|
||||
COMMIT 0
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
|
Reference in New Issue
Block a user