diff --git a/src/database/sqlite/sqlite.cpp b/src/database/sqlite/sqlite.cpp index 609d980..a85261d 100644 --- a/src/database/sqlite/sqlite.cpp +++ b/src/database/sqlite/sqlite.cpp @@ -131,9 +131,7 @@ Types::User SQLite::get_user(unsigned long id) // Setup function sqlite_compile_to_cache(GET_USER_BY_ID, "SELECT acct FROM users WHERE id=?1"); - sqlite_exec(GET_USER_BY_ID, - {id}, - [&luser](sqlite3_stmt* stmt){ + sqlite_exec(GET_USER_BY_ID, {id}, [&luser](sqlite3_stmt* stmt){ luser.acct = reinterpret_cast(sqlite3_column_text(stmt, 0)); }); @@ -143,30 +141,13 @@ Types::User SQLite::get_user(unsigned long id) Types::User SQLite::get_user(const std::string& acct) { Types::User luser{0, {}, false, acct, {}, {}}; - int code = 0; - constexpr std::string_view sql{"SELECT id FROM users WHERE acct=?1"}; - auto begin = sql.begin(); - static sqlite3_stmt* stmt = nullptr; - - if (!stmt) code = sqlite3_prepare_v2(db, &(*begin), sql.length(), &stmt, nullptr); - - if (code == SQLITE_ERROR) - { - using namespace std::string_literals; - const std::string err_msg = "Couldn't: "s + std::string(sqlite3_errmsg(db)); - throw std::runtime_error(err_msg); - } - - code = sqlite3_bind_text(stmt, 1, acct.c_str(), acct.length(), nullptr); - - while ((code = sqlite3_step(stmt)) == SQLITE_ROW) - { + // Setup function + sqlite_compile_to_cache(GET_USER_BY_ACCT, "SELECT acct FROM users WHERE acct=?1"); + + sqlite_exec(GET_USER_BY_ID, {acct}, [&luser](sqlite3_stmt* stmt){ luser.id = sqlite3_column_int64(stmt, 0); - } - - - if (code == SQLITE_DONE) sqlite3_reset(stmt); + }); return luser; }