15 sqlite3_prepare_v2(db, sql, -1, &stmt_,
nullptr);
18 StmtGuard(sqlite3* db,
const std::string& sql)
noexcept {
19 sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt_,
nullptr);
24 sqlite3_finalize(stmt_);
30 explicit operator bool() const noexcept {
31 return stmt_ !=
nullptr;
33 sqlite3_stmt*
get() const noexcept {
38 return sqlite3_step(stmt_);
44 void bindText(
int col,
const std::string& v)
noexcept {
45 sqlite3_bind_text(stmt_, col, v.c_str(), -1, SQLITE_TRANSIENT);
48 sqlite3_bind_int(stmt_, col, v);
51 sqlite3_bind_int64(stmt_, col, v);
54 sqlite3_bind_double(stmt_, col, v);
58 const auto* t = sqlite3_column_text(stmt_, col);
59 return t ?
reinterpret_cast<const char*
>(t) : std::string{};
62 return sqlite3_column_int(stmt_, col);
65 return sqlite3_column_int64(stmt_, col);
68 return sqlite3_column_double(stmt_, col);
72 sqlite3_stmt* stmt_ =
nullptr;
StmtGuard & operator=(const StmtGuard &)=delete
std::string columnText(int col) const noexcept
sqlite3_stmt * get() const noexcept
int64_t columnInt64(int col) const noexcept
StmtGuard(const StmtGuard &)=delete
void bindInt(int col, int v) noexcept
double columnDouble(int col) const noexcept
StmtGuard(sqlite3 *db, const char *sql) noexcept
void bindInt64(int col, int64_t v) noexcept
StmtGuard(sqlite3 *db, const std::string &sql) noexcept
void bindText(int col, const std::string &v) noexcept
int columnInt(int col) const noexcept
void bindDouble(int col, double v) noexcept