views:

557

answers:

2

I've created an sqlite3 database from the command line and inserted several records. My app retrieves all of them and shows them just fine. I then go back and insert a few more records via the sqlite3 cli, erase the db file out of the simulator's documents directory so that it will be recopied from the main bundle, and the run the app again only to find that it only displays the original records I inserted. The new records do not show. I verified that the new db file was copied to the simulators documents directory, and when I point the sqlite3 cli at it, I can do a select * and see all the records.

What could be going on here? It almost seems as if the previous version of the db file is being cached somewhere and used instead of my updated version.

//Scott

A: 

I haven't verified his answer, but Stephan Burlot said:

Sqlite uses a cache for requests. Close & reopen the database from time to release cache memory.

(I don't think it's true that every SQLite instance caches requests, but that might be the case on the iPhone.)

Obviously you aren't concerned with memory, but if it is caching requests, maybe just a close and reopen is all you need.

If that isn't the case, my next guess would be that your app is not pointing to the file you think it is pointing to -- did you have it pointing to a database with a different name at one point and forget to update the app? You could verify this by updating the db from within your app, then checking for those updates with the CLI. You might just find that they are not looking at the same db.

Mark Rushakoff
+1  A: 

every time you rebuild and run an app in xcode, it creates a new folder under the iphone simulator's applications folder. If your sqlite db is being included from xcode the old db could be put in the new folder while the one your editing is in the old and now unused folder.

Kevlar
Where is xcode putting these new folders? I am only aware of projectname/build/Debug-iphonesimulator/projectname.app
skantner
I found it: /Users/username/Library/Application Support/iPhone Simulator/User/Applications/
skantner