On 8 Feb 2014, at 4:58pm, Tim Streater <t...@clothears.org.uk> wrote:
> On 07 Feb 2014 at 23:04, Simon Slavin <slav...@bigfraud.org> wrote: > >> You should not be manually setting any handle to null. Try calling >> ->finalize() on the statement and eventually ->close() on the database, which >> do more than just setting their value. If you are setting anything to null >> manually, this may be causing the problem you report. > > I made myself a simple testbed in PHP based on the code I posted last time. I > used a sleep call to make each turn round the while loop take a couple of > seconds, so the code took 20 secs to complete. In another Terminal window, I > ran a second script that tried to update the same database (with a 2000msec > timeout). Having established that this latter script got "database is > locked", I then rejigged the first script to fetch all the result rows before > entering the slow loop. This sufficed to allow the second script to run > without getting "database is locked" (i.e I didn't use ->finalize or ->close > in the first script). > > I had a look at the PHP sqlite3 interface code, and it looks like ->query > does prepare, step, and reset (if there are no errors). If ->query() is doing 'step()' then the PHP code does not work the same way SQLite3 does internally. SQLite would do 'step()' as part of ->fetchArray(). > Which of these obtains the lock on the db? The first 'step()'. Before then all PHP needs to know is the structure of the database, not about the data in it. The database needs to be locked from the first 'step()' to the last 'step()', though it can predict that it is finished if 'step()' returns 'no more rows'. So putting the above together you are still expected to use ->finalize() on the result set: it is the ->close() for that class and is the official way to release the handle. Don't set it to null manually, use ->finalize() on it. And, of course, eventually use ->close() on the database handle. Your solution may work for your test case, and it may work for this version of PHP using this version of SQLite, but I would recommend you use the API as documented. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users