将本地 SQLite 数据库与服务器 SQLite 数据库同步
是否可能,如果可以,如何有效地将本地数据库与全局数据库同步,以便在对本地版本执行操作时也会对全局数据库执行操作。简单地使用版本控制来颠覆全局是不可接受的,因为根据对数据库进行更改的人数,数据库可能会存在多个本地副本。换句话说,是否可以只拥有数据库的镜像,以便可以在本地访问它,即使它位于网络上的其他位置。
Is it possible, and if so how can I effectively sync a local database with a global one such that when an action is taken on the local version it is also made on the global database. Simply using version control to subvert the global is unacceptable because there could be several local copies of the database according to the number of people making changes to the database. In other words is it possible to just have a mirror of the database so it can be accessed locally even though it is somewhere else on a network.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同步数据库是一个非常复杂的主题。最简单的方法是在应用程序级别(或通过自定义 sqlite 包装器)保存针对每个系统运行的所有查询的记录,然后在同步时再次运行这些查询。
当您有多个源或双向同步时,这会成为问题。由于操作顺序不同(假设启用了引用完整性),在一个数据库上运行良好的查询可能在另一个数据库上失败。
另一种更复杂但更可靠的方法是跟踪每个表的完整事务历史记录。您还需要知道每笔交易中哪些记录受到影响,以及每笔交易中的顺序。完成后,您可能需要一种方法来检测何时会出现问题并自动解决它们。
Synchronizing databases if a very complex topic. The simplest approach is to keep a record at the application level (or though a custom sqlite wrapper) of all queries run against each system and then run those again when synchronizing.
This becomes problematic when you have multiple sources or two way synchronization. Queries that ran fine on one database may fail on an other due to different order of operations (assuming referential integrity is enabled).
Another more complex but robust approach is to keep track of a full transaction history for each table. You'll also need to know which records were affected in each transaction, and the order within each transaction. When that's done, you'll probably need a way to detect when problems will occur and automatically work around them.