0
我的功能不會將任何條目添加到現有的SQL數據庫。任何想法?sql不會添加新條目。 :(
sqlite3 *database;
sqlite3_stmt *compiledStatement;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSString *tmpSQLStatement = [NSString stringWithFormat:@"INSERT INTO data (test) VALUES ('teststring');"];
const char *sql = [tmpSQLStatement UTF8String];
if(sqlite3_prepare_v2(database, sql, -1, &compiledStatement, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
}
沒有ERRORMESSAGE被調用。但不幸的是不添加任何。
你也不想爲每個查詢打開SQLite數據庫打開一次,然後關閉時,你是完全與數據庫進行。對於你準備好的聖在關閉數據庫之前,您需要sqlite3_finalize該語句以避免錯誤。 – 2009-11-21 15:35:51