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

add support to directly execute statements - EXECUTE IMMEDIATE #65

Open
GitMensch opened this issue Jun 27, 2022 · 2 comments
Open

add support to directly execute statements - EXECUTE IMMEDIATE #65

GitMensch opened this issue Jun 27, 2022 · 2 comments

Comments

@GitMensch
Copy link
Contributor

Feature Request

https://docs.oracle.com/cd/A97630_01/appdev.920/a96109/pco09dyn.htm#774
https://www.postgresql.org/docs/14/ecpg-dynamic.html

EXEC SQL
    EXECUTE IMMEDIATE 'some hard-coded sql here'
END-EXEC
EXEC SQL AT :dbs
    EXECUTE IMMEDIATE :stmt
END-EXEC

As a wide-supported way to execute something that has no bind parameters (only the statement if not given by literal) and no result set (The SQLCA structure would still be set, so checkingSQLCODE and friends still would be possible).
:stmt should be a "plain" pic x item, but it would be nice to optional be able to use a varlength group, too.


Workaround

use prepared statements, as this currently works only correct with varlength groups (tracked under #64) you need to change the statement definition first:

-       77 SQL-COMMAND  PIC X(50)
-            VALUE "DELETE FROM TESTTABLE WHERE I > ?".
+       01 SQL-COMMAND.
+         03 SQL-COMMAND-LEN PIC 9(9) VALUE 50.
+         03 SQL-COMMAND-ARR PIC X(50)
+            VALUE "DELETE FROM TESTTABLE WHERE I > ?".

and then use that in COBOL

      *  place statement to execute into SQL-COMMAND-ARR, then
           MOVE FUNCTION LENGTH(FUNCTION TRIM(SQL-COMMAND-ARR))
             TO SQL-COMMAND-LEN.
           EXEC SQL AT :DBS
               PREPARE P1 FROM :SQL-COMMAND
           END-EXEC.
      *
           IF SQLCODE NOT = 0
              DISPLAY "PREPARE ERROR"
              STOP RUN
           END-IF.
      *
           EXEC SQL AT :DBS
              EXECUTE P1
           END-EXEC.
@yutaro-sakamoto
Copy link
Contributor

This function may have been developed in a past project of ours.
We will consider the possibility of releasing it as OSS.

@GitMensch
Copy link
Contributor Author

@yutaro-sakamoto wrote in 2022:

We will consider the possibility of releasing it as OSS.

Any update?

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

No branches or pull requests

2 participants