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/include/boost/sqlite/extension.hpp | |
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/include/boost/sqlite/extension.hpp')
-rw-r--r-- | subprojects/boost-sqlite/include/boost/sqlite/extension.hpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/subprojects/boost-sqlite/include/boost/sqlite/extension.hpp b/subprojects/boost-sqlite/include/boost/sqlite/extension.hpp new file mode 100644 index 0000000..32553fa --- /dev/null +++ b/subprojects/boost-sqlite/include/boost/sqlite/extension.hpp @@ -0,0 +1,67 @@ +// +// Copyright (c) 2022 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) +// + +#ifndef BOOST_SQLITE_EXTENSION_HPP +#define BOOST_SQLITE_EXTENSION_HPP + +#define BOOST_SQLITE_COMPILE_EXTENSION 1 +#include <boost/sqlite/detail/config.hpp> +#include <boost/sqlite/connection.hpp> +#include <boost/sqlite/detail/catch.hpp> +#include <boost/config.hpp> + + +/** @brief Declare a sqlite module. + @ingroup reference + + @param Name The name of the module + @param Conn The parameter name of the connection + + This macro can be used to create an sqlite extension. + + @note When defining BOOST_SQLITE_COMPILE_EXTENSION (was is done in extension.hpp) + sqlite will use an inline namespace to avoid symbol clashes. + + @par Examples + + @code{.cpp} + + BOOST_SQLITE_EXTENSION(extension, conn) + { + create_scalar_function( + conn, "assert", + [](boost::sqlite::context<>, boost::span<boost::sqlite::value, 1u> sp) + { + if (sp.front().get_int() == 0) + throw std::logic_error("assertion failed"); + }); + } + + @endcode{.cpp} + + */ +#define BOOST_SQLITE_EXTENSION(Name, Conn) \ +void sqlite_##Name##_impl (boost::sqlite::connection Conn); \ +extern "C" BOOST_SYMBOL_EXPORT \ +int sqlite3_##Name##_init( \ + sqlite3 *db, \ + char **pzErrMsg, \ + const sqlite3_api_routines *pApi) \ +{ \ + using boost::sqlite::sqlite3_api; \ + SQLITE_EXTENSION_INIT2(pApi); \ + \ + BOOST_SQLITE_TRY \ + { \ + sqlite_##Name##_impl(boost::sqlite::connection{db, false}); \ + return SQLITE_OK; \ + } \ + BOOST_SQLITE_CATCH_ASSIGN_STR_AND_RETURN(*pzErrMsg); \ +} \ +void sqlite_##Name##_impl(boost::sqlite::connection Conn) + +#endif //BOOST_SQLITE_EXTENSION_HPP |