OLD | NEW |
1 # 2009 February 27 | 1 # 2009 February 27 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # | 11 # |
12 # $Id: temptrigger.test,v 1.3 2009/04/15 13:07:19 drh Exp $ | 12 # $Id: temptrigger.test,v 1.3 2009/04/15 13:07:19 drh Exp $ |
13 | 13 |
14 set testdir [file dirname $argv0] | 14 set testdir [file dirname $argv0] |
15 source $testdir/tester.tcl | 15 source $testdir/tester.tcl |
| 16 set testprefix temptrigger |
16 | 17 |
17 ifcapable {!trigger || !shared_cache} { finish_test ; return } | 18 ifcapable {!trigger || !shared_cache} { finish_test ; return } |
18 | 19 |
19 # Test cases: | 20 # Test cases: |
20 # | 21 # |
21 # temptrigger-1.*: Shared cache problem. | 22 # temptrigger-1.*: Shared cache problem. |
22 # temptrigger-2.*: A similar shared cache problem. | 23 # temptrigger-2.*: A similar shared cache problem. |
23 # temptrigger-3.*: Attached database problem. | 24 # temptrigger-3.*: Attached database problem. |
24 # | 25 # |
25 | 26 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 # temptrigger-3.2: Check that the temp trigger is correctly fired. | 151 # temptrigger-3.2: Check that the temp trigger is correctly fired. |
151 # | 152 # |
152 # temptrigger-3.3: Update the schema of 'test2.db' using an external | 153 # temptrigger-3.3: Update the schema of 'test2.db' using an external |
153 # connection. This forces [db] to reload the 'test2.db' | 154 # connection. This forces [db] to reload the 'test2.db' |
154 # schema. Check that the temp trigger is still fired | 155 # schema. Check that the temp trigger is still fired |
155 # correctly. | 156 # correctly. |
156 # | 157 # |
157 # temptrigger-3.4: Check that the temp trigger can be dropped without error. | 158 # temptrigger-3.4: Check that the temp trigger can be dropped without error. |
158 # | 159 # |
159 do_test temptrigger-3.1 { | 160 do_test temptrigger-3.1 { |
160 catch { file delete -force test2.db test2.db-journal } | 161 catch { forcedelete test2.db test2.db-journal } |
161 catch { file delete -force test.db test.db-journal } | 162 catch { forcedelete test.db test.db-journal } |
162 sqlite3 db test.db | 163 sqlite3 db test.db |
163 sqlite3 db2 test2.db | 164 sqlite3 db2 test2.db |
164 execsql { CREATE TABLE t2(a, b) } db2 | 165 execsql { CREATE TABLE t2(a, b) } db2 |
165 execsql { | 166 execsql { |
166 ATTACH 'test2.db' AS aux; | 167 ATTACH 'test2.db' AS aux; |
167 CREATE TEMP TABLE tt2(a, b); | 168 CREATE TEMP TABLE tt2(a, b); |
168 CREATE TEMP TRIGGER tr2 AFTER INSERT ON aux.t2 BEGIN | 169 CREATE TEMP TRIGGER tr2 AFTER INSERT ON aux.t2 BEGIN |
169 INSERT INTO tt2 VALUES(new.a, new.b); | 170 INSERT INTO tt2 VALUES(new.a, new.b); |
170 END; | 171 END; |
171 } | 172 } |
(...skipping 22 matching lines...) Expand all Loading... |
194 | 195 |
195 do_test temptrigger-3.4 { | 196 do_test temptrigger-3.4 { |
196 # Before the bug was fixed, the following 'DROP TRIGGER' hit an | 197 # Before the bug was fixed, the following 'DROP TRIGGER' hit an |
197 # assert if executed. | 198 # assert if executed. |
198 #execsql { DROP TRIGGER tr2 } | 199 #execsql { DROP TRIGGER tr2 } |
199 } {} | 200 } {} |
200 | 201 |
201 catch { db close } | 202 catch { db close } |
202 catch { db2 close } | 203 catch { db2 close } |
203 | 204 |
| 205 |
| 206 #------------------------------------------------------------------------- |
| 207 # Test that creating a temp table after a temp trigger on the same name |
| 208 # has been created is an error. |
| 209 # |
| 210 reset_db |
| 211 do_execsql_test 4.0 { |
| 212 CREATE TABLE t1(x); |
| 213 CREATE TEMP TRIGGER tr1 BEFORE INSERT ON t1 BEGIN |
| 214 SELECT 1,2,3; |
| 215 END; |
| 216 } |
| 217 |
| 218 do_execsql_test 4.1 { |
| 219 CREATE TEMP TABLE t1(x); |
| 220 } |
| 221 |
| 222 #------------------------------------------------------------------------- |
| 223 # Test that no harm is done if the table a temp trigger is attached to is |
| 224 # deleted by an external connection. |
| 225 # |
| 226 reset_db |
| 227 do_execsql_test 5.0 { |
| 228 CREATE TABLE t1(x); |
| 229 CREATE TEMP TRIGGER tr1 BEFORE INSERT ON t1 BEGIN SELECT 1,2,3; END; |
| 230 } |
| 231 |
| 232 do_test 5.1 { |
| 233 sqlite3 db2 test.db |
| 234 execsql { DROP TABLE t1 } db2 |
| 235 } {} |
| 236 |
| 237 do_execsql_test 5.2 { |
| 238 SELECT * FROM sqlite_master; |
| 239 SELECT * FROM sqlite_temp_master; |
| 240 } { |
| 241 trigger tr1 t1 0 |
| 242 {CREATE TRIGGER tr1 BEFORE INSERT ON t1 BEGIN SELECT 1,2,3; END} |
| 243 } |
| 244 db2 close |
| 245 |
| 246 #------------------------------------------------------------------------- |
| 247 # Check that if a second connection creates a table in an attached database |
| 248 # with the same name as a table in the main database that has a temp |
| 249 # trigger attached to it nothing goes awry. |
| 250 # |
| 251 reset_db |
| 252 forcedelete test.db2 |
| 253 |
| 254 do_execsql_test 6.0 { |
| 255 CREATE TABLE t1(x); |
| 256 CREATE TEMP TRIGGER tr1 BEFORE INSERT ON t1 BEGIN |
| 257 SELECT raise(ABORT, 'error'); |
| 258 END; |
| 259 ATTACH 'test.db2' AS aux; |
| 260 } |
| 261 |
| 262 do_test 6.1 { |
| 263 sqlite3 db2 test.db2 |
| 264 execsql { CREATE TABLE t1(a, b, c); } db2 |
| 265 } {} |
| 266 |
| 267 do_execsql_test 6.2 { |
| 268 SELECT type,name,tbl_name,sql FROM aux.sqlite_master; |
| 269 INSERT INTO aux.t1 VALUES(1,2,3); |
| 270 } { |
| 271 table t1 t1 {CREATE TABLE t1(a, b, c)} |
| 272 } |
| 273 |
| 274 do_catchsql_test 6.3 { |
| 275 INSERT INTO main.t1 VALUES(1); |
| 276 } {1 error} |
| 277 db2 close |
| 278 |
204 finish_test | 279 finish_test |
OLD | NEW |