Dear hackers, As declared last month, I propose again the new ECPG grammar, DECLARE STATEMENT. This had been committed once, but it removed from PG12 because of some problems. In this mail, I want to report some problems that previous implementation has, produce a new solution, and attach a WIP patch.
[Basic function, Grammar, and Use case] This statement will be used for the purpose of designating a connection easily. Please see below: https://www.postgresql.org/message-id/flat/4E72940DA2BF16479384A86D54D0988A4D80D3C9@G01JPEXMBKW04 The Oracle's manual will also help your understanding: https://docs.oracle.com/en/database/oracle/oracle-database/19/lnpcc/embedded-SQL-statements-and-directives.html#GUID-0A30B7B4-BD91-42EA-AACE-2E9CBF7E9C1A [Issues] That's why this feature has been reverted. 1. The namespace of the identifier was not clear. If you use a same identifier for other SQL statements, these interfered each other and statements might be executed at the unexpected connection. 2. Declaring at the outside of functions was not allowed. This specification is quite different from the other declarative statements, so some users might be confused. For instance, the following example was rejected. ``` EXEC SQL DECLARE stmt STATEMENT; int main() { ... EXEC SQL DECLARE cur CURSOR FOR stmt; ... } ``` 3. These specifications were not compatible with other DBMSs. [Solutions] The namespace is set to be a file unit. This follows other DBMSs. When the DECLARE SATATEMENT statement is read, the name, identifier and the related connection are recorded. And if you use the declared identifier in order to prepare or declare cursor, the fourth argument for ECPGdo(it represents the connection) will be overwritten. This declaration is enabled only the precompile phase. [Limitations] The declaration must be appeared before using it. This also follows Pro*C precompiler. A WIP patch is attached. Confirm that all ECPG tests have passed, however, some documents are not included. They will be added later. I applied the pgindent as a test, but it might be failed because this is the first time for me. Best regards Hayato Kuroda FUJITSU LIMITED E-Mail:kuroda.hay...@fujitsu.com
DeclareStmt01.patch
Description: DeclareStmt01.patch