0

我想按变量排序数据,然后选择第一条记录。但它不起作用。这是我的代码:

NSString *s = [db stringForQuery:@"SELECT cardInfo.?, cardInfo.?, cardInfo.? FROM cardInfo WHERE cardInfo.currentBalance > ? ORDER BY cardInfo.? DESC, cardInfo.? DESC, cardInfo.? ASC ", first, second, third, [NSNumber numberWithDouble:money], first, second, third];

如果我将其更改为按常量排序,它会起作用。

NSString *s = [db stringForQuery:@"SELECT a, b, c FROM cardInfo WHERE cardInfo.currentBalance > ? ORDER BY a DESC, b DESC, c ASC ",[NSNumber numberWithDouble:money]];

有谁知道如何纠正它?非常感谢。

4

2 回答 2

0

我已经解决了这个问题。我换?使用 %@ 并且可以正常工作

[db stringForQuery:[NSString stringWithFormat:@"SELECT cardInfo.%@, cardInfo.%@, cardInfo.%@ FROM cardInfo WHERE cardInfo.currentBalance > %@ ORDER BY cardInfo.%@, cardInfo.%@,cardInfo.%@ ", first, second,third,  [NSNumber numberWithDouble:money], first, second, third]];
于 2013-04-18T11:48:24.873 回答
0

是的。 ORDER BY cardInfo.?尝试参数化元数据,列名。准备好的语句只允许您参数化数据

你可以说

where tablename.colname = ?

你不能说

where ?.colname = 'foo'

HTH。

于 2013-04-18T05:36:52.063 回答