diff options
author | John Ankarström <john@ankarstrom.se> | 2021-09-17 20:57:05 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-09-17 20:57:05 +0200 |
commit | 361bb55f01ba28960a8127b0a16c1e7a7a8de61a (patch) | |
tree | ff0479af1c9283c8a0546025022ebc54616a9a75 /db.c | |
parent | 2810ad72aeb973a898034d6875922284062c5ce0 (diff) | |
download | cforum-361bb55f01ba28960a8127b0a16c1e7a7a8de61a.tar.gz |
Rewrite mktpl script in C
The Perl version didn't handle multiple interpolations on the same line.
Diffstat (limited to 'db.c')
-rw-r--r-- | db.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -0,0 +1,36 @@ +#include <err.h> +#include <stdlib.h> +#include <sqlite3.h> +#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; +}
\ No newline at end of file |