Hi,

I also spend some time with a similar application and sqlite
is doing quite well so far, however you will get BUSY states
and LOCK states under "normal" condition and you will need
to handle them.
I skipped to use the busy handler and the busy timeout and do
the handling by my selve. typically like:

---
prepare:

n = 0;
do
{
   rc = sqlite3_prepare_v2(db, SqlStr, -1, hs, 0);
   if( (rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED) )
   {
     n++;
     Sleep(SQLTM_TIME);
   }
}while( (n < SQLTM_COUNT) && ((rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED)));
---

step:
n = 0;
do
{
   rc = sqlite3_step(hs);
   if( (rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED) )
   {
     Sleep(SQLTM_TIME);
     n++;
   }
}while( (n < SQLTM_COUNT) && ((rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED)));

----

When you do a write operation it turns out to be useful to encapsulate them
with a exclusive transaction.
hope this helps

Marcus

Marco Bambini wrote:
> I have several threads inside an application and each thread opens a  
> connection to the same database.
> The application has been compiled with SQLITE_THREADSAFE = 1.
> One of the threads (just one) open another database connection to the  
> same database used by ALL threads for all the writing operations.
> 
> So I have N threads and N+1 db connections ... and the one db  
> connection is SHARED between all the threads just for WRITE operations  
> (the others N are used just for READ operations on the db).
> I thought that this approach could prevent my app from receiving a  
> SQLITE_LOCKED error... but sometimes it still occurs.
> Any idea of the reason of the error?
> Any idea about how to solve the issue without using the  
> sqlite3_busy_handler or sqlite3_busy_timeout functions?
> 
> Thanks a lot for the clarifications.

-- 
Marcus Grimm, MedCom GmbH Darmstadt, Rundeturmstr. 12, 64283 Darmstadt
Tel: +49(0)6151-95147-10
Fax: +49(0)6151-95147-20
--------------------------------------------------
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to