31 lines
701 B
C++
31 lines
701 B
C++
|
//
|
||
|
// Created by quentin on 1/18/23.
|
||
|
//
|
||
|
|
||
|
#include "database.h"
|
||
|
#include <sqlite3.h>
|
||
|
#include <stdexcept>
|
||
|
|
||
|
bool Database::doesAccountExist(const std::string &account, sqlite3 *db) {
|
||
|
sqlite3_stmt *stmt;
|
||
|
int rc = sqlite3_prepare_v2(db, "SELECT * FROM account WHERE name = ?", -1, &stmt, nullptr);
|
||
|
|
||
|
if (rc != SQLITE_OK) {
|
||
|
throw std::runtime_error("Failed to create account existing query");
|
||
|
}
|
||
|
|
||
|
sqlite3_bind_text(stmt, 1, account.c_str(), -1, SQLITE_TRANSIENT);
|
||
|
|
||
|
rc = sqlite3_step(stmt);
|
||
|
sqlite3_finalize(stmt);
|
||
|
|
||
|
if (rc == SQLITE_ROW) {
|
||
|
return true;
|
||
|
} else if (rc == SQLITE_DONE) {
|
||
|
return false;
|
||
|
} else {
|
||
|
throw std::runtime_error("Failed to step account existing statement.");
|
||
|
}
|
||
|
|
||
|
}
|