opensourcecobol / Open-COBOL-ESQL

Open Cobol ESQL (ocesql) is an open-source Embedded SQL pre-compiler and run-time library designed for COBOL applications which access an open-source database.
https://www.osscons.jp/osscobol/
GNU Lesser General Public License v3.0
50 stars 24 forks source link

When ocesql converts queries it repeats variable names, so then the cobol compiler will not compile #29

Open RobinHulk opened 2 years ago

RobinHulk commented 2 years ago

Hi

May be this bug is a bit hard to explein but I will try It happens when in a query you use structured variables like this

01 TRANSACTION . . 03 ID . . 03 AMOUNT

01 CUSTUMER . . 03 ID . . 03 NAME

PROBLEM: Both structured variables has a subfield ID. Same name for both. This is valid in cobol but ocesql tis not aware of it

Example: When you use the TRANSACTION.ID on a query:

SELECT T.AMOUNT FROM TRANSACTIONS T INTO :TRANSACTION-AMOUNT WHERE T.ID = :TRANSACTION.ID

This last variable :TRANSACTION.ID will casuse the problem since ID varrable has the same name on TRANSACTION as in CUSTOMER structured varables

When this is translated by ocesql it does this OCESQL CALL "OCESQLSetSQLParams" USING OCESQL BY VALUE 9 OCESQL BY VALUE 9 OCESQL BY VALUE 0 OCESQL BY REFERENCE ID <---- PROBLEM this is wrong since the compiler wont realize whose ID is it (Transaction´s or Cusromers´s ?)

The correct way to do this would have been to consider the structured variable name for level 01. This means to be done like this

OCESQL BY REFERENCE ID OF TRANSACTION

Of course if you name all variables with different names you wont have this problem, but this is not the way the COBOL variables works since sctrucured variables with rerpeated names are used a lot in cobol. Theres lots of programs already written like this, so changing them its not the best option. I think it should be better to fix it on ocesql

I hope mi explanation was clear enough, but feel free to ask for further information Could yoiy please fix this issue because its very important, specially for already written probrams that will change only the queries from oracle to porstrgres

Thanks Regards