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

Parse error with mysql string literal that ends in b' or x' #593

Closed
bigslack opened this issue Aug 29, 2013 · 1 comment
Closed

Parse error with mysql string literal that ends in b' or x' #593

bigslack opened this issue Aug 29, 2013 · 1 comment

Comments

@bigslack
Copy link

Using Flyway API for v2.2.1.

Flyway is throwing an MySQLSyntaxErrorException when I try to run the following script.

DROP TABLE IF EXISTS `bug_test`;

CREATE TABLE `bug_test` (
  `description` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `bug_test` VALUES (' X');

--comment here

I get the following stack trace:

Exception in thread "main" com.googlecode.flyway.core.api.FlywayException: Migration of schema `gdb-test` to version 2013.0.0.0.1 failed! Please restore backups and roll back database and code!
    at com.googlecode.flyway.core.command.DbMigrate.migrate(DbMigrate.java:199)
    at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:872)
    at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:1)
    at com.googlecode.flyway.core.Flyway.execute(Flyway.java:1200)
    at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:819)
    at com.cmt.test.utils.ConfigUtils.runFlyway(ConfigUtils.java:103)
    at com.cmt.test.utils.ConfigUtils.main(ConfigUtils.java:381)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--comment here' at line 3
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2713)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2663)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:888)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:730)
    at com.googlecode.flyway.core.dbsupport.JdbcTemplate.executeStatement(JdbcTemplate.java:230)
    at com.googlecode.flyway.core.dbsupport.SqlScript.execute(SqlScript.java:89)
    at com.googlecode.flyway.core.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:72)
    at com.googlecode.flyway.core.command.DbMigrate$2.doInTransaction(DbMigrate.java:252)
    at com.googlecode.flyway.core.command.DbMigrate$2.doInTransaction(DbMigrate.java:1)
    at com.googlecode.flyway.core.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:56)
    at com.googlecode.flyway.core.command.DbMigrate.applyMigration(DbMigrate.java:250)
    at com.googlecode.flyway.core.command.DbMigrate.access$7(DbMigrate.java:237)
    at com.googlecode.flyway.core.command.DbMigrate$1.doInTransaction(DbMigrate.java:189)
    at com.googlecode.flyway.core.command.DbMigrate$1.doInTransaction(DbMigrate.java:1)
    at com.googlecode.flyway.core.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:56)
    at com.googlecode.flyway.core.command.DbMigrate.migrate(DbMigrate.java:138)
    ... 6 more

When I turned on debug I noticed that Flyway was trying to execute more than just the statement:

...
[2013-08-29 15:55:05,782] DEBUG SqlScript : Found statement at line 1: DROP TABLE IF EXISTS `bug_test`
[2013-08-29 15:55:05,783] DEBUG SqlScript : Found statement at line 3: CREATE TABLE `bug_test` (
  `description` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
[2013-08-29 15:55:05,784] DEBUG SqlScript : Executing SQL: DROP TABLE IF EXISTS `bug_test`
[2013-08-29 15:55:05,784] DEBUG SqlScript : Executing SQL: CREATE TABLE `bug_test` (
  `description` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
[2013-08-29 15:55:05,848] DEBUG SqlScript : Executing SQL: INSERT INTO `bug_test` VALUES (' X');

--comment here
[2013-08-29 15:55:05,850] DEBUG TransactionTemplate : Rolling back transaction...
[2013-08-29 15:55:05,850] DEBUG TransactionTemplate : Transaction rolled back
...

This behavior works if the string literal ends with a [space]X|B'

My guess it is is related to recent changes to

protected String extractAlternateOpenQuote(String token) {
        if (token.startsWith("\"")) {
            return "\"";
        }
        if (token.startsWith("B'")) {
            return "B'";
        }
        if (token.startsWith("X'")) {
            return "X'";
        }
        return null;
    }

Note: this behavior was not happening in v2.1.1.

@axelfontaine
Copy link
Contributor

Thank you so much for this Adam! Great contribution!

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