- Make sure you're compiling SQLite with *-DTHREADSAFE=1*. - Make sure that each thread opens the database file and keeps its own sqlite structure. - Make sure you handle the likely possibility that one or more threads collide when they access the db file at the same time: handle * SQLITE_BUSY* appropriately. - Make sure you enclose within transactions the commands that modify the database file, like *INSERT*, *UPDATE*, *DELETE*, and others.
Whenever I get the SQLITE_MISUSE or SQLITE_BUSY errors when "it should work", I discover that I have a statement left over in execution mode without it having been sqlite3_reset(...). Perhaps the same is true in your case. andy On 6/18/07, Sabyasachi Ruj <[EMAIL PROTECTED]> wrote:
But the following link http://www.sqlite.org/cvstrac/wiki/wiki?p=MultiThreading says nothing that I have to synchronize at the application level to create multiple connections, until the same database connection is being shared! Ref: The four points in 'Short Answer' section. BTW: for a DBMS it does not make sense if the application programmer has to synchronize to create multiple connection. And synhing will have considerable performance drop also. On 6/18/07, John Stanton <[EMAIL PROTECTED]> wrote: > > Threadsafe only means that threads do not access global data elements or > that they synchronize (serialize) access to global data. It does > nothing to synchronize threads. That is up to the application > programmer. Sqlite uses POSIX file locks for synchronixation but if you > are in a totally threaded environment you can use thread sync functions > like mutexes or the finer grained read and write lock thread primitives. > > If you are accessing Sqlite across a network file locks are the way to > go, but do depend upon network implementations and settings. If you > have multiple processes on one OS you can sync using semaphores. > > Using textbook style synchronization ensures that you have minimal > problems and optimal performance. > > Sabyasachi Ruj wrote: > > But I think we do not have to take care of synchronizing sqlite access. > > sqlite internally does if it is compiled with THREADSAFE=1. > > > > On 6/18/07, John Stanton <[EMAIL PROTECTED]> wrote: > > > >> > >> The problem is fairly straight forward. Sqlite is a single resource > >> being shared by multiple thyreads so you just use fundamental > >> synchronization logic as you would when sharing any resource between > >> competing threads. > >> > >> Sabyasachi Ruj wrote: > >> > Hi, > >> > > >> > I am using sqlite in a multithreaded environment. I have take > >> > reasonable like not sharing sqlite* handles. I am creating a new > >> sqlite* > >> > >> > for > >> > every thread. > >> > > >> > Where can we get more info on working with SQLite in a multithreaded > >> > environment? > >> > > >> > The application is working as a service in windows. > >> > > >> > sqlite3_step() is failing with the following error message: > >> > > >> > * SQL error or missing database > >> > SQL logic error or missing database* > >> > > >> > I am getting this message after running the application for quite a > >> long > >> > time (few days). > >> > And then if I execute *PRAGMA INTEGRITY_CHECK* on that table, I get > the > >> > same > >> > error message. > >> > > >> > My application updates the database very 2 mins and the corruption > >> happend > >> > randomly > >> > > >> > I dont have any clue how to debug this! > >> > > >> > Thanks. > >> > > >> > On 5/11/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >> > > >> >> "Sabyasachi Ruj" < [EMAIL PROTECTED]> wrote: > >> >> > Hi, > >> >> > Is there any way to programmatically fix a corrupted sqlite > >> database? > >> >> > I am using sqlite version 3.3.8 with C APIs > >> >> > > >> >> > >> >> Sometimes VACUUM or REINDEX will help, but usually not. > >> >> You can also try to recover using: > >> >> > >> >> sqlite3 OLD.DB .dump | sqlite3 NEW.DB > >> >> > >> >> But that doesn't always work either. The best approach > >> >> is to avoid corruption in the first place. > >> >> -- > >> >> D. Richard Hipp <[EMAIL PROTECTED]> > >> >> > >> >> > >> >> > >> >> > >> > ----------------------------------------------------------------------------- > >> > >> > >> >> > >> >> To unsubscribe, send email to [EMAIL PROTECTED] > >> >> > >> >> > >> > ----------------------------------------------------------------------------- > >> > >> > >> >> > >> >> > >> >> > >> > > >> > > >> > >> > >> > >> > ----------------------------------------------------------------------------- > >> > >> To unsubscribe, send email to [EMAIL PROTECTED] > >> > >> > ----------------------------------------------------------------------------- > >> > >> > >> > > > > > > > > ----------------------------------------------------------------------------- > To unsubscribe, send email to [EMAIL PROTECTED] > > ----------------------------------------------------------------------------- > > -- Sabyasachi

