Insert on a table with NULL boost::optional fields (MSSQL)

You find a bug using QxOrm library and you know how to fix it : submit a patch on this forum

Insert on a table with NULL boost::optional fields (MSSQL)

Postby JonCat » 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.
JonCat
 
Posts: 9
Joined: Tue May 29, 2018 7:31 am

Re: Insert on a table with NULL boost::optional fields (MSSQ

Postby qxorm » Mon Jun 04, 2018 7:51 pm

Hello,

Thx for your patch !
Here is a version which includes your patch : https://www.qxorm.com/version/QxOrm_1.4.5_BETA_14.zip

Instead of writing return QVariant(QVariant(T()).type());, I created a class named qx::trait::construct_null_qvariant<T> (to be able to register your own types).
Please let me know if it works as expected.

Here is the changes log of this version :
- Fix an issue in qx::IxSqlQueryBuilder class when QxOrm library is used in a multi-thread environment
- Support latest version of boost (1.66)
- Update boost portable binary serialization classes to version 5.1 (provided by https://archive.codeplex.com/?p=epa)
- Fix an issue building SQL query for Oracle database (doesn't support AS keyword for table alias)
- Improve qx::QxClassX::registerAllClasses() function : possibility to initialize all relations (useful to work with introspection engine)
- Improve qx::IxPersistable interface : provide new methods toJson() / fromJson()
- Improve documentation/website : change http://www.qxorm.com by https://www.qxorm.com everywhere
- Fix fetching relations with soft delete putting SQL condition in the JOIN part instead of WHERE part
- Fix SQL generator for Oracle database : use new limit/pagination syntax (version Oracle > 12.1)
- Improve SQL generator interface : add 'onBeforeSqlPrepare()' method to modify/log SQL queries in custom classes
- Add an option in qx::QxSqlDatabase class to format SQL query (pretty-printing) before logging it (can be customized creating a qx::dao::detail::IxSqlGenerator sub-class)
- Fix an issue with boost/std::optional (to manage NULL database values) and some databases : if optional is empty, then create a NULL QVariant based on QVariant::Type
- Add an option in qx::QxSqlDatabase class to insert square brackets in SQL queries for table name and/or column name (to support specific database keywords)
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Insert on a table with NULL boost::optional fields (MSSQ

Postby JonCat » Tue Jun 05, 2018 9:04 pm

Works as expected - thanks!
JonCat
 
Posts: 9
Joined: Tue May 29, 2018 7:31 am

Re: Insert on a table with NULL boost::optional fields (MSSQ

Postby qxorm » Wed Jun 06, 2018 3:20 pm

Works as expected - thanks!

Great !
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Submit a patch

Who is online

Users browsing this forum: No registered users and 4 guests

cron