Android Question How to synch databases

Discussion in 'Android Questions' started by Silv, Feb 14, 2015.

  1. Silv

    Silv Member Licensed 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.
     
  2. KMatle

    KMatle Expert Licensed 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?)
     
  3. Silv

    Silv Member Licensed User

    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.
     
  4. KMatle

    KMatle Expert Licensed User

    Are you able to identify the rows by id/device on the serverside? (less entries/rows to check).
     
  5. keirS

    keirS Well-Known Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice