我正在尝试从本地数据库文件中读取数据。但是我收到以下错误...
无法打开数据库并显示消息“没有这样的表:recentViewd”。
sqlite3_stmt *statement = NULL;
sqlite3 *database;
NSString *sqLiteDb = [[NSBundle mainBundle] pathForResource:@"databaseFile"
ofType:@"db"];
NSLog(@"%s",[sqLiteDb UTF8String]);
if (sqlite3_open([sqLiteDb UTF8String], &database) != SQLITE_OK) {
NSLog(@"Failed to open database!");
}
//NSLog(@" %d, %d ",sqlite3_step(statement),SQLITE_ROW);
const char *sql = "SELECT ID FROM recentlyViewd";
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
int primaryKey = sqlite3_column_int(statement, 0);
NSLog(@"%d",primaryKey);
}
}
else {
NSLog(@"Failed to open database with message '%s'.", sqlite3_errmsg(database));
sqlite3_close(database);
}
if (statement) {
sqlite3_finalize(statement);
}
在这里,我只是想打开并读取数据库文件。