如何有效地与同步Web数据库的Andr​​oid数据库 [英] How to efficiently sync Android database with web database

查看:143
本文介绍了如何有效地与同步Web数据库的Andr​​oid数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid应用程序数据库与我的Web服务器上的中央数据库同步。我的问题是有效地同步了。

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

表设置为ID(主键),镇。
Android应用程序想要的人所有的ID在给定的城镇

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

我现在的流程是:

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
    }
}

有没有像一份声明WHERE _id IN(ID1,ID2,ID3,ID4 ....),将作为补充,如果已经有/更新?
还是我将它完全错了?

Is there a statement like WHERE _id IN(id1, id2, id3, id4 ....) that would act as add/update if already there?? Or am I going about it completely wrong?

感谢

推荐答案

那么,为什么你更新数据,在同步的时候着你删除Android设备的所有数据,并从服务器添加的最新数据

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)

这篇关于如何有效地与同步Web数据库的Andr​​oid数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆