diff options
author | John Turner <jturner.usa@gmail.com> | 2025-09-14 00:16:10 -0400 |
---|---|---|
committer | John Turner <jturner.usa@gmail.com> | 2025-09-14 00:16:10 -0400 |
commit | 13e0821fd783a1d5083d825af53cf20e8dcbfd76 (patch) | |
tree | 1ea363b0f13b3e87d177100e6ae6b9f30a2de1b8 /subprojects/boost-sqlite/test/static_resultset.cpp | |
parent | aa55cb93036a89c64c08e08f4e1de4fa1fd5a775 (diff) | |
parent | efcea3a80da7c4479d5fe168435ecc9fd06bdc72 (diff) | |
download | sqlite-kv-bench-13e0821fd783a1d5083d825af53cf20e8dcbfd76.tar.gz |
Merge commit 'efcea3a80da7c4479d5fe168435ecc9fd06bdc72' as 'subprojects/boost-sqlite'
Diffstat (limited to 'subprojects/boost-sqlite/test/static_resultset.cpp')
-rw-r--r-- | subprojects/boost-sqlite/test/static_resultset.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/subprojects/boost-sqlite/test/static_resultset.cpp b/subprojects/boost-sqlite/test/static_resultset.cpp new file mode 100644 index 0000000..6a9b7c0 --- /dev/null +++ b/subprojects/boost-sqlite/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 |