DevWithZachary
DevWithZachary

Reputation: 3675

FMDatabase errors out when running update query

I have the below line which crashes on FMDB when it runs with:

-[FMDatabase executeUpdate:error:withArgumentsinArray:orDictionary:orVAList:]

My code is:

NSInteger entryID = 1;
[db executeUpdate:@"UPDATE formQue SET Processed='true' WHERE EntryID=?", entryID];

Happy to show more code etc. but I have narrowed the crash down to happening at this line and it does not really effect any other code.

Table:

formQue(EntryID INTEGER PRIMARY KEY, CustomerID int, Title text, FName text, LName text, DOB text, Country text, Email text, Nationality text, Processed text, courseType text, Notes text, YearEntry text, Event text)

And this is what xcode looks like when the crash happens

enter image description here

Upvotes: 0

Views: 1589

Answers (1)

mttrb
mttrb

Reputation: 8345

The problem is that FMDB expects the bind arguments to be objects. You are using an NSInteger which is a simple C type.

From the FMDB class documentation:

Optional parameters to bind to ? placeholders in the SQL statement. These should be Objective-C objects (e.g. NSString, NSNumber, etc.), not fundamental C data types (e.g. int, char *, etc.).

Try boxing the argument into an NSNumber:

NSInteger entryID = 1;
[db executeUpdate:@"UPDATE formQue SET Processed='true' WHERE EntryID=?", [NSNumber numberWithIntger:entryID]];

Or more succinctly using the modern syntax:

NSInteger entryID = 1;
[db executeUpdate:@"UPDATE formQue SET Processed='true' WHERE EntryID=?", @(entryID)];

Upvotes: 3

Related Questions