我正在使用下面的代码,但是 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.
}
关于ios - 如何在sqlite ios中插入包含“字符的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23267347/