> On 12 January 2016 at 13:26, Scott Hess <shess at google.com> wrote: > > > On Mon, Jan 11, 2016 at 9:12 PM, Felipe Gasper <felipe at felipegasper.com> > > wrote: > > > > > On 11 Jan 2016 9:06 PM, Rowan Worth wrote: > > > > > >> * if it returns SQLITE_OK and zero rows, the schema hasn't been > created > > >> yet > > >> > > > > > > Sure; however, by the time you do the next action it?s possible that > > > something else will be creating the schema. This is the condition that > > I?m trying to avoid.
Then just do: set timeout to something BEGIN IMMEDIATE PRAGMA user_version; if returned value is *not* the user/schema version you want make it so IN THIS TRANSACTION { ... create/update schema ... PRAGMA user_version=x; } COMMIT; This is race condition free and will even work with an existing database in WAL mode ... There is no need for all the complication -- it is really quite simple. Rather than rely on the user_version, you could check anything you like. The secret sauce is to do all the checking and updating INSIDE the single IMMEDIATE transaction.