Skip to content

Commit

Permalink
Fixed flyway#2011: SQL Server parsing issue when string literal is fo…
Browse files Browse the repository at this point in the history
…llowed by as keyword without a space in between
  • Loading branch information
Axel Fontaine committed May 17, 2018
1 parent fce4a4c commit 52dc199
Showing 1 changed file with 11 additions and 1 deletion.
Expand Up @@ -29,7 +29,12 @@ public class SQLServerSqlStatementBuilder extends SqlStatementBuilder {
/**
* Regex for keywords that can appear before a string literal without being separated by a space.
*/
private static final Pattern KEYWORDS_BEFORE_STRING_LITERAL_REGEX = Pattern.compile("^(LIKE)('.*)");
private static final Pattern KEYWORDS_BEFORE_STRING_LITERAL_REGEX = Pattern.compile("^(LIKE|AS)('.*)");

/**
* Regex for keywords that can appear after a string literal without being separated by a space.
*/
private static final Pattern KEYWORDS_AFTER_STRING_LITERAL_REGEX = Pattern.compile("(.*')(LIKE|AS)");

private static final Pattern NON_TRANSACTIONAL_STATEMENT_REGEX = Pattern.compile("^(BACKUP|RESTORE|(CREATE|DROP|ALTER) DATABASE) .*");

Expand Down Expand Up @@ -75,6 +80,11 @@ protected String cleanToken(String token) {
token = beforeMatcher.group(2);
}

Matcher afterMatcher = KEYWORDS_AFTER_STRING_LITERAL_REGEX.matcher(token);
if (afterMatcher.find()) {
token = afterMatcher.group(1);
}

return token;
}
}

0 comments on commit 52dc199

Please sign in to comment.