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

"NULL indicators" on cursors fetch does not return -1 on NULL values #179

Open sergiosa61 opened 7 months ago

sergiosa61 commented 7 months ago

Trying to use the cursors with the null indicators I verified that in the presence of null values ​​a zero value is always returned.

01 COM-NULL-IND PIC S9(4) COMP.

      * Cursor declaration
           EXEC SQL
            DECLARE CUR_ST_EMPTBL CURSOR FOR
              SELECT PAYRATE, COM
              FROM EMPTABLE 
                WHERE LNAME = 'XYZ1' AND 
                    FNAME = 'ABC1' AND 
                    COM IS NULL
           END-EXEC.

      *  open cursor
           EXEC SQL
               OPEN CUR_ST_EMPTBL
           END-EXEC
           MOVE SQLCODE TO DISP-CODE
           DISPLAY 'open ' DISP-CODE.
           DISPLAY 'open ' SQLERRM.

      *  fetch a data item
           EXEC SQL
               FETCH CUR_ST_EMPTBL
                 INTO :PAYRATE, :COM:COM-NULL-IND
           END-EXEC.
      *  loop until no more data
           PERFORM UNTIL SQLCODE < 0 OR SQLCODE = 100

      *  display the record
           DISPLAY 'commission: [' COM ']'

           DISPLAY 'COM-NULL-IND: [' COM-NULL-IND ']'

           IF COM-NULL-IND < 0
               DISPLAY LNAME ': commission is null'
           ELSE

execution display fetch

commission: [000+]
COM-NULL-IND: [+00000]

In single-row SELECT it works correctly

       EXEC SQL
           SELECT PAYRATE, COM
            INTO :PAYRATE, :COM:COM-NULL-IND
            FROM EMPTABLE 
                WHERE LNAME = 'XYZ1' AND 
                    FNAME = 'ABC1' AND 
                    COM IS NULL
       END-EXEC.

      *  display the record
           DISPLAY 'commission: [' COM ']'

           DISPLAY 'COM-NULL-IND: [' COM-NULL-IND ']'

           IF COM-NULL-IND < 0
               DISPLAY LNAME ': commission is null'
           ELSE

execution display select

commission: [000+]
COM-NULL-IND: [-00001]
          : commission is null

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 commented 7 months ago

Hi, With the following modification it seems to work now

--- gixsql-1.0.20b/runtime/libgixsql/gixsql.cpp 2023-04-26 17:50:25.000000000 +0200
+++ gixsql-1.0.20bV2/runtime/libgixsql/gixsql.cpp       2024-04-12 17:09:46.267734476 +0200
@@ -820,7 +820,9 @@
                }

                int sql_code_local = DBERR_NO_ERROR;
-               (*it)->createCobolData(buffer.get(), datalen, &sql_code_local);
+               char* _data_bfr = is_null ? nullptr : buffer.get();
+               uint64_t _data_len = is_null ? 0 : datalen;
+               (*it)->createCobolData(_data_bfr, _data_len, &sql_code_local);
                if (sql_code_local) {
                        setStatus(st, dbi, sql_code_local);
                        sqlcode = sql_code_local;