diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-11-26 12:16:49 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2020-03-04 14:54:59 +0100 |
commit | 9cc156c65ab04c8b9d23def4b06ea84af92c68a4 (patch) | |
tree | 0f4c8cca03e1dda670ae96897b9619f52347af85 | |
parent | fa6b8916373c4efed35a7d7dd271a11023d5f074 (diff) |
#941 use dbi layer from actualizaCreacionImagen()
-rw-r--r-- | sources/ogAdmServer.cpp | 68 | ||||
-rw-r--r-- | sources/ogAdmServer.h | 2 |
2 files changed, 35 insertions, 35 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp index e4dd915..e3db607 100644 --- a/sources/ogAdmServer.cpp +++ b/sources/ogAdmServer.cpp @@ -1460,26 +1460,15 @@ static bool RESPUESTA_Apagar(TRAMA* ptrTrama, struct og_client *cli) // ________________________________________________________________________________________________________ static bool RESPUESTA_CrearImagen(TRAMA* ptrTrama, struct og_client *cli) { - char msglog[LONSTD]; - Database db; - Table tbl; char *iph, *dsk, *par, *cpt, *ipr, *ido; struct og_dbi *dbi; char *idi; bool res; - if (!db.Open(usuario, pasguor, datasource, catalog)) { - db.GetErrorErrStr(msglog); - syslog(LOG_ERR, "cannot open connection database (%s:%d) %s\n", - __func__, __LINE__, msglog); - return false; - } - dbi = og_dbi_open(&dbi_config); if (!dbi) { syslog(LOG_ERR, "cannot open connection database (%s:%d)\n", __func__, __LINE__); - db.Close(); return false; } @@ -1501,7 +1490,7 @@ static bool RESPUESTA_CrearImagen(TRAMA* ptrTrama, struct og_client *cli) cpt = copiaParametro("cpt",ptrTrama); ipr = copiaParametro("ipr",ptrTrama); - res=actualizaCreacionImagen(db, tbl, idi, dsk, par, cpt, ipr, ido); + res=actualizaCreacionImagen(dbi, idi, dsk, par, cpt, ipr, ido); liberaMemoria(idi); liberaMemoria(par); @@ -1512,8 +1501,6 @@ static bool RESPUESTA_CrearImagen(TRAMA* ptrTrama, struct og_client *cli) if (!res) syslog(LOG_ERR, "Problem processing update\n"); - db.Close(); // Cierra conexión - return res; } // ________________________________________________________________________________________________________ @@ -1534,76 +1521,89 @@ static bool RESPUESTA_CrearImagen(TRAMA* ptrTrama, struct og_client *cli) // true: Si el proceso es correcto // false: En caso de ocurrir algún error // ________________________________________________________________________________________________________ -bool actualizaCreacionImagen(Database db, Table tbl, char *idi, char *dsk, +bool actualizaCreacionImagen(struct og_dbi *dbi, char *idi, char *dsk, char *par, char *cpt, char *ipr, char *ido) { - char msglog[LONSTD], sqlstr[LONSQL]; + const char *msglog; + dbi_result result; int idr,ifs; /* Toma identificador del repositorio correspondiente al ordenador modelo */ - snprintf(sqlstr, LONSQL, + result = dbi_conn_queryf(dbi->conn, "SELECT repositorios.idrepositorio" " FROM repositorios" " LEFT JOIN ordenadores USING (idrepositorio)" " WHERE repositorios.ip='%s' AND ordenadores.idordenador=%s", ipr, ido); - if (!db.Execute(sqlstr, tbl)) { - db.GetErrorErrStr(msglog); + 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 (!tbl.Get("idrepositorio", idr)) { // Toma dato - tbl.GetErrorErrStr(msglog); // Error al acceder al registro - og_info(msglog); + if (!dbi_result_next_row(result)) { + syslog(LOG_ERR, + "repository does not exist in database (%s:%d)\n", + __func__, __LINE__); + dbi_result_free(result); return false; } + idr = dbi_result_get_uint(result, "idrepositorio"); + dbi_result_free(result); /* Toma identificador del perfilsoftware */ - snprintf(sqlstr, LONSQL, + result = dbi_conn_queryf(dbi->conn, "SELECT idperfilsoft" " FROM ordenadores_particiones" " WHERE idordenador=%s AND numdisk=%s AND numpar=%s", ido, dsk, par); - if (!db.Execute(sqlstr, tbl)) { - db.GetErrorErrStr(msglog); + 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 (!tbl.Get("idperfilsoft", ifs)) { // Toma dato - tbl.GetErrorErrStr(msglog); // Error al acceder al registro - og_info(msglog); + if (!dbi_result_next_row(result)) { + syslog(LOG_ERR, + "software profile does not exist in database (%s:%d)\n", + __func__, __LINE__); + dbi_result_free(result); return false; } + ifs = dbi_result_get_uint(result, "idperfilsoft"); + dbi_result_free(result); /* Actualizar los datos de la imagen */ - snprintf(sqlstr, LONSQL, + result = dbi_conn_queryf(dbi->conn, "UPDATE imagenes" " SET idordenador=%s, numdisk=%s, numpar=%s, codpar=%s," " idperfilsoft=%d, idrepositorio=%d," " fechacreacion=NOW(), revision=revision+1" " WHERE idimagen=%s", ido, dsk, par, cpt, ifs, idr, idi); - if (!db.Execute(sqlstr, tbl)) { - db.GetErrorErrStr(msglog); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", __func__, __LINE__, msglog); return false; } + dbi_result_free(result); + /* Actualizar los datos en el cliente */ - snprintf(sqlstr, LONSQL, + result = dbi_conn_queryf(dbi->conn, "UPDATE ordenadores_particiones" " SET idimagen=%s, revision=(SELECT revision FROM imagenes WHERE idimagen=%s)," " fechadespliegue=NOW()" " WHERE idordenador=%s AND numdisk=%s AND numpar=%s", idi, idi, ido, dsk, par); - if (!db.Execute(sqlstr, tbl)) { - db.GetErrorErrStr(msglog); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", __func__, __LINE__, msglog); return false; } + dbi_result_free(result); + return true; } // ________________________________________________________________________________________________________ diff --git a/sources/ogAdmServer.h b/sources/ogAdmServer.h index 9b9da07..7f09226 100644 --- a/sources/ogAdmServer.h +++ b/sources/ogAdmServer.h @@ -51,7 +51,7 @@ bool enviaComando(TRAMA *ptrTrama,const char*); bool Levanta(char**, char**, int, char*); bool WakeUp(int,char*,char*,char*); void PasaHexBin(char *,char *); -bool actualizaCreacionImagen(Database,Table,char*,char*,char*,char*,char*,char*); +bool actualizaCreacionImagen(struct og_dbi *,char*,char*,char*,char*,char*,char*); bool actualizaRestauracionImagen(struct og_dbi *,char*,char*,char*,char*,char*); bool actualizaHardware(Database, Table,char* ,char*,char*,char*); bool cuestionPerfilHardware(Database,Table,char*,char*,int,char*,char*,int *,int); |