正在製作一個帶有嵌入式SQLite數據庫的iOS應用程序。所以我讓我的數據庫在一個SQLite管理員,並將其拖到我的Xcode項目,就像在教程中說的。 當我嘗試打開我的數據庫時,出現此錯誤:「內存不足」。不知道它是SQLite的錯誤還是什麼,但我的文件很小,以避免內存問題。嘗試在SQLite中打開數據庫的錯誤(iOS)
這是我的代碼初始化我的數據庫:
- (id)initWithPath:(NSString *)path {
if (self = [super init]) {
BOOL success;
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"SoundLib_DB.sqlite"];
if ([fileManager fileExistsAtPath:dbPath] == NO) {
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"SoundLib_DB" ofType:@"sqlite"];
[fileManager copyItemAtPath:resourcePath toPath:dbPath error:&error];
}
success = [fileManager fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
sqlite3 *dbConnection;
//Here is when I get the error, at trying to open the DB
if (sqlite3_open_v2("SoundLib", &dbConnection, SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK) {
NSLog(@"[SQLITE] Unable to open database!");
NSLog(@"%s Prepare failure '%s' (%1d)", __FUNCTION__, sqlite3_errmsg(database), sqlite3_errcode(database));
return nil;
}
database = dbConnection;
}
return self;
}
請輸入錯誤 –
您在'sqlite3_open_v2'調用中沒有使用數據庫的實際文件路徑。 – omz
是的,'sqlite3_open_v2(「SoundLib」,&dbConnection,...'不只是魚腥味,它是錯誤的 –