-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To change the statement separator during SQL execution, use the following command on a separate line: --#SET TERMINATOR <separator> This command does not change the separator permanently but for a single SQL execution only. See also menu File --> New Session Properties --> tab SQL --> section "Statement separator" Thanks to Roland Tapken for the pull request
- Loading branch information
1 parent
384023f
commit 368a60e
Showing
9 changed files
with
222 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...c/net/sourceforge/squirrel_sql/fw/sql/querytokenizer/ChangeStatementSeparatorSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package net.sourceforge.squirrel_sql.fw.sql.querytokenizer; | ||
|
||
import net.sourceforge.squirrel_sql.fw.sql.commentandliteral.SQLCommentAndLiteralHandler; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class ChangeStatementSeparatorSupport | ||
{ | ||
private static final String SET_TERMINATOR_COMMAND = "#SET TERMINATOR "; | ||
private final String _script; | ||
private final String _lineCommentBegin; | ||
private String _terminatorCommandInclLineCommentPrefix; | ||
|
||
private final boolean _scriptContainsTerminatorActive; | ||
|
||
public ChangeStatementSeparatorSupport(QueryTokenizePurpose queryTokenizePurpose, String script, String lineCommentBegin) | ||
{ | ||
_script = script; | ||
_lineCommentBegin = lineCommentBegin; | ||
_terminatorCommandInclLineCommentPrefix = _lineCommentBegin + SET_TERMINATOR_COMMAND; | ||
|
||
_scriptContainsTerminatorActive = | ||
queryTokenizePurpose == QueryTokenizePurpose.STATEMENT_EXECUTION | ||
&& StringUtils.containsIgnoreCase(script, _terminatorCommandInclLineCommentPrefix); | ||
} | ||
|
||
/** | ||
* Check for a line that contains '--#SET TERMINATOR x' to change the current new statement separator | ||
* The line may start by spaces or tabs. Other characters are not allowed. | ||
*/ | ||
public String findSetTerminatorInstruction(final int searchStartPos, SQLCommentAndLiteralHandler commentAndLiteralHandler) | ||
{ | ||
if(false == isActive()) | ||
{ | ||
return null; | ||
} | ||
|
||
if(commentAndLiteralHandler.isInLiteral() || commentAndLiteralHandler.isInMultiLineComment()) | ||
{ | ||
return null; | ||
} | ||
|
||
if(false == StringUtils.startsWithIgnoreCase(_script.substring(searchStartPos), _terminatorCommandInclLineCommentPrefix)) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
{ | ||
return null; | ||
} | ||
|
||
if(isCommandPrecededBySpacesOrTabsOnly(_script, searchStartPos)) | ||
This comment has been minimized.
Sorry, something went wrong.
Cybso
Author
Contributor
|
||
{ | ||
return null; | ||
} | ||
|
||
// Only when the comment starts on a new line | ||
This comment has been minimized.
Sorry, something went wrong.
Cybso
Author
Contributor
|
||
int newLinePos = _script.indexOf('\n', searchStartPos); | ||
if(newLinePos > searchStartPos + _terminatorCommandInclLineCommentPrefix.length()) | ||
{ | ||
String terminator = _script.substring(searchStartPos + _terminatorCommandInclLineCommentPrefix.length(), newLinePos).trim(); | ||
if(!terminator.isEmpty()) | ||
{ | ||
return terminator; | ||
} | ||
} | ||
|
||
|
||
return null; | ||
} | ||
|
||
private static boolean isCommandPrecededBySpacesOrTabsOnly(String script, int searchStartPos) | ||
{ | ||
// Check if the comment is only preceded by spaces or tabs | ||
int j = searchStartPos; | ||
while(j-- > 0) | ||
{ | ||
char c = script.charAt(j); | ||
if(c == '\n') | ||
{ | ||
// Found the start of the line, break the loop | ||
break; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
else if(c != ' ' && c != '\t') | ||
{ | ||
// Found non-whitespace character | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public boolean isActive() | ||
{ | ||
return _scriptContainsTerminatorActive; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
sql12/core/src/net/sourceforge/squirrel_sql/fw/sql/querytokenizer/I18NStrings.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
QueryTokenizer.change.statement.separator.message=Changing statement separator for current execution from statement #{0} on to {1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
sql12/core/src/net/sourceforge/squirrel_sql/fw/sql/querytokenizer/QueryTokenizePurpose.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.sourceforge.squirrel_sql.fw.sql.querytokenizer; | ||
|
||
public enum QueryTokenizePurpose | ||
{ | ||
STATEMENT_EXECUTION, | ||
OTHER | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The IBM documentation specifies that #SET TERMINATOR has to be uppercase, but personally I'm fine with this
https://www.ibm.com/docs/en/ida/9.1.2?topic=terminators-changing-sql-statement-terminator