diff options
Diffstat (limited to 'compiledsql.cpp')
-rw-r--r-- | compiledsql.cpp | 32 |
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(); + } +} + |