summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdbpp/unittests/testUtils.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/libdbpp/unittests/testUtils.cpp b/libdbpp/unittests/testUtils.cpp
index 578609a..34e172d 100644
--- a/libdbpp/unittests/testUtils.cpp
+++ b/libdbpp/unittests/testUtils.cpp
@@ -41,3 +41,20 @@ BOOST_AUTO_TEST_CASE( execute )
db->execute("UPDATE forEachRow SET a = 2");
}
+BOOST_AUTO_TEST_CASE( columns )
+{
+ auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto sel = DB::SelectCommandPtr(db->newSelectCommand("SELECT a, b, c, d, e FROM forEachRow ORDER BY a LIMIT 1"));
+ sel->execute();
+ BOOST_REQUIRE_THROW((*sel)[5], DB::ColumnIndexOutOfRange);
+ BOOST_REQUIRE_THROW((*sel)[-1], DB::ColumnIndexOutOfRange);
+ BOOST_REQUIRE_EQUAL(0, (*sel)[0].colNo);
+ BOOST_REQUIRE_EQUAL(4, (*sel)[4].colNo);
+ BOOST_REQUIRE_EQUAL("c", (*sel)[2].name);
+ BOOST_REQUIRE_EQUAL(0, (*sel)["a"].colNo);
+ BOOST_REQUIRE_EQUAL(4, (*sel)["e"].colNo);
+ BOOST_REQUIRE_THROW((*sel)["f"], DB::ColumnDoesNotExist);
+ BOOST_REQUIRE_THROW((*sel)["aa"], DB::ColumnDoesNotExist);
+ BOOST_REQUIRE_THROW((*sel)[""], DB::ColumnDoesNotExist);
+}
+