comments on using luasqlite db:nrows

Posted by Fiendish on Sat 12 Nov 2011 06:19 AM — 2 posts, 10,413 views.

USA Global Moderator #0
The documentation for db:nrows (and possibly db:rows and db:urows as well) should note that you should never break or return before the for loop is finished, because that apparently leaves the table locked as I've discovered the hard way. You can test this by doing something like "PRAGMA wal_checkpoint;" (assuming your journal_mode is set to WAL) after breaking out of the db:nrows loop and then checking the error code.
Amended on Sat 12 Nov 2011 03:25 PM by Fiendish
Australia Forum Administrator #1
Yes I wondered about that. Hence my caution when doing this:


for a in db:nrows "SELECT * FROM sqlite_master WHERE name = 'rooms_lookup' AND type = 'table'" do
    table_exists = true
  end  -- for


Although you should only get one match, I let the for loop iterate and "clean up" afterwards.

Documentation amended for the next release.