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

Parameters in cursor usage with prepared statements are not considered #181

Open
sergiosa61 opened this issue Apr 8, 2024 · 0 comments
Open

Comments

@sergiosa61
Copy link

sergiosa61 commented Apr 8, 2024

Hi, this is the example that generates the error:
[libgixsql-pgsql] [error] ERROR (7 - 08P01): ERROR: bind message supplies 0 parameters, but prepared statement "" requires 1


           01 DYNSTMT1   SQL TYPE IS VARCHAR(1000).
      *  declare cursor for select 
           EXEC SQL 
              DECLARE  CUR_EMPTABLE CURSOR FOR SQLSTMT1 
           END-EXEC .

       PROCEDURE DIVISION. 

           EXEC SQL START TRANSACTION END-EXEC.

           MOVE "SELECT  " &
                "    E.ENO , " &
                "    E.LNAME , " &
                "    E.FNAME , " &
                "    E.STREET || ',' ||  " &
                "    E.CITY || ',' ||  " &
                "    E.ST || '' ||  " &
                "       ZIP AS  " & 
                "    ADDRESS , " &
                "    E.DEPT , " &
                "    E.PAYRATE , " &
                "    CASE " &
                "        WHEN E.COM IS NOT NULL THEN E.COM " &
                "        ELSE 0.00 " &
                "    END AS COMMISSION , " &
                "    COALESCE(E.DNUM1 , " &
                "    0.00) + COALESCE(E.DNUM2 , " &
                "    0.00) + COALESCE(E.DNUM3 , " &
                "    0.00) AS TOTAL_DNUM , " &
                "    E.MISCDATA " &
                "FROM" &
                "    EMPTABLE E " &
                "WHERE" &
                "    LNAME = TRIM($1)"
           TO DYNSTMT1-ARR.

           MOVE FUNCTION LENGTH(FUNCTION TRIM(DYNSTMT1-ARR))
                TO DYNSTMT1-LEN.

           EXEC SQL 
               PREPARE SQLSTMT1 FROM :DYNSTMT1
           END-EXEC.

           MOVE "XYZ1"  TO WEMPNAME

      *  open cursor
           MOVE "OPEN CUR_EMPTABLE USING :WEMPNAME" TO SQL-STEP
           DISPLAY "SQL-STEP " SQL-STEP
           EXEC SQL
               OPEN CUR_EMPTABLE USING :WEMPNAME
           END-EXEC 

I attach two cobol sources with the same cursor. The first one has the cursor declaration in working and works correctly. The second is the one that uses the prepared statement and generates the error.
Bug181.zip

Comparing the sources after running gixpp I find these differences

Immagine 2024-04-08 112005

By modifying the second source like this:

GIXSQL*
GIXSQL*   ESQL CURSOR DECLARATIONS (START)
GIXSQL     GO TO GIX-SKIP-CRSR-INIT.
GIXSQL GIXSQL-CI-P-TSQL179B1-CUR-EMPTABLE.
GIXSQL     CALL "GIXSQLStartSQL"
GIXSQL     END-CALL
GIXSQL     CALL "GIXSQLSetSQLParams" USING
GIXSQL         BY VALUE 16
GIXSQL         BY VALUE 10
GIXSQL         BY VALUE 0
GIXSQL         BY VALUE 0
GIXSQL         BY REFERENCE WEMPNAME
GIXSQL         BY REFERENCE 0
GIXSQL     END-CALL
GIXSQL     CALL "GIXSQLCursorDeclareParams" USING
GIXSQL         BY REFERENCE SQLCA
GIXSQL         BY REFERENCE x"00"
GIXSQL         BY VALUE 0
GIXSQL         BY REFERENCE "TSQL179B1_CUR_EMPTABLE" & x"00"
GIXSQL         BY VALUE 0
GIXSQL         BY REFERENCE SQ0001
GIXSQL         BY VALUE 0
GIXSQL         BY VALUE 1
GIXSQL     END-CALL
GIXSQL     CALL "GIXSQLEndSQL"
GIXSQL     END-CALL.
GIXSQL GIX-SKIP-CRSR-INIT.
GIXSQL*
GIXSQL*   ESQL CURSOR DECLARATIONS (END)

The program works correctly.

The gixpp version

gixpp -V
gixpp - the ESQL preprocessor for Gix-IDE/GixSQL
Version: 1.0.20b
libgixpp version: 1.0.20b

The cobc version

cobc -V
cobc (OpenCOBOL) 2.0.0
Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Keisuke Nishida
Copyright (C) 2006-2012 Roger While
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Built     Nov 30 2023 11:35:35
Packaged  Feb 11 2012 12:36:31 UTC
C version "8.3.0"

Os Version

cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
sergiosa61 added a commit to sergiosa61/gixsql that referenced this issue May 14, 2024
Parameters in cursor usage with prepared statements are not considered
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

1 participant