]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/ssqlite3.hh
Merge pull request #14267 from ZaphodB/master
[thirdparty/pdns.git] / pdns / ssqlite3.hh
CommitLineData
12471842
PL
1/*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
fc3c07b4 4 *
12471842
PL
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.
fc3c07b4 8 *
12471842
PL
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.
fc3c07b4 12 *
12471842
PL
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.
fc3c07b4 17 *
12471842
PL
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.
fc3c07b4 21 */
e8c59f2d 22#pragma once
0b67a76d
BH
23#include <sqlite3.h>
24#include "pdns/backends/gsql/ssql.hh"
25
26class SSQLite3 : public SSql
27{
28private:
29 //! Pointer to the SQLite database instance.
ca0b6be1 30 sqlite3* m_pDB{nullptr};
0b67a76d 31
a464c196 32 bool m_dolog;
0f310932 33 bool m_in_transaction;
cb8934ae 34 static int busyHandler(void*, int);
ca0b6be1 35
b81ad966
FM
36 void executeImpl(const string& query);
37
0b67a76d
BH
38public:
39 //! Constructor.
ca0b6be1 40 SSQLite3(const std::string& database, const std::string& journalmode, bool creat = false);
0b67a76d
BH
41
42 //! Destructor.
7e5efe3c 43 ~SSQLite3() override;
0b67a76d 44
a59a9c23 45 std::unique_ptr<SSqlStatement> prepare(const string& query, int nparams) override;
346805ce
AT
46 void execute(const string& query) override;
47 void setLog(bool state) override;
0b67a76d 48
346805ce
AT
49 void startTransaction() override;
50 void commit() override;
51 void rollback() override;
0b67a76d 52
ca0b6be1 53 sqlite3* db() { return this->m_pDB; };
0b67a76d 54
7e5efe3c 55 [[nodiscard]] bool inTransaction() const { return m_in_transaction; };
e237ea04 56
0b67a76d 57 //! Used to create an backend specific exception message.
ca0b6be1 58 SSqlException sPerrorException(const std::string& reason) override;
0b67a76d 59};