Skip to content

Commit

Permalink
Fix #2577: Snowflake bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MikielAgutu committed Nov 28, 2019
1 parent 81e49e3 commit 77bf492
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,29 @@
package org.flywaydb.core.internal.database.snowflake;

import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.parser.Parser;
import org.flywaydb.core.internal.parser.ParsingContext;
import org.flywaydb.core.internal.parser.*;

import java.io.IOException;

public class SnowflakeParser extends Parser {
public SnowflakeParser(Configuration configuration, ParsingContext parsingContext) {
super(configuration, parsingContext, 2);
}

@Override
protected boolean isAlternativeStringLiteral(String peek) {
if (peek.startsWith("$$")) {
return true;
}

return super.isAlternativeStringLiteral(peek);
}

@Override
protected Token handleAlternativeStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException {
String doubleDollarQuote = (char) reader.read() + reader.readUntilIncluding("$$");
reader.swallowUntilExcluding(doubleDollarQuote);
reader.swallow(doubleDollarQuote.length());
return new Token(TokenType.STRING, pos, line, col, null, null, context.getParensDepth());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,30 @@ public String readUntilIncluding(char delimiter) throws IOException {
return result.toString();
}

/**
* Reads all characters in this stream until the delimiting sequence is encountered.
*
* @param delimiterSequence The delimiting sequence.
* @return The string read, including the delimiting characters.
*/
public String readUntilIncluding(String delimiterSequence) throws IOException {
StringBuilder result = new StringBuilder();

do {
int r = read();
if (r == -1) {
break;
}
char c = (char) r;

result.append(c);
if (result.toString().endsWith(delimiterSequence)) {
break;
}
} while (true);
return result.toString();
}

/**
* Reads all characters in this stream as long as they can be part of a keyword.
*
Expand Down

0 comments on commit 77bf492

Please sign in to comment.