Insert on a table with NULL boost::optional fields (MSSQL)
Posted: Tue May 29, 2018 8:19 am
We're seeing an error message from MSSQL Server when attempting to perform an insert on a table with boost::optional fields, where we have left one or more optional field as NULL.
I don't recall the specific error message as we've since modified qxorm to fix it, but effectively it was unhappy that the bound data type of the optional field did not match the type it was expecting.
The modifications are as follows:
In the toVariant functions in:
QxBoostOptionalOnly.h (approx line 98)
QxStdOptional.h (approx line 113)
And the corresponding templated toVariant function in:
QxConvert_ToVariant.inl (approx line 161)
Modify return QVariant(); to return QVariant(QVariant(T()).type());.
This ensures the uninitialised variant is of the correct type when it is bound to the query.
I don't recall the specific error message as we've since modified qxorm to fix it, but effectively it was unhappy that the bound data type of the optional field did not match the type it was expecting.
The modifications are as follows:
In the toVariant functions in:
QxBoostOptionalOnly.h (approx line 98)
QxStdOptional.h (approx line 113)
And the corresponding templated toVariant function in:
QxConvert_ToVariant.inl (approx line 161)
Modify return QVariant(); to return QVariant(QVariant(T()).type());.
This ensures the uninitialised variant is of the correct type when it is bound to the query.