Making a sqlite file stay existent between runs of the program

Posted by Cocorico on Stack Overflow See other posts from Stack Overflow or by Cocorico
Published on 2010-04-24T02:31:40Z Indexed on 2010/04/24 2:33 UTC
Read the original article Hit count: 303

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about sqlite

Related posts about xcode