i have a database file "myDB.db" (it have only one Table), and i put that file to assets folder, my app copy the data from it, i can read data there is no problem, but when i try to add a new ROW in my Table the new row only existing in data folder that mean if i clear data or reinstall my app i lose my new ROW. how to add that ROW to my file in assets folder "myDB.db"? or how to replace the new database from my data/data folder to my old file "myDB.db" in assets folder?
i use this code
sorry for my bad ENGLISH.
You cannot do that in the app. Assets are read-only.
You can modify the database on your computer and replace the source version of the asset that gets bundled in the APK.
For versioning preinstalled databases and without the problems with the code you're using, consider sqlite-asset-helper.
Related
I have created a database android app for my college that stores students records and all the record are store in sqlitedatabse and the file name is STUDENT.sqlite.But that file is hidden and can be seen only if phone is rooted.so i need a solution so that the aap gets install it should show separate folder for it and the sqlite file mustbe there in it.so that when i put all records in that and save i can give that file so another person and he can view the same record.no need of entering all records again he can just change the sqlite file.
Maybe you can copy all records from your database into a public or shared directory on sd-card?
Rename the database file to yourdatabase.db and put it in your projects assets folder and on first run of application just copy that database to data directory of android system.
Im trying to use ionic with the SQLite plugin (https://github.com/brodysoft/Cordova-SQLitePlugin) and I was able to create and use a database, but in my app i need a prepopulated database.
I see methods of achieving this by placing the database in the platforms/android/assets folder in the ionic project, and then copying it, on the first android run, to the "correct location".
My question is, why is it needed to copy it to another location? why cant I just access it from the assets folder which the application creates? If it was an image, i wouldnt need to change its place either, i would use it from the assets, so why not the db too?
Your database file in the assets folder is stored in an exported file format (minimum storage space required, but not for interactive use). The Android SQLite Database needs to import this file. This means reading and storing it in a new format for better searching/reading and writing.
So it is not a simple copying process it's an interaction and after the import your database does not read from your assets folder any longer. So replacing your database in your assets folder does not update your imported database.
You can use this project to import your database in android: https://github.com/jgilfelt/android-sqlite-asset-helper
I have an sqlite database I want to distribute with my application. It's about 3mb. If I understand correctly, I can't directly open it if it resides in my app's /raw or /assets folder, right? We need to first copy it out of that directly as in:
Get the SQLite path within the Assets Folder
So my app will consume twice the disk space as it normally would? I don't understand why it's necessary to have the database file be in a particular folder?
Thanks
So my app will consume twice the disk space as it normally would?
Yes. Technically, probably more, as your database is compressed inside the APK file.
I don't understand why it's necessary to have the database file be in a particular folder?
It is not necessary for the database file to be in a particular folder. However, assets/ is a folder on your development machine; it is a part of the APK file on the device. Same goes for everything in res/raw/.
BTW, I recommend SQLiteAssetHelper for copying the database out of assets/.
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.
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.
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.
Im doing an app which uses sqlite db file in assets folder, There is a screen in my app having a button 'check for update'.
Client has given me an URL link to update db file(which gives a sqlite file).
When user clicks on the button i need to upgrade the old db file with new db file from URL.
Please suggest me how i can do this, or give me a reference to follow
Thank you
The assets folder is read-only, so you won't be able to change or replace that copy.
Basically, you need to copy your DB file out of the assets folder into a writable application directory (probably from getFilesDir() or getExternalFilesDir()). You'll open this copy when you are actually operating, and you'll replace it with the new DB from the web when your user hits the UPDATE button. Because a SQLite database is just a file, there's no problem with deleting the old one and replacing it with a new one. (Close the old one before deleting, of course, for cleanliness.)