What happens after app upgrade, will it keep the database from previous version or flush out all data?
All application data (including stored files, SharedPreferences, and SQLite databases) is kept during updates.
Note that the SQLiteOpenHelper also provides an onUpgrade() method that you can use to upgrade the SQLite database when the database's schema changes. Do not confuse this with application upgrades though!
Related
I have a question related to database, i know this is not a right platform related to question but i know here i can find great developer.
My query is,
"I am going to develop an app which deal with SQLite
Database and a lots of data into the App and user saves a lot data.
so, what if i release new update to play store and user update the app;
will the user get all the data from the SQLite they saved in the previous version of app 'or' the user have to save info again into the database?"
No, it won't get deleted.
Database will get deleted if it meets following scenarios :
If developer programmatically tries to clean data of the app / User clears data of the app from App info page.
if Developer upgrades Database version after update (It'll call onUpgrade() method in SQLiteOpenHelper & developer has cleared all
table content there).
It depends on the way you are using the database, but in general what you are searching for is "database migration". You can define how the database should behave on an update (database version increased). If you did not modify your database schema, then it will stay the same as before updating the app.
In case you use room: Migrating Room databases
In case you use SQLiteOpenHelper: onUpgrade
I have an App on Playstore. The app is named Credit Flow.It is used to track income and expenses of an individual.
I use local Sqlite Db to save all the transactions(they are not saved on any server).
I am new to pushing apk updates. My question here is that if I upload a new Apk on playstore will it erase the existing user's Local Db?
If so how can I prevent that?
My question here is that if I upload a new Apk on playstore will it erase the existing user's Local Db?
No. Assuming you are using your database in the default directory, your database will remain untouched.
The database will only be removed if the user uninstalls your application, or goes into the app settings and clears your app's data.
Also note that onUpgrade() will not be called on your SQLiteOpenHelper. That method is only called when you increment the version number passed into the SQLiteOpenHelper constructor.
No, the data is preserved. But ensure your using the same package name. Updates do not alter sharedpreferences or databases or other files that generated in run time
I'm trying to figure out the best way to handle database upgrades and versioning.
At the moment I delete the database and log users out when I do a point release, which isn't a great experience.
Can anyone recommend any tips for doing this?
Your database version is independent of your app version. If your database schema doesn't change at all, you shouldn't need to do anything to your database during an update.
When your database schema changes, you should handle database updates in onUpgrade() of your SQLiteOpenHelper. This method is called when you try to access your database and you have updated your database version, as described in the Data Storage Options documentation.
If you are using a third party library to handle your databases, it should either handle the upgrade for you or provide similar functionality.
There is no universal strategy for upgrading your database here. What you do depends completely on what your schema looked like before the upgrade and what the new schema looks like. Depending on what changed, you might create new tables or columns, delete tables or columns, update rows in the database, or move data between tables. If you have a specific question about how to migrate your data, create a new question describing the new and old schemas.
The way we do it is that we run a routine every time the app starts that calls a stored proc on the server to get SQL that upgrades the database if it is necessary. (The sql can be quite involved: dropping tables and recreates them with new structures and inserting new values). We store the version of the database in the database itself and upgrades to the new version.
We don't use the onUpgrade() call.
Please forgive me if this question has been answered - I searched and couldn't find it.
I have an Android app that I want to upgrade, and it uses a SQLite Database. I want to update some of the application logic in the app, but there will be no updates to the database schema or contents. I basically need to keep the database exactly as-is for the user.
Do I need to do anything in onUpgrade to ensure that the database is kept, or can I leave the DB stuff alone for this update?
The onUpgrade() method is used incases of version change. Which means the database stored in the phone needs to be altered or dropped or deleted and a new database to be created. As your application does not have any of these requirements you can leave the DB stuff for this update.
This related article may help you with your question.
The way that I understand it, is that you need to put your database changing code in onUpdate() if you WANT to update between versions. But since you don't intend to, and are probably keeping the database version the same, then you will most likely have no issues at all.
Upgrading will NOT interfere with SQLite. Changes to db structure will not be implemented unless you programmatically do so (in onUpgrade method) or you uninstall and reinstall your app.
As long as it is the SAME application that you are upgrading, your db will not be affected and your data will not be affected either. If you change the signing key used in building your apk, your db will be recreated.
Conversely, if you change database structure at any given point, your onUpgrade method will come into play. You will be forced to backup, drop, recreate and repopulate tables which have been changed between versions (oher tables remain untouched both in structure and in data).
NOTE: In debugging, i just uninstall and reinstall the app every time i make db changes, but in production you DONT want to do that.
I hava an android application which consists sqlite database in the assets folder.
In the DB I have several tables, which one of them is user data (which is updated over time by using the application - when the user installs the application this table is empty).
The other tables store data that I update.
The question is: when a user gets an updated version of my application (with sqlite database in the assets folder) from the market, I need to keep the data the user updated by using the application, but i do want to update the other tables (which consist my data).
What is the correct way to do it?
Thank You :)
Keep a version number for each change and implement the onUpgrade method for the possible combinations. See more in the javadoc for SQLiteOpenHelper
Since you said your tables are empty when the Database is first created, it shouldn't be necessary to add the Database from the /assets-folder.
Instead, you can use a SQLiteOpenHelper, which offers an onCreate()-method that can do the initial table-creation (an add some example data if necessary).
If you then update your app, you simply increase the Database-version and the onUpgrade()-method is called, where you can then perform the Database update.
See this other question: Run some code when user update my app
If your app comes with a huge Database and inserting entry's in the SQLiteOpenHelper isn't the right way to go, you can still check if the Database already exists and then do the updating (through the onUpgrade()-method) and keep the users data.