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)
- build a table on server side (ID, Town, UpdateTime)
- add triger on UPDATE/INSERT to modify UpdateTime
- store LastUpdate time on device with fx SharedPreferences
- send LastUpdate to server
- build JSON or XML with ID, Town from a table WHERE UpdateTime > LastUpdate +(place in JSON or XML) (CurrentTime GETDATE() from DB)
- do insert/updates in device db update, LastUpdate to CurrentTime
精彩评论