Does MySQL permit callbacks in C such that when a change happens in the database, like an insert, that is performed by a different program or by the user at the command line, I can be notified?
I am guessing that it doesn't, because mysqlclient is a library, not a running thread. But I may as well ask.
Create a trigger like so.
There are triggers for
INSERT
,DELETE
,UPDATE
And they can fire
BEFORE
orAFTER
the action.The trigger
BEFORE
the action can cancel the action by forcing an error, like so.This will prevent deletion of record 1.
A before UPDATE Trigger can even change the values updated.
Hope you'll be Trigger happy.
You can use triggers combined with UDFs (user defined functions) so that the corresponding action on the database executes a trigger that calls a C/C++ function.
Just consider that this mechanism runs your code inside the mysql server process, not in the client side.
Well you could attach a trigger to user defined function, and have it call an external program, that would then notify your code..
http://dev.mysql.com/doc/refman/5.0/en/faqs-triggers.html#qandaitem-B-5-1-10
MySQL's triggers allow you to hook into insert/update/delete queries and do something additional. You could log them in a separate table, for example.