ios - 如何在 FMResultSet 中传递两个查询

标签 ios objective-c ios7 fmdb

我写了这段代码:-

[database open];

    NSString *stringQuery = [NSString stringWithFormat:@"SELECT email, firstName, id, lastName, phone FROM contacts WHERE id = '%@'", _stringID];

    NSString *stringQuery2 = [NSString stringWithFormat:@"SELECT id, status FROM members WHERE id = '%@'", _stringID];

    FMResultSet *result = [AppDel.database executeQueryWithFormat:stringQuery, stringQuery2];

    if ([result next])
    {
        labelEmail.text = [result stringForColumn:@"email"];
        labelFirstName.text = [result stringForColumn:@"firstName"];
        labelLastName.text = [result stringForColumn:@"lastName"];
        labelCellPhone.text = [result stringForColumn:@"phone"];

        labelSignInStatus.text = [result stringForColumn:@"status"];
    }

    [result close];

    [database close];

当我通过 labelSignInStatus.text 传递它时,它给了我 labelCellPhone.text 的值,它们显示“警告:我找不到名为‘status’的列”,当我在 Sqlite 浏览器中传递查询时,它们给了我正确的结果.我还再次创建了名为 FMResultSet *result1 的 FMResultSet 对象,并通过查询向我显示相同的错误。 谁能帮助我如何在 FMResultSet 中传递两个查询。 谢谢

最佳答案

您不能将 2 个查询传递给 executeQueryWithFormat。这不是它的本意。您可以传递一个查询,然后传递一些参数。如果你打算自己格式化 sql,那么只需使用 executeQuery:(NSString *) sql

您在这里尝试做什么并不完全清楚,但您可能需要进行 SQL 连接。所以你的问题是一个 SQL 问题,而不是我认为的 FMResult 集问题。

也许你需要这样的东西:

NSString *stringQuery = [NSString stringWithFormat:@"SELECT c.email, c.firstName, c.id, m.status c.lastName, c.phone FROM contacts c, members m where c.id=m.id and c.id='%@'", _stringID];

FMResultSet *result = [AppDel.database executeQuery:stringQuery];

这样会返回一行,其中联系人与成员具有相同的 ID。然后您的其余代码应该可以工作。

关于ios - 如何在 FMResultSet 中传递两个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25102609/

相关文章:

objective-c - 自动将文件复制到App Document文件夹

iphone - 在 CoreBluetooth 框架中从未见过任何有关在后台保持连接事件的内容

iphone - 不兼容的整数到指针的转换?什么?

iphone - ios - 如何找到 UITextView 中文本的可见范围?

ios - 重新加载导航栏 UIBarButtonItem

ios - 如何在 iOS 7 启动期间更改状态栏样式

iOS 7 UITableView 问题 - 尝试设置滑动以删除已有单元格的单元格

ios - 如何从 UIWebView(或 WKWebView)访问 asset catalog 中的图片资源

ios - 加密 128 位字符串的过程

objective-c - 使用组件分离形成 NSArray 并使用重复元素形成另一个数组