【问题标题】:How to use select statement with multiple where values in objc?如何在objc中使用带有多个where值的select语句?
【发布时间】:2014-10-13 18:45:27
【问题描述】:

我认为这不是正确的格式,因为控制台在 nslog 检索所有权结果时停止。我需要解决这个问题吗?创建一个临时表来存储 qr 的 where 然后搜索 where 用户?还是我可以更新我的 sql 语句?

[database executeQuery:@"select * from ownership where qrcode = ? and user = ?;", ktQRcode, userktid];

NSLog(@"retrieving ownership results through qrcode and userid");

while ([results next]) {

    OWNERSHIP *ktownership = [OWNERSHIP new];

    ktownership.uniqueIDownership = [results intForColumn:@"id"];

    ktownership.user = [results intForColumn:@"user"];

    ktownership.qrcode = [results intForColumn:@"qrcode"];

    ktownership.create_at = [results dateForColumn:@"create_at"];

    [foundOwnership addObject:ktownership];

    ownershipcount = [foundOwnership count];

    NSLog(@"addnewownership count: %lu", foundOwnership.count);

    NSLog(@"addnewownership Array: %@", foundOwnership);

【问题讨论】:

  • “它停止”是什么意思 - 您是否收到错误消息或堆栈跟踪?您是否不小心在该行上设置了断点(空白处的蓝色标志)?

标签: ios sql objective-c fmdb


【解决方案1】:

您没有向我们展示您分配results 变量的位置。您还应该检查失败,例如:

FMResultSet *results = [database executeQuery:@"select * from ownership where qrcode = ? and user = ?;", ktQRcode, userktid];

if (!results) {
    NSLog(@"select error: %@", [database lastErrorMessage]);
} else {
    NSLog(@"retrieving ownership results through qrcode and userid");
}

while ([results next]) {

    OWNERSHIP *ktownership = [OWNERSHIP new];

    // the rest of your code here
}

【讨论】:

  • 好的,我这样做了,但我没有收到错误消息
  • 那么我现在做的是只选择 qrcode = 的地方?
  • 然后我只在 ktownership.user == userid 时将结果添加到我的数组中
  • 我不明白这个问题:你是说当你将user 条件添加到你的where 子句时你没有得到任何记录,但是如果你从SQL,你得到了很多记录,包括你最初寻找的记录?您绝对不必检索所有内容然后手动过滤它。听起来像是有一些简单的数据问题,但根据提供的有限信息,根本不清楚问题是什么。
猜你喜欢
  • 2019-01-05
  • 1970-01-01
  • 1970-01-01
  • 2013-07-07
  • 2016-08-11
  • 1970-01-01
  • 1970-01-01
  • 2021-03-14
  • 1970-01-01
相关资源
最近更新 更多