I have recently encountered the same cross-thread library misuse bug, and ended up re-implement a C++ wrapper to be thread-aware and thread-safe. It's not yet feature complete, compared to CPPSQLite3DB, but it does have several good enhancements:
* signed 64-bit integer parameter binding support. * signed 64-bit integer column value support. * automatic per-thread connection creation. * string_reference and blob_reference binding support (minimizes copies and memory allocations, important in the client-side game industry). * precompiled statement support with execution states to support binding & result sets. Eventually it will be more aware of sqlite3 features currently exposed via PRAGMA commands. But at the moment, it works well enough for me. andy On 5/16/07, Ed Pasma <[EMAIL PROTECTED]> wrote:
Hello, I have no inside-knowledge from SQLite, but I'am in the circumstance to easily do this experiment. Hope I understand it right and that you consider a sort of pipe-lining. Anyway, I started the two threads A and B, and made A exclusively do all the sqlite3_prepare calls, and B the rest, including sqlite3_step. This almost immediately raises "library routine called out of sequence". It occurs as soon as the processing of A and B overlap, that means A is preparing statement #2 while B is still executing #1. So the experimental conclusion is that this won't work. But this applies only to the pipelining idea. The serializing to use a single connection may still offer an interesting new locking model. Regards, Ed Pasma Op 14-mei-2007, om 13:04 heeft Jiri Hajek het volgende geschreven: > Hello, > > I have tried to search all the documentation about threading in > SQLite, but > I'm still somewhat confused. > > It's often suggested to create a pool of sqlite3 structures, but > what if I > would like to have only only sqlite3 connection and serialize all > the DB > operations to one thread (name it 'A') that would prepare and > execute all > the queries. I guess that this would work well... > > However, it would be too time consuming to serialize every call to > sqlite3_step(), so I wonder whether it can be called in another > thread. So > my scenario is: > > 1. Thread B wants to open a query 'SELECT * FROM Tbl1' > 2. Thread A is used to prepare the query 'SELECT * FROM Tbl1' using > sqlite3_prepare16_v2() and using the same sqlite3 DB connection as for > possibly some other running SQL statements. > 3. Thread B now repeatedly calls sqlite3_step(), > sqlite3_column_text16() and > similar functions in order to get all rows from DB. > 4. Thread A is used to call sqlite3_finalize() on the openned query. > > So my questions are: > a. Would the code described above work. > b. In step 3., do I have to somehow make sure that calls to > sqlite3_step() > don't interfere with other SQLite processing in thread A, e.g. by > Windows > CriticalSections? Is anything like this also needed for > sqlite3_column_text16()? > > Thanks for any explanation, > Jiri ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------