Android Question How to synch databases

Silv

Member
Licensed User
Longtime User
Hi all, i working on shopping application and i use websockets to synchronize list with other devices with same id. I have a problem with synching databases. I have 2 databases local and web. And i got stuck in how to synch them, for example when 1 device disconnected, then 2 device made changes , and 1 device connect again, how to synch this changes? Is anybody have an idea? Thanks.
 

Silv

Member
Licensed User
Longtime User
Without knowing further details of your apps or logic:

Can rows be added/changed on both sides? Then it could be tricky (which one leads?)
Rows can be changes on both sides, my shopping app reading data from local db. So anytime device connect with id, it should replace changes from web db to local db...
And also it need to add changes to web database if changes was applied while it was disconnected.
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
Several ways of doing this depending on the complexity of the database. A very simple way is to use SQL Triggers. This allows you to keep a log of all the changes made with a few SQL statements. On the Web database have a table that stores the ID of each device and date and time when the last sync was done. Each time the device connects you can select all the updates from the web db log since the last sync and all the updates from the device using the log on the device.

There are other more complex methods for large databases that use check sums on whole tables, groups of rows and then individual rows.
 
Upvote 0
Top