#include "compiledsql.h" #include #include CompiledSQL::CompiledSQL(SQLite::Database& db, const std::string& stmt): m_db{db}, m_query{stmt}, m_stmt{}, m_isSelect{} { if ( #if __cplusplus >= 202002 stmt.starts_with("SELECT ") #else boost::algorithm::starts_with(stmt, "SELECT ") #endif ) { m_isSelect = true; } else { m_isSelect = false; } } bool CompiledSQL::execute() { if (m_isSelect) { return m_stmt->executeStep(); } else { return m_stmt->exec(); } } CompiledSQL::Guard::Guard(CompiledSQL& cs): m_cs{cs} { if (!m_cs.m_stmt) { m_cs.m_stmt = std::make_shared(m_cs.m_db, m_cs.m_query); } } CompiledSQL::Guard::~Guard() { m_cs.m_stmt->reset(); }