I'm making a query using POCO::Data with ODBC Connector, and I need to check for NULL values from code. In the documentation, the Recordset object is supposed to have the function isNull, but the code I download here does not contains such a method (version 1.4.6p4 right now).
How can I check then if a value is NULL with POCO library? I'm trying to create a JSON string with the data retrieved from database.
My actual code looks like this:
Session session(bdName, conn);
Statement select(session);
select << sSQL;
select.execute();
RecordSet rs(select);
bool more = rs.moveFirst();
std::size_t cols = rs.columnCount();
sResult = "{\"rowsField\":[";
while (more) {
if (sResult.back() != '[') sResult += ','; // Not first time
sResult += "{\"columnsField\":[";
for (std::size_t col = 0; col < cols; ++col) {
std::string cName = rs.columnName (col);
std::string tName = getPocoTypeName(rs.columnType(col));
std::string val = "";
if (!rs[col] || rs.value(col).isEmpty())
val = "NULL"; // DOES NOT WORK
else
val = rs[col].convert<std::string>();
if (col != 0) sResult += ',';
sResult += "\n{\"nameField\":\"" + cName + '\"';
sResult += ",\"typeField\":\"" + tName + '\"';
sResult += ",\"valueField\":\"" + val + '\"';
sResult += "}"; // each JSON column/value
}
sResult += "]}\n"; // columnsField (one per row)
more = rs.moveNext();
}