As far as I know, SQLite does not support multiple
simultaneous writers.

I believe you need to be ready to handle SQLITE_BUSY
and SQLITE_SCHEMA errors on every call in a multi-
threaded application.

SQLITE_BUSY...
http://www.sqlite.org/cvstrac/wiki?p=MultiThreading

SQLITE_SCHEMA...
http://www.sqlite.org/faq.html#q17

The wiki page for multithreaded applications suggests
that you use a loop to keep retrying on SQLITE_BUSY
but that does not work well, especially since that
loop should check for SQLITE_SCHEMA and also have some
count to prevent infinite loops.  Also  backing out of
your multiple successful calls to sqlite3_steps() after
a single call in a nested loop fails further complicates
things, I think.  Try use the sqlite3_busy_timeout() or
sqlite3_busy_handler() instead.

-
Kervin


RexChan(TP/HK) wrote:
> Hi all,
>  
> I meet the problem of multi_thread writing in version 3.2.1.  First I create 
> two threads A and B and each thread has its own db structure. each thread 
> uses the following SQL commands to do the insert action.
>  
> BEGIN;
> .
> insert record 200 times
> .
> .
> END;
>  
> Thread A does the insert first and Thread B inserts records during Thread A 
> is doing the insert action.
>  
> Then the SQLITE_BUSY error is returned to Thread A when doing the "END;" SQL 
> statement.  And Thread B is also returned to SQLITE_BUSY.
> And my question is:
>  
> 1.  Is it a normal when the error is returned to Thread A when doing the 
> "END;" SQL statement?
>  
> It seems the Thread A is locking the db although the insert 200 records 
> action has been done and it wants to do the "END" SQL statement.
>  
> Because I am using ver 2.8.16 and using the same code, it does not happen the 
> SQLITE_BUSY using its own db structure in each thread.
> Do I miss something to do the locking or setting some parameters? thanks!
>  
> Best regards,
> Rex
> 

Reply via email to