Search code examples
iossqlitefmdb

iOS sqlite/FMDB update not working


This isn't as easy and specific to ask as I'd like, but I'm really stuck with something. I followed this tutorial, recreating it very similar for an iPad app: http://www.highoncoding.com/Articles/836_Persisting_iOS_Application_Data_in_SQLite_Database_Using_FMDB.aspx

The issue I'm running into is the edit customer and save portion. I've thrown in NSLog's with the customers new name that I edit, and it gets pushed through all the functions, so I'm thinking it's breaking in the update command.

It could also possibly be with the customerID, or some minuscule setting in the storyboard that I'd never find.

If anyone has any ideas, let me know. I can zip up my code for anyone as well.


Solution

  • The issue is with your update query, your each column values were not separated with commas.

    -(BOOL) updateClient:(Client *) client
    {
        FMDatabase *db = [FMDatabase databaseWithPath:[Utility getDatabasePath]];
    
        [db open];
    
        BOOL success = [db executeUpdate:[NSString stringWithFormat:@"UPDATE clients SET name = '%@', phone = '%@', address = '%@', email = '%@', notes = '%@' WHERE id = %d", client.Name, client.Phone, client.Address, client.Email, client.Notes, client.clientId]];
    
        [db close];
        return success;
    }