summaryrefslogtreecommitdiffhomepage
path: root/compiledsql.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'compiledsql.cpp')
-rw-r--r--compiledsql.cpp42
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();
+}
+