Skip to content

Commit f5fd2dd

Browse files
committed
Added support for SET TERMINATOR instruction
This allows to temporarily change the statement separator with an inline comment and thus supports to execute statements that uses the semicolon within their expression, for example triggers or procedures with `BEGIN..END` blocks. Example: ```sql DROP PROCEDURE foobar; --#SET TERMINATOR ! CREATE PROCEDURE foobar BEGIN declare v char(10); select value into v from sometable; if v = 'test' then update sometable set value = ''; end if; END! --#SET TERMINATOR ; LABEL ON PROCEDURE foobar IS 'Example'; ``` This commit fixes feature request 433 on sourceforge (https://sourceforge.net/p/squirrel-sql/feature-requests/433/). It currently only supports the default QueryTokenizer. The statement separator is only changed for the current execution.
1 parent 384023f commit f5fd2dd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sql12/core/src/net/sourceforge/squirrel_sql/fw/sql/querytokenizer/QueryTokenizer.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ public void setScriptToTokenize(String script)
164164
for (int i = 0; i < script.length(); ++i)
165165
{
166166
final NextPositionAction nextPositionAction = commentAndLiteralHandler.nextPosition(i);
167+
if (!commentAndLiteralHandler.isInLiteral() && !commentAndLiteralHandler.isInMultiLineComment()) {
168+
// Check for a line that contains '--#SET TERMINATOR x' to change the current new statement separator
169+
if (script.startsWith(_lineCommentBegin + "#SET TERMINATOR ", i)) {
170+
if (i == 0 || script.charAt(i-1) == '\n') {
171+
// Only when the comment starts on a new line
172+
int newLinePos = script.indexOf('\n', i);
173+
if (newLinePos > 0 && newLinePos > i+18) {
174+
String terminator = script.substring(i + 16 + _lineCommentBegin.length(), newLinePos).trim();
175+
if (!terminator.isEmpty()) {
176+
s_log.info("changing statement separator to '" + terminator + "'");
177+
setQuerySep(terminator);
178+
}
179+
}
180+
}
181+
}
182+
}
167183

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

0 commit comments

Comments
 (0)