问题描述
这并不像我想的那样简单和具体,但我真的被某些事情困住了.我遵循了本教程,为 iPad 应用程序重新创建了非常相似的内容:http://www.highoncoding.com/Articles/836_Persisting_iOS_Application_Data_in_SQLite_Database_Using
我遇到的问题是编辑客户和保存部分.我已经将 NSLog 与我编辑的客户新名称一起放入了 NSLog 中,并且它会通过所有功能进行推送,所以我认为它在更新命令中被破坏了.
它也可能与 customerID 相关,或者故事板中我从未找到的一些微小设置.
如果有人有任何想法,请告诉我.我也可以为任何人压缩我的代码.
问题在于您的更新查询,您的每列值没有用逗号分隔.
-(BOOL) updateClient:(Client *) 客户端{FMDatabase *db = [FMDatabase databaseWithPath:[Utility getDatabasePath]];[数据库打开];BOOL 成功 = [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]];[数据库关闭];返回成功;}
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.
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;
}
这篇关于iOS sqlite/FMDB 更新不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!