From a675dbb083af5bd64e33097754042cf54fef8b8b Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Fri, 19 Jul 2024 14:13:57 +0200 Subject: client: split revision query when updating image information a simple cleanup to help diagnose problems, not behaviour change expected. --- src/client.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/client.c b/src/client.c index 0d898d7..ca446d7 100644 --- a/src/client.c +++ b/src/client.c @@ -624,6 +624,7 @@ static bool og_dbi_update_image(struct og_dbi *dbi, const char *msglog; dbi_result result; int repo_id, sw_id; + uint32_t revision; /* find repository identifier by repository ip and computer ID. */ result = dbi_conn_queryf(dbi->conn, @@ -688,13 +689,32 @@ static bool og_dbi_update_image(struct og_dbi *dbi, } dbi_result_free(result); + result = dbi_conn_queryf(dbi->conn, + "SELECT revision FROM imagenes WHERE idimagen=%s", + img_info->image_id); + 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)) { + syslog(LOG_ERR, + "no image found with id '%s' database (%s:%d)\n", + img_info->image_id, __func__, __LINE__); + dbi_result_free(result); + return false; + } + revision = dbi_result_get_uint(result, "revision"); + dbi_result_free(result); + /* attach image to partition. */ result = dbi_conn_queryf(dbi->conn, "UPDATE ordenadores_particiones" - " SET idimagen=%s, revision=(SELECT revision FROM imagenes WHERE idimagen=%s)," - " fechadespliegue=NOW()" + " SET idimagen=%s, revision=%u, fechadespliegue=NOW()" " WHERE idordenador=%s AND numdisk=%s AND numpar=%s", - img_info->image_id, img_info->image_id, + img_info->image_id, revision, computer_id, img_info->disk, img_info->part); if (!result) { dbi_conn_error(dbi->conn, &msglog); -- cgit v1.2.3-18-g5258