mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 19:25:53 +02:00
nvl reversed to DynamicAny
This commit is contained in:
@@ -53,6 +53,7 @@ using Poco::AnyCast;
|
|||||||
using Poco::InvalidAccessException;
|
using Poco::InvalidAccessException;
|
||||||
using Poco::RangeException;
|
using Poco::RangeException;
|
||||||
using Poco::BadCastException;
|
using Poco::BadCastException;
|
||||||
|
using Poco::NotFoundException;
|
||||||
using Poco::Data::SQLite::InvalidSQLStatementException;
|
using Poco::Data::SQLite::InvalidSQLStatementException;
|
||||||
using Poco::Int64;
|
using Poco::Int64;
|
||||||
|
|
||||||
@@ -1649,9 +1650,17 @@ void SQLiteTest::testNull()
|
|||||||
assert (rs.moveNext());
|
assert (rs.moveNext());
|
||||||
assert (!rs.isNull("i"));
|
assert (!rs.isNull("i"));
|
||||||
assert (rs["i"] == 2);
|
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.isNull("r"));
|
||||||
|
assert (rs.nvl("r", 123) == 123);
|
||||||
|
assert (rs.nvl("r", 1.5) == 1.5);
|
||||||
|
|
||||||
assert (rs.isNull("v"));
|
assert (rs.isNull("v"));
|
||||||
assert (rs["v"] == "");
|
assert (rs["v"] == "");
|
||||||
|
assert (rs.nvl("v", s) == "123");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -179,26 +179,24 @@ public:
|
|||||||
DynamicAny value(const std::string& name, std::size_t row) const;
|
DynamicAny value(const std::string& name, std::size_t row) const;
|
||||||
/// Returns the data value at named column, row location.
|
/// Returns the data value at named column, row location.
|
||||||
|
|
||||||
template <typename C>
|
DynamicAny nvl(const std::string& name, const DynamicAny& deflt) const
|
||||||
const C& nvl(const std::string& name, const C& deflt) const
|
|
||||||
/// Returns the value in the named column of the current row
|
/// Returns the value in the named column of the current row
|
||||||
/// if the value is not NULL, or deflt otherwise.
|
/// if the value is not NULL, or deflt otherwise.
|
||||||
{
|
{
|
||||||
if (isNull(name))
|
if (isNull(name))
|
||||||
return deflt;
|
return deflt;
|
||||||
else
|
else
|
||||||
return value<C>(name, _currentRow);
|
return value(name, _currentRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename C>
|
DynamicAny nvl(std::size_t index, const DynamicAny& deflt) const
|
||||||
const C& nvl(std::size_t index, const C& deflt) const
|
|
||||||
/// Returns the value in the given column of the current row
|
/// Returns the value in the given column of the current row
|
||||||
/// if the value is not NULL, or deflt otherwise.
|
/// if the value is not NULL, or deflt otherwise.
|
||||||
{
|
{
|
||||||
if (isNull(index))
|
if (isNull(index, _currentRow))
|
||||||
return deflt;
|
return deflt;
|
||||||
else
|
else
|
||||||
return value<C>(index, _currentRow);
|
return value(index, _currentRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
const RowIterator& begin();
|
const RowIterator& begin();
|
||||||
@@ -301,7 +299,7 @@ private:
|
|||||||
if (typeFound)
|
if (typeFound)
|
||||||
throw NotFoundException(format("Column name: %s", name));
|
throw NotFoundException(format("Column name: %s", name));
|
||||||
else
|
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;
|
std::size_t _currentRow;
|
||||||
|
Reference in New Issue
Block a user