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.


If something else created the schema between check and use, what's the
problem?

You can avoid this by doing:
 - query sqlite_master.
 - if the query returns rows, the schema exists, exit; else
 - open a transaction.
 - query sqlite_master.
 - if the query returns rows, the schema exists, end transaction and exit;
else
 - create the schema.
 - commit transaction.

Or, just use CREATE IF NOT EXISTS style when creating the schema, and you
will successfully not create it the second time.  Or just pay attention to
your error codes in the create code.

-scott

Reply via email to