Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i notify my C or C++ application program when an update or changes happens in mysql database

Tags:

c++

c

mysql

How can i notify my C or C++ application program when an update or changes happens in mysql database. Are there any special libraries serving this purpose?

like image 357
valmiki Avatar asked Sep 17 '25 04:09

valmiki


1 Answers

There isn't one out-of-the-box feature in MySQL to do this. But it is definitely possible. The following is not a step-by-step instruction, but rather the route to take.

  1. Create a UDF (user-defined function) for MySQL that does something that you can catch with your application, e.g. send a message over network. Here is an example of an UDF that can send STOMP messages. I'm sure you can adapt that to meet your needs.

  2. Implement the corresponding "receive messages" functionality into your application. For example, if your UDF sends messages over a socket, make your application listen to that socket.

  3. Create a trigger that fires on the events that you're trying to catch (e.g. certain UPDATEs). This trigger can call your UDF from step 1 to send messages to your application (which you'll receive thanks to step 2).

like image 161
Carsten Avatar answered Sep 19 '25 18:09

Carsten