MySQL回调-有这样的事情吗?

发布于 2024-12-01 22:19:27 字数 73 浏览 0 评论 0原文

我想知道在 INSERT 或 UPDATE 之后是否有相当于使用 mysql 的回调函数的东西,它可以返回我行 # 以及这些行的值。

I was wondering if there's such thing as the equivalent as a callback function using mysql after an INSERT or UPDATE which could return me the row # and maybe values of such rows.

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

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

发布评论

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

评论(3

你的背包 2024-12-08 22:19:27

您可以创建在插​​入时调用的触发器更新。它们不返回值,但可以设置您可以在其外部读取的变量。

You can create triggers that are called on insert and update. They do not return value, but they can set variables you can read outside them.

美男兮 2024-12-08 22:19:27

正如您所说,我不知道有任何回调,但肯定可以从您的调用应用程序中检索最后插入的 ID,以防您没有指定它并且数据库已生成自动增量值。您应该已经知道其他值,因为您已经插入了它们。

如果你需要知道数据库服务器中的这些值,你可以有一个在每次插入时执行的 SQL 触发器,这样你就可以对新插入的记录进行更多处理,例如在另一个表中写入一些内容等...

I am not aware of any callback as you say but surely from your calling application you can retrieve the last inserted ID in case you did not specify it and the db has generated an auto increment value. Other values you should already know because you have inserted them.

if you need to know those values within the database server, you can have a SQL trigger which is executed at every insert so you can do more processing on the newly inserted record, for example write something in another table etc...

鲜血染红嫁衣 2024-12-08 22:19:27

这在目前的 MySQL 中不可用。我认为有两种方法可以实现这一目标:

  1. 您必须使用轮询来模拟它 - 一种相当丑陋的方法,编程简单,但对服务器来说却很困难。
  2. 请参阅

This would be a handy generic UDF for MySQL and bring it something that it has consistently lacked in comparison to Firebird / Interbase, which they call events, not to be confused with MySQL timed events. The timed event feature of MySQL on the other hand is something that Firebird & Interbase lacked the last time I looked at them.

如果您(或后来的读者)决定通过 UDF 进行操作,请参阅此处的 Firebird 事件描述 - 这是一个很好的设计规范:http://www.janus-software.com/fbmanual/manual.php?book=php&topic=49

This isn't available in MySQL as it stands. I think there are two methods to achieve this:

  1. You would have to simulate it with polling - a rather ugly method, easy on the programming but tough on the server.
  2. See Does MySQL permit callbacks in C such that when a change happens, I can be notified? - write a user defined function that could notify a registered listener using some proprietary method of your devising. Tougher on the programmer, easy on the server. In this case make sure your UDF is robust, doesn't freeze while passing a notification to a listener who may have died, etc.

This would be a handy generic UDF for MySQL and bring it something that it has consistently lacked in comparison to Firebird / Interbase, which they call events, not to be confused with MySQL timed events. The timed event feature of MySQL on the other hand is something that Firebird & Interbase lacked the last time I looked at them.

See this for a Firebird event description in case you (or some later reader) decides to do it via UDF - it's a good design spec to aim at: http://www.janus-software.com/fbmanual/manual.php?book=php&topic=49

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