Add new test file e_droptrigger.test.

FossilOrigin-Name: d23ef9b88c6705219e5138e50f0f351f6401c401
This commit is contained in:
dan 2010-11-29 12:06:45 +00:00
parent 6ea28d6d84
commit ccc7ff4d34
6 changed files with 293 additions and 49 deletions

View File

@ -1,8 +1,5 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Fix\svarious\scompiler\swarnings.
D 2010-11-26T16:49:59
C Add\snew\stest\sfile\se_droptrigger.test.
D 2010-11-29T12:06:45
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 4547616ad2286053af6ccccefa242dc925e49bf0
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -357,6 +354,7 @@ F test/diskfull.test 0cede7ef9d8f415d9d3944005c76be7589bb5ebb
F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
F test/e_createtable.test b8f5286879315d5b7f4cc5ead1afda4846f0c0bb
F test/e_delete.test 55d868b647acc091c261a10b9b0cb0ab660a6acb
F test/e_droptrigger.test 0b96c0df9b6390c728d9e15ff046419b678ddf44
F test/e_expr.test 4e004d1f5187d4bbc9ca3d55660a8d164dd59f4e
F test/e_fkey.test 38039b840ab19331000b0f0eb1d82baa7208a67a
F test/e_fts3.test 75bb0aee26384ef586165e21018a17f7cd843469
@ -420,7 +418,7 @@ F test/fts2r.test b154c30b63061d8725e320fba1a39e2201cadd5e
F test/fts2token.test d8070b241a15ff13592a9ae4a8b7c171af6f445a
F test/fts3.test 672a040ea57036fb4b6fdc09027c18d7d24ab654
F test/fts3_common.tcl 4d8eec9db565fed9098f45c378f28e1657802011
F test/fts3aa.test 5327d4c1d9b6c61021696746cc9a6cdc5bf159c0
F test/fts3aa.test 909d5f530d30a8e36b9328d67285eae6537c79c0
F test/fts3ab.test 09aeaa162aee6513d9ff336b6932211008b9d1f9
F test/fts3ac.test 636ed7486043055d4f126a0e385f2d5a82ebbf63
F test/fts3ad.test e40570cb6f74f059129ad48bcef3d7cbc20dda49
@ -548,7 +546,7 @@ F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb
F test/mallocI.test a88c2b9627c8506bf4703d8397420043a786cdb6
F test/mallocJ.test b5d1839da331d96223e5f458856f8ffe1366f62e
F test/mallocK.test d79968641d1b70d88f6c01bdb9a7eb4a55582cc9
F test/malloc_common.tcl 053003b3d925a4dbfd5159819a542266e5c8ed84
F test/malloc_common.tcl 27087a2bfad8f695ca6f8b463ecac5d71b9b0712
F test/manydb.test b3d3bc4c25657e7f68d157f031eb4db7b3df0d3c
F test/memdb.test 0825155b2290e900264daaaf0334b6dfe69ea498
F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2
@ -662,7 +660,7 @@ F test/tclsqlite.test 8c154101e704170c2be10f137a5499ac2c6da8d3
F test/tempdb.test 19d0f66e2e3eeffd68661a11c83ba5e6ace9128c
F test/temptable.test f42121a0d29a62f00f93274464164177ab1cc24a
F test/temptrigger.test b0273db072ce5f37cf19140ceb1f0d524bbe9f05
F test/tester.tcl 45e8f7b56ef93c5c66886f1bbd05dda78d248d86
F test/tester.tcl 0c8c0a7c4d5944026728f33a1c06e014b1648768
F test/thread001.test a3e6a7254d1cb057836cb3145b60c10bf5b7e60f
F test/thread002.test afd20095e6e845b405df4f2c920cb93301ca69db
F test/thread003.test b824d4f52b870ae39fc5bae4d8070eca73085dca
@ -892,14 +890,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 3c3d076b42da36cd5413749ec022d0349325edfa
R 6eb1d3796cc6e7f30b85a46219b5a41c
U drh
Z dad7028ef2a2e95ebd4d4284381d5339
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFM7+U6oxKgR168RlERArCCAJ9Ms95IkrYzcyhjnhaA4kTfC+owCwCdG6XU
6RTdcghjuTo4XsP3zh0JwEk=
=o/S3
-----END PGP SIGNATURE-----
P c412f61229b6ab1ac90b932afd56f7c5e3ba1cfe
R f6821cb801bbf518113f282c058b1797
U dan
Z 0f3972e8a27cc6750e06c0fccb7d1885

View File

@ -1 +1 @@
c412f61229b6ab1ac90b932afd56f7c5e3ba1cfe
d23ef9b88c6705219e5138e50f0f351f6401c401

218
test/e_droptrigger.test Normal file
View File

@ -0,0 +1,218 @@
# 2010 November 29
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file implements tests to verify that the "testable statements" in
# the lang_droptrigger.html document are correct.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set ::testprefix e_createtable
ifcapable !trigger { finish_test ; return }
proc do_droptable_tests {nm args} {
uplevel do_select_tests [list e_createtable-$nm] $args
}
proc list_all_triggers {{db db}} {
set res [list]
$db eval { PRAGMA database_list } {
if {$name == "temp"} {
set tbl sqlite_temp_master
} else {
set tbl "$name.sqlite_master"
}
lappend res {*}[
db eval "SELECT '$name.' || name FROM $tbl WHERE type = 'trigger'"
]
}
set res
}
proc droptrigger_reopen_db {{event INSERT}} {
db close
forcedelete test.db test.db2
sqlite3 db test.db
set ::triggers_fired [list]
proc r {x} { lappend ::triggers_fired $x }
db func r r
db eval "
ATTACH 'test.db2' AS aux;
CREATE TEMP TABLE t1(a, b);
INSERT INTO t1 VALUES('a', 'b');
CREATE TRIGGER tr1 AFTER $event ON t1 BEGIN SELECT r('temp.tr1') ; END;
CREATE TABLE t2(a, b);
INSERT INTO t2 VALUES('a', 'b');
CREATE TRIGGER tr1 BEFORE $event ON t2 BEGIN SELECT r('main.tr1') ; END;
CREATE TRIGGER tr2 AFTER $event ON t2 BEGIN SELECT r('main.tr2') ; END;
CREATE TABLE aux.t3(a, b);
INSERT INTO t3 VALUES('a', 'b');
CREATE TRIGGER aux.tr1 BEFORE $event ON t3 BEGIN SELECT r('aux.tr1') ; END;
CREATE TRIGGER aux.tr2 AFTER $event ON t3 BEGIN SELECT r('aux.tr2') ; END;
CREATE TRIGGER aux.tr3 AFTER $event ON t3 BEGIN SELECT r('aux.tr3') ; END;
"
}
# EVIDENCE-OF: R-52650-16855 -- syntax diagram drop-trigger-stmt
#
do_droptable_tests 1.1 -repair {
droptrigger_reopen_db
} -tclquery {
list_all_triggers
} {
1 "DROP TRIGGER main.tr1"
{main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3}
2 "DROP TRIGGER IF EXISTS main.tr1"
{main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3}
3 "DROP TRIGGER tr1"
{main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3}
4 "DROP TRIGGER IF EXISTS tr1"
{main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3}
5 "DROP TRIGGER aux.tr1"
{main.tr1 main.tr2 temp.tr1 aux.tr2 aux.tr3}
6 "DROP TRIGGER IF EXISTS aux.tr1"
{main.tr1 main.tr2 temp.tr1 aux.tr2 aux.tr3}
7 "DROP TRIGGER IF EXISTS aux.xxx"
{main.tr1 main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3}
8 "DROP TRIGGER IF EXISTS aux.xxx"
{main.tr1 main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3}
}
# EVIDENCE-OF: R-61172-15671 The DROP TRIGGER statement removes a
# trigger created by the CREATE TRIGGER statement.
#
foreach {tn tbl droptrigger before after} {
1 t1 "DROP TRIGGER tr1" {temp.tr1} {}
2 t2 "DROP TRIGGER tr1" {main.tr1 main.tr2} {main.tr1 main.tr2}
3 t3 "DROP TRIGGER tr1" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2}
4 t1 "DROP TRIGGER tr2" {temp.tr1} {temp.tr1}
5 t2 "DROP TRIGGER tr2" {main.tr1 main.tr2} {main.tr1}
6 t3 "DROP TRIGGER tr2" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2}
7 t1 "DROP TRIGGER tr3" {temp.tr1} {temp.tr1}
8 t2 "DROP TRIGGER tr3" {main.tr1 main.tr2} {main.tr1 main.tr2}
9 t3 "DROP TRIGGER tr3" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr2}
} {
do_test 2.$tn.1 {
droptrigger_reopen_db
execsql " INSERT INTO $tbl VALUES('1', '2') "
set ::triggers_fired
} $before
do_test 2.$tn.2 {
droptrigger_reopen_db
execsql $droptrigger
execsql " INSERT INTO $tbl VALUES('1', '2') "
set ::triggers_fired
} $after
}
# EVIDENCE-OF: R-50239-29811 Once removed, the trigger definition is no
# longer present in the sqlite_master (or sqlite_temp_master) table and
# is not fired by any subsequent INSERT, UPDATE or DELETE statements.
#
# Test cases e_droptrigger-1.* test the first part of this statement
# (that dropped triggers do not appear in the schema table), and tests
# droptrigger-2.* test that dropped triggers are not fired by INSERT
# statements. The following tests verify that they are not fired by
# UPDATE or DELETE statements.
#
foreach {tn tbl droptrigger before after} {
1 t1 "DROP TRIGGER tr1" {temp.tr1} {}
2 t2 "DROP TRIGGER tr1" {main.tr1 main.tr2} {main.tr1 main.tr2}
3 t3 "DROP TRIGGER tr1" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2}
4 t1 "DROP TRIGGER tr2" {temp.tr1} {temp.tr1}
5 t2 "DROP TRIGGER tr2" {main.tr1 main.tr2} {main.tr1}
6 t3 "DROP TRIGGER tr2" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2}
7 t1 "DROP TRIGGER tr3" {temp.tr1} {temp.tr1}
8 t2 "DROP TRIGGER tr3" {main.tr1 main.tr2} {main.tr1 main.tr2}
9 t3 "DROP TRIGGER tr3" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr2}
} {
do_test 3.1.$tn.1 {
droptrigger_reopen_db UPDATE
execsql "UPDATE $tbl SET a = 'abc'"
set ::triggers_fired
} $before
do_test 3.1.$tn.2 {
droptrigger_reopen_db UPDATE
execsql $droptrigger
execsql "UPDATE $tbl SET a = 'abc'"
set ::triggers_fired
} $after
}
foreach {tn tbl droptrigger before after} {
1 t1 "DROP TRIGGER tr1" {temp.tr1} {}
2 t2 "DROP TRIGGER tr1" {main.tr1 main.tr2} {main.tr1 main.tr2}
3 t3 "DROP TRIGGER tr1" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2}
4 t1 "DROP TRIGGER tr2" {temp.tr1} {temp.tr1}
5 t2 "DROP TRIGGER tr2" {main.tr1 main.tr2} {main.tr1}
6 t3 "DROP TRIGGER tr2" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2}
7 t1 "DROP TRIGGER tr3" {temp.tr1} {temp.tr1}
8 t2 "DROP TRIGGER tr3" {main.tr1 main.tr2} {main.tr1 main.tr2}
9 t3 "DROP TRIGGER tr3" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr2}
} {
do_test 3.2.$tn.1 {
droptrigger_reopen_db DELETE
execsql "DELETE FROM $tbl"
set ::triggers_fired
} $before
do_test 3.2.$tn.2 {
droptrigger_reopen_db DELETE
execsql $droptrigger
execsql "DELETE FROM $tbl"
set ::triggers_fired
} $after
}
# EVIDENCE-OF: R-37808-62273 Note that triggers are automatically
# dropped when the associated table is dropped.
#
do_test 4.1 {
droptrigger_reopen_db
list_all_triggers
} {main.tr1 main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3}
do_test 4.2 {
droptrigger_reopen_db
execsql "DROP TABLE t1"
list_all_triggers
} {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3}
do_test 4.3 {
droptrigger_reopen_db
execsql "DROP TABLE t1"
list_all_triggers
} {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3}
do_test 4.4 {
droptrigger_reopen_db
execsql "DROP TABLE t1"
list_all_triggers
} {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3}
finish_test

View File

@ -196,9 +196,32 @@ do_test fts3aa-6.2 {
do_test fts3aa-6.3 {
execsql {SELECT content FROM t1 WHERE rowid = -1}
} {{three four}}
breakpoint
do_test fts3aa-6.4 {
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'}
} {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31}
# Test creation of FTS3 and FTS4 tables with columns that contain
# an "=" character.
#
do_execsql_test fts3aa-7.1 {
CREATE VIRTUAL TABLE t2 USING fts3(xyz=abc);
SELECT xyz FROM t2;
} {}
do_catchsql_test fts3aa-7.2 {
CREATE VIRTUAL TABLE t3 USING fts4(xyz=abc);
} {1 {unrecognized parameter: xyz=abc}}
do_catchsql_test fts3aa-7.3 {
CREATE VIRTUAL TABLE t3 USING fts4(xyz = abc);
} {1 {unrecognized parameter: xyz = abc}}
do_execsql_test fts3aa-7.4 {
CREATE VIRTUAL TABLE t3 USING fts3(tokenize=simple, tokenize=simple);
SELECT tokenize FROM t3;
} {}
do_catchsql_test fts3aa-7.5 {
CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple);
} {1 {unrecognized parameter: tokenize=simple}}
finish_test

View File

@ -135,6 +135,7 @@ proc do_faultsim_test {name args} {
}
}
#-------------------------------------------------------------------------
# Procedures to save and restore the current file-system state:
#
@ -144,29 +145,16 @@ proc do_faultsim_test {name args} {
# faultsim_restore_and_reopen
# faultsim_delete_and_reopen
#
proc faultsim_save {} {
foreach f [glob -nocomplain sv_test.db*] { forcedelete $f }
foreach f [glob -nocomplain test.db*] {
set f2 "sv_$f"
file copy -force $f $f2
}
proc faultsim_save {args} { uplevel db_save $args }
proc faultsim_save_and_close {args} { uplevel db_save_and_close $args }
proc faultsim_restore {args} { uplevel db_restore $args }
proc faultsim_restore_and_reopen {args} {
uplevel db_restore_and_reopen $args
sqlite3_extended_result_codes db 1
sqlite3_db_config_lookaside db 0 0 0
}
proc faultsim_save_and_close {} {
faultsim_save
catch { db close }
return ""
}
proc faultsim_restore {} {
foreach f [glob -nocomplain test.db*] { forcedelete $f }
foreach f2 [glob -nocomplain sv_test.db*] {
set f [string range $f2 3 end]
file copy -force $f2 $f
}
}
proc faultsim_restore_and_reopen {{dbfile test.db}} {
catch { db close }
faultsim_restore
sqlite3 db $dbfile
proc faultsim_delete_and_reopen {args} {
uplevel db_delete_and_reopen $args
sqlite3_extended_result_codes db 1
sqlite3_db_config_lookaside db 0 0 0
}
@ -176,12 +164,6 @@ proc faultsim_integrity_check {{db db}} {
if {$ic != "ok"} { error "Integrity check: $ic" }
}
proc faultsim_delete_and_reopen {{file test.db}} {
catch { db close }
foreach f [glob -nocomplain test.db*] { file delete -force $f }
sqlite3 db $file
}
# The following procs are used as [do_one_faultsim_test] callbacks when
# injecting OOM faults into test cases.

View File

@ -1375,6 +1375,36 @@ proc sql36231 {sql} {
return ""
}
proc db_save {} {
foreach f [glob -nocomplain sv_test.db*] { forcedelete $f }
foreach f [glob -nocomplain test.db*] {
set f2 "sv_$f"
file copy -force $f $f2
}
}
proc db_save_and_close {} {
db_save
catch { db close }
return ""
}
proc db_restore {} {
foreach f [glob -nocomplain test.db*] { forcedelete $f }
foreach f2 [glob -nocomplain sv_test.db*] {
set f [string range $f2 3 end]
file copy -force $f2 $f
}
}
proc db_restore_and_reopen {{dbfile test.db}} {
catch { db close }
db_restore
sqlite3 db $dbfile
}
proc db_delete_and_reopen {{file test.db}} {
catch { db close }
foreach f [glob -nocomplain test.db*] { file delete -force $f }
sqlite3 db $file
}
# If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set
# to non-zero, then set the global variable $AUTOVACUUM to 1.
set AUTOVACUUM $sqlite_options(default_autovacuum)