Attached databases and triggers

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Attached databases and triggers

Michael J. Sviridov
Hi All

Is it possible to perform an INSERT, UPDATE or DELETE on an attached
database from within the body of a trigger? Attached databases seemed to be
evaluated properly when they are in the WHEN clause of a trigger but not
when they are in the actual body.

Example:

sqlite3 db1
sqlite> CREATE TABLE A (R TEXT);
sqlite> INSERT INTO A VALUES('Test');
sqlite> .quit

sqlite3 db2
sqlite> CREATE TABLE B (R TEXT);
sqlite> INSERT INTO B VALUES('Test');
sqlite> CREATE TRIGGER T AFTER DELETE ON B
sqlite> BEGIN
sqlite> DELETE FROM A WHERE R = OLD.R;
sqlite> END;
sqlite> ATTACH db1 as db1;
sqlite> SELECT COUNT(*) FROM A;
1
sqlite> DELETE FROM B;
SQL error: No such table: main.A
sqlite>

Any help would be appreciated!

Michael.