I added a table to a database that my application uses and wrote some code to work with that table. Everything worked fine for my on my phone and in the emulator, so I sent the update to the market.
This cause me to receive quite a few stack traces in the developers console cause by
android.database.sqlite.SQLiteException: no such table: flag
(flag is the new table).
This got me to wondering, are databases deleted when the application is updated? Presently in my application I am looking to see if the database exists, and if it does then I don't recreate it.
I didn't catch this before I sent out the update because I uninstalled the application before uploading the debug version.
I've since rolled out a quick update that has a try catch blocks around all accesses to the new table(which should have been there in the first place, I know, I know).
User data is not deleted, including databases.
Your DB has a version number. When you update your app, you advance the version number so that you can detect a present "old" DB.
This can be used to trigger a migration routine. In your case it should have added new table to the DB.
SQLiteOpenHelper is the answer.
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
The Question is how exactly google play updates apps.
I mean does it remove older app exactly from files or it just append on it .
For example in my app i have a local database ,after update, will my older local database become removed?
Your old application is definitely deleted. Your app is compiled and packaged, it won't be opened by Google.
As far your database, if you made changes to your database you need to change the "database version" before publishing. And put code inside the onUpgrade() method of your SQL database. This is how you can successfully change your database. If you want to delete the old database, you can delete it inside the method. The database is on the user's device, and will stay there forever until they delete your app or your code deletes it.
I hope I'm understanding your question.
I'm writting a small app for gym exercises. I keep my records in SQLiteDatabase and I want this app to start running as fast as I finish main part of the app. But further I want to develop this app and add some more features. There will be some records in a database yet. How can I save this records and move it to new version of the app? I'm developing with Android Studio, and each run app is installed from the scratch(before previous version is unistalled and all data is deleted?) if there were any changes, right? So, how can I keep old records and add them to new version app? I have seen some answers with onUpgrade, but it wasn't that specific that i can understand them, beacause they don't tell anything about upgrading only app, not the databse. And sorry for my English :)
Installing a new version of your app doesn't necessarily remove its data (unless you uninstall it manually before installation or just clear data manually).
Also, if you change your database structure in an update, you can override
SQLiteOpenHelper's onUpgrade method in order to handle database updates properly.
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 have been testing my app which uses the dbadapter from Reto Meir's earthquake example. Everything was going ok for several days but when debugging with the app on the device today I got the 'no such table' error. I changed the name of the database and all runs well again. This doesn't give me much confidence regarding potential other users.
Since it seems impossible to see the database on the phone, by design I suppose, I can't see how to find out what caused the problem and take steps to avoid it. The database appears to open ok at the start of the program but errors when handling a select query. Just changing the name of the table doesn't fix it, it has to be a new database name.
As the change of name allows it to run ok I can't see that the code is wrong. I wonder if the data becomes corrupted.
I've also found that after successfully inserting a row, then later getting a cursor to allitems sometimes produces a -1 error against a get for one of the column names. How can a column name drop out of the columns index?
I've googled this type of problem and whilst there are a lot of folks with the problem and a lot of replies I can't find anything which informs on the underlying reason for these problems - which is what I am after.
I was having the same problem with this. I was changing the version number, uninstalling application etc... in the end it was due to me not submitting the transaction of the sql call. It might be worth checking out the answer in the following for some clarity - https://stackoverflow.com/a/13568419/1634369
The database is available on the phone and if you can 'adb shell' to the phone, you can also use sqlite3 command line shell to connect, examine, query and modify your database. It's pretty much the same functionality as you'd get with oracle's or mysql's command line tools.
You can see some more details here for example:
http://www.infinitezest.com/articles/using-sqlite-from-shell-in-android.aspx
As for "no such table" case - it really depends on where you store your database. You can choose (at DB creation time) where the database is stored - it might be the internal /data/data (usually) folder where your application resides or you could (mistakenly) create it in cache space - cache can be cleaned at any time whenever Android's OS finds that it needs more space, so this might explain why your database disappeared.
Another possibility is that instead of reinstalling the application, you uninstalled it and installed in two steps. Uninstalling application also deletes all the private data for the application (on most phones, but not on all), whereas reinstalling application (For example by clicking Run in eclipse) does not delete the data. In any case - in you application's onCreate you should recreate the database including all tables - always if you find it has not been yet created - because you never know if you run application for the first or subsequent time.
Please explicitly link to the example you reference.
The way I understand it, you create your own database at launch, unless the database already exists on the device, in which case the database creation is skipped. Correct?
If that is correct, then the only thing you need to do is uninstall the application whenever you update the database design (to remove the old database, with the old table names, etc) and re-install, so the database is recreated with the new table names.
Otherwise you will have updated application code that tries to work with an outdated database.