0

在字符串中转义 sqlite 格式说明符的正确方法是什么?

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];

    NSDate *today = [NSDate date];
    NSString *todaysDate = [dateFormatter stringFromDate:today];

    NSString *SQL = [NSString stringWithFormat: @"SELECT id,strftime(\"%Y-%m-%d\") as `date`,word,term FROM words WHERE `date` <= '%@' ORDER BY `date` DESC LIMIT 1",todaysDate];

谢谢

4

1 回答 1

0

弄清楚了。要转义“%”,请使用“%%”。

NSString *SQL = [NSString stringWithFormat: @"SELECT id,strftime(\"%%Y-%%m-%%d\") as `date`,word,term FROM words WHERE `date` <= '%@' ORDER BY `date` DESC LIMIT 1",todaysDate];
于 2012-01-30T15:45:14.083 回答