-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opening and closing of databases #9
Comments
Below is an alternative close implementation, using a variation of sanity code that I use in my projects. This close code prints out the SQL of the open statements, attempts to finalize them, and retries that a few (100) times. If it was solely a temporary issue (busy or logged flag, but no open statements) no error is thrown. If there were unfinalized statements, an error is thrown - but the database is closed gracefully then instead of having an unclosed zombie sqlite3 connection. Please see the "todo" comment below. There should be the SQL logged which wasn't finalized. I didn't implement this yet.
|
Thanks for the fix. Could you create a pull request in order to review and test the changes at ease? |
@benstadin If after you review the current state of master you think your change would still be appropriate please open a PR with your proposal. Closing this issue. |
Hi,
I think the implementation of Java_org_sqlite_core_NativeDB__1open() and Java_org_sqlite_core_NativeDB__1close()in NativeDB.c is wrong against the behaviour of SQLite databases:
Secondly, trying to close a db may or may not be successfull: If there is an unfinalized prepared statement the db will never be closed by SQLite. The result of sqlit3_close() must be checked in any case.
If this is however for whatever reason intended behaviour that the db is closed, there should rather be sqlite3_close_v2() called, so that the db is closed when the last statement was finalized.
So I'd simple remove the sqlite3_close from within the open() method, and change close to this:
JNIEXPORT void JNICALL Java_org_sqlite_core_NativeDB__1close(
JNIEnv *env, jobject this)
{
int err = sqlite3_close(gethandle(env, this));
if (err == SQLITE_OK) {
//clearSpatialiteCacheForHandle(gethandle(env, this));
sethandle(env, this, 0);
}
else {
throw_errorcode(env, this, err);
}
}
Kind regards
Ben
Readups:
https://www.sqlite.org/c3ref/close.html
The text was updated successfully, but these errors were encountered: