I have a perfectly working trigger. As I'm adding in more tests I'm finding that I want to alter this trigger to dynamically select the database based on the current database. In production this trigger resided in database rdata
and talks to default
. However in testing the trigger resides in test_rdata
and talks to test_default
. How can I modify the below trigger to dynamically select the right database
DROP TRIGGER IF EXISTS `af_rdata_data_trigger_4` $$
CREATE TRIGGER af_rdata_data_trigger_4
AFTER INSERT on Results FOR EACH ROW
BEGIN
DECLARE project_id INT;
-- Do this first - another table may have already created it..
INSERT INTO default.rdata_project (`user`,`result_number`, `created_on`)
VALUES (USER(), NEW.LBLDGRUNNO, NOW()) ON DUPLICATE KEY UPDATE last_update=NOW();
-- Now push in our values
-- THIS IS WHAT NEEDS TO BE DYNAMIC!!
UPDATE default.rdata_project project JOIN Results
ON project.result_number = Results.LBLDGRUNNO SET
project.annual_total_cost = Results.FTOTCOST
WHERE project.result_number=NEW.LBLDGRUNNO;
END$$
DELIMITER ;
Thanks much!