在字符串中转义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];
由于
答案 0 :(得分: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];