SQLite Forum

Attaching to DB *AFTER* Transaction started
Login
I have found that the attach will succeed, but the transaction may fail.

Consider process A connected to a.db and process B connected to b.db. Both may issue begin immediate sucessfully. Both may attach to the other process's file and read from it. But both will be locked out of writing, until one issues rollback, at which point it will stall in the subsequent begin immediate until the other process ends it's own transaction.

If both of the processes are already connected to a common file c.db, the second begin immediate will stall (waiting for the lock on c.db).

My guess is that attaching a database does not itself acquire a lock, even if a previous begin immediate acquired locks on all the previously attached databases. Instead, normal locking is performed as required by the statements issued in the transaction.