2010-02-22 177 views
0

我试图将一个NSString值绑定到我的SQL查询中,但它不工作,我不知道我在做什么错。 这里是我的查询:LIKE语句的Sqlite3_bind(Objective-C)


Select * from fiche where fichetype = 'EVENT' and sdate like '?%' ORDER BY cdate DESC 

而且我使用的这部分代码的值绑定:


sqlite3_bind_text(getEventStatement, 1, [value UTF8String], -1, SQLITE_TRANSIENT); 

这个查询工作在我的数据库罚款,但没有在Xcode。我也尝试类似的东西:


Select * from fiche where fichetype = 'EVENT' and sdate GLOB '?*' ORDER BY cdate DESC 

这一个在Xcode的工作,但所有值都显示,?*不起作用。

有人吗?谢谢,

回答

0

对于那些与LIKE声明有同样问题的人来说,这里是为我工作的解决方案。 首先我改变我的查询这样的:


Select * from fiche where fichetype = 'EVENT' and sdate like ?001 ORDER BY cdate DESC 

不要把引号的参数令牌001,然后创建一个把%到你正在寻找一个新的字符串:


NSString *theString = [NSString stringWithFormat:@"%@%%", myValue]; 

最后,只需要字符串绑定到准备好的语句是这样的:


sqlite3_bind_text(getEventStatement, 1, [theString UTF8String], -1, SQLITE_STATIC); 

有乐趣,