I'm trying to execute (migrate) SQL scripts (MariaDB flavour). I am using Flyway in order to run the scripts. However, some scripts fail...
The script which fails:
CREATE TRIGGER my_cool_trigger
BEFORE UPDATE ON my_db
FOR EACH ROW
BEGIN
DECLARE n INT;
SET n = (SELECT COUNT(uuid) FROM my_db WHERE uuid != NEW.uuid AND a_uuid = NEW.a_uuid AND number = NEW.number AND event_id IS NULL AND t_begin < NEW.t_end AND t_end > NEW.t_begin);
IF n > 0 THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Oof. ERROR!!!';
END IF;
END;
Error message:
Migration cool_script.sql failed ------------------------------------------------------ SQL State : 42000 Error Code : 1064 Message : (conn=2661) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 6
When I try to execute the same scripts thru Java (they are run as Prepared Statements, sent over JDBC to MariaDB) everything goes as planned without any errors.
Java:
connection.prepareStatement(sql).execute();
I can really not explain to myself why that is happening.