如何使用iphone中的Clause从sqlite表中获取数据

时间:2013-10-14 06:24:50

标签: iphone ios ipad sqlite

我在正常条件下从两个表中选择数据它工作正常但是如果我使用where子句它不会返回任何内容。

这是查询

NSString *select =[NSString stringWithFormat:@"SELECT *from ContentMaster As ml LEFT JOIN ContentTagging As cat ON cat.ContentID = ml.ContentID where cat.ContenTagText= %@" , appDelegate.tagInput];

这是查询的NSLog

SELECT *from ContentMaster As ml LEFT JOIN ContentTagging  ON cat.ContentID = ml.ContentID where cat.ContenTagText= Tag1

1 个答案:

答案 0 :(得分:1)

将ContenTagText放在''中,因为它正在比较字符串

NSString *select =[NSString stringWithFormat:@"SELECT * from ContentMaster As ml LEFT JOIN ContentTagging As cat ON cat.ContentID = ml.ContentID where cat.ContenTagText= \'%@\'" , appDelegate.tagInput];

查询将是:

SELECT *from ContentMaster As ml LEFT JOIN ContentTagging  ON cat.ContentID = ml.ContentID where cat.ContenTagText= 'Tag1'
希望它会有所帮助。