0

I need to deal with sqlite db placed in asset folder in Android project. The issue is that usually we create a copy of asset db at runtime and all the queries are done on this copy, but the problem is that when I clear the cache it will remove all updates; so I need to update the asset file not the copy that has been created on runtime.

Can I insert update delete the asset sqlite file?

Actually I want to preserve modifications on DB, and I don't want to loose these changes when clearing application data from settings.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Amt87
  • 5,493
  • 4
  • 32
  • 52
  • 3
    possible duplicate of [How to insert data into the database file which is in the assets folder](http://stackoverflow.com/questions/8700262/how-to-insert-data-into-the-database-file-which-is-in-the-assets-folder) – Joachim Isaksson May 10 '12 at 06:45
  • Thank you it make better understanding; but I need to know if this copy of DB will be deleted when clearing data in application settings?? I want to preserve the modification such insert, update, delete – Amt87 May 10 '12 at 06:59
  • http://stackoverflow.com/questions/9109438/using-already-created-database-with-android/9109728#9109728 – Yaqub Ahmad May 10 '12 at 09:08

2 Answers2

2

You CANNOT modify resources (assets, raw, drawable, etc.) of an .apk once its built. They are read-only, so what ever goes-in will always remain as it is - until you update the .apk with the newer stuff.

waqaslam
  • 67,549
  • 16
  • 165
  • 178
1

You can not get the old record once you cleared the cache, and cant even update the asset file, once the apk file is generated as it is READ-ONLY. Yeah if you want assistance on how to use already ready database then this link will help you for sure.

Using your own SQlite Database in android applications

And i think if you can copy database from assets folder, then, you can get it from sdcard too. dont know much about it.

mayank_droid
  • 1,015
  • 10
  • 19
  • Thank, yes you are right; and about creating db on sdcard is shown link above by Joachim Isaksson... Actually the major issue is preserving changes even after clearing cache; something like COMMIT – Amt87 May 10 '12 at 07:17
  • 1
    look the part you saying commit, same as clearing the cache data, once you clear it you can not save it, but better you manage it from txt file, such as user credentials. And a person who will clear the cache, definatley, need to format all the data of the application as something goes wrong by him. So better dont modify the android application's nature. Rather than that you can ask user to take a backup of its setting or whatever it is. and if user wants to clear it then let him do. – mayank_droid May 10 '12 at 07:26