fix: binding of COMP numeric host variables - #209
Open
david-marconis wants to merge 1 commit into
Open
Conversation
david-marconis
force-pushed
the
fix-comp-numeric-binding
branch
from
June 15, 2026 12:09
c9622bb to
43c9e01
Compare
A numeric host variable is always rendered to a decimal display string by
SqlVar::createRealData (and parsed back by createCobolData), regardless of
its COBOL USAGE. gixpp, however, sets CBL_FIELD_FLAG_BINARY for any USAGE
BINARY item, including COMP integers. Every backend keys its parameter
transmission on that flag:
- ODBC : SQL_C_BINARY (DbInterfaceODBC.cpp)
- SQLite : sqlite3_bind_blob (DbInterfaceSQLite.cpp)
- PgSQL : binary format / OID_BYTEA (DbInterfacePGSQL.cpp)
- MySQL : MYSQL_TYPE_BLOB (DbInterfaceMySQL.cpp)
- Oracle : DPI_ORACLE_TYPE_BLOB (DbInterfaceOracle.cpp)
So a COMP host variable had its rendered ASCII digits ("42") transmitted as
raw binary. Db2/ODBC rejects this with SQLSTATE 22003 "numeric value out of
range"; SQLite/others silently bind a blob that never matches, so a lookup
keyed on a COMP column returns no rows (SQLCODE 100). COMP-3 was unaffected
only because gixpp does not flag it binary.
Fix: In the SqlVar constructor clear the binary flag for numeric types, so
every backend stays on the text path. Also trim db_data_len for the
COMP_TYPE_*_BINARY cases so the trailing NULs left by snprintf in the
length-sized buffer are not sent to the database.
Add regression test TSQL044A (COMP host var as WHERE parameter and FETCH
target); fails on the unfixed runtime, passes with the fix, across all
configured backends.
david-marconis
force-pushed
the
fix-comp-numeric-binding
branch
from
June 15, 2026 12:10
43c9e01 to
405d2e3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A numeric host variable is always rendered to a decimal display string by
SqlVar::createRealData(and parsed back bycreateCobolData), regardless of its COBOLUSAGE.gixpp, however, setsCBL_FIELD_FLAG_BINARYfor anyUSAGE BINARYitem, includingCOMPintegers, and every backend keys its parameter transmission on that flag:SQL_C_BINARYsqlite3_bind_blobOID_BYTEAMYSQL_TYPE_BLOBDPI_ORACLE_TYPE_BLOBSo a
COMPhost variable had its rendered ASCII digits ("42") transmitted as raw binary. Db2/ODBC rejects this withSQLSTATE 22003("numeric value out of range"); SQLite and the others silently bind a blob that never matches, so a lookup keyed on aCOMPcolumn returns no rows (SQLCODE 100).COMP-3was unaffected only becausegixppdoes not flag it binary.Fix
A single, backend-agnostic change in
SqlVar:db_data_lenfor theCOBOL_TYPE_*_BINARYcases so the trailing NULs left bysnprintfin the length-sized buffer are not sent to the database.Test
Adds
TSQL044A(aCOMPhost variable used as aWHEREparameter and aFETCHtarget). It fails on the unfixed runtime and passes with the fix, across all configured backends.Verification
Checked against SQLite and Db2 (LUW, via unixODBC + the IBM clidriver):
COMP,COMP-3, signed,V99decimal, negative and 8-byte values all round-trip correctly as bothWHERE-clause parameters andFETCH ... INTOtargets.