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 an escaped backslash #594

Closed
bigslack opened this issue Aug 30, 2013 · 2 comments
Closed

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 ('C\\');
--this part gets executed too along with above statement

When Flyway goes runs MySQLSqlStatementBuilder.removeEscapedQuotes(token) on the token 'C\\' the result is 'C\ instead of 'C'. This leads to not having a closing TokenType.QUOTE to terminate the literal and it doesn't turn out well.

A possible solution would be to removed escaped backslashes before attempting to remove escaped quotes and double quotes. i.e.

protected String removeEscapedQuotes(String token) {
        String noEscapedBackslashes = StringUtils.replaceAll(token, "\\\\","");
        String noBackslashEscapes = StringUtils.replaceAll(StringUtils.replaceAll(noEscapedBackslashes, "\\'", ""), "\\\"", "");
        return StringUtils.replaceAll(noBackslashEscapes, "''", "");
    }
@mjiderhamn
Copy link

I ran into this issue too, and worked around it by adding a space between the escaped backslash and the quote, and then trimming that space with RTRIM(). In the above example that would be

INSERT INTO `bug_test` VALUES (RTRIM('C\\ '));

@axelfontaine
Copy link
Contributor

Once again, thank you so much Adam!

I've added you to the hall of fame: http://flywaydb.org/contribute/hallOfFame.html

Cheers
Axel

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

3 participants