i need hints for SQLite; I receive in SOAP or REST format a large XML (betwen 200 and 5000 entries depending on the user, with around 30 columns) that i parse to a local SQLite db.
This operation takes too much time for the users (from 10 seconds up to 2 minutes), so i wanted to know :
Is it possible under a window server (Delphi XE2 home made server) to create the SQLite database file and send the whole file to the mobile; Then on mobile side, replace the database file with the new one (data are not modified on client side, i can replace file with no regrets ^^ ) ?
On a rooted mobile, i just can't find the SQLite database file (searched for it with esFileExplorer, /data, /dbdata, /sdcard/data... nowhere) so i just don't know where i will have to put that file in the end...
Yes, its possible.
You can download the database having latest data & replace it with current database. Find an example here of "How to use existing data base", link for sample project is also there.
EDIT:
You need to modify it according to your needs.
You can delete your existing database by using context.deleteDatabase(DATABASE_NAME);
Related
I want to create a sqlite database file in a web service, so I dont have to read a json in the android device and wait for it to read the json, convert it to an object and then insert it to the database.
When the json is huge, with a lot of data, that process its to long for be waiting in an android device.
I would like to generate the database file of sqlite in the webservice, so that, instead of returning the json, it returns the sqlite database, and in android, I just need to save the database, so that, it is ready to use.
That would save a lot of time!
SQLite have libraries for almost any kind of server side language.
SQLite db is just a file so after is created you shall compress is in a zip and use volley library to dl the file over http.
Decompress the zip and connect to it.
I have no idea about which kind of data and which amount you need to transfer but if the data is organised properly the processing should be so long. Also you have to take in consideration that using JSON you can "ask" to receive only updates (delta) and this is something that is not possible if you download all the db each time.
Update: for this kind a data I would go to a different approach. Use docs from google publishing api to upload every specific period of time the db in an extension pack for your app. so most of the dl'ing process is even before the "install" on the device itself. When the app is first running will contact your server and get the latest updates since the db was created (I suppose that even that is a week you are talking about less than a hundred rows)...
I want to upload local sqlite database file at server but in sql format. Is it possible to directly save it in mysql supported format? The file is uploaded successfully on server but its just a flat file of sqlite db. When i open it in editplus or import it in phpmyadmin, it shows error. But when I manually export the database from sqlite manager in .sql extension, it successfully gets open in readable format in editplus. Please help me with this problem. Thanks in advance !
AFAIK you are talking about two completely different things.
Its like comparing a DB dump file to a properly exported file like an xml file with schema and data information from Oracle or MySql
When you export you get a file with or without .sql extension and it means a file with set of queries like DDL or DML create,insert etc. That may be sequentially run to execute all the commands in it and provide you with the right schema and data present in that file.
Whereas a DB file that is created via app is specific to the device and is an .sqlite file which is specific to sqlite browser and that may read it and not a set of queries only that you may open in edit-plus or a text editor.
Sqlite DB file that you find on your device is dynamically generated pages to maintain the integrity of the db.
For more info you must read,
Format of sqlite database
Sorry I don't have code but the idea is,
--Edit with algo--
Assuming you have the create commands for all tables and constraints with you , as they are not going to change most of the time.
You may use this function as a Utility to create and maintain the sql
command list for you parallel to the db you have.
void createExportCommands()
{
...
- Read all tables one by one using a `Cursor`
- Based on specific tables/columns create queries
i.e. String query="insert into "+your_table+" values("+cursor.getString(0),....+");";
- Write this data into a file called export_data.sql and keep updating it in background
}
Perhaps its not the best approach but it will solve your issue.
I am developing an app in which i would need a local database.
So as per my knowledge there are two ways to do it:
First is to add pre filled database file in assets folder & make copy of local database from it the very first time app is started.
Second is using script to download it from Server for first time of app use?
First way have been pretty well answered by this guy Using your own sqlite database in android application
Can someone help how can i go with second way of download data from Server?
Should i use JSON/XML for getting that data from my Server?
Or should i go with first option since my app has only around 150 to 200 rows in the db file?
Go for the local db for the following reasons:
The users would have great on boarding experience as they can very quickly start seeing the utility of the app since you provide some data on first run without any delay that might be added when you fetch data from the server.
Do it for sure if the db doesn't increase the apk size significantly.
You must use php only if you need get information from the server, with php and json is better ...
http://www.vogella.com/articles/AndroidJSON/article.html
and if you only need share local information, only needs use MYsqLite ...
http://www.vogella.com/articles/AndroidSQLite/article.html
We've got an android app and an iPhone app (same functionality) that use sqlite for local data storage. The apps initially come with no data, then on the first run they receive data from a remote server and store it in a sqlite database. The sqlite database is created by the server and the apps download it as one file, which is then used buy the apps. The database file is not very large by today's standards, but not a tiny one either - about 5-6 MB.
Now, once in a while, the apps need to refresh the data from the server. There a few approaches I can think of:
Download a new full database from the server and replace the existing one. This one sounds like the simplest way to deal with the problem were it not for a repeated 5-6 MB downloads. The apps do prompt the user whether they want to download the updates, so this may not be too much of a problem.
Download a delta database from the server, containing only the new/modified records and in some form information about what records to delete. This would lead to a much smaller download size, but the work on the client side is more complicated. I would need to read one database and, based on what is read, update another one. To the best of my knowledge, there's not way with sqlite to do something like insert into db1.table1 (select * from db2.table1) where db1 and db2 are two sqlite databases containing table1 of the same structure. (The full sqlite database contains about 10 tables with the largest one probably containing about 500 records or so.)
Download delta of the data in some other format (json, xml, etc.) and use this info to update the database in the app. Same as before: not to much problem on the server side, smaller download size than the full database, but quite a painful process to do the updates.
Which of the three approaches you recommend? Or maybe there's yet another way that I missed?
Many thanks in advance.
After much considerations and tries-and-errors, I went for a combination of options (2) and (3).
If no data is present at all, then the app downloads a full database file from the server.
If data is present and an update is required, the app downloads some database from the server. And checks the content of a particular value in a particular table. That value will state whether the new database is to replace the original or whether it contains deletions/updates/inserts
This turns out to be the fastest way (performance-wise) and leaves all the heavy lifting (determining whether to put everything into one database or just an update) to the server. Further, with this approach, if I need to modify the algorithm to, say, always download the full database, it would only be a change on the server without the need to re-compile and re-distribute the app.
Is there a way you can have a JSON field for each of the tables? For instance, if you got a table named users, have a column named "json" that stores the JSON for each of the users. In essence, it would contain the information the rest of the fields have.
So when you download the delta in JSON, all you got to do is insert the JSON's into the tables.
Of course with this method, you will need to do additional work in parsing the JSON and creating the model/object from it, but it's just an extra 3-4 small steps.
I will recommend approach 3, because app will download the json file more fast and local db will be updated more easily avoid overhead of more internet usages.
Just create a empty db initially according to server db and then regularly updated the same by fetching json
I have access to a set of remote XML files stored in a server (XML files of a MySql database tables).
I have to import and create my own SQLite BD to use them with the android mobile app. When remote XML files update(When MySql database information change), the SQLite DB also Should change accordingly.
Can any one guide me how to accomplish this task this.
Sample coding/ reference/ Idea highly appreciated.
1.Download and Parse the XML files
2.Store them in SQLite database
3.Write a background scheduled service which executes the code for corresponding the above 1 and 2.
Or
Use the Cloud to Device message from your server to the android app to update your SQLite database(but I thought the above 1 and 2 points may need here also.It is all about your logic how you develop the application).
You can try my xsl template
http://code.google.com/p/mysql2sqlite-xslt/.