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.
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.
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...
This isn't available in MySQL as it stands. I think there are two methods to achieve this:
- You would have to simulate it with polling - a rather ugly method, easy on the programming but tough on the server.
- 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.
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
精彩评论