Hello to all.
I'm using MySQL with ZEOS and I need to catch some events from MySQL. I would like to know if is it possible to know when a table have been modified (insert, delete or just update a record) for refreshing the data.
The application that I'm developing is going to be used by several users, so I need to know when the data are modified by other user in order to refresh the dbgrid.
Thanks in advance.
Anthony.
How to catch events from MySQL?
Moderators: gto, cipto_kh, EgonHugeist
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
Not supported by mysql as far as I know.
You could add triggers to your database table to monitor changes and insert/update records into a log table or a 'last changed' (one entry per monitored table) table. In your app you need to refresh a separate query against this log table every X seconds.
Mark
You could add triggers to your database table to monitor changes and insert/update records into a log table or a 'last changed' (one entry per monitored table) table. In your app you need to refresh a separate query against this log table every X seconds.
Mark
Hi TonyG.
MySQL supports triggers for a long time now. Please see the manual.
DROP TABLE IF EXISTS Capital;
CREATE TABLE Capital
SELECT Country.Name AS Country, City.Name AS Capital,
City.Population
FROM Country, City
WHERE Country.Capital = City.ID;
delimiter //
CREATE TRIGGER Capital_bi
BEFORE INSERT
ON Capital
FOR EACH ROW
SET NEW.Population =
IF(NEW.Population < 0, 0, TRUNCATE(NEW.Population,-3));
//
delimiter ;
INSERT INTO Capital VALUES
('CountryA','CityA',-39),
('CountryB','CityB',123456);
Regards, Tonci
MySQL supports triggers for a long time now. Please see the manual.
DROP TABLE IF EXISTS Capital;
CREATE TABLE Capital
SELECT Country.Name AS Country, City.Name AS Capital,
City.Population
FROM Country, City
WHERE Country.Capital = City.ID;
delimiter //
CREATE TRIGGER Capital_bi
BEFORE INSERT
ON Capital
FOR EACH ROW
SET NEW.Population =
IF(NEW.Population < 0, 0, TRUNCATE(NEW.Population,-3));
//
delimiter ;
INSERT INTO Capital VALUES
('CountryA','CityA',-39),
('CountryB','CityB',123456);
Regards, Tonci
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
Hi Tonci,
This is not what 'Firebird events' is about. Firebird events are signals the server sends to a client that requested to be notified. They can be fired by triggers or stored procedures.
Mysql only sends data to the client if that client first asks something. So you have to write a query to poll the server if there is some message waiting in a queue (which can be put there by triggers, inserts, ...).
I think technically this is more or less the same for Firebird, but there the mechanism of saving messages on the server until polled by the client and the automatic polling is build in. (I may be technically wrong about this, but I think the explanation will do to understand the difference.)
Mark
This is not what 'Firebird events' is about. Firebird events are signals the server sends to a client that requested to be notified. They can be fired by triggers or stored procedures.
Mysql only sends data to the client if that client first asks something. So you have to write a query to poll the server if there is some message waiting in a queue (which can be put there by triggers, inserts, ...).
I think technically this is more or less the same for Firebird, but there the mechanism of saving messages on the server until polled by the client and the automatic polling is build in. (I may be technically wrong about this, but I think the explanation will do to understand the difference.)
Mark
Mark.
"I would like to know if is it possible to know when a table have been modified (insert, delete or just update a record) for refreshing the data."
I would say trigger would serve here just fine, possibly adding record to some temporary table which I can then pool from my code.
Anyway, I suck in most other servers but expensive ones.
Regards, Tonci.
"I would like to know if is it possible to know when a table have been modified (insert, delete or just update a record) for refreshing the data."
I would say trigger would serve here just fine, possibly adding record to some temporary table which I can then pool from my code.
Anyway, I suck in most other servers but expensive ones.
Regards, Tonci.