Skip to content
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

Database might be busy when close is called #702

Open
kanoshin opened this issue Jun 22, 2017 · 2 comments
Open

Database might be busy when close is called #702

kanoshin opened this issue Jun 22, 2017 · 2 comments

Comments

@kanoshin
Copy link

Hello,

according to SQLite documentation sqlite3_close might return SQLITE_BUSY (http://www.sqlite.org/c3ref/close.html). It usually means that there are not finalized statements.

I see that this plugin don't handle such scenario, it might lead to creation of new database connections when sqlite3_open will be called later, right?

From http://sqlite.1065341.n5.nabble.com/handling-sqlite3-close-SQLITE-BUSY-td35617.html:

You can force connection closing in case
of SQLITE_BUSY result by forcible finalizing of all statements. Use
http://www.sqlite.org/c3ref/next_stmt.html for iterating all
statements and sqlite3_finalize on each of them. After that
sqlite3_close should complete successfully.

@kanoshin
Copy link
Author

kanoshin commented Jun 22, 2017

@brodybits thank you.
I think this might fix errors that sometimes occur right after app navigates to different page or recreates database connection:
{\"result\":{\"code\":5,\"sqliteCode\":1,\"message\":\"cannot start a transaction within a transaction\"}}
{\"result\":{\"code\":0,\"sqliteCode\":14,\"message\":\"unable to open database file\"}}
{\"result\":{\"code\":0,\"sqliteCode\":5,\"message\":\"sqlite3_step failure: database is locked\"}}

@brodycj
Copy link
Contributor

brodycj commented Oct 26, 2017

This looks like yet another problem with using "standard" Web SQL transaction calls (database.transaction() and database.readTransaction()) together with multi-page apps, possibly related to #666. It would be better to use database.executeSql() and database.sqlBatch() calls as documented instead.

The database.transaction() and database.readTransaction() calls are deprecated and scheduled to be removed from this plugin version ref: #720, #690

An additional suggestion is to consider using https://github.com/brodybits/sql-promise-helper to get a nice, clean Promise-based API, also working on the Browser platform today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants