blob: 32553fa0e996a10beef352bebcfb8efe3ece6d59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
|