如何在sqlite ios中插入包含“character”的string

我使用下面的代码,但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”厚)

要在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. } 

对于double值,使用这个: –

 sqlite3_bind_double(compiledStatement, 1, [quantity UTF8String], -1, SQLITE_TRANSIENT);