summaryrefslogtreecommitdiff
path: root/subprojects/boost-sqlite/include/boost/sqlite/extension.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/boost-sqlite/include/boost/sqlite/extension.hpp')
-rw-r--r--subprojects/boost-sqlite/include/boost/sqlite/extension.hpp67
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