Making a sqlite file stay existent between runs of the program
- by Cocorico
Hi! I'm having a problem with some sqlite code for an iPhone program in Xcode. I was opening my database like this:
int result = sqlite3_open("stealtown.db", &database);
Which is how they had it in a book I was looking at while I type the program. But then, that way of opening a database it only works when you run in simulator, not on device. So I finally figure out I need to do this:
NSString *file = [[NSBundle mainBundle] pathForResource:@"stealtown" ofType:@"db"];
int result = sqlite3_open([file UTF8String], &database);
And that works on device, EXCEPT one thing: Each time you launch the program, it starts as if you had never created the database, and when you stick an entry in the table, it's the ONLY entry in that table.
When I used the first code on the simulator, I could open my program 6 times, each time adding 1 entry to a table, and at the end, I had 6 entries in that table. With the second code, I do exact same thing but each time there is only 1 entry in that table. Am I explaining this okay, I hope so, it's hard sometimes for me.
Anyone maybe know why this would be?