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

Conversation

Cybso
Copy link
Contributor

@Cybso Cybso commented Nov 28, 2024

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:

DROP PROCEDURE foobar;

CREATE PROCEDURE foobar
BEGIN
    --#SET TERMINATOR !
    declare v char(10);
    select value into v from sometable;
    if v = 'test' then
        update sometable set value = '';
    end if;
    --#SET TERMINATOR ;
END;

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.

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.
@Cybso Cybso force-pushed the add-support-for-SET_TERMINATOR-inline branch from 514893b to 0894f47 Compare November 28, 2024 16:36
This makes this feature compatible to IBM CLP and Data Architect.
The documentation states:

> The statement must be uppercase and in a comment. There can be leading spaces before the --, but there cannot be spaces between -- and #SET TERMINATOR x

https://www.ibm.com/docs/en/ida/9.1.2?topic=terminators-changing-sql-statement-terminator
gerdwagner pushed a commit that referenced this pull request Nov 30, 2024
  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
@gerdwagner
Copy link
Member

Was merged with several adjustments. Please take a look if it still works for you. Most of your code is now in the new ChangeStatementSeparatorSupport class.

Thanks for your pull request.

@Cybso
Copy link
Contributor Author

Cybso commented Dec 1, 2024

Was merged with several adjustments. Please take a look if it still works for you. Most of your code is now in the new ChangeStatementSeparatorSupport class.

I haven't completely figured out the integration, but it looks pretty good at first glance. I have added three small notes to the commit. In particular, the method isCommandPrecededBySpacesOrTabsOnly is named incorrectly or the return value is the wrong way around. However, since the call also takes this into account, it still works at the moment, it's just not intuitive:

      if(isCommandPrecededBySpacesOrTabsOnly(_script, searchStartPos))
      {
         return null;
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants