Files
spark/src/lib/utils/Sqlite_utils.cpp
T
John Colvin 3b1a2357cc fix build (client): Change 'WIN32' macros to '_WIN32'
Not sure exactly how this broke, but the WIN32 macro is no longer defined.
2023-01-02 18:42:39 -05:00

45 lines
1.2 KiB
C++

#ifndef _WIN32
#include "Sqlite_utils.h"
#include "bts_assert.h"
#include <cstring>
namespace bts {
namespace sqlite {
void exec_nofail(sqlite3 *db, const char *sql) {
char *error_message = nullptr;
int result = sqlite3_exec(db, sql, nullptr, nullptr, &error_message);
bts_assert_msg(result == SQLITE_OK, error_message);
}
void exec_nofail(sqlite3_ptr &db, const char *sql) {
return exec_nofail(db.get(), sql);
}
sqlite3_ptr open_db(const char *path) {
sqlite3 *temp;
if (sqlite3_open(path, &temp) == SQLITE_OK) {
return sqlite3_ptr(temp, sqlite3_close);
} else {
LOG(Gen, Error, "Failed to open database {}", std::string(path));
return null_db();
}
}
sqlite3_stmt_ptr prepare_query(sqlite3 *db, const char *query) {
sqlite3_stmt *pquery;
const char *tail = nullptr;
sqlite3_prepare_v2(db, query, -1, &pquery, &tail);
bts_assert(
tail == nullptr ||
strlen(tail) == 0); // A tail indicates multiple statements in prepared
// statement string
return sqlite3_stmt_ptr(pquery, sqlite3_finalize);
}
sqlite3_stmt_ptr prepare_query(sqlite3_ptr &db, const char *query) {
return prepare_query(db.get(), query);
}
} // namespace sqlite
} // namespace bts
#endif