English 中文(简体)
FMDB open database
原标题:
  • 时间:2010-10-07 10:59:37
  •  标签:
  • fmdb

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];




相关问题
deleting row in SQLite 3

In UITableView, I want to delete a row and remove that row on database, but my query of sqlite don t works. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)...

FMDB query is not taking any effect on the DB

I am using FMDB in my app to do some updates in my DB. Problem is when I update my table with executeUpdate function, it update my table BUT if I copy the same .sqlite file from project to at another ...

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 ...

FMDB SQLite question: row count of a query?

does anyone know how to return the count of a query when using FMDB? If I executeQuery @"select count(*) from sometable were..." I get an empty FMResultSet back. How can I get the row count of the ...

Writing to sqlite db using fmdb?

Ok so I understand that fmdb is totally outdated, and core data is where it s at, but for now, I just need to tweak an app I m working on that uses fmdb to read from a sqlite db in the resources ...

How do I import a class into an iPhone project?

I m sure this is very easy but I m trying to get the fmdb sqlite wrapper to work in an iPhone project. I ve grabbed the files via SVN, and there are h and m files inside an src folder. I d ...

热门标签