summaryrefslogtreecommitdiff
path: root/test/static_resultset.cpp
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
commitefcea3a80da7c4479d5fe168435ecc9fd06bdc72 (patch)
tree5cb0177e17b1b00a177f2e830e809f606334571b /test/static_resultset.cpp
downloadsqlite-kv-bench-efcea3a80da7c4479d5fe168435ecc9fd06bdc72.tar.gz
Squashed 'subprojects/boost-sqlite/' content from commit 3378e35
git-subtree-dir: subprojects/boost-sqlite git-subtree-split: 3378e353705271e569cf4ba15c467b840a39798c
Diffstat (limited to 'test/static_resultset.cpp')
-rw-r--r--test/static_resultset.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/test/static_resultset.cpp b/test/static_resultset.cpp
new file mode 100644
index 0000000..6a9b7c0
--- /dev/null
+++ b/test/static_resultset.cpp
@@ -0,0 +1,95 @@
+//
+// Copyright (c) 2024 Klemens Morgenstern (klemens.morgenstern@gmx.net)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+
+#include <boost/sqlite/static_resultset.hpp>
+#include <boost/sqlite/connection.hpp>
+
+#include <boost/describe/class.hpp>
+
+#include "test.hpp"
+
+using namespace boost;
+
+BOOST_AUTO_TEST_CASE(tuple)
+{
+ sqlite::connection conn;
+ conn.connect(":memory:");
+ conn.execute(
+#include "test-db.sql"
+ );
+
+ using tup = std::tuple<sqlite_int64, sqlite::string_view, sqlite::string_view>;
+
+ bool found = false;
+ for (tup t : conn.query<tup>("select id, first_name, last_name from author where last_name = 'hodges';"))
+ {
+ BOOST_CHECK(std::get<1>(t) == "richard");
+ found = true;
+ }
+ BOOST_CHECK(found);
+
+ found = false;
+ for (tup t : conn.prepare("select id, first_name, last_name from author where last_name = ?;")
+ .execute<tup>({"hodges"}))
+ {
+ BOOST_CHECK(std::get<1>(t) == "richard");
+ found = true;
+ }
+ BOOST_CHECK(found);
+
+ BOOST_CHECK_THROW(conn.query<tup>("select first_name, last_name from author where last_name = 'hodges';"),
+ system::system_error);
+ conn.close();
+}
+
+struct author
+{
+ std::string last_name;
+ std::string first_name;
+};
+
+#if __cplusplus < 202002L
+BOOST_DESCRIBE_STRUCT(author, (), (last_name, first_name));
+#endif
+
+#if __cplusplus > 201402L
+
+BOOST_AUTO_TEST_CASE(reflection)
+{
+ sqlite::connection conn;
+ conn.connect(":memory:");
+ conn.execute(
+#include "test-db.sql"
+ );
+
+
+ bool found = false;
+ for (author t : conn.query<author>("select first_name, last_name from author where last_name = 'hodges';"))
+ {
+ BOOST_CHECK(t.first_name == "richard");
+ BOOST_CHECK(t.last_name == "hodges");
+ found = true;
+ }
+ BOOST_CHECK(found);
+
+ found = false;
+ for (author t : conn.prepare("select first_name, last_name from author where last_name = ?;")
+ .execute<author>({"hodges"}))
+ {
+ BOOST_CHECK(t.first_name == "richard");
+ BOOST_CHECK(t.last_name == "hodges");
+ found = true;
+ }
+ BOOST_CHECK(found);
+
+ BOOST_CHECK_THROW(conn.query<author>("select id, first_name, last_name from author where last_name = 'hodges';"),
+ system::system_error);
+ conn.close();
+}
+
+#endif