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

PG: issue with prepared statements #99

Open
GitMensch opened this issue Jul 29, 2022 · 3 comments
Open

PG: issue with prepared statements #99

GitMensch opened this issue Jul 29, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@GitMensch
Copy link
Contributor

GitMensch commented Jul 29, 2022

EXECL SQL PREPARE S1 FROM :command

then open + fetch + close

EXECL SQL DEALLOCATE PREPARE S1

--> results in return code -106, PG complaining about "s1 not prepared".

changing the code to use all lower-case "s1" works.

The reason: the first statements are processed by GixSQL and S1 is passed "as is".
The last statement is directly passed to the DB and parsed there "as sql" - and in this process converted to "all lower-case".

Two possible solutions:

  • either lower-case the name of the stmt_name before it is passed to the DB (this may be PG specific and needs to be upper-cased or can be ignored with other DBs..)
  • or explicit handle DEALLOCATE PREPARE X like PREPARE X FROM is handled

Workaround for PG in the meantime: change all prepared statement names in all COBOL source to lower-case.

@mridoni mridoni added the bug Something isn't working label Jul 29, 2022
@mridoni
Copy link
Owner

mridoni commented Jul 30, 2022

This raises a somewhat interesting point: in PostgresQL DEALLOCATE is used to explicitly deallocate a preparate statement. In SQL Server it is used to deallocate a cursor. While there is currently no driver for it, SQL Server could still be reached with an ODBC connection, so I guess the second solution is not possible.

I will think how I can work my way around it.

@mridoni
Copy link
Owner

mridoni commented Jul 30, 2022

There is actually no need to work around it. PostgreSQL itself forces the statement name to lowercase, as with all identifiers (I had a look in the pg_prepared_statements view), so we can apply your proposed solution #1 and force all to lowercase as well.

The only problem could be when using quoted identifiers for prepared statements (PostgreSQL, as usual, doesn't modify them) but I guess that is such a corner case that one could apply a restriction (i.e. "please don't do that").

@mridoni mridoni added the ready label Jul 30, 2022
mridoni added a commit that referenced this issue Aug 15, 2022
This is a maintenance pre-release for GixSQL. It fixes a few issues and adds two new databases drivers (Oracle and SQLite). The next "standard" release (presumably v1.0.18) will have feature parity for all database drivers.

- Added new Oracle driver, based on ODPI
- Added new SQLite driver
- Solution for "PG: issue with prepared statements" (#99)
- Solution for "PCursors cannot be re-opened after close" (#98)
- Solution for "libgixpp: setStatus is called for errors without DBI parm passed - sets SQLERRM" (#94)
- Solution for "error handling (especially for 07001)" (#92)
- Solution for "show-stopper bug in pgsql_prepare" (#91)
- Solution for "PREPARE does not work with VARLENGTH groups (ocesql compat)" (#79)
- Partial solution for "PREPARE does not work with VARLENGTH groups (ocesql compat)" (#68)
- Solution for "The PostgreSQL driver needs START TRANSACTION before using cursors" (#14)
- Solution for "FR: support EXEC SQL VAR" (#21)
- Fixed a bug in "problems with "codegen / logic issue for "GIXSQLCursorDeclareParams" (#88)
- Fixed COMP-3 handling in drivers other than PostgreSQL
- Rewrote the test suite (still MSTest-based) to dynamically generate a matrix of test to be run on the various platforms/database drivers
mridoni added a commit that referenced this issue Aug 23, 2022
- Added new Oracle driver, based on ODPI
- Added new SQLite driver
- All the drivers have been updated and now implement the complete set of supported features
- Solution for "PG: issue with prepared statements" (#99)
- Solution for "PCursors cannot be re-opened after close" (#98)
- Solution for "libgixpp: setStatus is called for errors without DBI parm passed - sets SQLERRM" (#94)
- Solution for "error handling (especially for 07001)" (#92)
- Solution for "show-stopper bug in pgsql_prepare" (#91)
- Solution for "PREPARE does not work with VARLENGTH groups (ocesql compat)" (#79)
- Partial solution for "PREPARE does not work with VARLENGTH groups (ocesql compat)" (#68)
- Solution for "The PostgreSQL driver needs START TRANSACTION before using cursors" (#14)
- Solution for "FR: support EXEC SQL VAR" (#21)
- Fixed a bug in "problems with "codegen / logic issue for "GIXSQLCursorDeclareParams" (#88)
- Solution for "FR: allow mapping of "NoRecCode"' (#95) - added --no-rec-code parameter to gixpp
- Tokens in the parser have been labeled to improve diagnostics (pulled PR #96 by @GitMensch)
- Fixed COMP-3 handling in drivers other than PostgreSQL
- Rewrote the test suite (still MSTest-based) to dynamically generate a matrix of test to be run on the various platforms/database drivers
- Added options for parameter generation in gixpp (-a was removed)
- Added new GIXSQL_FIXUP_PARAMS option for runtime, to automatically convert parameter format in prepared statments
- "Native" cursors are now the default for the PostgreSQL driver
- "Smart" cursor initialization is now the default for all cursors, including those declared in WORKING-STORAGE (-L was removed from gixpp), should fix #101
- Removed dynamic cursor emulation from the ODBC driver when using PostgreSQL
@mridoni mridoni removed the ready label Aug 24, 2022
@GitMensch
Copy link
Contributor Author

It seems like e62e34c did "something" for this but did not add any new testsuite entries.
Are those missing or can they be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants