crodri
crodri

Reputation: 1

SQLGetData doesn't work in the same way after install KB5019959

I'm trying to retrive a float value from a SQL Server database into a double variable, I'm using this code:

bool CDataAccess::GetValue(UINT col, double& value)
{
    int retCode = SQLGetData(m_hstmt, col, SQL_C_DOUBLE, &value, 0, &m_cbValue);
    ...
}

That code was working fine until last week when Windows update KB5019959 was installed; if I uninstall this update everything works fine again.

If I use SQL_C_FLOAT as parameter or change column type to double, it works, but that change will carry a hugh refactor...

Upvotes: 0

Views: 493

Answers (1)

Nathan W
Nathan W

Reputation: 55502

There seems to be a possible change in behavior with how BufferLength is treated with doubles in the later versions of the driver when 0 is passed as the value. 0 used to work however no longer does for the default driver.

The following will return the correct data from my testing:

    SQLDOUBLE value;
    SQLLEN lengthIndicator = 0;
    SQLRETURN r;
    r = SQLGetData(hstmt, col, SQL_C_DOUBLE, &value, sizeof(value), &lengthIndicator);

NOTE: sizeof(value) being passed as BufferLength vs 0 like before

We have encountered the same bug in QGIS which implementing the above fix has resolved the issue (https://github.com/qgis/QGIS/issues/50865)

Upvotes: 0

Related Questions