Reputation: 83
OK so at the initial loading of my app, I read from a sqlite database. I use this code to open it:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"golfScores.sqlite"];
if(sqlite3_open([path UTF8String], &database) == SQLITE_OK){
I've been lead to believe that this opens the database from the app directory, not the app bundle. Everything works fine within the app when adding, deleting, or updating records. I can close the app and reopen it and the data appears as it should. The problem is that if I go and look at the database with the Terminal, nothing has changed. It's completely different. So it must be using and saving to a database within the bundle, right? How can I get the app to update the database in the app directory?
Upvotes: 0
Views: 139
Reputation: 1913
Your code looks correct to me and it sounds as if it is working just fine! You are definitely not accessing your application bundle. Files in the bundle are not meant to be edited by your application because it breaks the code signing. They can be read, however, using the NSBundle class.
I would guess that whatever you're looking at with Terminal is not the same database file that your application is accessing.
Upvotes: 4