Replication between MySql and Sqlite (E vice versa)

Posted on

Question :

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

My problem is being the moment that I need to do a replication between the bases.

Example: If I’ve already loaded an in-app list with a customer’s name and number and need to change the number there in the bank, this change does not come to the application. Unless I recreate the database in the application. I hope I can be clear.

I researched but found nothing useful, just wanted a hint of how to do, if someone else has done something like that, simply the ‘best way’ way to solve this.


Answer :

Implementing this kind of thing is never simple. A first suggestion is to put a timestamp on each line, so that you have how to know the “version” of each row, there you have a base to compare if the line in the local SQLite is obsolete compared to the database and vice -versa.

If you store somewhere when it was time for the last synchronization of each phone, you can even do a SELECT filtering through the timestamp (equal to or greater than the last synchronization) and you easily pick up the changed lines, support multiple cellphones synchronizing at the same time.

A more annoying problem is the issue of removing lines. If the table (s) involved never removes lines, ok. If they are removed, you need to log (log) these removals somewhere with the timestamp so that they are part of the update received by the cell phone.


There is no way to do replication directly.

You need to create a Webservice / API to do the communication.

This is a bit complex because you need to be careful about controlling the version of the data.

There is a business framework that aims to simplify this work: link

It also offers a free version, with limitations regarding access to the source code.


Leave a Reply

Your email address will not be published. Required fields are marked *