我想像这样制作sql select语句:
NSLog(@"sql = %@",[NSString stringWithFormat:@"select * from Table1 Where ID = %i AND '%@' = strftime('%Y',startDate)",ID,date]);
但它打印给我:
sql = select * from Table1 Where ID = 1 AND '2012' = strftime('Y',startDate)
%Y变为Y,我怎么能阻止这个?
答案 0 :(得分:4)
添加另一个%
以转义%
字符:
NSLog(@"sql = %@",[NSString stringWithFormat:@"select * from Table1 Where ID = %i AND '%@' = strftime('%%Y',startDate)",ID,date]);
答案 1 :(得分:1)
添加类似NSLog(@"sql = %@",[NSString stringWithFormat:@"select * from Table1 Where ID = %i AND '%@' = strftime('%%Y',startDate)",ID,date]);