Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update sqlite database when server database get updated

Tags:

android

I am working on updating the database on a Mobile device which is using SQLITE db, which should get updated as server updates it's database i.e wamp server.
Can anyone suggests me any ideas on how to achieve this.
I don't want to read the whole server database as it would increase the Data Usage while reading the whole database just for a single update or for multiple update. Update is done in the product table and only the price field is updated by server side.

like image 748
Sumit Avatar asked Jul 14 '12 06:07

Sumit


People also ask

How do I create a SQLite database UPDATE?

Introduction to SQLite UPDATE statement First, specify the table where you want to update after the UPDATE clause. Second, set new value for each column of the table in the SET clause. Third, specify rows to update using a condition in the WHERE clause. The WHERE clause is optional.

How do you check if the DB is updated?

The simple way to determine if the data has been altered is to put a timestamp column on each relevant table, and a trigger on insert and update that updates this row to Now . If you want to make searching for new data fast, put an index on this column. Then store in another table the last time you checked for updates.

Which SQLite statement is used to UPDATE data into table?

SQLite UPDATE Query is used to modify the existing records in a table. You can use WHERE clause with UPDATE query to update selected rows, otherwise all the rows would be updated.


1 Answers

You can define a service in your app that periodically asks if there are updated data in your server db. On the server side you can implement a web-service that will receive a json object in which you will put the current date, the table name you want to check for updates and other info based on your purposes. I'll explaine myself better with an example: 1) when the app starts a background service will also start. This service will query (for instance every 3 minutes) your webservice to see if there are new updates for a specified table. 2) The webservice will receive the table name you want to check and the datetime preferably in unix timestamp. For instance you want want to see if there are new records for the table "products" after 2012-08-20 22:00:00 . You can create a json object and a http request with this information within your app and pass it to the server side. 3) Your web-service will respond to you giving a json array with all the data that are being added or modified after 2012-08-20 22:00:00. Of course in the server db you have to store this information (basically each record will have a field with the datetime of first insertion / last modification)
4) You can then update your local sqlite database.

Probably this is not very efficient but it works.

Andrea

like image 108
jiraya85 Avatar answered Oct 19 '22 19:10

jiraya85