在应用程序启动时将外部数据库与 SQLite 数据库同步
我的 Android 应用程序有一个 SQLite 数据库,它存储服务器上另一个数据库中的一些数据的副本。当用户打开应用程序时,我想将本地副本同步到外部主控。用户可能已经访问过相关网站并插入/更新/删除了数据。
如果只是插入/更新,可以使用时间戳,但由于它们可以删除数据,我不确定如何检查已删除的行。
那么,了解更改内容并更新本地副本的最佳方法是什么?
I have an SQLite database for my Android app that stores a copy of some data from another database on a server. When the user opens the app, I want to sync the local copy to the external master. The user may have been on the related website and inserted/updated/deleted data.
If it was just insert/update, timestamps could be used, but as they could delete data, I'm not sure how to go about checking for deleted rows.
So, what's the best way to tell what's changed and update the local copy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将添加一个表来审核删除(包含已删除记录的关键字段)并在同步时传输该表,并在成功同步后清除该表。
I'd add a table to audit the deletes (containing key fields of the deleted records) and transfer that on sync, and after a successful sync clear the table down.
嗯,我们正在开发 iOS 项目,如果服务器响应更新版本,该项目会将其数据库与服务器同步。
我们的服务器增量存储执行的 SQL,并根据请求将所有这些更改复合到特定日期并压缩发送到应用程序,我的 Objective-C 包装器在其中从下载的文件执行 SQL 语句。
也许同样的方法对你也有好处。
Hm, we are working on iOS project, which will sync it's database with server if server will respond what it have newer version.
Our server incrementally stores performed SQL and on request if compounds all those changes to specific date and gziped sends to the application, where my Objective-C wrapper execute SQL statement from downloaded file.
May be same approach will be good for you too.