开发者

How to bind a NSString into a sqlite sql statement

开发者 https://www.devze.com 2023-02-16 02:31 出处:网络
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 开发者_开发知识

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消