nvl reversed to DynamicAny

This commit is contained in:
Aleksandar Fabijanic 2007-10-23 19:40:06 +00:00
parent 65587e39a3
commit 98191f1b2b
2 changed files with 15 additions and 8 deletions

View File

@ -53,6 +53,7 @@ using Poco::AnyCast;
using Poco::InvalidAccessException;
using Poco::RangeException;
using Poco::BadCastException;
using Poco::NotFoundException;
using Poco::Data::SQLite::InvalidSQLStatementException;
using Poco::Int64;
@ -1649,9 +1650,17 @@ void SQLiteTest::testNull()
assert (rs.moveNext());
assert (!rs.isNull("i"));
assert (rs["i"] == 2);
Poco::Int64 i64 = 0;
assert (rs.nvl("i", i64) == 2);
assert (rs.nvl("i", 123) == 2);
assert (rs.isNull("r"));
assert (rs.nvl("r", 123) == 123);
assert (rs.nvl("r", 1.5) == 1.5);
assert (rs.isNull("v"));
assert (rs["v"] == "");
assert (rs.nvl("v", s) == "123");
}

View File

@ -179,26 +179,24 @@ public:
DynamicAny value(const std::string& name, std::size_t row) const;
/// Returns the data value at named column, row location.
template <typename C>
const C& nvl(const std::string& name, const C& deflt) const
DynamicAny nvl(const std::string& name, const DynamicAny& deflt) const
/// Returns the value in the named column of the current row
/// if the value is not NULL, or deflt otherwise.
{
if (isNull(name))
return deflt;
else
return value<C>(name, _currentRow);
return value(name, _currentRow);
}
template <typename C>
const C& nvl(std::size_t index, const C& deflt) const
DynamicAny nvl(std::size_t index, const DynamicAny& deflt) const
/// Returns the value in the given column of the current row
/// if the value is not NULL, or deflt otherwise.
{
if (isNull(index))
if (isNull(index, _currentRow))
return deflt;
else
return value<C>(index, _currentRow);
return value(index, _currentRow);
}
const RowIterator& begin();
@ -301,7 +299,7 @@ private:
if (typeFound)
throw NotFoundException(format("Column name: %s", name));
else
throw NotFoundException(format("Column type: %s, name: %s", typeid(C).name(), name));
throw NotFoundException(format("Column type: %s, name: %s", std::string(typeid(T).name()), name));
}
std::size_t _currentRow;