I'm writing a program in C# that needs to insert data in multiple tables. The first insert returns a last insert rowid, which is in turn used to perform an insert on the other tables. In pseudo code:
INSERT INTO TableFoo (Col2, Col3, Col4, etc.) VALUES (@Bla2, @bla3, @bla4);
Immediately after this insert I get the last insert id by:
SELECT last_insert_rowid() AS RowId;
I retrieve the RowId column in a datareader and store it in an int "RowId". Finally I insert some more tables like:
INSERT INTO TableBar (FooId, Col2) VALUES (RowId, @BSomeMoreBla)");
The question: If possible, I want to perform this bunch of inserts (and a select RowId) in 1 transaction to prevent some half-saved data. Is it possible to use a transaction in this scenario and what would be the preferred way?
A SQLite transaction? C#'s System.Transactions namespace? A third way to perform an atomic database multi-insert...?