From c9fa963e71258c5adfb71cf1996cd1bcb33df0bb Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 26 Feb 2023 08:54:17 +0100 Subject: Start with copy of whiteboard --- compiledsql.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 compiledsql.h (limited to 'compiledsql.h') 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 + +#include + +class CompiledSQL +{ +public: + CompiledSQL(SQLite::Database& db, const std::string& stmt); + + // index 1-based as in SQLite + template + void bind(int index, T value) + { + m_stmt->bind(index, value); + } + + bool execute(); + + // index 0-based as in SQLite + template + 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 m_stmt; + bool m_isSelect; // In SQLite, SELECT statements will be handled w/ executeStep(), others w/ exec() +}; + -- cgit v1.2.3