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

SQL Server: Incorrect syntax error using GOTO and Labels #2307

Closed
rglidden opened this issue Feb 15, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@rglidden
Copy link

commented Feb 15, 2019

Which version and edition of Flyway are you using?

Flyway Pro Edition (20 schemas) 6.0.0-beta

If this is not the latest version, can you reproduce the issue with the latest one as well?

(Many bugs are fixed in newer releases and upgrading will often resolve the issue)

Issue only occurs in 6.0.0 Beta. 5.2.4 works properly.

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Command-Line

Which database are you using (type & version)?

SQL Server 2017 Developer Edition

Which operating system are you using?

Windows 10

What did you do?

We have a stored procedure that (unfortunately) uses a GOTO statement and a label. When the migration to create the stored procedure is executed via Flyway 6.0.0-beta, it gives an 'Incorrect syntax' error.

Here is a small sample script that will also reproduce the same issue. This works in Flyway 5.2.4 as well as SQL Server Management Studio.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE OR ALTER PROCEDURE [dbo].[Test_Goto]
AS
BEGIN
    SET NOCOUNT ON;
    DECLARE @MyVar INT;
    SET @MyVar = 1;

    IF (@MyVar = 1)
    BEGIN
        GOTO Label
        PRINT 'This will not be printed.';
    END;

Label:
    PRINT 'This will always be printed';
END;
What did you expect to see?
Migrating schema [dbo] with repeatable migration dbo.Test Goto
Successfully applied 1 migrations to schema [dbo] (execution time 00:00.074s)
What did you see instead?
Migrating schema [dbo] with repeatable migration dbo.Test Goto
ERROR: Migration of schema [dbo] with repeatable migration dbo.Test Goto failed! Changes successfully rolled back.
ERROR:
Migration R__dbo.Test_Goto.sql failed
-------------------------------------
SQL State  : S0001
Error Code : 102
Message    : Incorrect syntax near 'BEGIN'.
Location   : sql\Stored Procedures\R__dbo.Test_Goto.sql (C:\git\CATSA_BPSS\Database\Flyway\sql\Stored Procedures\R__dbo.Test_Goto.sql)
Line       : 5
Statement  : CREATE OR ALTER PROCEDURE [dbo].[Test_Goto]
AS
BEGIN
    DECLARE @MyVar INT;

    BEGIN
@axelfontaine

This comment has been minimized.

Copy link
Contributor

commented Feb 15, 2019

Thank you for giving the beta a spin. This will be fixed in time for GA.

axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Mar 14, 2019

@axelfontaine

This comment has been minimized.

Copy link
Contributor

commented Mar 14, 2019

Thanks again for your very clear bug report and detailed analysis. This was a tremendous help in fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.