views:

537

answers:

2

Hi

I am developing an Adobe AIR application which stores data locally using a SQLite database. At any time, I want the end user to synchronize his/her local data to a central MySQL database.

Any tips, advice for getting this right? Performance and stability is the key (besides security ;))

+1  A: 

I can think of a couple of ways:

  1. Periodically, Dump your MySQL database and create a new SQLite database from the dump. You can then serve the SQLite database (SQLite databases are contained in a single file) for your users client to download and replace the current database.

  2. Create a diff script that generates the necessary statements to bring the current database up to speed (various INSERT, UPDATE and DELETE statements). To do this, you must record the time of each change continuously in your database (the time of creation and update for each row, and keep a history of deleted rows). User's client will download the diff file (a text file of the various statements) and apply it on the local database.

Both approaches have their own pros and cons - by dumping the entire database, you make sure all the data gets through. It is also much easier than creating the diff, however it might put more load on the server, depending on how often does the database gets updated between dumps.

On the other hand, diffing between the database will give you just the data that changed (hopefully), but it is more open to logical errors. It will incur an additional overhead on the client as well, since it will have to create/update all the necessary records instead of just copying a file.

Eran Galperin
A: 

If you're just sync'ing from the server to client, Eran's solution should work.

If you're just sync'ing from the client to the server, just reverse it.

If you're sync'ing both ways, have fun. You'll at minimum probably want to keep change logs, and you'll need to figure out how to deal with conflicts.

derobert