#include #include #include #include "db.h" struct user * getuser(int id) { sqlite3_stmt *stmt; struct user *user; if(sqlite3_prepare(db, "SELECT name, hash FROM users WHERE oid = ?", -1, &stmt, 0) != SQLITE_OK) goto null; if(sqlite3_bind_int(stmt, 1, id) != SQLITE_OK) goto null; if(sqlite3_step(stmt) != SQLITE_ROW) goto null; if(!(user = malloc(sizeof(struct user)))) err(1, "malloc"); user->id = id; user->name = sqlite3_column_text(stmt, 0); user->hash = sqlite3_column_text(stmt, 1); sqlite3_finalize(stmt); return user; null: sqlite3_finalize(stmt); return NULL; }