Search code examples
iossqlfmdb

How do I see success of the following FMDatabase executeUpdate statement?


The following code does not give any error but does not do the insert and I can't figure out why. I am still a novice and wanted to know the best way to see the result of this query or see if there is an error message. I'm sure its something simple like "BOOL success = [database executeUpdate...] then print BOOL. Thanks in advance.

if ([database open]) {
    [database executeUpdate:@"insert into CONDITION (condition_id, condition_name, condition_detail, condition_area, condition_date, active) values(?, ?, ?, ?, ?)",
    [NSNumber numberWithInt:self.condition_id], self.condition_name, self.condition_detail, self.condition_area, self.condition_date, [NSNumber numberWithInt:myInt] ];

    [database close];

Solution

  • The executeUpdate method has return value and the FMDatabase saved lastErrorMessage:

    BOOL isSuccessful = [database executeUpdate:@"insert into CONDITION (condition_id, condition_name, condition_detail, condition_area, condition_date, active) values(?, ?, ?, ?, ?)",
        [NSNumber numberWithInt:self.condition_id], self.condition_name, self.condition_detail, self.condition_area, self.condition_date, [NSNumber numberWithInt:myInt] ];
    if (!isSuccessful) {
        NSLog(@"%@", database.lastErrorMessage);
    }