get_all_node_records(): display any error encountered and return success status

In many cases we'll want to bail out with an error if the node list can't
be retrieved for any reason. This saves some repetitive coding.
This commit is contained in:
Ian Barwick
2018-06-26 10:44:31 +09:00
parent bb4fdcda98
commit b0a2ee2259
6 changed files with 41 additions and 18 deletions

View File

@@ -2098,12 +2098,12 @@ _populate_node_records(PGresult *res, NodeInfoList *node_list)
}
void
bool
get_all_node_records(PGconn *conn, NodeInfoList *node_list)
{
PQExpBufferData query;
PGresult *res = NULL;
bool success = true;
initPQExpBuffer(&query);
appendPQExpBuffer(&query,
@@ -2115,21 +2115,22 @@ get_all_node_records(PGconn *conn, NodeInfoList *node_list)
res = PQexec(conn, query.data);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
log_db_error(conn, query.data, _("get_all_node_records(): unable to execute query"));
}
termPQExpBuffer(&query);
/* this will return an empty list if there was an error executing the query */
_populate_node_records(res, node_list);
PQclear(res);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
log_db_error(conn, query.data, _("get_all_node_records(): unable to execute query"));
success = false;
}
return;
PQclear(res);
termPQExpBuffer(&query);
return success;
}
void
get_downstream_node_records(PGconn *conn, int node_id, NodeInfoList *node_list)
{