aboutsummaryrefslogtreecommitdiff
path: root/src/cmd_attachments.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd_attachments.c')
-rw-r--r--src/cmd_attachments.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/cmd_attachments.c b/src/cmd_attachments.c
index b1590fd..7721086 100644
--- a/src/cmd_attachments.c
+++ b/src/cmd_attachments.c
@@ -111,7 +111,7 @@ static yyjson_mut_val *h_attachment_put(struct req *r)
" AND filename=?3",
-1, &st, NULL) != SQLITE_OK) {
free(content);
- return fail(r, "INTERNAL", "database error");
+ return db_error(r);
}
sqlite3_bind_int64(st, 1, r->org_id);
sqlite3_bind_blob(st, 2, hash, 32, SQLITE_TRANSIENT);
@@ -149,7 +149,7 @@ static yyjson_mut_val *h_attachment_put(struct req *r)
"content,created_at,created_by) VALUES(?1,?2,?3,?4,?5,?6,?7,?8)",
-1, &st, NULL) != SQLITE_OK) {
free(content);
- return fail(r, "INTERNAL", "database error");
+ return db_error(r);
}
sqlite3_bind_int64(st, 1, r->org_id);
sqlite3_bind_blob(st, 2, hash, 32, SQLITE_TRANSIENT);
@@ -163,7 +163,7 @@ static yyjson_mut_val *h_attachment_put(struct req *r)
sqlite3_finalize(st);
free(content);
if (rc != SQLITE_DONE)
- return fail(r, "INTERNAL", sqlite3_errmsg(r->db));
+ return db_sqlite_error(r);
int64_t id = db_last_id(r->db);
if (voucher_id) {
@@ -232,14 +232,14 @@ static yyjson_mut_val *h_attachment_unlink(struct req *r)
"DELETE FROM voucher_attachments WHERE org_id=?1"
" AND voucher_id=?2 AND attachment_id=?3",
-1, &st, NULL) != SQLITE_OK)
- return fail(r, "INTERNAL", "database error");
+ return db_error(r);
sqlite3_bind_int64(st, 1, r->org_id);
sqlite3_bind_int64(st, 2, voucher_id);
sqlite3_bind_int64(st, 3, id);
int rc = sqlite3_step(st);
sqlite3_finalize(st);
if (rc != SQLITE_DONE)
- return fail(r, "INTERNAL", sqlite3_errmsg(r->db));
+ return db_sqlite_error(r);
if (sqlite3_changes(r->db) == 0)
return fail(r, "NOT_FOUND", "link not found");
char *reqjson = audit_args_json(r->args);
@@ -260,7 +260,7 @@ static yyjson_mut_val *h_attachment_get(struct req *r)
"SELECT filename,mime,size_bytes,content,sha256,created_at"
" FROM attachments WHERE org_id=?1 AND id=?2",
-1, &st, NULL) != SQLITE_OK)
- return fail(r, "INTERNAL", "database error");
+ return db_error(r);
sqlite3_bind_int64(st, 1, r->org_id);
sqlite3_bind_int64(st, 2, id);
if (sqlite3_step(st) != SQLITE_ROW) {
@@ -321,7 +321,7 @@ static yyjson_mut_val *h_attachment_list(struct req *r)
" WHERE va3.org_id=a.org_id AND va3.attachment_id=a.id))"
" AND a.id>?4 ORDER BY a.id LIMIT ?5",
-1, &st, NULL) != SQLITE_OK)
- return fail(r, "INTERNAL", "database error");
+ return db_error(r);
sqlite3_bind_int64(st, 1, r->org_id);
sqlite3_bind_int64(st, 2, voucher_id);
sqlite3_bind_int(st, 3, unlinked);