summaryrefslogtreecommitdiffhomepage
path: root/compiledsql.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-01 14:53:05 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-01 14:53:05 +0100
commitcbf1ba38794ab6a323441dcc3b0e5e942f7ab386 (patch)
treec20619b90a1f9ca512aa5e1db9354178e2c2726d /compiledsql.cpp
parent1f679124bba936e7905c7f4c83186d0c961dca61 (diff)
Added CompiledSQL class, Test coverage
Diffstat (limited to 'compiledsql.cpp')
-rw-r--r--compiledsql.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/compiledsql.cpp b/compiledsql.cpp
new file mode 100644
index 0000000..a3503af
--- /dev/null
+++ b/compiledsql.cpp
@@ -0,0 +1,32 @@
+#include "compiledsql.h"
+
+CompiledSQL::CompiledSQL(SQLite::Database& db):
+ m_stmt{},
+ m_db{db},
+ m_isSelect{}
+{
+}
+
+void CompiledSQL::init(const std::string& stmt)
+{
+ if (m_stmt) {
+ m_stmt->reset();
+ } else {
+ if (stmt.starts_with("SELECT ")) {
+ m_isSelect = true;
+ } else {
+ m_isSelect = false;
+ }
+ m_stmt = std::make_shared<SQLite::Statement>(m_db, stmt);
+ }
+}
+
+bool CompiledSQL::execute()
+{
+ if (m_isSelect) {
+ return m_stmt->executeStep();
+ } else {
+ return m_stmt->exec();
+ }
+}
+