blob: 2aa371f5a31ac84bf94e80709445855636048171 (
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
|
// Copyright (c) 2022 Klemens D. Morgenstern
//
// 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/hooks.hpp>
#include <boost/sqlite/connection.hpp>
#include "test.hpp"
using namespace boost;
BOOST_AUTO_TEST_CASE(hooks)
{
sqlite::connection conn(":memory:");
conn.execute(
#include "test-db.sql"
);
bool called = false;
auto l =
[&](int op, core::string_view db, core::string_view table, sqlite3_int64 ) noexcept
{
BOOST_CHECK(op == SQLITE_INSERT);
BOOST_CHECK(db == "main");
BOOST_CHECK(table == "library");
called = true;
};
sqlite::update_hook(conn, l);
// language=sqlite
conn.query(R"(
insert into library ("name", "author") values
('mustache',(select id from author where first_name = 'peter' and last_name = 'dimov'));
)");
BOOST_CHECK(called);
#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
auto hk = [](sqlite::preupdate_context ctx,
int op,
const char * db_name,
const char * table_name,
sqlite3_int64 current_key,
sqlite3_int64 new_key) noexcept
{
};
preupdate_hook(conn, hk);
#endif
}
|