summaryrefslogtreecommitdiffstats
path: root/src/dbi.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2023-12-19 12:02:55 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2023-12-19 12:20:34 +0100
commit7292c306593b348463916130c23b86a9021866f1 (patch)
tree8cc0d2f6194fa489a7ee47d0e9d7c0759b9e424d /src/dbi.c
parentbad351b1d738c3ca42d2516c643bf9b5f5144c57 (diff)
rest: no assumption on description field in create/imagev1.2.5-7
do not use description field to decide if this is a new image or an update. add og_dbi_get_image() to check if the image exists. If it is not found, then add new image entry to database. update og_dbi_add_image() to update the image.id field.
Diffstat (limited to 'src/dbi.c')
-rw-r--r--src/dbi.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/dbi.c b/src/dbi.c
index 0c7f030..fd93fcf 100644
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -169,28 +169,11 @@ int og_dbi_get_room_info(struct og_dbi *dbi, struct og_room *room,
#define OG_UNASSIGNED_SW_ID 0
#define OG_IMAGE_DEFAULT_TYPE 1 /* monolithic */
-int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image)
+int og_dbi_add_image(struct og_dbi *dbi, struct og_image *image)
{
const char *msglog;
dbi_result result;
- result = dbi_conn_queryf(dbi->conn,
- "SELECT nombreca FROM imagenes WHERE nombreca = '%s'",
- image->name);
- if (!result) {
- dbi_conn_error(dbi->conn, &msglog);
- syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
- __func__, __LINE__, msglog);
- return -1;
- }
-
- if (dbi_result_next_row(result)) {
- syslog(LOG_ERR, "image creation attempt with already used image name (%s:%d)\n",
- __func__, __LINE__);
- dbi_result_free(result);
- return -1;
- }
- dbi_result_free(result);
result = dbi_conn_queryf(dbi->conn,
"INSERT INTO imagenes (nombreca, "
@@ -216,7 +199,34 @@ int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image)
}
dbi_result_free(result);
- return dbi_conn_sequence_last(dbi->conn, NULL);
+ image->id = dbi_conn_sequence_last(dbi->conn, NULL);
+
+ return 0;
+}
+
+bool og_dbi_get_image(struct og_dbi *dbi, struct og_image *image)
+{
+ const char *msglog;
+ dbi_result result;
+
+ result = dbi_conn_queryf(dbi->conn,
+ "SELECT nombreca, idimagen FROM imagenes WHERE nombreca = '%s'",
+ image->name);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return false;
+ }
+
+ if (dbi_result_next_row(result)) {
+ image->id = dbi_result_get_uint(result, "idimagen");
+ dbi_result_free(result);
+ return true;
+ }
+ dbi_result_free(result);
+
+ return false;
}
int og_dbi_get_repository_ip(const struct og_dbi *dbi, const uint64_t image_id,