How can I set a NULL value with QSqlQuery::addBindValue()?
-
I have a sql string like this in QSqlQuery
"insert into BankAccountStatement_Scotia(id, fk_CompoundStatement, owner, account, isDollarAccount, initialBalance, booksBalance, retenidoDiferido, availableBalance, date, inputFile) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
what parameter can I feed addBindValue to make it represent NULL? Or do I absolutely need to change my sql string by removing the field that I want to leave NULL?
-
@JonB It actually works!!
However when reading the record instead of NULL it is represented by 0 (the field is an optional integer -- that is std::optional<int>).So if I compare the record going in with the record read they are not the same!!
Any way around this?
Intercepting the reading from the database to represent the NULL value as a std::nullopt??
-
@JonB You are correct. Reading the value returns QVariant{} (debugger reads (null))... But how do I check for a null value?
I tried this:
QVariant value = rec.value(1); if (rec.value(1) == QVariant()) { fk_CompoundStatement = std::nullopt; }
but the if does not return true even though value is (null) according to debugger!!
-