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
Related
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)
This is my first time working on a Xamarin App and I am new to the app development world so I need some help figuring out this process.
Currently I run a php web service that generates some SQL files that I run in DB Browser and I get a database file which I then put into my Assets and Resources Folder. Using each platform's API I copy the database into a writable folder and use that to run my queries.
I followed this really helpful tutorial and it worked perfectly fine.
https://medium.com/#hameedkunkanoor/creating-a-sqlite-databse-and-storing-your-data-in-your-android-and-ios-application-in-xamarin-2ebaa79cdff0 .
After the "initial" setup I store a timestamp in a local table and and the next time the user opens the app I pass that timestamp and retrieve data that is older than that timestamp. The I update that timestamp and continue the process. That data is sent back in JSON format and make the updates to the tables.
My only concern is if a new version were to come out where I add a new table or a new column which is not present in the current version of my Database, how should I take care of those update Web Service calls? Is there a way of monitoring my DB version? I read somewhere where I could just ignore the new data that is not present already, like table or columns, but I'm not really sure how to do that.
I also saw that if I call CreateTable on my current tables I could potentially update them?
Also for future reference each time I develop a new app would I need to regenerate a new database file to store in the assets/resources folder? Is there a more automated process for this? Along with monitoring the version of my database?
Any Help/Tutorials/Suggestions would be greatly appreciated.
You have to remember that CreateTable it's already doing the columns update for you, because internally it calls a method called MigrateTable which you can see here for further clarification: https://github.com/praeclarum/sqlite-net/blob/master/src/SQLite.cs#L562.
However you could have to handle more advanced modification to your database, like adding triggers or something similar.
In that case i suggest you to perform modifications manually.
In Xamarin Forms i've ended up with this:
https://gist.github.com/matpag/b2545cc22c8e22449cd7eaf6b4910396
Could not be the best strategy ever but seems to work for me.
Summarizing :
You have to save the database version in an internal flag of the SQlite database called user_version accessible with PRAGMA keyword.
Every time you get the database connection, you have to perform a check and see if the current database version is the same as the app last database version.
If not you need to perform a database update and set the new current version.
Reference here.
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.
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.
Periodically my application must update the database.
This update may not be automatic. When user access the app, there will be a check if there is a new database available. After verification, if there is a new version will prompt the user if they want to update the database. Given permission, start the download of the new file sqlite, which will replace the old file.
The new file has the same structure as the old file, but with more rows in the table. In addition, the database contains only one table.
I'm looking for a viable solution to two days and found nothing that could help me.
Thank you in advance for attention!
You can't change files that are distributed inside your .apk. You will need to download this additional file somewhere else, then in your code you will have to decide which one to use at the time it is opened.
once any update is available in market user will download it and if new version of your app its database version does't match onUpdate method is called you can override it and do what ever you want to do.
another thing you can copy your database at data/data/databases/yourdatabase.db by simply FileOutputStream