I know a simple way that can back up database. Its directly have a copy of the .db file. But the issue is when you have to update the database tables with new columns, then the backups are of no use as it is with the old design.
The work around is to have the data parsed and stored into a file. But I am not sure how easy and safe is this.
Please let me know what you feel about this subject and also let me know if you have a better idea is mind. A sample code would be handy. Thank you for your advice and time. Thank you.
You bring an interesting point up - I haven't personally thought of that before.
You can always store the "version" of your database in the database file itself (perhaps in the file name). Then, when you open the database, you can retrieve its version and have the SQLiteDatabaseHelper run its onUpgrade() method to add any new columns.
Related
the scenario is that -- in my application client would make dynamic edit text (of which i m not sure ), but i want to store all the information he creates. All other part have been done.
I just want to know which is the best way to store them in File OR in Database.
As if some says in Database, i want to know how?
and if in File, why?
I will encrypt and decry pt the data too.
Any help would be appreciable.
Thanks in advance.
Store the data in a database. If you're doing Android development, simply use SQLite - http://www.sqlite.org/.
There are many reasons not to store the data on the file system:
It is easier to query a database than a file system. You can quickly and easily answer questions like "How many records do I have?" or "How many items in a given category do I have?"
If you do this in the file system, you'll have to write your own code around querying.
SQLite has strong data types that enforce a schema. If you just write to a file, you'll have to ensure an ID is an integer etc. The database can do this for you.
From my experience when writing files to the file system, I've always ended up with orphaned files. You write them and then forget they are there and they never get deleted. It's annoying. With a database you can easily assess the state of the database and remove old/unused records.
I have some really huge data that is required for my android app. I've put it into a sqlite db now. Roughly it is 39k rows and 5 columns. I want this data to be available for my app.
I'm kind of confused as to how I ship my app with it. i can ship the db file with it like discussed in this thread. or I can somehow create XML out of that data and ship it along. But the XML would be really huge. So what is the right way of doing it?
I do not want to download it after user installs the app. That'd be my last option if there are no better clean ways of doing it.
This should help you.
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Basically just ship the database with your apk file.
I think shipping your DB could make some problems with compatibility.
Maybe it will be better to use GZIP'ed SQL code bundled to your .APK?
Or instead of XML for intermediate representation you can use google protobuf, which is most effective data representation format(Also, if you have a lot of strings, you can use it in combination with GZIP).
Check the example here to achieve this functionality.
Hello
I'm working on an android program that uses a database. My database is going include about 300 to 400 records.
My question is what is be best way to work with the database.
Should I create the database at run time via code and insert the records "manually" every time the program starts, or should I use an external database, that's located in the /assetes folder of the program?
If the second option is the way to go, could someone please give me an advice on how to do that, because I can't find any toturial that covers this subject.
Thank you!
There's another option, which is to initialize the database the first time the program is launched. See the SQLiteOpenHelper class, and especially the onCreate method in that class.
Here is a tutorial for the 2nd option you mentioned.
Put your db in the asset folder and if DB does not exist in /data/data/YOUR_PACKAGE/databases/, it will copy the database over.
I want to store some data that should remain also after application uninstall and to be accessible by a new version of this application.
Share preferences/files are not a solution as they are removed when program is uninstalled, also writing to internal memory is not a solution (also removed with uninstall).
Writing to external public folders I see that is not removed but this would require an external SD Card and don't want to be constrained by this.
I don't know about using the SQLite database, how it works? It could be a solution for what I want ?
Or any other solutions would be appreciated.
The databases made by your app will be stored in /data/data/your.package.name/databases/ and will be deleted on uninstallation of the app.
So, that's not a solution. I think the only way would be using the SD-card.
It sounds like you got this right. Writing to SD-card is the only really persistent way to store data.
edit:
The Data Backup might also have something going for it, but don't take my word for it ;).
Use SharedPreference or by using SQLitedatabase
1) create temporary table (with the same structure as original) and copy data from the original table into this new one 2) drop the original table 3) create the new original table (i.e. with more columns, with other column names, etc.)4) copy data back from the temporary table to this new original one 5) drop the temporary table
Okay, so I am still learning to do some coding here, and I seem to have gotten stuck.
I want to have a select number of documents added to a package for the Android OS
but I don't know how to store said documents. Do I add them all under res/raw, or make an SQLite database and call from there?
More importantly, I need to be able to call those documents when a search criteria is added.
I was on the Android reference site, and they add write functions for the SQLite db, which I would prefer not having as an option.
What kind of database should I implement here?
I would prefer a link to an example, but anything would help at this point.
Try reading this.
Notepad example
or make an SQLlite database and call from there?
No you don't create a SQLlite database it will be created for you after your App start the database call.
See this SQLiteOpenHelper
And SQLiteDatabase