How to protect sqflite database when updating flutter app - android

I use an sqflite database in my app. The database is filled with entries by the users. It is essential that the database is unchanged when I deliver a new app version.
When I deploy a new version of the app as apk to my real phone the database is deleted. Is there a way to protect the database during update?
I wonder if it is the method how I deploy the new app version? I use "flutter install". Maybe the uninstall method removes everything from the app including the database and creates a fresh app directory!?

flutter install deletes app and database. The solution is to use streamed install. Instead of flutter install, run this: adb install build/app/outputs/flutter-apk/app.apk. This will update the app and leave the database intact.
You must have sdk platform-tools installed and an environment variable pointing to the platform-tools.

You can get the contents of old database and store it in temporary database and save all the old content in new database and after successful insert delete temporary database.
In short following pseudo code may help:
tempdb.data = getOldDatabaseContent
newDatabase.data = tempdb.data
delete(tempdb)

Related

Android ROOM database testing uninstall within Androiid Studio - how to survive reinstall of app

I am developing an app that uses the ROOM database implemetation. The database is simple with only 2 tables.
I am trying to simulate what will happen with the persisted data when the app is uninstalled and reinstalled, hoping that it will be included in the default google app backup.
This is where I am confused - Within Android Studio I start a debugging session that re installs the App after Uninstall - I can add data to database running the app in a debug session or normally from the device. The database survives a restart etc of the phone and updated data remains.
BUT when I uninstall and reinstall using a debugging session I have a version of the database come across somehow from android studio - one from earlier debugging - All of the changes since last reinstall are lost.
Where is this database copy coming from and more importantly how can I make sure that my db changes survive an app uninstall and reinstall.
I am using the path returned by getdatabasepath()
Any help or pointers appreciated on approaches to ensure this dataset survives app reinstall.
I am building the DB as follows
return Room.databaseBuilder(context,
MyDb.class,
Constants.DB_NAME).allowMainThreadQueries().build();
And getting an instance of the DB like so
MyDB = DigiDocketDB.getInstance(MainActivity.this);
Cheers,
Courtney.

Android-app: Old database still exists after switching to room database

After switching to a room database I deleted the SQLite-Helper Class. But if I install my app the old database is still created on my smartphone.
I opened the the device file explorer and found under my project-folder
/databases with the following databases
local.db which is my old database with date of 1970-01-19 and 2.5 MBytes
local_db which is the new room database
local_db-shm and local_db-wal whhich seem to be some room data
Even if I uninstall the app and reinstall it the local.db appears again. Deleting it does not help too.
But I think that I have deleted all the old SQLiteHelper Code. So does anyone know, where I might find the key to getting rid of the old database?
If the manifest (AndroidMainfest.xml) has android:allowBackup="true", this could result in the data being restored automatically by the backup manager. From your description of the issue this could well be the cause.
Try changing to use android:allowBackup="false", uninstalling the App and then re-installing.

How can i update sqllite dynamically?

I have set app my sql lite database for my app. Is there any way to update the database without republishing the app? For example i want to add a new user in the sqlite database. Do i have to upgrade the database version on my app and publish it again? Is the remote database the only solution for dynamic android database?
If i've understood, you want "deploy" a new db for your app. You can do that but you need root access because in other case you don't have permission. Something like:
adb push yourNewDB data/data/this.is.your.package/databases
Then enter in shell:
adb shell
Then kill the process for your App:
ps
kill pid
There's no simple way to upgrade your app without republishing it unless you have an update system integrated on your app.
The simplest (and standard) solution is to republish and upgrade your DB version number, then the onUpgrade() callback will get called. There you should check the current DB and upgrade as required. Following your example, you just have to check if that user exists and if not create it.
You can remotely provide updates to your DB via an online service. This could provide whole new DB file for file replace or alternatively provide delta CRUD updates via xml or json. But you will need to code your update method into the app before publishing.

Delete old database and copy new database on application update

My requirement is quite different than the normal scenario. I want to delete old database and copy new database on application update. I search the same on different forums and everyone saying that to run update scripts for that. But It's not fit with my requirements. My client want to delete the old and copy the new database for each release. Because our client can update any application version at a time.
It would be great if there is an alternative to do this on application update.
Note: Our application is not available on Google play store so We are updating application programmatically. If any new version available for user than we are prompting them with new version available. And in background we are downloading new apk file and re-direct user to INSTALL intent once download will complete.
Why don't you run a SELECT statement of all your tables put them in a public shared txt file and then when new version installed read the file and run an insert script
EDIT
delete your db with the above instruction
context.deleteDatabase(DATABASE_NAME);
Why don't you use the number version of your database ?
My client want to delete the old and copy the new database for each
release. Because our client can update any application version at a
time.
=> it will exactly do what you need (or I don't exactly understand >_<)
You increment it in your new released version of application then the SQLOpenHelper will run the onUpgrade method. You just have to write your upgrade script to be executed.
You can read this answer for more details

Delate database while reinstallation android

Hello
In my android application when the user reinstall the app again i would like to delete the existing database and create a fresh new one.
How could i know that the user is reinstalling the app or is quering for the updates request.
How could i delete a file in raw folder?
Please share your valuable suggestions.
Thanks in advance:)
Hello In my android application when the user reinstall the app again i would like to delete the existing database and create a fresh new one.
If by "reinstall", you mean "uninstall and reinstall", your existing database will be deleted during the uninstall process, assuming it resides in the normal database location (i.e., not on external storage).
How could i know that the user is reinstalling the app
You don't.
How could i delete a file in raw folder?
In Android? You don't. Resources cannot be modified or removed at runtime.
Reinstalling application deletes all data for the application. If you mean reinstalling is upgrading then you can observe the new version number in the SQLiteOpenHelper.onUpgrade() method.
To delete the database file, it is explained here (Database Delete Android).

Categories

Resources