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

bigslack opened this issue Aug 30, 2013 · 2 comments

Parse error with mysql string literal that ends in an escaped backslash #594

bigslack opened this issue Aug 30, 2013 · 2 comments


Copy link

@bigslack bigslack commented Aug 30, 2013

Using Flyway API for v2.2.1.

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


CREATE TABLE `bug_test` (
  `description` varchar(255) NOT NULL

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, "''", "");
Copy link

@mjiderhamn mjiderhamn commented Sep 10, 2013

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\\ '));
Copy link

@axelfontaine axelfontaine commented Sep 12, 2013

Once again, thank you so much Adam!

I've added you to the hall of fame:


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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.