我在 Sqlite 数据库应用程序中执行此查询,即“Base.app”(可以在 Mac App Store 上找到),我得到三个结果行。如果我在 iOS6 上执行下面的代码,我也会得到三行。然而,在 iOS 5.1 上只返回一行。没有错误。如果我删除 GROUP BY 和 HAVING,我可以在 iOS6 和 DB 应用程序上重现一行的结果。但是为什么iOS5会忽略这些呢?
SELECT COUNT(Sub.intItemID) AS intNumSubFolders, Items.*, Files.*
FROM Items
LEFT JOIN Items AS Sub ON Sub.intParentID = Items.intItemID AND Sub.intObjectType IN (2, 3, 6)
LEFT JOIN Files ON Files.intItemID = Items.intItemID
WHERE Items.intParentID= 2905837
GROUP BY Items.intItemID HAVING Items.intItemVersion=MAX(Items.intItemVersion)
这是我使用的代码:
using ( SqliteCommand oCmd = new SqliteCommand ( "SELECT COUNT(Sub.intItemID) AS intNumSubFolders, Items.*, Files.*" +
" FROM Items" +
" LEFT JOIN Items AS Sub ON Sub.intParentID = Items.intItemID AND Sub.intObjectType IN (2, 3, 6)" +
" LEFT JOIN Files ON Files.intItemID = Items.intItemID " +
" WHERE Items.intParentID=@intItemID" +
" GROUP BY Items.intItemID HAVING Items.intItemVersion=MAX(Items.intItemVersion)", oConn ) )
{
oCmd.Parameters.AddWithValue ( "@intItemID", iID );
using ( var oReader = oCmd.ExecuteReader ( ) )
{
while ( oReader.Read ( ) )
{
// getting here only once
}
oReader.Close ();
}
}
有人可以解释为什么会发生这种情况吗?在 iOS5 上确认。在 iOS6 中,它按预期工作。