我在iPad開發項目中寫入SQLite數據庫時遇到問題。這裏是我的代碼,用insert語句寫入數據庫。當我執行語句時,Sqlite不會發回錯誤,但數據仍未保存在數據庫中。在iOS/iPad開發中寫入SQLite
我的INSERT語句的簡化版本:
//Insert Into POHeader(CustID, CatalogName) Values('0', 'webdemo')
@try {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"Orders.db"];
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: %@", sqlite3_errmsg(db));
}
sql = [self prepareSqlForPOHeader];
sqlite3_stmt *sqlStatement;
int sqlResult = (sqlite3_prepare_v2(db, sql, -1, &sqlStatement, NULL));
if (sqlResult != SQLITE_OK)// (sqlite3_prepare_v2(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
{
NSLog(@"Problem with prepare statement: %@", sqlite3_errmsg(db));
}else{
//success
}
sqlite3_finalize(sqlStatement);
}
@catch (NSException *exception) {
NSLog(@"Problem with prepare statement: %@", sqlite3_errmsg(db));
}
@finally {
sqlite3_close(db);
}
不完全是我的區域,但不應該有實際執行準備好的語句的東西嗎? (sqlite3_step?) – 2012-08-10 15:49:32
只是一個雖然我研究這更多。應用程序中的數據庫通過刪除資源文件夾中的現有SQLite數據庫來創建。這是否會使其成爲只讀,SQLite不會因某種原因返回此錯誤? – Mike 2012-08-10 15:50:53