Skip to content

Dumping triggers with semicolon separated statements #76

@MalteWunsch

Description

@MalteWunsch

When slimdumping a table with triggers that contain semicolon separated statements, these semicolons are not escaped. slimdump would output something like this:

-- BEGIN TRIGGERS mytable
CREATE TRIGGER `mytrigger`
    AFTER INSERT ON `mytable`
    FOR EACH ROW
    BEGIN
        DECLARE myvariable INT;
        SET myvariable = (SELECT COUNT(*) FROM othertable);
        IF (myvariable = 0) THEN
            ...;
        END IF;
    END;

Result is a syntax error.

The usual solution for that is to set a custom delimiter. E.g. using mysqldump gives something like this:

DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`test`@`localhost`*/ /*!50003 TRIGGER `mytrigger`
    AFTER INSERT ON `mytable`
    FOR EACH ROW
    BEGIN
        DECLARE myvariable INT;
        SET myvariable = (SELECT COUNT(*) FROM othertable);
        IF (myvariable = 0) THEN
            ...;
        END IF;
    END */;;
DELIMITER ;

(I'm not sure what the comments are about)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions