我在更新我的 sqlite 数据库时遇到问题,所以如果有人能帮助我,我将非常感激。我尝试了所有可能的示例和教程,但没有。在我的 sqlite 表中,我有 9 个属性,但我只需要更新三个。
const char *sql = "UPDATE studentNotes SET title = ? , note = ? , existingAudioNote = ? , audioNoteName = ? , audioNoteDuration = ? , existingPdf = ? , pdfFileName = ? WHERE id = ?";
if(sqlite3_open([[AppDelegate getDatabasePath]UTF8String], &database) == SQLITE_OK){
if (sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK){
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
else {
sqlite3_bind_text(updateStmt, 1, [noteTitle UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 2, [noteText UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 3, [noteExistingAudioNote UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 4, [noteAudioName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 5, [audioNoteDuration UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 6, [existingPdf UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStmt, 7, [pdfFileName UTF8String], -1, SQLITE_TRANSIENT);
if (SQLITE_DONE != sqlite3_step(updateStmt)){
NSAssert1(0, @"Error while updating data. '%s'", sqlite3_errmsg(database));
}
sqlite3_reset(updateStmt);
}
}
sqlite3_close(database);
我尝试使用此代码,但是当我从我的类调用此方法到视图时,它不起作用。有任何想法吗 ?