1
我正在iOS上執行一個按鈕來更新SQlite數據。我可以使用Firefox SQLite Manager更新這個值,但是使用下面的代碼會出現「無法提交,沒有事務處於活動狀態」的問題。請說明一下。謝謝。iOS sqlite無法提交,沒有事務處於活動狀態
= - (ID *)updateBanks {
sqlite3_stmt *statement = NULL;
const char *branch_no = "MAYBANK1";
const char *address = "KLCC";
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"banks.sqlite"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured.");
}
if(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK)
{
const char *sql = "Update Maybank Set address = ? Where branch_no = ?";
if(sqlite3_prepare_v2(db, sql, -1, &statement, NULL)==SQLITE_OK){
sqlite3_bind_text(statement, 1, address, -1, SQLITE_TRANSIENT);
//sqlite3_bind_text(updateStmt, 1, [address.text UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 2, branch_no, -1, SQLITE_TRANSIENT);
}
}
char* errmsg;
sqlite3_exec(db, "COMMIT", NULL, NULL, &errmsg);
if(SQLITE_DONE != sqlite3_step(statement)){
NSLog(@"Error while updating. %s", sqlite3_errmsg(db));
}
else{
}
sqlite3_finalize(statement);
sqlite3_close(db);
return 0;
}
此外,主包中的SQLite文件是隻讀的,所以任何UPDATE,INSERT和DELETE都會失敗。 – rckoenes
@rckoenes謝謝! –