From f7160a063d5dedd9525b306534109b96087f1896 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 29 Jan 2023 13:19:33 +0100 Subject: Add SQL VACUUM to cleanup --- compiledsql.cpp | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'compiledsql.cpp') diff --git a/compiledsql.cpp b/compiledsql.cpp index 818ab35..b8d6d70 100644 --- a/compiledsql.cpp +++ b/compiledsql.cpp @@ -1,31 +1,25 @@ #include "compiledsql.h" +#include + #include -CompiledSQL::CompiledSQL(SQLite::Database& db): - m_stmt{}, +CompiledSQL::CompiledSQL(SQLite::Database& db, const std::string& stmt): m_db{db}, + m_query{stmt}, + m_stmt{}, m_isSelect{} { -} - -void CompiledSQL::init(const std::string& stmt) -{ - if (m_stmt) { - m_stmt->reset(); - } else { - if ( + if ( #if __cplusplus >= 202002 - stmt.starts_with("SELECT ") + stmt.starts_with("SELECT ") #else - boost::algorithm::starts_with(stmt, "SELECT ") + boost::algorithm::starts_with(stmt, "SELECT ") #endif - ) { - m_isSelect = true; - } else { - m_isSelect = false; - } - m_stmt = std::make_shared(m_db, stmt); + ) { + m_isSelect = true; + } else { + m_isSelect = false; } } @@ -38,3 +32,15 @@ bool CompiledSQL::execute() } } +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(); +} + -- cgit v1.2.3