使用Qt和SQLite数据库的并发 [英] Concurrency using Qt and SQLite databases

查看:1274
本文介绍了使用Qt和SQLite数据库的并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个非常简单的小应用程序,将使用Qt / SQLite。有时,应用程序将从办公室周围的多台计算机访问共享的SQLite数据库。

I'm working on a very simple small application which will be using Qt/SQLite. Sometimes the application will be accessing shared SQLite databases from multiple computers around the office.

有一种方法来检测

此外,可以通过其他计算机监视数据库的连接(所以他们知道谁在编辑数据库该数据库)?

Also, can connections to the DB be monitored by other computers (so they know who's editing the DB)?

理想情况下,我不想在数据库中为协作目的创建一个单独的表,不值得设置计时器和循环监测活动;我想知道,如果有什么内置的我可以利用,以确保每个人都连接是一直在同一页上有效的方式。

Ideally, I don't want to create a separate table in the database for 'collaborative' purposes, and it's not worth setting up timers and loops just to monitor activity; I'd just like to know if there's anything built-in I could leverage to make sure everyone connected is always 'on the same page' in an efficient way.

最后一个手段,会Qt信号监测SQLite数据库文件的最后修改时间是一个可靠的方法来跟踪是否有更新,或者Qt SQLite驱动程序倾向于触摸数据库文件之外的SQL事务?

As a last resort, would a Qt signal monitoring the SQLite database files' last modification time be a reliable way to track if there has been an update, or does the Qt SQLite driver tend to touch the database file outside of SQL transactions?

推荐答案

我同意这将是非常好的,如果这很容易,但它不是。 SQLite不提供任何直接提供这种功能的机制。 sqlite3_update_hook 系统只监视必须在监视进程中的一个连接。

I agree that it'd be very nice if this were easy, but it isn't. SQLite doesn't provide any mechanisms to directly provide such functionality. The sqlite3_update_hook system only monitors one connection that must be within the monitoring process.

您可以做的是创建本地分布式通知系统。大致:

What you could do is to create a local distributed notification system. Roughly:


  1. 创建一个调用自定义SQLite函数的SQL触发器。

  1. Create an sql trigger that calls a custom SQLite function.

自定义SQLite函数将一个事件发布到一些通知程序 QObject 。这需要通过 extern'C'{...} 存根。

The custom SQLite function posts an event to some notifier QObject. This needs to be done via an extern 'C' {...} stub.

通知程序 QObject 在本地子网上广播什么已更改和在哪里。

The notifier QObject broadcasts on the local subnet what has changed and where. This can be picked up by all of your applications running on the network.

如果你真的很聪明,你可以拥有一个自定义代理模型在接收通知并发送相关信号的sqlite模型之上。

If you want to be really, really clever, you can have a custom proxy model on top of the sqlite model that receives the notifications and sends relevant signals.

这整个事情可以非常,非常简单,如果你是一个特定的情况,不是一个一般的解决方案。这听起来很复杂:)如果你想看看可能会涉及到否则,看此处

This whole thing can be very, very simple, if you're after a particular case, not a general solution. It only sounds complicated :) If you want to see what might be involved otherwise, look here.

这篇关于使用Qt和SQLite数据库的并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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