From b81ad966107dcf8b873c3abcc111a4bd9c85a3d6 Mon Sep 17 00:00:00 2001 From: Fred Morcos Date: Tue, 28 Nov 2023 09:51:39 +0100 Subject: [PATCH] Don't call virtual methods from SSQLite3 constructor --- pdns/ssqlite3.cc | 15 ++++++++++----- pdns/ssqlite3.hh | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pdns/ssqlite3.cc b/pdns/ssqlite3.cc index 660c561b7810..2fecbba5bfa5 100644 --- a/pdns/ssqlite3.cc +++ b/pdns/ssqlite3.cc @@ -290,24 +290,24 @@ SSQLite3::SSQLite3(const std::string& database, const std::string& journalmode, { if (access(database.c_str(), F_OK) == -1) { if (!creat) { - throw sPerrorException("SQLite database '" + database + "' does not exist yet"); + throw SSqlException("SQLite database '" + database + "' does not exist yet"); } } else { if (creat) { - throw sPerrorException("SQLite database '" + database + "' already exists"); + throw SSqlException("SQLite database '" + database + "' already exists"); } } if (sqlite3_open(database.c_str(), &m_pDB) != SQLITE_OK) { - throw sPerrorException("Could not connect to the SQLite database '" + database + "'"); + throw SSqlException("Could not connect to the SQLite database '" + database + "'"); } m_dolog = false; m_in_transaction = false; sqlite3_busy_handler(m_pDB, busyHandler, nullptr); if (journalmode.length() != 0) { - execute("PRAGMA journal_mode=" + journalmode); + executeImpl("PRAGMA journal_mode=" + journalmode); } } @@ -338,7 +338,7 @@ std::unique_ptr SSQLite3::prepare(const string& query, int nparam return std::make_unique(this, m_dolog, query); } -void SSQLite3::execute(const string& query) +void SSQLite3::executeImpl(const string& query) { char* errmsg = nullptr; std::string errstr1; @@ -364,6 +364,11 @@ void SSQLite3::execute(const string& query) } } +void SSQLite3::execute(const string& query) +{ + executeImpl(query); +} + int SSQLite3::busyHandler([[maybe_unused]] void* userData, [[maybe_unused]] int invocationsSoFar) { Utility::usleep(1000); diff --git a/pdns/ssqlite3.hh b/pdns/ssqlite3.hh index 29a1e10c9e99..77b67171b5c0 100644 --- a/pdns/ssqlite3.hh +++ b/pdns/ssqlite3.hh @@ -33,7 +33,8 @@ private: bool m_in_transaction; static int busyHandler(void*, int); -protected: + void executeImpl(const string& query); + public: //! Constructor. SSQLite3(const std::string& database, const std::string& journalmode, bool creat = false);