I was running an older version of 5.1.7 beta so I figured the best course of action was to upgrade to 5.1.11 beta.
Well the problem still exists, and I found that the cause was due to the syntax of the DELIMITER command. Assuming the creation of the schema tables, here is an example of what I found.
Running in an interactive mysql session the following works
DROP TRIGGER ins_film; DELIMITER ;; CREATE TRIGGER `ins_film` AFTER INSERT ON `film` FOR EACH ROW BEGIN INSERT INTO film_text (film_id, title, description) VALUES (new.film_id, new.title, new.description); END;; DELIMITER ;
On a side note, why does DROP TRIGGER not contain the IF EXISTS syntax like DROP DATABASE and DROP TABLE. It’s a shame, it’s a nice SQL extension that MySQL provides.
Now running the same SQL in a mysqltest test (with appropiate create tables) produces the following error
TEST RESULT ------------------------------------------------------- sakila-trigger [ fail ] Errors are (from /opt/mysql/mysql-test/var/log/mysqltest-time) : mysqltest: At line 53: Extra delimiter "" found (the last lines may be the most important ones)
It seems, that the DELIMITER command within mysql accepts a line terminator as a statement terminator, while in mysqltest, this is not so.
The solution is to be more strict in the mysqltest, using the following syntax, note the first and list DELIMITER lines are terminated by the appropiate delimiter in use.
DELIMITER //; CREATE TRIGGER `ins_film` AFTER INSERT ON `film` FOR EACH ROW BEGIN INSERT INTO film_text (film_id, title, description) VALUES (new.film_id, new.title, new.description); END// DELIMITER ;//
Surprisingly, this syntax does then not work in mysql? Is this a bug? I’m note sure, perhaps somebody could let me know.