Skip to content

Commit

Permalink
Don't call virtual methods from SSQLite3 constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
fredmorcos committed Nov 28, 2023
1 parent 7e5efe3 commit b81ad96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions pdns/ssqlite3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -338,7 +338,7 @@ std::unique_ptr<SSqlStatement> SSQLite3::prepare(const string& query, int nparam
return std::make_unique<SSQLite3Statement>(this, m_dolog, query);
}

void SSQLite3::execute(const string& query)
void SSQLite3::executeImpl(const string& query)
{
char* errmsg = nullptr;
std::string errstr1;
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion pdns/ssqlite3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b81ad96

Please sign in to comment.