Ios SQL语句被拒绝
我试图通过此方法将用户注释插入sqliteDB,但由于某些原因,它不会传递此Ios SQL语句被拒绝,ios,sqlite,Ios,Sqlite,我试图通过此方法将用户注释插入sqliteDB,但由于某些原因,它不会传递此if语句 if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK){} 我不确定,但我认为我的SQLStatement被拒绝了,或者是出于某种原因 (void) insertQuickNoteInDataBase:(NSString *)name :(NSString *)note{ sql
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\u errmsg
记录错误。但问题很可能是查询中的逗号以及where
子句。Insert语句不应包含where
子句。也许您的意思是使用更新:
"UPDATE detail SET QuickNote = ? WHERE name = ?"
此外,对
sqlite3\u bind\u xxx
的调用需要有适当的索引。绑定索引从1开始并向上。你用的是8,然后是2。你想要1,然后是2。你说对了,我本来想在语句中使用“更新”而不是“插入”,我只是再试了一次,效果很好!感谢RMADDYRMADY-从DB“select(QuickNote)from detail where name=?”返回值是否正确??