0

I am using FMDB wrapper class for database in my iphone app.

App freezes many times when i call a class with database execute update query.

Sample :

    BOOL success = [database executeUpdate:@"UPDATE JOBTABLE SET ST = ? WHERE jobid = ?",@"Accepted",[NSNumber numberWithInt:[jobIDStr intValue]]];

I am trying tested this by adding logs before and after this code. In console the line before its is printed, and then the app freezes.

I am calling function which includes this line of code from other class.

I had tried call this method using below code as well

Addjob *addjob=[[AddJob Alloc]init];
[addjob performSelectorInBackground:@selector(addJobHttpRequest) withObject:Nil];

This has also not worked for me. The function addjob contains the database update query.

TechFanatic
  • 1,218
  • 4
  • 13
  • 31
  • can you paste `addJobHttpRequest` function code – arthankamal May 29 '13 at 10:19
  • You can hit the 'pause' button in XCode when the app is in the frozen state, and have a better look at where its frozen (usually an infinite loop/recursion). The code seems ok, calling the method in the main thread is the right way (a FMDatabase object should be used in a single thread). – alex-i May 29 '13 at 10:21
  • shall i call it using [addjob addJobHttpRequest]; or the method using calling in background is ok. – TechFanatic May 29 '13 at 10:35
  • @arthan.v this problem is not only with addjobhttp function, i have started facing this problem for most of the function in which database update is used.It was working fine previously.After IOS update, i think it has started giving this issue. – TechFanatic May 29 '13 at 10:48
  • @TechFanatic presuming that you've created your `database` instance in the main thread, you may need to call (in not in the main thread) `[addjob performSelectorInMainThread:@selector(addJobHttpRequest) withObject:nil waitUntilDone:NO];`, or handle the query to get called in the main thread from inside `addJobHttpRequest`. – alex-i May 29 '13 at 10:54
  • @alex-i i had tried with pause , its always stopping on update query itself. I want to call function with database query from other class. – TechFanatic May 29 '13 at 11:53
  • @alex-i addjob performSelectorInMainThread:@selector(addJobHttpRequest) withObject:nil waitUntilDone:NO]; I had tried this as well still its hangs on that line of code. Previously it used to work properly. – TechFanatic May 29 '13 at 12:02
  • @arthan.v can you give me link to sample how to use FMDB? – TechFanatic May 29 '13 at 12:07
  • @TechFanatic please make a screenshot while xcode is paused, and with `Debugger Navigator` (on the left) visible (shows the call stack). – alex-i May 29 '13 at 12:15
  • @TechFanatic, i guess some flaw in your function. May be infinite loop or something. Try printing NSLog before and after that line. use `breakpoints and NSZombie enabled`. and try printing `[database lastErrorMessage]` to find the problem – arthankamal May 29 '13 at 12:21
  • @alex-i Thanks for your help , i was able to solve the issue. – TechFanatic May 31 '13 at 07:46
  • @arthan.v Thanks for your help , i was able to solve the issue. – TechFanatic May 31 '13 at 07:46

2 Answers2

1

In AddJob.h

Create

    Addjob *addjob=[[AddJob Alloc]init];

And try accessing function .m file.

0

if([db open])

NSString *queryStr ;

    queryStr = [NSString stringWithFormat:@"Update yourTableName set DatabasefieldName = '%@' where serial=%i ",databaseFieldValue,serialValue intValue]];

    [db executeUpdate:queryStr];
Mital
  • 241
  • 1
  • 5
  • Not good if you care about sanitization - for instance `txtDbFieldName.text` could be used to create an sql injection. – alex-i May 29 '13 at 10:24