最近做ios数据库相关的基本操作(增、删、改、查)遇到一些问题,其中 error:"unrecognized token: ":""
sql语句如下:
sql1 = [NSString stringWithFormat:@" update cars set macString2= %@ where id = %@",macStr,carId];
sql2 = [NSString stringWithFormat:@" UPDATE cars SET location2 = %@ WHERE id = %@",location,carId];
出现上述问题的解决方案是在@%上加单引号:
sql1 = [NSString stringWithFormat:@" update cars set macString2= '%@' where id = '%@'",macStr,carId];
sql2 = [NSString stringWithFormat:@" UPDATE cars SET location2 = '%@' WHERE id = '%@'",location,carId];
或者用?的方式
sql1 = [NSString stringWithFormat:@" insert into cars(macStr)values (?)"];