1
我想使用SQLite的框架來創建一個數據庫 - 我已經建立了幾個方法來獲取文件路徑,並再打開數據庫,但我得到一個「無法打開數據庫」的錯誤(因爲你可以看到我已經註銷sqlite3_open的結果)IOS - SQLite數據庫不開放
這是我的頭文件:
#import "sqlite3.h"
@interface ProgListViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate, UIAlertViewDelegate>
{
sqlite3 *db;
}
-(NSString *) filePath;
-(void)openDB;
這是我實現文件:
//file path to db
-(NSString *) filePath {
NSLog(@"pathtest");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"];
}
//open the db
-(void)openDB {
NSLog(@"opentest");
if (sqlite3_open([[self filePath] UTF8String], &db) !=SQLITE_OK) {
NSLog(@"%d", sqlite3_open([[self filePath] UTF8String], &db));
sqlite3_close(db);
NSLog(@"Database failed to open");
} else {
NSLog(@"database opened");
}
}
有任何想法嗎?
我確實,謝謝! –