summaryrefslogtreecommitdiffstats
path: root/src/dbi.c
diff options
context:
space:
mode:
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,