David Swigger wrote:

I open two connections: pConn1 = sqlite_open(m_sDbPath.c_str(),0,NULL); pConn2 = sqlite_open(m_sDbPath.c_str(),0,NULL);

I do the query and compile a query on conn1, then
start stepping through the rows of results.

If I try to do any execs using pConn2 - I always get
an error code saying the database is locked.


As pointed out by others, the query is doing a read-lock on the databae which prevents writes to the database from other connections.

Several things you can do here:

  1:  Use sqlite_get_table() or the equivalent to load
      the entire result set into memory.  This will release
      the read-lock quickly and allow you to write as you
      step throught the result set.

  2:  Copy the result set into a temporary table then
      step through the temporary table.  Like this:

        CREATE TABLE results AS SELECT <your-query-here>;
        SELECT * FROM results;

      Read-locks are not held when reading from temporary
      tables so you should be able to write to the main
      database while the SELECT of the temporary tables
      is on-going.

  3:  Sometimes an ORDER BY clause on the SELECT statement
      will cause the entire result set to be read into memory.
      (This happens if the ORDER BY clause cannot be satisfied
      by an index.)  This is usually considered a bug, but in
      your case, you might be able to employ this property as
      a feature.  As soon as the result set is entirely in
      memory, the read-lock is released and other threads can
      begin writing to the database.

  4:  If you only do a single sqlite_open() and then compile
      the query and the inserts from that one connection,
      then you can read and write the database at the same
      time.  You still won't be able to read and write the
      same table at the same time, but you can read and write
      separate tables in the same database.



--
D. Richard Hipp -- [EMAIL PROTECTED] -- 704.948.4565


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to