Reputation: 811
I have created the application which is based on Sqlite database.
So in my app, initially i have created the Sqlite db with one data and i have added that db into my "Resource" folder in my project.
While app running at first time, checking db in Documents folder(Sandbox) if no file means, copy the db from Resource to Document folder.
After that every insert and delete operations performing on Db in Document folder only. not on db in Resource folder.
So, i have inserted 50 items in db and then i have deleted the app from Simulator(or) device.
When deleting app, db also deleted with that.
My question is ==> How to overwrite the Sqlite db(in Resource folder) with db(in Documents folder) when every updation in app(insert, delete)?
because db file in Documment folder getting update while inserting items into that.
I am using XCode 4.2 with iOS 5 sdk.
Upvotes: 2
Views: 1999
Reputation: 9866
You cannot change the Resource bundle once you created (i.e app file). You cannot overwrite the SQLite db into resource folder of your bundle.
If you still want to keep previous db then just copy it from simulator path and replace whenever you clean and build the app.
EDIT:
You can go to /Users//Library/Application Support/iPhone Simulator/"Simulator version you use"/Application/"check all folder to find your app inside this folder"/ "YOUR APP.app"
Then Right Click APP file and Click Show Package Content. Now you will be able to see the resources you used in App file. You can search your DB and BACKUP/REPLACE it.
Upvotes: 3
Reputation: 11
Its true that there is no way to copy that document folder data again to resource bundle, so i will suggest u to take a backup of that db before deleting the application from simulator or from the device.
Upvotes: 0
Reputation: 10251
You have to do this by opening another handle for the database in your resource folder and perform the operation for that too. I assume you need it only when you run it in simulator for convenience.
You cannot do this when you run in device.
Upvotes: 0
Reputation: 1445
There is no way you can modify any resource present inside the application bundle.
That's why we copy the database file to the documents directory of the application, so we can modify the file.
If you want to preserve data, you backup the data using the iCloud service.
Upvotes: 1
Reputation: 69469
First off the database file in the app bundle (resource folder) is read only and can't be changed by the app.
Second when an update is installed, all the files in the app bundle get replaced by the files in the update. The files in the document directory aren't touched.
if you need to update the database file in the document directory you will need to implement an update method some where and keep track of the versie of the database used.
Upvotes: 1