我在 iPad 开发项目中写入 SQLite 数据库时遇到问题。这是我使用插入语句写入数据库的代码。当我执行语句时,Sqlite 没有发回错误,但数据仍然没有保存在数据库中。
我的插入语句的简化版本:
//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);
}