0

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...

2
  • Would something like this work? float tmp; int retCode = SQLGetData(m_hstmt, col, SQL_C_FLOAT, &tmp, 0, &m_cbValue); *value = tmp;? My C++ is rusty... Nov 15, 2022 at 15:07
  • Hi Joachim! Yes, if I use a float variable it works, but I need that my method GetValue(UINT col, double& value) will be able to work when database column was float or double.
    – crodri
    Nov 15, 2022 at 15:40

1 Answer 1

0

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)

1
  • 1
    With sizeof(value) everything works again, many thanks!!
    – crodri
    Nov 28, 2022 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.