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

Added support for SET TERMINATOR instruction #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ public void setScriptToTokenize(String script)
for (int i = 0; i < script.length(); ++i)
{
final NextPositionAction nextPositionAction = commentAndLiteralHandler.nextPosition(i);
if (!commentAndLiteralHandler.isInLiteral() && !commentAndLiteralHandler.isInMultiLineComment()) {
String newQuerySep = findSetTerminatorInstruction(script, i);
if (newQuerySep != null) {
s_log.info("changing statement separator to '" + newQuerySep + "'");
setQuerySep(newQuerySep);
}
}

curOriginalQuery.append(script.charAt(i));

Expand Down Expand Up @@ -206,6 +213,37 @@ public void setScriptToTokenize(String script)
_queryIterator = _queries.iterator();
}

/**
* Check for a line that contains '--#SET TERMINATOR x' to change the current new statement separator
* The line may start with spaces or tabs. Other characters are not allowed.
*/
private String findSetTerminatorInstruction(String script, final int i) {
if (script.startsWith(_lineCommentBegin + "#SET TERMINATOR ", i)) {
// Check if the comment is only preceded with space or tabs
int j = i;
while (j-- > 0) {
char c = script.charAt(j);
if (c == '\n') {
// Found the start of the line, break the loop
break;
} else if (c != ' ' && c != '\t') {
// Found non-whitespace character
return null;
}
}

// Only when the comment starts on a new line
int newLinePos = script.indexOf('\n', i);
if (newLinePos > i + 16 + _lineCommentBegin.length()) {
String terminator = script.substring(i + 16 + _lineCommentBegin.length(), newLinePos).trim();
if (!terminator.isEmpty()) {
return terminator;
}
}
}
return null;
}

/**
* Returns the number of queries that the tokenizer found in the script
* given in the last call to setScriptToTokenize, or 0 if
Expand Down