是否可以监听关系型数据库的更新?

发布于 2024-08-25 05:39:38 字数 204 浏览 5 评论 0原文

是否可以监听关系数据库更新?例如,我的网络应用程序想要通过 Comet 技术向客户端发送数据更新。我可以让程序定期轮询数据库,但这不会具有高性能和可扩展性。

如果应用程序可以覆盖数据库的“事件处理程序”,那么每次更新给定的数据库表数据时,应用程序都可以收到通知。这听起来更有希望,但我没有找到任何具体的例子。这是侦听器模式。

常见的关系型数据库支持这样的功能吗?

Is it possible to listen to relation database update? For example, my web app want to send data update to client through Comet technology. I can have the program to poll the database periodically, but that would not be performant and scalable.

If app can hood to a "event handler" of database, then app can get notification every time given database table data is updated. This sounds more promising, but I didn't find any concrete example for it. This is listener pattern.

Does common relational database support such feature?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒中人 2024-09-01 05:39:38

MS SQL Server 自 2005 年起就有查询更改通知。以下是有关如何使用该功能的更多信息:http://msdn.microsoft.com/en-us/library/ms175110.aspx

我认为 Oracle 从 10g 版本开始就已经有了这个。以下是更多信息:http://download.oracle。 com/docs/cd/B19306_01/appdev.102/b14251/adfns_dcn.htm

我不知道有任何其他常见的 RDBMS 支持此功能。

MS SQL Server has had query change notifications since 2005. Here's more information on how to use the feature: http://msdn.microsoft.com/en-us/library/ms175110.aspx

Oracle has had this since version 10g, I think. Here's more information: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_dcn.htm

I don't know of any other common RDBMSes that support this.

━╋う一瞬間旳綻放 2024-09-01 05:39:38

这绝对是非标准的,所以总的来说答案是否定的。一些数据库(Oracle、SQL Server)已经提出了专有的解决方案(就像许多其他情况一样 - SQL 标准在某些情况下受到严重限制)。

但最后,它仍然在轮询。对不起。数据库无法将事件转发给应用程序。

对于 SQL Server,更改通知将是 SQL SERVER 上消息队列中的一个条目(使用 SQL Server 消息代理),并且您仍然需要轮询该队列。

也就是说,可以使用“长轮询” - 您启动一个单独的线程,询问数据库下一次更改......阻塞(等待)直到它发生。

使用

WAITFOR (RECEIVE * FROM MyQueue);

语法风格。该请求将被阻塞,直到基本上收到一些东西。

现在,如果您使用像 MySQL 这样的“通用”数据库 - 我认为您已经完成了。如:不支持。这绝对是更高端的企业特征。

It is definitely non-standard so in general the answer is NO. Some databases (Oracle, SQL Server) have come up with proprietary solutions (like also for so many other cases - the SQL standard is seriously limited in some scenarios).

At the end, though, it STILL is polling. Sorry. There is no way for the database to forward the event to the application.

In case of SQL Server, the change notification will be an entry in a message queue on SQL SERVER (using the SQL Server message broker) and you still have to poll the queue.

That said, a "long poll" can be used - you start a separae thread that asks the database for the next change.... blocking (waiting) until it happens.

Using the

WAITFOR (RECEIVE * FROM MyQueue);

style of syntax. the request will block until basicallly something is received.

Now, if you use "common" databases like MySQL - I think you are done. As in: no support. It is definitely a higher end enterprise geature.

触ぅ动初心 2024-09-01 05:39:38

您可以查看Firebird事件

You can take a look at Firebird event

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文