From 98191f1b2b690c4fda1983701b2a1ac706dd9cd2 Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Tue, 23 Oct 2007 19:40:06 +0000 Subject: [PATCH] nvl reversed to DynamicAny --- Data/SQLite/testsuite/src/SQLiteTest.cpp | 9 +++++++++ Data/include/Poco/Data/RecordSet.h | 14 ++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Data/SQLite/testsuite/src/SQLiteTest.cpp b/Data/SQLite/testsuite/src/SQLiteTest.cpp index 6a5403e04..33127cc89 100644 --- a/Data/SQLite/testsuite/src/SQLiteTest.cpp +++ b/Data/SQLite/testsuite/src/SQLiteTest.cpp @@ -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"); } diff --git a/Data/include/Poco/Data/RecordSet.h b/Data/include/Poco/Data/RecordSet.h index 7aa2048a1..3c1f0cba5 100644 --- a/Data/include/Poco/Data/RecordSet.h +++ b/Data/include/Poco/Data/RecordSet.h @@ -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 - 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(name, _currentRow); + return value(name, _currentRow); } - template - 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(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;