开发者

How to efficiently sync Android database with web database

My android app database syncs with a central database on my web server. My problem is efficiently syncing it.

The table is set up as "id" (primary key), "town". The android app wants all the ids of the people in a given town

My current process is:

get list of all ids for town "A"
set all existing records in Android database to "old"
add/update ids in the list to "current"
delete any records still set as "old"

The bottle neck comes in the add/update process which is:

for each id {
    result = update WHERE _id = id
    if (result == 0) {
        add record
    }
}

Is there a statement like WHERE _id IN(id1, id2, id3, id4 ....) that would act as add/up开发者_运维技巧date if already there?? Or am I going about it completely wrong?

Thanks


then why you updating the data, at the time of synch cant you delete all the data in android device and add the latest data from the server

i am saying this because it will flexible, first delete all and insert all(latest ones)


  1. build a table on server side (ID, Town, UpdateTime)
  2. add triger on UPDATE/INSERT to modify UpdateTime
  3. store LastUpdate time on device with fx SharedPreferences
  4. send LastUpdate to server
  5. build JSON or XML with ID, Town from a table WHERE UpdateTime > LastUpdate +(place in JSON or XML) (CurrentTime GETDATE() from DB)
  6. do insert/updates in device db update, LastUpdate to CurrentTime
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜