9

Possible Duplicate:
how to sync SQLite database on android phone with MySQL database on server?

I am wondering what is the best approach to updating a database on an Application.

We have a mysql database that handles everything on the main server, but I want to replicate this on my app. I would like to copy the database (mysql) on the android device so that both stay up-to-date. this would not have to happen in real time, but could be scheduled once every week, or when a change is made to the SQL database.

How would i do such a thing?

As in should I send this out as an update to the application and create the changed database, or should I use some way of getting the database to be changed on the server, and the SQLite data base be copied across to the android app.

Or ... is there some nice clever way of doing this??

Thanks Pat

Community
  • 1
  • 1
pat
  • 95
  • 1
  • 1
  • 10

2 Answers2

3

Why not use a timestamp (or version field) in the mysql database on your server, then when the android app is run it imply checks the timestamp/version to see if there is a change since it needs to be updated. If the timestamp/version is newer than previously found download the updated dataset else simply use what is already stored.

Peetz
  • 167
  • 1
  • 14
  • Thanks Peetz Nice Idea with a timestamp, but how do i download the data set to the phone? or should I send it out as an App update? This is the bit where i get confused as to the setup of the design. – pat Jun 14 '11 at 09:06
  • 1
    No need to use an App Update, just form a connection with your server (i.e. a specific page written soley for this purpose) and pass it some parameters. This should then echo an XML or JSON data set back to the device. Not sure of the exact code but something along the lines of XMLHTTPRequest may be the way forward. – Peetz Jun 15 '11 at 08:10
1

Unless you want to process the whole data on the device (depending on how big the database..etc...) it's probably better to do the conversion offline on the server and transfer the files. There are some tools available to convert your MySQL database into SQLite. http://forums.mysql.com/read.php?145,68269,92627

Matthieu
  • 16,103
  • 10
  • 59
  • 86