]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of PowerDNS or dnsdist. | |
3 | * Copyright -- PowerDNS.COM B.V. and its contributors | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * In addition, for the avoidance of any doubt, permission is granted to | |
10 | * link this program with OpenSSL and to (re)distribute the binaries | |
11 | * produced as the result of such linking. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | */ | |
22 | #pragma once | |
23 | #include <sqlite3.h> | |
24 | #include "pdns/backends/gsql/ssql.hh" | |
25 | ||
26 | class SSQLite3 : public SSql | |
27 | { | |
28 | private: | |
29 | //! Pointer to the SQLite database instance. | |
30 | sqlite3* m_pDB{nullptr}; | |
31 | ||
32 | bool m_dolog; | |
33 | bool m_in_transaction; | |
34 | static int busyHandler(void*, int); | |
35 | ||
36 | void executeImpl(const string& query); | |
37 | ||
38 | public: | |
39 | //! Constructor. | |
40 | SSQLite3(const std::string& database, const std::string& journalmode, bool creat = false); | |
41 | ||
42 | //! Destructor. | |
43 | ~SSQLite3() override; | |
44 | ||
45 | std::unique_ptr<SSqlStatement> prepare(const string& query, int nparams) override; | |
46 | void execute(const string& query) override; | |
47 | void setLog(bool state) override; | |
48 | ||
49 | void startTransaction() override; | |
50 | void commit() override; | |
51 | void rollback() override; | |
52 | ||
53 | sqlite3* db() { return this->m_pDB; }; | |
54 | ||
55 | [[nodiscard]] bool inTransaction() const { return m_in_transaction; }; | |
56 | ||
57 | //! Used to create an backend specific exception message. | |
58 | SSqlException sPerrorException(const std::string& reason) override; | |
59 | }; |