Can't refresh iphone sqlite3 database

天大地大妈咪最大 提交于 2019-12-24 08:55:01

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1314940/cant-refresh-iphone-sqlite3-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!