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.
Related
I'm new with dealing with the .sqlite3 in iphone, I created a sqlite3 file in
/Users/myLab/Library/Application Support/iPhone Simulator/5.1/Applications/308C4355-D8EE-4524-A7F9-638DEB68B298/Documents/file.sqlite3
and I inserted the tables into it using Terminal.app and everything works ok with my app.
but when I moved this application to another device, opened by xcode and trying to run it, I discovered that my tables are not found in this .sqlite3 file in another device.
how can I save my tables in .sqlite3 file??
Whereas this much info is adiquate to answer you question though i am providing some checkmarks to check for:
Do you have file.sqlite3 in your app resource folder?
Do you have that given table in that resource file.sqlite3 file?
Have you made any changes to the file.sqlite3 placed in the resource folder while app is running? if yes then try deleting that file.sqlite3 from the resource and add again to the resources.
All these checkpoints may make your app work well.
BestLuck..
I've tried using sqlite3_open statement, but the database is created at root level of my hard disk.
I can actually try to copy it to the bundle document folder. But,
Where will the database created if I execute it during the iPhone runtime? (Since I use iOS Simulator, it is created on root level).
How to create the database at the documents folder level immediately?
I'm sorry if I can't make myself clear enough, I'm really new working with database and stuffs.
Thank you for your attention.
You can not write to the main bundle, because it is signed with SSL certificate. But you can write to the document directory. Have a look at this link of how to create database at runtime in documents directory - create sqlite db programmatically in iphone sdk
You should create database file template with no content, but with structure, that you plan to use in your app. Add this template to your project Resources folder. Then, when app started, copy that file to Documents folder and use it.
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'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.
I want to know when we install an application where does the database of the application resides. Like Does it resides in the application bundle or sandbox.
Also when we upgrade it why does not it affects the existing database. For example, if I make some changes to database table and reinstall it, it still uses the previous table. So how does it actually works at the background.
You choose the location by providing a path to a db file when you call sqlite3_open. The path should almost certainly be to a file in your Documents directory, since any place else either won't be backed up (tmp) or won't be accessible (the app bundle, or paths outside your sandbox).
Since you manage the file, you could also create a .db file on your computer with the default database contents, put that in your app bundle, and then copy it over to Documents the first time your app comes up and finds no file in the expected location.