【问题标题】:Sql Join does not show the new inserted rows in sqlite tableSql Join 不显示 sqlite 表中新插入的行
【发布时间】:2013-10-28 00:52:31
【问题描述】:

我有在其中插入数据的 iPhone 应用程序。当我在没有任何条件的情况下获取所有数据时它工作正常,然后如果给定任何条件(如

)它工作正常

以下查询则不显示任何内容。

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


const char *sql = [select UTF8String];        

如果我使用select * form ContentMaster,它不会显示任何使用它的东西,那么它会显示所有添加的记录。

【问题讨论】:

  • 顺便说一句,您永远不应该使用stringWithFormat 来构建您的SQL 语句。如果tagInput 中有一个撇号怎么办?你的代码会失败。你应该。始终使用? 占位符,然后将文本值与sqlite3_bind_text 绑定。
  • sqlite3_prepare_v2 是否返回 SQLITE_OK?如果没有,sqlite3_errmsg 报告了什么?也许您可以为两个表共享更多代码以及schema table_info()ContenTagText 看起来很可疑。 (是ContentTagText 吗?)但是如果没有更多的代码、有关表模式的信息以及表中的一些记录,我们很难为您提供帮助。
  • tagInput的值是多少?

标签: iphone ios sql sqlite


【解决方案1】:

试试这个。

SELECT * from ContentMaster  
LEFT JOIN ContentTagging 
ON ContentMaster.ContentID = ContentTagging.ContentID 
WHERE ContentTagging.ContenTagText= \'%@\'"

【讨论】:

  • 为什么?这有什么不同?
猜你喜欢
  • 1970-01-01
  • 2017-10-23
  • 2012-01-07
  • 2011-05-14
  • 1970-01-01
  • 2023-02-04
  • 2014-09-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多