From 1def4fa9fff00ccffeec97a07ecea6457098dd90 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 8 Nov 2015 02:01:17 +0000 Subject: Test column indexing --- libdbpp/unittests/testUtils.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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); +} + -- cgit v1.2.3