[BUG] SqlDescribeCol error with prepared statements
See original GitHub issueDescribe your system
odbcPackage Version:>=2.4.0-beta.2(2.4.0-beta.1works)- ODBC Driver: IBM i Access ODBC Driver
- Database Name: Db2 for i
- Database Version:
- Database OS: IBM i 7.4
- Node.js Version: 14.15.1 (14.17.5 in IBM i test)
- Node.js OS: Tested on both Windows 10 & IBM i 7.4
Describe the bug
When running any query via a prepared statement, empty data is returned. Enabling trace shows the call to SqlDescribeCol is failing. The same queries work when run with connection.query(), they only fail when using connection.createStatement().
I’m assuming there is something more complex going on here so I’m looking to start a discussion here. Wondering what other information might be useful.
Expected behavior
Expected same return structure from the same query regardless of whether it is run with connection.query() or as a prepared statement. In my test, I used select * from qiws.qcustcdt as my query. Running the query with connection.query() produced the following output, so I expected that too from the run with a prepared statement:
Test Code
const odbc = require('odbc');
(async function() {
const connection = await odbc.connect("Driver={IBM i Access ODBC Driver};System=my.ibmi.ip.address;Uid=usrprf;Pwd=passwd;NAM=1;CCSID=1208"); // Using just DSN=*LOCAL when on IBM i
const result = await connection.query('SELECT * FROM QIWS.QCUSTCDT');
console.log(result);
})();
Output
[
{
CUSNUM: 938472,
LSTNAM: 'Henning ',
INIT: 'G K',
STREET: '4859 Elm Ave ',
CITY: 'Dallas',
STATE: 'TX',
ZIPCOD: 75217,
CDTLMT: 5000,
CHGCOD: 3,
BALDUE: 37,
CDTDUE: 0
},
{
CUSNUM: 839283,
LSTNAM: 'Jones ',
INIT: 'B D',
STREET: '21B NW 135 St',
CITY: 'Clay ',
STATE: 'NY',
ZIPCOD: 13041,
CDTLMT: 400,
CHGCOD: 1,
BALDUE: 100,
CDTDUE: 0
},
{
CUSNUM: 392859,
LSTNAM: 'Vine ',
INIT: 'S S',
STREET: 'PO Box 79 ',
CITY: 'Broton',
STATE: 'VT',
ZIPCOD: 5046,
CDTLMT: 700,
CHGCOD: 1,
BALDUE: 439,
CDTDUE: 0
},
{
CUSNUM: 938485,
LSTNAM: 'Johnson ',
INIT: 'J A',
STREET: '3 Alpine Way ',
CITY: 'Helen ',
STATE: 'GA',
ZIPCOD: 30545,
CDTLMT: 9999,
CHGCOD: 2,
BALDUE: 3987.5,
CDTDUE: 33.5
},
{
CUSNUM: 397267,
LSTNAM: 'Tyron ',
INIT: 'W E',
STREET: '13 Myrtle Dr ',
CITY: 'Hector',
STATE: 'NY',
ZIPCOD: 14841,
CDTLMT: 1000,
CHGCOD: 1,
BALDUE: 0,
CDTDUE: 0
},
{
CUSNUM: 389572,
LSTNAM: 'Stevens ',
INIT: 'K L',
STREET: '208 Snow Pass',
CITY: 'Denver',
STATE: 'CO',
ZIPCOD: 80226,
CDTLMT: 400,
CHGCOD: 1,
BALDUE: 58.75,
CDTDUE: 1.5
},
{
CUSNUM: 846283,
LSTNAM: 'Alison ',
INIT: 'J S',
STREET: '787 Lake Dr ',
CITY: 'Isle ',
STATE: 'MN',
ZIPCOD: 56342,
CDTLMT: 5000,
CHGCOD: 3,
BALDUE: 10,
CDTDUE: 0
},
{
CUSNUM: 475938,
LSTNAM: 'Doe ',
INIT: 'J W',
STREET: '59 Archer Rd ',
CITY: 'Sutter',
STATE: 'CA',
ZIPCOD: 95685,
CDTLMT: 700,
CHGCOD: 2,
BALDUE: 250,
CDTDUE: 100
},
{
CUSNUM: 693829,
LSTNAM: 'Thomas ',
INIT: 'A N',
STREET: '3 Dove Circle',
CITY: 'Casper',
STATE: 'WY',
ZIPCOD: 82609,
CDTLMT: 9999,
CHGCOD: 2,
BALDUE: 0,
CDTDUE: 0
},
{
CUSNUM: 593029,
LSTNAM: 'Williams',
INIT: 'E D',
STREET: '485 SE 2 Ave ',
CITY: 'Dallas',
STATE: 'TX',
ZIPCOD: 75218,
CDTLMT: 200,
CHGCOD: 1,
BALDUE: 25,
CDTDUE: 0
},
{
CUSNUM: 192837,
LSTNAM: 'Lee ',
INIT: 'F L',
STREET: '5963 Oak St ',
CITY: 'Hector',
STATE: 'NY',
ZIPCOD: 14841,
CDTLMT: 700,
CHGCOD: 2,
BALDUE: 489.5,
CDTDUE: 0.5
},
statement: 'SELECT * FROM QIWS.QCUSTCDT',
parameters: [],
return: undefined,
count: 11,
columns: [
{
name: 'CUSNUM',
dataType: 2,
columnSize: 6,
decimalDigits: 0,
nullable: false
},
{
name: 'LSTNAM',
dataType: 1,
columnSize: 8,
decimalDigits: 0,
nullable: false
},
{
name: 'INIT',
dataType: 1,
columnSize: 3,
decimalDigits: 0,
nullable: false
},
{
name: 'STREET',
dataType: 1,
columnSize: 13,
decimalDigits: 0,
nullable: false
},
{
name: 'CITY',
dataType: 1,
columnSize: 6,
decimalDigits: 0,
nullable: false
},
{
name: 'STATE',
dataType: 1,
columnSize: 2,
decimalDigits: 0,
nullable: false
},
{
name: 'ZIPCOD',
dataType: 2,
columnSize: 5,
decimalDigits: 0,
nullable: false
},
{
name: 'CDTLMT',
dataType: 2,
columnSize: 4,
decimalDigits: 0,
nullable: false
},
{
name: 'CHGCOD',
dataType: 2,
columnSize: 1,
decimalDigits: 0,
nullable: false
},
{
name: 'BALDUE',
dataType: 2,
columnSize: 6,
decimalDigits: 2,
nullable: false
},
{
name: 'CDTDUE',
dataType: 2,
columnSize: 6,
decimalDigits: 2,
nullable: false
}
]
]
To Reproduce Steps to reproduce the behavior:
- Install any version of odbc >=2.4.0-beta.2 (2.4.0-beta.1 works)
- Install latest IBM i odbc driver for windows
- Run query ‘select * from qiws.qcustcdt’ using the code below
Code Included here:
- Test code
- Bad output
- Debug log from ODBC from turning TRACE on in odbcinst.ini
Test Code (prepared statement)
const odbc = require('odbc');
(async function() {
const connection = await odbc.connect("Driver={IBM i Access ODBC Driver};System=my.ibmi.ip.address;Uid=usrprf;Pwd=passwd;NAM=1;CCSID=1208"); // Using just DSN=*LOCAL when on IBM i
const statement = await connection.createStatement();
await statement.prepare('SELECT * FROM QIWS.QCUSTCDT');
const result = await statement.execute();
console.log(result);
})();
Output
[
{ '': 0 },
{ '': 0 },
{ '': 0 },
{ '': 33.5 },
{ '': 0 },
{ '': 1.5 },
{ '': 0 },
{ '': 100 },
{ '': 0 },
{ '': 0 },
{ '': 0.5 },
statement: 'SELECT * FROM QIWS.QCUSTCDT',
parameters: undefined,
return: undefined,
count: -1,
columns: [
{
name: '',
dataType: 2,
columnSize: 6,
decimalDigits: 0,
nullable: false
},
{
name: '',
dataType: 1,
columnSize: 8,
decimalDigits: 0,
nullable: false
},
{
name: '',
dataType: 1,
columnSize: 3,
decimalDigits: 0,
nullable: false
},
{
name: '',
dataType: 1,
columnSize: 13,
decimalDigits: 0,
nullable: false
},
{
name: '',
dataType: 1,
columnSize: 6,
decimalDigits: 0,
nullable: false
},
{
name: '',
dataType: 1,
columnSize: 2,
decimalDigits: 0,
nullable: false
},
{
name: '',
dataType: 2,
columnSize: 5,
decimalDigits: 0,
nullable: false
},
{
name: '',
dataType: 2,
columnSize: 4,
decimalDigits: 0,
nullable: false
},
{
name: '',
dataType: 2,
columnSize: 1,
decimalDigits: 0,
nullable: false
},
{
name: '',
dataType: 2,
columnSize: 6,
decimalDigits: 2,
nullable: false
},
{
name: '',
dataType: 2,
columnSize: 6,
decimalDigits: 2,
nullable: false
}
]
]
Trace log
[ODBC][2751605][1629226420.640890][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 1806c7070
[ODBC][2751605][1629226420.647903][SQLSetEnvAttr.c][189]
Entry:
Environment = 1806c7070
Attribute = SQL_ATTR_ODBC_VERSION
Value = 3
StrLen = -5
[ODBC][2751605][1629226420.647939][SQLSetEnvAttr.c][381]
Exit:[SQL_SUCCESS]
[ODBC][2751608][1629226421.611267][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 18069da50
[ODBC][2751608][1629226421.611308][SQLSetEnvAttr.c][189]
Entry:
Environment = 18069da50
Attribute = SQL_ATTR_ODBC_VERSION
Value = 3
StrLen = -5
[ODBC][2751608][1629226421.611338][SQLSetEnvAttr.c][381]
Exit:[SQL_SUCCESS]
[ODBC][2751615][1629226431.739743][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 1806cefd0
[ODBC][2751615][1629226431.739803][SQLSetEnvAttr.c][189]
Entry:
Environment = 1806cefd0
Attribute = SQL_ATTR_ODBC_VERSION
Value = 3
StrLen = -5
[ODBC][2751615][1629226431.739848][SQLSetEnvAttr.c][381]
Exit:[SQL_SUCCESS]
[ODBC][2751618][1629226432.499813][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 1806c6250
[ODBC][2751618][1629226432.499853][SQLSetEnvAttr.c][189]
Entry:
Environment = 1806c6250
Attribute = SQL_ATTR_ODBC_VERSION
Value = 3
StrLen = -5
[ODBC][2751618][1629226432.499882][SQLSetEnvAttr.c][381]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226433.617634][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 180531bd0
[ODBC][2751622][1629226433.617690][SQLSetEnvAttr.c][189]
Entry:
Environment = 180531bd0
Attribute = SQL_ATTR_ODBC_VERSION
Value = 3
StrLen = -5
[ODBC][2751622][1629226433.617731][SQLSetEnvAttr.c][381]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226433.658754][SQLAllocHandle.c][377]
Entry:
Handle Type = 2
Input Handle = 180531bd0
UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2-INTERNAL'
[ODBC][2751622][1629226433.658869][SQLAllocHandle.c][513]
Exit:[SQL_SUCCESS]
Output Handle = 180535670
[ODBC][2751622][1629226433.658917][SQLDriverConnect.c][748]
Entry:
Connection = 180535670
Window Hdl = 0
Str In = [DSN=*LOCAL][length = 10 (SQL_NTS)]
Str Out = 18061bf50
Str Out Max = 2048
Str Out Ptr = 0
Completion = 0
[ODBC][2751622][1629226434.041330][SQLDriverConnect.c][1725]
Exit:[SQL_SUCCESS]
Connection Out [[DSN=*LOCAL][length = 10 (SQL_NTS)]]
[ODBC][2751622][1629226434.041406][SQLGetInfo.c][236]
Entry:
Connection = 180535670
Info Type = SQL_MAX_COLUMN_NAME_LEN (30)
Info Value = 180501f60
Buffer Length = 2
StrLen = 0
[ODBC][2751622][1629226434.041454][SQLGetInfo.c][236]
Entry:
Connection = 180535670
Info Type = SQL_TXN_ISOLATION_OPTION (72)
Info Value = 180501f68
Buffer Length = 4
StrLen = 0
[ODBC][2751622][1629226434.047529][SQLGetInfo.c][236]
Entry:
Connection = 180535670
Info Type = SQL_GETDATA_EXTENSIONS (81)
Info Value = 18061e4a8
Buffer Length = 0
StrLen = 0
[ODBC][2751622][1629226434.048233][SQLAllocHandle.c][560]
Entry:
Handle Type = 3
Input Handle = 180535670
[ODBC][2751622][1629226434.048310][SQLAllocHandle.c][1105]
Exit:[SQL_SUCCESS]
Output Handle = 180567fd0
[ODBC][2751622][1629226434.048765][SQLPrepare.c][196]
Entry:
Statement = 180567fd0
SQL = [SELECT * FROM QIWS.QCUSTCDT][length = 27 (SQL_NTS)]
[ODBC][2751622][1629226434.068560][SQLPrepare.c][377]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.068603][SQLNumParams.c][144]
Entry:
Statement = 180567fd0
Param Count = 180569c1e
[ODBC][2751622][1629226434.068634][SQLNumParams.c][231]
Exit:[SQL_SUCCESS]
Count = 180569c1e -> 0
[ODBC][2751622][1629226434.068954][SQLSetStmtAttr.c][265]
Entry:
Statement = 180567fd0
Attribute = SQL_ATTR_ROW_ARRAY_SIZE
Value = 1
StrLen = 0
[ODBC][2751622][1629226434.068989][SQLSetStmtAttr.c][928]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.069017][SQLSetStmtAttr.c][265]
Entry:
Statement = 180567fd0
Attribute = SQL_ATTR_ROW_STATUS_PTR
Value = 180502670
StrLen = 0
[ODBC][2751622][1629226434.069045][SQLSetStmtAttr.c][928]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.069074][SQLExecute.c][187]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.077744][SQLExecute.c][357]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.077777][SQLRowCount.c][173]
Entry:
Statement = 180567fd0
Row Count = 180569c60
[ODBC][2751622][1629226434.077807][SQLRowCount.c][247]
Exit:[SQL_SUCCESS]
Row Count = 180569c60 -> -1 (64 bits)
[ODBC][2751622][1629226434.077836][SQLNumResultCols.c][156]
Entry:
Statement = 180567fd0
Column Count = 180569c38
[ODBC][2751622][1629226434.077864][SQLNumResultCols.c][251]
Exit:[SQL_SUCCESS]
Count = 180569c38 -> 11
[ODBC][2751622][1629226434.077893][SQLSetStmtAttr.c][265]
Entry:
Statement = 180567fd0
Attribute = SQL_ATTR_ROW_BIND_TYPE
Value = 0
StrLen = 0
[ODBC][2751622][1629226434.077921][SQLSetStmtAttr.c][928]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.077948][SQLSetStmtAttr.c][265]
Entry:
Statement = 180567fd0
Attribute = SQL_ATTR_ROWS_FETCHED_PTR
Value = 180569c80
StrLen = 0
[ODBC][2751622][1629226434.077975][SQLSetStmtAttr.c][928]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078004][SQLDescribeCol.c][247]
Entry:
Statement = 180567fd0
Column Number = 1
Column Name = 1805646b0
Buffer Length = 1
Name Length = 180564c02
Data Type = 180564c04
Column Size = 180564c08
Decimal Digits = 180564c10
Nullable = 180564c20
[ODBC][2751622][1629226434.078193][SQLDescribeCol.c][504]
Exit:[SQL_ERROR]
[ODBC][2751622][1629226434.078222][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078252][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078282][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078310][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078340][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078368][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078399][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078426][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078455][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078483][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078513][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078541][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078569][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078597][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078626][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078653][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078682][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078709][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078739][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078766][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078795][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078822][SQLFetch.c][352]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.078852][SQLFetch.c][162]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078880][SQLFetch.c][352]
Exit:[SQL_NO_DATA]
[ODBC][2751622][1629226434.078908][SQLCloseCursor.c][139]
Entry:
Statement = 180567fd0
[ODBC][2751622][1629226434.078936][SQLCloseCursor.c][234]
Exit:[SQL_SUCCESS]
[ODBC][2751622][1629226434.108352][SQLFreeHandle.c][387]
Entry:
Handle Type = 3
Input Handle = 180567fd0
[ODBC][2751622][1629226434.108424][SQLFreeHandle.c][490]
Exit:[SQL_SUCCESS]
[ODBC][2751625][1629226442.948105][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 18069b710
[ODBC][2751625][1629226442.948144][SQLSetEnvAttr.c][189]
Entry:
Environment = 18069b710
Attribute = SQL_ATTR_ODBC_VERSION
Value = 3
StrLen = -5
[ODBC][2751625][1629226442.948172][SQLSetEnvAttr.c][381]
Exit:[SQL_SUCCESS]
[ODBC][2751628][1629226443.717858][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 1806c16b0
[ODBC][2751628][1629226443.717904][SQLSetEnvAttr.c][189]
Entry:
Environment = 1806c16b0
Attribute = SQL_ATTR_ODBC_VERSION
Value = 3
StrLen = -5
[ODBC][2751628][1629226443.717942][SQLSetEnvAttr.c][381]
Exit:[SQL_SUCCESS]
Additional context Interestingly, all of the other calls in the trace appear to be succeeding. For example, the correct number of result records is returned, they just don’t contain the right data.
The failure occurs in the call to SqlDescribeCol on line 169 of the included trace output above (about 2/3 of the way down).
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
Hey, thanks for raising this issue! I just ran into this problem as well when trying to upgrade to 2.4.0, would love to know if there’s a fix for this or a way I can help. Really appreciate this package!
Should be in 2.4.1. Closing, but feel free to reopen if you still see the issue.