Cleanup ugly function
FossilOrigin-Name: 5c0ec775ebba2b7c5926159a43ea037df373031e86b44acaee0c3606c0723c76
This commit is contained in:
parent
620e246d42
commit
0ade3e421e
1 changed files with 6 additions and 25 deletions
|
@ -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<const char*>(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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue