`close()` doesn't work.
Opened this issue · 3 comments
the callback passed to close
almost inevitably gets passed an error object. unfortunately, the sqlite result code is not attached, so it's hard to guess at why.
I've hacked some printfs into the close routines and it seems that the returned error is always 5-> SQLITE_BUSY which is mentioned in the man page for close: "If sqlite3_close() is called on a database connection that still has outstanding prepared statements or BLOB handles, then it returns SQLITE_BUSY."
I'm afraid my c++ isn't too hot, but it seems that sqlite3_finalize
is never called on the prepared statement handle in the case of Prepare
(PrepareAndStep does call finalize)
Steps to reproduce:
If the tests are changed to log an error in the close callback, none of the tests are able to close without error. ( not sure how to attach a patch here, and I'm not sure if it makes sense to...)
Hi there,
I'm running into this as well. If you have a patch with a fix or a test case, you could fork and issue a pull request or add it to https://gist.github.com/. It would be much appreciated.
Will
I've put together a very simple test case.
Steps to reproduce:
git clone git@github.com:willwhite/node-sqlite.git
cd node-sqlite
git checkout closedbfix
node-waf configure build
git submodule update --init
./run-tests
I added a simple check to the tests in my "closedbfix" branch.
It should complain: "Error: Error closing database"
Not only is close()
returning an error object, but running lsof
reveals that files are being left open. The tests are all using memory databases, but it's easy to switch the path so it uses a real file. Then you can test using the lsof approach.
For .close() to work, make sure that you call .finalize() on all statements. If there are any statements that are not finalized, .close() fill fail.