IBM Support

PM18147: SQLFETCH() RETURNS SQLSTATE 01004 WHEN FETCHING A VARCHAR COLUMNINTO SQL_C_WCHAR WHEN PCBVALUE AND RGBVALUE ARE CONTIGUOUS

A fix is available

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • SQLFetch() returns SQL_SUCCESS_WITH_INFO and SQLSTATE 01004 when
    fetching from a VARCHAR column into a buffer of C data type
    SQL_C_WCHAR.  The problem only occurs when pcbValue and rgbValue
    are contiguous in memory.
    
    Trace from unsuccessful SQLFetch() (rc=SQL_SUCCESS_WITH_INFO)
    when pcbValue and rgbValue are adjacent in memory:
    
    SQLBindCol( hStmt=1, iCol=1, fCType=SQL_C_WCHAR,
    rgbValue=&2157502c,
    cbValueMax=65402, pcbValue=&21575028 )
    
    Trace from successful SQLFetch() when pcbValue and rgbValue are
    non-adjacent:
    
    SQLBindCol( hStmt=1, iCol=1, fCType=SQL_C_WCHAR,
    rgbValue=&2157502c,
    cbValueMax=65402, pcbValue=&213a1658 )
    

Local fix

  • Use pcbValue and rgbValue not contiguous will bypass the problem
    

Problem summary

  • ****************************************************************
    * USERS AFFECTED: All users of DB2 UDB for z/OS Version 9      *
    *                 ODBC/CLI.                                    *
    ****************************************************************
    * PROBLEM DESCRIPTION: 1. SQLFetch() returns SQLSTATE 01004    *
    *                         and SQL_SUCCESS_WITH_INFO when       *
    *                         fetching from a VARCHAR column       *
    *                         into a bound buffer of C data type   *
    *                         SQL_C_WCHAR and when the output      *
    *                         string is nul-terminated. The        *
    *                         warning only occurs when rgbValue    *
    *                         and pcbValue are contiguous in       *
    *                         memory.                              *
    *                      2. Insertion of UTF-16 data into        *
    *                         VARCHAR or LONG VARCHAR columns      *
    *                         fails with SQLSTATE HY001.           *
    *                      3. When fetching from a CHAR column of  *
    *                         a stored procedure result set into   *
    *                         SQL_C_WCHAR, only the first row is   *
    *                         retrieved in UNICODE.                *
    ****************************************************************
    * RECOMMENDATION:                                              *
    ****************************************************************
    1. When fetching from a VARCHAR column into a bound variable
       of C data type SQL_C_WCHAR, SQLFetch() fails with SQLSTATE
       01004 and return code SQL_SUCCESS_WITH_INFO.  This only
       occurs if the parameters pcbValue and rgbValue on the
       SQLBindCol() call are consecutive in memory.  To be more
       specific, when the length buffer pointed to by pcbValue
       is in the 4 bytes preceding rgbValue.
    
    2. When inserting UTF-16 data stored in buffers of C data type
       SQL_C_WCHAR into VARCHAR or LONG VARCHAR columns, the
       insertion fail with SQLSTATE HY001.
    
    3. When fetching from a CHAR column of a stored procedure
       result set into SQL_C_WCHAR, only the first row is returned
       in UTF-16.
    

Problem conclusion

  • 1. Code has been changed to fetch without any warnings from
       VARCHAR columns into SQL_C_WCHAR when pcbValue and rgbValue
       are consecutive in memory. This fix does not apply if
       you've disabled nul-termination of character data through
       the environment attribute SQL_ATTR_OUTPUT_NTS.
    
    2. Code has been changed to correctly insert UTF-16 data into
       VARCHAR and LONG VARCHAR columns.
    
    3. Code has been changed to fetch all rows from a stored
       procedure result set in UTF-16 when the C data type of
       the output buffer is SQL_C_WCHAR.
    

Temporary fix

Comments

APAR Information

  • APAR number

    PM18147

  • Reported component name

    DB2 ODBC/JDBC/S

  • Reported component ID

    5740XYR02

  • Reported release

    917

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2010-07-11

  • Closed date

    2010-10-18

  • Last modified date

    2010-12-02

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

    UK61483

Modules/Macros

  •    CLIRETR  CLISDA   DSNAOCLI DSNAOC0R DSNAOC0U
    DSNAOC06 DSNAOC22 DSNAOC27 DSNAOG0R DSNAOG0U DSNAOG06 DSNAOG22
    DSNAOG27 DSNAOSDK
    

Fix information

  • Fixed component name

    DB2 ODBC/JDBC/S

  • Fixed component ID

    5740XYR02

Applicable component levels

  • R917 PSY UK61483

       UP10/11/02 P F011

Fix is available

  • Select the PTF appropriate for your component level. You will be required to sign in. Distribution on physical media is not available in all countries.

[{"Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSEPEK","label":"Db2 for z\/OS"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"917"}]

Document Information

Modified date:
04 March 2021