Reputation: 1197
I am developing an application that uses an SQLite trigger that is in the form
CREATE TRIGGER bar_to_foo AFTER INSERT ON bar
BEGIN
DELETE * FROM foo;
INSERT INTO foo SELECT FROM bar;
END;
Multiple users will be using the application at the same time and potentially inserting into bar at the same time.
My question is: is there a chance that the triggers will execute in parallel? If so, the two deletes may happen before the inserts, which would result in a foo that contains bar twice over. This is not what I want - ideally, I'd the entirety of the trigger to execute before it reruns. If this is not default behavior in sqlite, is there a way to specify that this should happen?
Upvotes: 1
Views: 302
Reputation: 180070
SQLite properly serializes all transactions. (And when you are not using explicit transaction, each top-level statement will be wrapped in an automatic transaction.)
No two transactions can write to the same database at the same time, whether from inside a trigger or in any other way.
Upvotes: 2