我正在使用以下代码,但sqlite给我错误
NSArray* a = [NSArray arrayWithObjects:
@"\""
@"\\ \"",
nil];
quantity=[quantity stringByReplacingOccurrencesOfString:[a objectAtIndex:0 ] withString:[a objectAtIndex:1]];
queryString = [NSString stringWithFormat:@"INSERT INTO SHOPINGLIST (QUANTITY) VALUES (\"%@\")",quantity];
它给出错误: - 接近“diax1”:查询INSERT INTO SHOPINGLIST中的语法错误 原始数量= 1片,中等(4-1 / 2“diax1 / 8”厚)
答案 0 :(得分:2)
要在iOS中的SQLite中插入特殊字符,请使用占位符(也请检查Sqlite中允许使用哪些特殊字符):
queryString = @"INSERT INTO SHOPINGLIST (QUANTITY) VALUES (?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, queryString, -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_text(compiledStatement, 1, [quantity UTF8String], -1, SQLITE_TRANSIENT);
// Use sqlite3_bind_text for string values. For other type of values, check sqlite documentation.
// .... And So on.
}
答案 1 :(得分:1)
表示双倍值,请使用: -
sqlite3_bind_double(compiledStatement, 1, [quantity UTF8String], -1, SQLITE_TRANSIENT);