Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 940
TRD Avatar asked Dec 09 '22 06:12

TRD


1 Answers

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)

like image 191
altschuler Avatar answered Dec 23 '22 20:12

altschuler