diff options
Diffstat (limited to 'compiledsql.h')
-rw-r--r-- | compiledsql.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/compiledsql.h b/compiledsql.h new file mode 100644 index 0000000..bb1062c --- /dev/null +++ b/compiledsql.h @@ -0,0 +1,45 @@ +// Helper Class for SQLite backed storage + +#pragma once + +#include <memory> + +#include <SQLiteCpp/SQLiteCpp.h> + +class CompiledSQL +{ +public: + CompiledSQL(SQLite::Database& db, const std::string& stmt); + + // index 1-based as in SQLite + template<typename T> + void bind(int index, T value) + { + m_stmt->bind(index, value); + } + + bool execute(); + + // index 0-based as in SQLite + template<typename T> + T getColumn(const int index) + { + return m_stmt->getColumn(index); + } + + class Guard + { + public: + Guard(CompiledSQL& cs); + ~Guard(); + private: + CompiledSQL& m_cs; + }; + +private: + SQLite::Database& m_db; + std::string m_query; + std::shared_ptr<SQLite::Statement> m_stmt; + bool m_isSelect; // In SQLite, SELECT statements will be handled w/ executeStep(), others w/ exec() +}; + |