Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger delimiter problem (again?) #3894

Open
peterhalicky opened this issue May 14, 2024 · 0 comments
Open

Trigger delimiter problem (again?) #3894

peterhalicky opened this issue May 14, 2024 · 0 comments

Comments

@peterhalicky
Copy link

peterhalicky commented May 14, 2024

Using FlyWay 10.13.0 community, Java API client, MariaDB 10.6.16, running on MacOS (I don't think this one's relevant though).

I'm running the following migration:

CREATE TABLE TABLE1
(
    id       INT auto_increment NOT NULL,
    tenantId INT                NOT NULL,
    CONSTRAINT TABLE1_PK PRIMARY KEY (id)
);

CREATE TABLE TABLE2
(
    userId   varchar(100) NOT NULL,
    tenantId INT          NOT NULL,
    CONSTRAINT TABLE2_PK PRIMARY KEY (userId, tenantId)
);

CREATE OR REPLACE TRIGGER TABLE1_before_insert
    BEFORE INSERT
    ON TABLE1
    FOR EACH ROW
BEGIN
    IF NOT EXISTS(SELECT ut.tenantId FROM TABLE2 ut WHERE ut.tenantId = NEW.tenantId AND ut.userId = @param_user_id)
    THEN
        SIGNAL SQLSTATE '45000'
            SET MESSAGE_TEXT = 'Not allowed';
    END IF;
END

And it fails with the following:

org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException: Script V01__bug.sql failed
--------------------------
SQL State  : 42000
Error Code : 1064
Message    : (conn=4) 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 9
Location   : /Users/peto/Documents/src/emark/inphinity-app/sql-script-test/src/test/resources/flyway-bug/V01__bug.sql (/Users/peto/Documents/src/emark/inphinity-app/sql-script-test/src/test/resources/flyway-bug/V01__bug.sql)
Line       : 15
Statement  : CREATE OR REPLACE TRIGGER TABLE1_before_insert
    BEFORE INSERT
    ON TABLE1
    FOR EACH ROW
BEGIN
    IF NOT EXISTS(SELECT ut.tenantId FROM TABLE2 ut WHERE ut.tenantId = NEW.tenantId AND ut.userId = @param_user_id)
    THEN
        SIGNAL SQLSTATE '45000'
            SET MESSAGE_TEXT = 'Not allowed'


	at org.flywaydb.core.internal.command.DbMigrate.doMigrateGroup(DbMigrate.java:387)
	at org.flywaydb.core.internal.command.DbMigrate.lambda$applyMigrations$1(DbMigrate.java:277)
	at org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate.execute(TransactionalExecutionTemplate.java:59)
	at org.flywaydb.core.internal.command.DbMigrate.applyMigrations(DbMigrate.java:276)
	at org.flywaydb.core.internal.command.DbMigrate.migrateGroup(DbMigrate.java:249)
	at org.flywaydb.core.internal.command.DbMigrate.lambda$migrateAll$0(DbMigrate.java:144)
	at org.flywaydb.database.mysql.MySQLNamedLockTemplate.execute(MySQLNamedLockTemplate.java:62)
	at org.flywaydb.database.mysql.MySQLConnection.lock(MySQLConnection.java:154)
	at org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory.lock(JdbcTableSchemaHistory.java:149)
	at org.flywaydb.core.internal.command.DbMigrate.migrateAll(DbMigrate.java:144)
	at org.flywaydb.core.internal.command.DbMigrate.migrate(DbMigrate.java:102)
	at org.flywaydb.core.Flyway.lambda$migrate$0(Flyway.java:211)
	at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:210)
	at org.flywaydb.core.Flyway.migrate(Flyway.java:156)
	at xyz.inphinity.sql.TestFlywayOnMariaDB.testFlyway(TestFlywayOnMariaDB.java:37)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: org.flywaydb.core.internal.sqlscript.FlywaySqlScriptException: Script V01__bug.sql failed
--------------------------
SQL State  : 42000
Error Code : 1064
Message    : (conn=4) 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 9
Location   : /Users/peto/Documents/src/emark/inphinity-app/sql-script-test/src/test/resources/flyway-bug/V01__bug.sql (/Users/peto/Documents/src/emark/inphinity-app/sql-script-test/src/test/resources/flyway-bug/V01__bug.sql)
Line       : 15
Statement  : CREATE OR REPLACE TRIGGER TABLE1_before_insert
    BEFORE INSERT
    ON TABLE1
    FOR EACH ROW
BEGIN
    IF NOT EXISTS(SELECT ut.tenantId FROM TABLE2 ut WHERE ut.tenantId = NEW.tenantId AND ut.userId = @param_user_id)
    THEN
        SIGNAL SQLSTATE '45000'
            SET MESSAGE_TEXT = 'Not allowed'

	at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.handleException(DefaultSqlScriptExecutor.java:252)
	at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.executeStatement(DefaultSqlScriptExecutor.java:214)
	at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.execute(DefaultSqlScriptExecutor.java:136)
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.executeOnce(SqlMigrationExecutor.java:69)
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.lambda$execute$0(SqlMigrationExecutor.java:61)
	at org.flywaydb.core.internal.database.DefaultExecutionStrategy.execute(DefaultExecutionStrategy.java:31)
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:60)
	at org.flywaydb.core.internal.command.DbMigrate.doMigrateGroup(DbMigrate.java:379)
	... 17 more
Caused by: java.sql.SQLSyntaxErrorException: (conn=4) 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 9
	at org.mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:289)
	at org.mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:378)
	at org.mariadb.jdbc.message.ClientMessage.readPacket(ClientMessage.java:172)
	at org.mariadb.jdbc.client.impl.StandardClient.readPacket(StandardClient.java:915)
	at org.mariadb.jdbc.client.impl.StandardClient.readResults(StandardClient.java:854)
	at org.mariadb.jdbc.client.impl.StandardClient.readResponse(StandardClient.java:773)
	at org.mariadb.jdbc.client.impl.StandardClient.execute(StandardClient.java:697)
	at org.mariadb.jdbc.Statement.executeInternal(Statement.java:1035)
	at org.mariadb.jdbc.Statement.execute(Statement.java:1165)
	at org.mariadb.jdbc.Statement.execute(Statement.java:493)
	at org.flywaydb.core.internal.jdbc.JdbcTemplate.executeStatement(JdbcTemplate.java:210)
	at org.flywaydb.core.internal.sqlscript.ParsedSqlStatement.execute(ParsedSqlStatement.java:88)
	at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.executeStatement(DefaultSqlScriptExecutor.java:209)
	... 23 more

Seems to me that issue #2666 is either back or wasn't fixed quite correctly. (The script works when launched through other tool, IntelliJ IDEA's DB query console in my case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant