« A Preview of iPhone OS 3.0 | Main | Create Delegate Protocols for the iPhone »

April 03, 2009

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a010535e1becf970c01156eda4420970c

Listed below are links to weblogs that reference Errors: SQLite3 Database Doesn't Remain Updated:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Dustin Swede

Thank you, Thank you, Thank you, Thank you

I've been struggling over this for the last day because my database was working when I initialize it but after that is didn't save anything. It was all because I was returning in the middle of looping through the columns without finalizing first. Thank you so much for pointing this out!

Michael

I had been struggling with the same problem, and was so happy to read this article as I had the same symptoms! However, when I added the sqlite3_finalize functions that I had missed out, it still didn't work. I noticed that the sqlite3_finalize function for one of my update queries returned an error code of 3, meaning "Access permission denied". What could be the cause of this? Thanks for the article though, I'm glad I've found out why my changes were not persisting!

Michael

Actually, scratch that, it appears that the sqlite3_finalize function is returning SQLITE_OKAY. However I still get the -journal database file after I quit the app. I have finalized all my statements and I am closing the database.

Michael

Ahh I figured it out! One of my obscure finalize statements never actually got reached for one of my prepared statements! As it was only a SELECT statement I didn't check it over because it has nothing to do with any data manipulation or transactions! That's a day's worth of development out of the window! But I won't make that mistake again!

Shannon Appelcline

I think my error was in a SELECT too. I'd update the article to note that, but it's probably sufficiently recorded by these comments.

Glad you got the problem fixed!

Eamon

Every poster on this sits is heading in the wrong direction !

Any sqlite3 database is installed with an app in the app bundle - which is not a writable folder on any iPhone OS.

You have to copy it over to the writable Documents folder with a function call (and make sure not to overwrite it again by get/set a NSUserDefaults user setting variable that you must permanently store on the phone). Also, you can't rewrite the Documents version back to the app bundle (of course !). Here's a code extract from how we do it ... originality is a delegate property that stores the state of the database (0 is original so copy from app bundle, 1 implies only use the writableDBPath i.e. the Documents version). Then rewrite the incremented originality after a 1st-time use to ensure the copy doesn't recur.


if (originality == 0) {
copied = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
originality++;
[self setUserDefaults];
}

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment