我在sql中遇到单引号问题。以下是声明。
如果用户名是妈妈,我该如何选择它?我也想考虑到有时候我可能不得不逃避'
,有时候不能
sqlStatement = [NSString stringWithFormat:@"SELECT * FROM USERS where NAME = '%@'",searchKeyword];
谢谢!
答案 0 :(得分:2)
您不应该像这样手动构造SQL查询。它为所有类型的SQL注入打开了大门,允许恶意用户在您的数据库上运行任意SQL。
相反,您应该使用绑定参数。见http://www.sqlite.org/c3ref/bind_blob.html
(我假设您打算进行SQLite查询)。