0

I have a FMDB executeUpdate which cause an infinite loop :

FMDatabase *db = [FMDatabase databaseWithPath:[CDDBManager getDatabasePath]];

[db closeOpenResultSets];
[db close];
NSLog(@"successfully pass closes");
[db open];
NSLog(@"successfully pass open");
[db setTraceExecution:YES];
BOOL success = [db executeUpdate:@"INSERT OR REPLACE INTO Player (id, ..., is_user) VALUES (?, ..., ?)",
                [NSNumber numberWithInt:self.player_id],
                ...
                [NSNumber numberWithInt:1]];

NSLog(@"end update");
[db close];

I call this method in two different VCs and in one it perfectly work ... in other I have an infinite loop (I print retry in the "do{} while()" of FMDB), so I don't see "end update" ... As you see, I already try to close all result sets and and the db ...

Anyone can see where I've failed ?

All suggestions are welcome.

Thomas Leduc
  • 1,092
  • 1
  • 20
  • 44
  • As a starter, I would check the result of the FMDB open call, it returns false if the open failed. Also, are both db calls on the same thread? – user352891 Apr 18 '13 at 01:26
  • A backtrace of all the threads would help out a ton- the database is probably locked in another thread (or even process). – ccgus Apr 18 '13 at 03:34
  • Ok, I've tried to get the return of open, the database was opened correctly ... How Can I have a backtrace ? All my thread are finished normally when I do the request :/ – Thomas Leduc Apr 18 '13 at 09:57
  • it's not SQLITE_LOCK but it's SQLITE_BUSY, I don't understand how my database can be busy .. The precedent work is finished ... – Thomas Leduc Apr 18 '13 at 10:21
  • Anyone have the same issue ? – Thomas Leduc Apr 19 '13 at 07:25

2 Answers2

1

I think we had the same problem. I was opening a connection for every method where I wanted to call my database. I fixed it by just opening the connection on init.

jcotham
  • 11
  • 1
  • Hum hum, and before that, you closed every time ? Because, it was the same to open/close every time :/ – Thomas Leduc Apr 19 '13 at 19:20
  • Yeah, I was opening and closing every time. – jcotham Apr 19 '13 at 19:25
  • Thank for your response, I gonna to switch branch and test your solution. Which "init" you talk about ? The view controller for example ? – Thomas Leduc Apr 19 '13 at 19:51
  • I'm just using the initialize block that gets called when the class is first called. – jcotham Apr 19 '13 at 23:03
  • Nothing to do ... the issue persist ... - Database busy - Unknown error finalizing or resetting statement (5: database is locked) - DB Query: INSERT OR REPLACE INTO Team(id, name, tag, emblem, back_color, bord_color, desc, powerpoint, ts) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) – Thomas Leduc Apr 22 '13 at 12:16
0

I'm sorry but it is a simple error in function where I close the FMResultSet after a return in condition clause ...

Thomas Leduc
  • 1,092
  • 1
  • 20
  • 44