Reputation: 1435
In my application i m using sqlite database.when i run it in iphone simulater it works fine.but it cant connect database with device.the path for that database is:
/Users/taxsmart7/Library/Application Support/iPhone Simulator/4.3/Applications/A644750D- 5175-4FF1-BDA7-6EDF65895180/Documents/BillSplitter.sqlite
when i connect with my device the database display blank.
Upvotes: 1
Views: 824
Reputation: 1865
If you need only read sqlite3 database it makes sense to work with database in app bundle.
You open database as in example:
NSString *pathname = [[NSBundle mainBundle] pathForResource:@"nameOfYourDatabase" ofType:@"sqlite3"]; // extension could not be .sqlite3!!! Have a look on your db file.
sqlite3 *database;
int res = sqlite3_open_v2([pathname UTF8String], &database, SQLITE_OPEN_READONLY, NULL);
if (res != SQLITE_OK) {
NSLog(@"Error opening database %@", pathname);
sqlite3_close(database);
}
If you need to write in database on first run of your app you need to copy database file from app bundle into app documents directory and then open database for read and write access.
Upvotes: 1
Reputation: 632
That's normal, this is the path of the database when running on simulator, saying differently : on your mac. The path to your application, and the whole "file system" hierarchy when running on device is totally different.
You shouldn't use any absolute path in your application, and work only from the application root folder, which is something like :
/private/var/mobile/Applications/A644750D-5175-4FF1-BDA7-6EDF65895180/
So if you wanna use a database in your application, you'll have to copy it in the bundle and find the right path to it, or to create one when excuting on device.
HTH
EDIT : the path scheme above may be wrong, I suspect it's just the path to the "Documents" folder reserved to the application. Anyway, my advice stays the same : use relative pathes.
Upvotes: 1