如何在objc中使用带有多个where值的select语句?

时间:2014-10-13 18:45:28

标签: ios sql objective-c fmdb

我不认为这是正确的格式,因为控制台在nslog检索所有权结果时停止。我需要解决这个问题吗?创建一个临时表来存储qr的位置,然后搜索用户的位置?或者我可以更新我的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);

1 个答案:

答案 0 :(得分:0)

您没有告诉我们您在哪里指定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
}