我正在尝试通过此方法将用户注释插入到 sqliteDB 中,但出于某种原因,它没有传递此 if
语句...
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK){}
我不确定,但我认为我的 SQLStatement 被拒绝或出于某种原因。
(void) insertQuickNoteInDataBase:(NSString *)name :(NSString *)note{
sqlite3 * database;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "insert into detail(QuickNote) values (?), where name = ?";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_text(compiledStatement, 8, [note UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 2, [name UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(compiledStatement))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
最佳答案
您需要使用 sqlite3_errmsg
记录错误。但问题很可能是查询中的逗号以及 where
子句。插入语句不应包含 where
子句。也许你的意思是使用更新:
"UPDATE detail SET QuickNote = ? WHERE name = ?"
此外,您对 sqlite3_bind_xxx
的调用需要有正确的索引。绑定(bind)索引从 1 开始并上升。您正在使用 8 然后 2。您想要 1 然后 2。
关于ios - SQLStatement 被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16350686/