编辑:
忙碌是重新使用的结果
compiledStatement
不删除以前编译的语句。您需要使用Finalize和Close函数适当地释放资源。
请参阅此处的文档。
http://sqlite.org/c3ref/stmt.html
const char * select = "select * from favorite_shows WHERE (show_id = ?)";
const char * update = "update favorite_shows SET is_favorite = ? WHERE (ID = ?)";
sqlite3_stmt *selectStmt;
sqlite3_stmt *updateStmt;
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
if(sqlite3_prepare_v2(database, select, -1, &selectStmt, NULL) == SQLITE_OK) {
sqlite3_bind_int(selectStmt, 1, self.ID);
if(sqlite3_step(selectStmt) == SQLITE_ROW) {
favID = sqlite3_column_int(selectStmt, 0);
isFav = (sqlite3_column_int(selectStmt, 2) == 1) ? 0 : 1;
sqlite3_finalize(selectStmt);
if(sqlite3_prepare_v2(database, update, -1, &updateStmt, NULL) == SQLITE_OK) {
sqlite3_bind_int(updateStmt, 1, isFav );
sqlite3_bind_int(updateStmt, 2, favID);
int error = sqlite3_step(updateStmt);
if (SQLITE_DONE != error) {
NSLog(@"error while updating favorite status");
} else {
sqlite3_finalize(updateStmt);
}
}
}
}
sqlite3_close(database);
}