开发者

FMDB executeUpdate DROP command does halt the app

I want to drop a table in my SQLite Database file named database.db. After using

NSLog(@"i show up in the console");
[db executeUpdate:@"DROP TABLE IF EXISTS `article`;"];
NSLog(@"i will not show up in the console");

the app stops at the position of the query. NSLog before the query is shown in console. NSlog directly after the query does not show up in the console window. Additionally a temporary file called database.db-journal is created and deleted continuously in the simulator app folder while the app is running. The app does NOT crash, does not giving any error and does not continue... Removing "IF EXISTS" in the query doesn't work, removing backticks doesn't work, removing semicolon doesn't work.

Enabling tracing of query only shows that FMDB is processing my query, nothing more 开发者_开发知识库shows up.

I'm really confused why this happens. I thought that the table has to be empty before it can be dropped and so I added a query to delete every record in it. But id doesn't matter, the app is still getting caught at the drop-query. Im running out of possibilities to resolve this error.

If I execute the drop command within SQLite Database Browser 2 everything works fine.

Further researches with the debugger showed that FMDB wrapper is going into an infinity loop because the return value of the statement equals to the SQLITE_LOCKED constant which means that the table I want to drop is locked. Sending "UNLOCK TABLES" in a previous query doesn't solve this. Why the table is locked? Why deleting records from a locked table will work?


I had the same issue, and got it solved by calling closeOpenResultSets on the FMDB instance just before the update, just like TRD said (though I didn't have to close and reopen the database completely)


I finally got rid of this nasty behaviour. I closed the database connection right before the drop query and reopened it immediately. If I have to guess I'd say that SELECT-Queries in earlier parts of my source code made the connection to be locked for DROP-statements. So closing the database connection and reopen it resets those locks. Hope this can help you @JLoewy.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜