开发者

FMDB open database

I'm trying to open a database that I have in my project inside Resources.

The problem is that it seems that its impossible to find the database file! I tried with the complete path, and it works, but this is not a good solution.

I would like to now how to open it!

I'm using this code: db = [FMDatabase databaseWithPath:@"bbdd.sql"];

I don't know how to find the other part of the "actual" path.

Do you have a solution for me?

开发者_运维问答

Thanks!!!!


You need to find the full path of the database in the your resource bundle, something like this :

NSString *databasePath = [[NSBundle mainBundle] pathForResource:@"mySQLiteDatabaseFile" ofType:@"sqlite3"];

There's a complete example in this thread Copying data to the Application Data folder on the iPhone


Get Document directory:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *dbPath = [documentDirectory stringByAppendingPathComponent:@"Test.db"];

Next

DB = [FMDatabase databaseWithPath:dbPath];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜