diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-29 13:19:33 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-29 13:19:33 +0100 |
commit | f7160a063d5dedd9525b306534109b96087f1896 (patch) | |
tree | d53dea199a65aaf9ceac8aca75e060444087f963 /compiledsql.cpp | |
parent | 19c343fc2ea6dbf7eeae3ac7000c5c877ddfec63 (diff) |
Add SQL VACUUM to cleanup
Diffstat (limited to 'compiledsql.cpp')
-rw-r--r-- | compiledsql.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
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 <iostream> + #include <boost/algorithm/string/predicate.hpp> -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<SQLite::Statement>(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<SQLite::Statement>(m_cs.m_db, m_cs.m_query); + } +} + +CompiledSQL::Guard::~Guard() +{ + m_cs.m_stmt->reset(); +} + |