How can I flush my sqlite database in my application when I click on a button?
I already have a database inside my app, when I click on a button it add some data into it.
I wanna know how to fluch the database after I click the button or maybe restart the application automatically.
Thanks,
Ok I find what I was looking for.
Don't really need to flush the database, the only things I had to do is to copy my database from the bundle to the document directory, because the database in the bundle is Read only.
Make a Copy of it allow to Write/Read access.
Add/Delete/Update data can be executed without problem after that.
Related
Unlike most sqlite apps where developers don't want to overwrite data in a sqlite database, I'm trying to enable an app to overwrite all data with future updates. The sqlite database will have the exact same name and have the same tables, I just want to be able to update the data contained in the database without making users delete the app and reinstall it. Is there an easy method to do this?
Thanks in advance!
A SQLite database file is just a normal file, so no special steps are needed. Get the path or URL to the file, and use NSFileManager's -removeItemAtPath:error: or -removeItemAtURL:error:. Then create the new database the same way you created the old one.
i need to place a backup database in my iphone. so i want any place outside my app folder where i can place the backup database so that if due to any problem my app crashes the user has a copy of his data.
any other idea except of placing data on a remote server is acceptable.
Why does it need to be outside your app folder, you could just copy and rename your database file and keep it in your app folder. I'm not sure it's possible to write outside your app folder.
My iPhone app uses a small database to store its settings and saved files. How can I ensure that the default database, with its default settings, gets distributed to anyone who downloads it along with the application files?
EDIT Sorry, I was in a rush when I posted this. I forgot to mention that the database needs to end up in the 'Documents' folder of the application so that it can be backed up at a later date by the user.
-Ash
Put it in "Resources". Then on your first launch, you'll need to load that file out of your mainBundle and save it to the Documents directory. The file will "come with" the app, but it won't live in the right place to get caught by backup.
A side-effect is that restoring the app to factory settings is as easy as deleting that file. Next launch, you can see you don't have your file, and copy a fresh one out of your bundle.
You include it as a file in the Resources folder of your application.
I want to save some images from my server to the iPhone app temporarily.
It is one of my application's purposes to, when the user closes the app, delete the saved images.
Again, when the user starts my application and taps on the corresponding button again, I need to save the data. I don't know how to start it, I know only we can do this with the help of NSFileManager.
Please can anyone guide me on how to start or write the code.. Thanks in Advance :)
Store the files in either the tmp or Library/Caches folder. In neither case will the files be automatically deleted, but they won't be backed up and so don't contribute permanently to the app's storage requirements. If you also want to delete the files on close, do it in -applicationWillTerminate.
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
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.
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.