MySQL回调-有这样的事情吗?
我想知道在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建在插入时调用的触发器更新。它们不返回值,但可以设置您可以在其外部读取的变量。
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.
正如您所说,我不知道有任何回调,但肯定可以从您的调用应用程序中检索最后插入的 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...
这在目前的 MySQL 中不可用。我认为有两种方法可以实现这一目标:
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:
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