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 Flyway parse error caused by comment block containing flyway configuration items #3862

Open
Phil-Factor opened this issue Mar 22, 2024 · 6 comments

Comments

@Phil-Factor
Copy link

Phil-Factor commented Mar 22, 2024

Which version and edition of Flyway are you using?

10.10.1

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

CLI

Which database are you using? (Type & version)

SQL Server 2017

Which operating system are you using?

Windows 10

What did you expect to see?

I have a SQL Callback called afterInfo__Toggle.sql 'that used to work fine but now triggers an error

What did you see instead?

flyway : ERROR: Unable to parse statement in .\migrations\Callbacks\afterInfo__Toggle.sql at line 1 col 1. See https://rd.gt/3ipi7Pm for more
information. Input length = 1
At line:1 char:1

  • flyway info
  •   + CategoryInfo          : NotSpecified: (ERROR: Unable t...nput length = 1:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    

Caused by: java.nio.charset.MalformedInputException: Input length = 1

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)

It was a callback that used to run I expected it to run without an error as it used to in a previous version

/*
Before this code can be used in a callback, you must have the following
default value for flyway.placeholders.Toggle set in the project flyway.conf
otherwise you'll get an error.
flyway.placeholders.Toggle=Yes
To turn the toggle on, use flyway.placeholders.Turnit=on otherwise
flyway.placeholders.Turnit=on
in the commandline, this will look like …
flyway info '-placeholders.Toggle=Yes' '-placeholders.Turnit=on'
You will, of course, need to add the DCL code that adds or removes
membership of the users roles (e.g. HR, Accounts) to the role that
allows access

*/

IF ('${Toggle}' = 'Yes')
BEGIN --only execute this if flyway.placeholders.Toggle=Yes
IF ('on' = '${TurnIt}') --if flyway.placeholders.Turnit=on
BEGIN /* the start of the block that you excecute to switch
the toggle on */ SELECT 'We have executed the code for turning the feature on'; END; ELSE IF ('off' = '${TurnIt}')--if flyway.placeholders.Turnit=off BEGIN /* the start of the block that you excecute to switch
the toggle off */
SELECT 'We have executed the code for turning the feature off';
END;
ELSE
BEGIN
SELECT 'We couldn''t recognise your ''${TurnIt}'' instructiions';
END;
END;

What did you expect to see?

A callback executed as usual

What did you see instead?

The error message reproduced above

@JasonLuo-Redgate
Copy link

Hi @Phil-Factor ,

I looked into the issue posted and here are my findings:

  • I copied the exact afterInfo__Toggle.sql file, but I got a different error message: Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'the'.

  • This was caused by this line --if flyway.placeholders.Turnit=off BEGIN /* the start of the block that you excecute to switch. The root cause is that the -- commented out the following BEGIN key word since they are in the same line.

  • After fixing that (Start a new line for that BEGIN key word), the statement works fine now.

image

@Phil-Factor
Copy link
Author

Phil-Factor commented Mar 27, 2024

My sample somehow got mangled during the paste-in process, The code used to work fine and hasn't changed. All I did was to upgrade flyway. Obviously, when the error happened, I removed the initial comment block and it then worked fine.

/*
Before this code can be used in a callback, you must have the following
default value for flyway.placeholders.Toggle set in the project flyway.conf
otherwise you'll get an error.
	flyway.placeholders.Toggle=Yes 
To turn the toggle on, use flyway.placeholders.Turnit=on otherwise
flyway.placeholders.Turnit=on
in the commandline, this will look like …
flyway info '-placeholders.Toggle=Yes' '-placeholders.Turnit=on' 
You will, of course, need to add the DCL code that adds or removes
membership of the users roles (e.g. HR, Accounts) to the role that
allows access

*/

IF ('${Toggle}' = 'Yes')
  BEGIN --only execute this if flyway.placeholders.Toggle=Yes
    IF ('on' = '${TurnIt}') --if flyway.placeholders.Turnit=on
      BEGIN /* the start of the block that you excecute to switch
	  the toggle on */
        SELECT 'We have executed the code for turning the feature on';
      END;
    ELSE IF ('off' = '${TurnIt}')--if flyway.placeholders.Turnit=off
      BEGIN /* the start of the block that you excecute to switch
	  the toggle off */
        SELECT 'We have executed the code for turning the feature off';
      END;
    ELSE
      BEGIN
        SELECT 'We couldn''t recognise your ''${TurnIt}'' instructiions';
      END;
  END;

@Phil-Factor
Copy link
Author

Phil-Factor commented Apr 3, 2024

{
"error": {
"errorCode": "ERROR",
"message": "Unable to parse statement in .\migrations\Callbacks\afterInfo__Toggle.sql at line 1 col 1. See https://rd.gt/3ipi7Pm for more information. Input length = 1",
"stackTrace": null,
"lineNumber": null,
"path": null,
"cause": {
"message": "Input length = 1",
"stackTrace": "java.nio.charset.MalformedInputException: Input length = 1\r\n\tat java.base/java.nio.charset.CoderResult.throwException(Unknown Source)\r\n\tat java.base/sun.nio.cs.StreamDecoder.implRead(Unknown Source)\r\n\tat java.base/sun.nio.cs.StreamDecoder.read(Unknown Source)\r\n\tat java.base/java.io.BufferedReader.fill(Unknown Source)\r\n\tat java.base/java.io.BufferedReader.read(Unknown Source)\r\n\tat org.flywaydb.core.internal.parser.UnboundedReadAheadReader.read(UnboundedReadAheadReader.java:55)\r\n\tat java.base/java.io.FilterReader.read(Unknown Source)\r\n\tat org.flywaydb.core.internal.util.BomStrippingReader.read(BomStrippingReader.java:40)\r\n\tat java.base/java.io.FilterReader.read(Unknown Source)\r\n\tat org.flywaydb.core.internal.parser.PlaceholderReplacingReader.read(PlaceholderReplacingReader.java:117)\r\n\tat java.base/java.io.FilterReader.read(Unknown Source)\r\n\tat org.flywaydb.core.internal.parser.PositionTrackingReader.read(PositionTrackingReader.java:33)\r\n\tat java.base/java.io.FilterReader.read(Unknown Source)\r\n\tat org.flywaydb.core.internal.parser.RecordingReader.read(RecordingReader.java:33)\r\n\tat java.base/java.io.FilterReader.read(Unknown Source)\r\n\tat org.flywaydb.core.internal.parser.PeekingReader.refillPeekBuffer(PeekingReader.java:73)\r\n\tat org.flywaydb.core.internal.parser.PeekingReader.peek(PeekingReader.java:187)\r\n\tat org.flywaydb.core.internal.parser.PeekingReader.peek(PeekingReader.java:169)\r\n\tat org.flywaydb.core.internal.parser.Parser.readToken(Parser.java:470)\r\n\tat org.flywaydb.core.internal.parser.Parser.getNextStatement(Parser.java:171)\r\n\tat org.flywaydb.core.internal.parser.Parser$ParserSqlStatementIterator.next(Parser.java:733)\r\n\tat org.flywaydb.core.internal.parser.Parser$ParserSqlStatementIterator.next(Parser.java:698)\r\n\tat org.flywaydb.core.internal.sqlscript.ParserSqlScript.parse(ParserSqlScript.java:71)\r\n\tat org.flywaydb.core.internal.sqlscript.ParserSqlScript.validate(ParserSqlScript.java:112)\r\n\tat org.flywaydb.core.internal.sqlscript.ParserSqlScript.executeInTransaction(ParserSqlScript.java:177)\r\n\tat org.flywaydb.core.internal.callback.SqlScriptCallbackFactory$SqlScriptCallback.canHandleInTransaction(SqlScriptCallbackFactory.java:107)\r\n\tat org.flywaydb.core.internal.callback.DefaultCallbackExecutor.execute(DefaultCallbackExecutor.java:118)\r\n\tat org.flywaydb.core.internal.callback.DefaultCallbackExecutor.onEvent(DefaultCallbackExecutor.java:66)\r\n\tat org.flywaydb.core.internal.command.DbInfo.info(DbInfo.java:56)\r\n\tat org.flywaydb.core.Flyway.lambda$info$1(Flyway.java:227)\r\n\tat org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:205)\r\n\tat org.flywaydb.core.Flyway.info(Flyway.java:226)\r\n\tat org.flywaydb.commandline.Main.executeOperation(Main.java:265)\r\n\tat org.flywaydb.commandline.Main.executeFlyway(Main.java:171)\r\n\tat org.flywaydb.commandline.Main.main(Main.java:114)\r\n",
"cause": null
}
}
}

@JasonLuo-Redgate
Copy link

JasonLuo-Redgate commented Apr 4, 2024

Hi @Phil-Factor ,

I have copied the exact new text format you posted, but I couldn't reproduce this error.
The SQL Callback is running fine locally.

image

image

@Phil-Factor
Copy link
Author

It looks like it's been fixed then. I'll upgrade to Flyway 10.11.1 and try it again

@JasonLuo-Redgate
Copy link

Many thanks @Phil-Factor. I will keep this ticket open for a while and welcome to raise any questions if this issue persists.

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

No branches or pull requests

2 participants