Hi all I am using the sqlite3 database in my iphone application but seems like I have a problem when I try to update a object in the table. Can anyone shortly explain how NSStrings can 开发者_开发知识库be added as placeholder? (Yes I know an ID should not be a NSString :))
This code snipplet updates the table:
NSString *affectedFactId = [fact factId];
char const *sqlStatement = sqlite3_mprintf("UPDATE facts SET isFavorite = 'yes' WHERE id=1");
This code snipplet fails:
NSString *affectedFactId = [fact factId];
char const *sqlStatement = sqlite3_mprintf("UPDATE facts SET isFavorite = 'yes' WHERE id='%@'", affectedFactId);
Thanks for explaining, Cheers, Doonot
Just set id to be an int not a string as you do. The intValue of NSString class will do that for you.
精彩评论