android – Replication between MySql and Sqlite (And vice versa)

Question:

I'm developing a system that integrates a MySQL database with an Android application (through a webservice ). I can already connect, pass data, change them in the bank through the App and things like that.

My problem is when I need to replicate between the bases.

Example: If I have already loaded a list in the app with the name and number of a customer and need to change the number there in the bank, this change does not come to the app. Unless I recreate the database in the app. (Hope I'm getting to be clear).

I researched it but I didn't find anything useful, I just wanted a suggestion on how to do it, if anyone has done something like that, simply the 'best way' way to solve this.

Answer:

Implementing this sort of thing is never simple. A first suggestion is to put a timestamp on each line, so that you can know the "version" of each line, then you have a basis to compare if the line in the local SQLite is obsolete in relation to the database and vice -versa.

If you store somewhere when was the time of the last synchronization of each cell, you can even do a SELECT filtering by timestamp (equal to or greater than the last synchronization) and you easily get the changed lines, and it's easy to support multiple cell phones synchronizing at the same time.

A more annoying issue is the line removal issue. If the table(s) involved never remove(s) rows, ok. If they remove, it is necessary to log (register) these removals somewhere, with the timestamp, so that they are part of the update received by the cell phone.

Scroll to Top