aboutsummaryrefslogtreecommitdiff
path: root/db_section.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-09-22 17:32:44 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2026-02-13 09:57:39 +0100
commit78bf2fe4a5bf37514f6dfd203ef969da0bf40c2e (patch)
tree33f9440b8ee0fa7a3b3ad033616d722d2101bb4d /db_section.c
parent107a2e43d54f9a42fb85b00b83cb0d9abb194680 (diff)
Setup project skeletonHEADmaster
Diffstat (limited to 'db_section.c')
-rw-r--r--db_section.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/db_section.c b/db_section.c
new file mode 100644
index 0000000..72aa227
--- /dev/null
+++ b/db_section.c
@@ -0,0 +1,59 @@
+#define _POSIX_C_SOURCE 200809L
+
+#include "db.h"
+#include <sqlite3.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void db_section_free(struct db_section *const s)
+{
+ if (!s)
+ return;
+
+ free(s->name);
+ free(s->desc);
+}
+
+int db_section(sqlite3 *const db, sqlite3_stmt *const stmt,
+ struct db_section *const s)
+{
+ unsigned long long id, catid;
+ char *name = NULL, *desc = NULL;
+
+ if (db_biguint(db, stmt, "id", &id))
+ {
+ fprintf(stderr, "%s: failed to get id\n", __func__);
+ goto failure;
+ }
+ else if (db_biguint(db, stmt, "catid", &catid))
+ {
+ fprintf(stderr, "%s: failed to get category id\n", __func__);
+ goto failure;
+ }
+ else if (!(name = db_str(db, stmt, "name")))
+ {
+ fprintf(stderr, "%s: failed to get name\n", __func__);
+ goto failure;
+ }
+ else if (!(desc = db_str(db, stmt, "description")))
+ {
+ fprintf(stderr, "%s: failed to get name\n", __func__);
+ goto failure;
+ }
+
+ *s = (const struct db_section)
+ {
+ .catid = catid,
+ .name = name,
+ .desc = desc,
+ .id = id
+ };
+
+ return 0;
+
+failure:
+ free(desc);
+ free(name);
+ return -1;
+}