I am using a local开发者_JS百科 sqlite3 database and I need to find out the path to it so I can open a connection. Are the paths for device/simulator different? How can I find them?
It depends on where you create your Database in your iphone application. The way I have created is under Documents folder of the sandbox and the path are always same for both of them.
NSString *databaseName = @"mainDB.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
So the path of the database is /Library/Application Support/iPhone Simulator/4.2/Applications//Documents/mainDB.sqlite
To open a database that is in your bundle, you can do:
sqlite3 *_database;
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"yourDbName.extension"];
sqlite3_open_v2([path UTF8String], &_database, SQLITE_OPEN_READONLY, NULL);
精彩评论