mridoni / gixsql

GixSQL is an ESQL preprocessor and a series of runtime libraries to enable GnuCOBOL to access PostgreSQL, ODBC, MySQL, Oracle and SQLite databases.
GNU General Public License v3.0
16 stars 8 forks source link

PG: issue with prepared statements #99

Open GitMensch opened 2 years ago

GitMensch commented 2 years ago

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:

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

mridoni commented 2 years ago

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 commented 2 years ago

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").

GitMensch commented 1 year ago

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