From efcea3a80da7c4479d5fe168435ecc9fd06bdc72 Mon Sep 17 00:00:00 2001 From: John Turner Date: Sun, 14 Sep 2025 00:16:10 -0400 Subject: Squashed 'subprojects/boost-sqlite/' content from commit 3378e35 git-subtree-dir: subprojects/boost-sqlite git-subtree-split: 3378e353705271e569cf4ba15c467b840a39798c --- include/boost/sqlite/extension.hpp | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 include/boost/sqlite/extension.hpp (limited to 'include/boost/sqlite/extension.hpp') diff --git a/include/boost/sqlite/extension.hpp b/include/boost/sqlite/extension.hpp new file mode 100644 index 0000000..32553fa --- /dev/null +++ b/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 +#include +#include +#include + + +/** @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 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 -- cgit v1.2.3