On Tue, 2005-09-06 at 15:49 -0400, Mark Drago wrote:

> 2. I could continue to write to the database in the single thread, but
> if the write fails, add the data to a queue and continue.  Then, when
> another piece of data has to be logged, and it succeeds, empty the queue
> and write all of the data from it into the sqlite DB. 

This is what I would do.  Except I would make the queue a
separate SQLite database which was connected to the primary
database using ATTACH.

Suppose the "queue" database is named "pending.db".  Then
when you open the primary database always immediately do
this:

    ATTACH DATABASE 'pending.db' AS pending;

Then when you want to make a log entry do the following
statements:

   INSERT INTO pending.log VALUES(...);
   INSERT INTO main.log SELECT * FROM pending.log;
   DELETE FROM pending.log;

When doing the above, abort after the first failure.
If the database is locked then the second statement will
fail, the DELETE will never occur and information will
accumulate in the "pending" database.  If the second
statement succeeds, then the information is subsequently
deleted from the pending database.

If you really want to make sure that the transfer from
pending to main is atomic, enclose the last two statements
in a transaction.
-- 
D. Richard Hipp <[EMAIL PROTECTED]>

Reply via email to