Discussion:
[soci-users] problem setting NULL value
Michael Surette
2015-09-23 16:03:09 UTC
Permalink
I am using soci 3.2.3 on Windows compiled with TDM-GCC.. It works
well except when I try to write NULL values.

I have the following statement instatiation which will not compile

statement statusInsert= (pgDB.prepare << sqlStatusInsert,

use(status.equip), use(status.serial), use(status.customer),
use(status.city), use(status.prov), use(status.country),
use(status.status),

use(date2tm(status.rma_issued), status.rma_issued ? i_ok : i_null),

use(date2tm(status.rcvd), status.rcvd ? i_ok : i_null),

use(date2tm(status.rfqc), status.rfqc ? i_ok : i_null),

use(date2tm(status.done), status.done ? i_ok : i_null),

use(date2tm(status.ship), status.ship ? i_ok : i_null),

use(status.workdays),

use(status.rma_number), use(status.rma_sequence),
use(status.special), use(status.estimate), use(status.tech),
use(status.notes)

);

It gives me compile errors like this

C:\Users\MSurette\Documents\SpiderOak
Hive\code\DOERS\statusSync\statusSync.cpp:293: error: no matching
function for call to 'use(tm, soci::indicator)'
use(date2tm(status.rma_issued), status.rma_issued ? i_ok : i_null),
^
sqlStatusInsert is a const char * to the sql INSERT statement.
date2tm takes a Date which is really a long, and converts it to a
std::struct tm.

If I use the single argument version of use() it works fine.

Any advice on how I could set these NULL values conditionally?
--
Mike
Mateusz Loskot
2015-09-27 22:06:34 UTC
Permalink
Post by Michael Surette
I am using soci 3.2.3 on Windows compiled with TDM-GCC.. It works
well except when I try to write NULL values.
I have the following statement instatiation which will not compile
statement statusInsert= (pgDB.prepare << sqlStatusInsert,
use(status.equip), use(status.serial), use(status.customer),
use(status.city), use(status.prov), use(status.country),
use(status.status),
use(date2tm(status.rma_issued), status.rma_issued ? i_ok : i_null),
[...]
It gives me compile errors like this
C:\Users\MSurette\Documents\SpiderOak
Hive\code\DOERS\statusSync\statusSync.cpp:293: error: no matching
function for call to 'use(tm, soci::indicator)'
use(date2tm(status.rma_issued), status.rma_issued ? i_ok : i_null),
I'd have expected it to work, but I haven't used/tested SOCI 3.2 for ages.
Post by Michael Surette
Any advice on how I could set these NULL values conditionally?
Regardless, I have updated SOCI tests specifically with your use case
and it compiles/runs well (see Travis CI and Appveyor):
https://github.com/SOCI/soci/commit/68a335707a9177e69c184a6180b001d1a2015b50

I'd suggest to try SOCI form the current master (to be released as
4.0, timeline unknown).

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net

------------------------------------------------------------------------------
Loading...