开发者

Sqlite Finalize statement failing

开发者 https://www.devze.com 2023-04-02 17:48 出处:网络
Error: sqlite3_finalize failed (database is locked). I have released memory also properl开发者_运维技巧y in each view. Has anyone faced this issue?I think you\'re hitting some legacy cruft in the SQLi

Error: sqlite3_finalize failed (database is locked). I have released memory also properl开发者_运维技巧y in each view. Has anyone faced this issue?


I think you're hitting some legacy cruft in the SQLite interface. To summarize, when you sqlite3_step and the result is an error, slite3_finalize will return the same error. Pay attention to the error from sqlite3_step and other SQLite calls, and ignore the error from slite3_finalize.

Per SQLite documentation for sqlite3_finalize:

If the most recent evaluation of the statement encountered no errors or or if the statement is never been evaluated, then sqlite3_finalize() returns SQLITE_OK. If the most recent evaluation of statement S failed, then sqlite3_finalize(S) returns the appropriate error code or extended error code.

It talks about the most recent evaluation of the statement rather than the finalize itself. This is nowhere near explicit enough, but there's another comment in the documentation that is:

Goofy Interface Alert: In the legacy interface, the sqlite3_step() API always returns a generic error code, SQLITE_ERROR, following any error other than SQLITE_BUSY and SQLITE_MISUSE. You must call sqlite3_reset() or sqlite3_finalize() in order to find one of the specific error codes that better describes the error.

It goes on to say this is fixed by the v2 APIs, but I think that's only partially correct. When using the v2 APIs, sqlite3_step returns an error code directly. However, there's no sqlite3_finalize_v2. And in my testing, sqlite3_finalize continues to return the error code from sqlite3_step.

In other words: Ignore the error from sqlite3_finalize. Pay attention to the error you're almost certainly getting but ignoring from sqlite3_step.


"Database is locked" means that (duh!) the database is locked. Some other sqlite operation against the database is still "pending", possibly because you failed to finalize an earlier query, or possibly because there's a query going on in an async thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消