#pragma once #include "Sql.hpp" #include #include namespace odhtdb { class SqlQueryException : public std::runtime_error { public: SqlQueryException(const std::string &errMsg) : std::runtime_error(errMsg) {} }; class SqlQuery { public: // Throws SqlQueryException on failure SqlQuery(sqlite3 *db, const char *sql, std::initializer_list args); ~SqlQuery(); // Return true if we got result, false if there are not rows left. // Throws SqlQueryException on failure bool next(); int getInt(int index); i64 getInt64(int index); // The returned blob is NOT a copy, it will be invalid after next call to @next or when SqlQuery is deallocated const DataView getBlob(int index); private: void checkColumnIndex(int index); private: sqlite3 *db; sqlite3_stmt *stmt; int numColumns; }; }