0
在SQLite數據庫行
我打算從一個自定義對象在我的SQLite數據庫中插入一個方法:不插入iOS中
- (void)insertCustomEntity:(CustomEntity *)customEntity
{
NSString *filePath = [FileMngr copyDatabaseToDocuments];
sqlite3 *database;
if (sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "INSERT OR REPLACE INTO Entities (id, type, timestamp, result) VALUES (?, ?, ?, ?)";
sqlite3_stmt *compiledStatement;
NSLog(@"Could not prepare statement: %s\n", sqlite3_errmsg(database));
if (sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
sqlite3_bind_int(compiledStatement, 1, customEntity.id);
sqlite3_bind_int(compiledStatement, 2, customEntity.type);
sqlite3_bind_int64(compiledStatement, 3, customEntity.timestamp);
sqlite3_bind_int(compiledStatement, 4, customEntity.result);
}
if(sqlite3_step(compiledStatement) == SQLITE_DONE) {
}
else {
NSLog(@"Step: %d\n", sqlite3_step(compiledStatement));
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
我已經做了一段時間,數據測試中被插入,但突然停止了,我現在正在第二個NSLog
獲得5步代碼。爲什麼會發生這種情況,如果它以前工作?我嘗試了幾個選項,例如在sqlite3_prepare_v2
中放置sqlite3_step(compiledStatement)
,但我一直無法插入。我做錯了什麼?
在此先感謝
是U投入的NSLog(@ 「%S」,sqlite3_errmsg(數據庫))後,歌廳任何類型的錯誤消息;並在其他部分放入相同的語句並檢查錯誤消息 –