jeudi 26 mars 2015

Notification for changed SQL query result

Given a database with multiple tables. I want to have a mechanism that notifies me, when the result of a given query changes.


For example, I have the following two tables



CREATE TABLE employee (
e_id int,
firstname varchar(255),
lastname varchar(255),
d_id int
);

CREATE TABLE department (
d_id int,
name varchar(255)
);


and the query



SELECT firstname
FROM employee
JOIN department
ON employee.d_id = department.d_id
WHERE department.name = "financial";


I want to be notified, when I execute an insert/update/delete command on either employee or department, but only if the command execution changes the result of the query. An operation that does not change the result of the query, e.g. an update of the column lastname should not lead to a notification.


I would like a solution that is independent of the DBMS, but if you know a solution for a specific DBMS don't hesitate to share it :-)


It would be great if the solution would also work for more complex queries, e.g. a query with subqueries and/or aggregate functions.


Another great feature would be prepared statements. For example, when I alter the given query by replacing "financial" by :department_name, I would get a parameterized notification with the department name as parameter.


I know about the trigger mechanism, however it does not seem to solve the problem.


Aucun commentaire:

Enregistrer un commentaire