From fa30382f2cec88b8986c0f916c996c778a7f64c1 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 13 Mar 2017 12:13:22 +0900 Subject: [PATCH] When retrieving a node record, set upstream_node_id correctly. -1 (NO_UPSTREAM_NODE) should be returned if the record's column is NULL. --- dbutils.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dbutils.c b/dbutils.c index 7e1d1711..97e293cf 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1872,7 +1872,16 @@ _get_node_record(PGconn *conn, char *cluster, char *sqlquery, t_node_info *node_ node_info->node_id = atoi(PQgetvalue(res, 0, 0)); node_info->type = parse_node_type(PQgetvalue(res, 0, 1)); - node_info->upstream_node_id = atoi(PQgetvalue(res, 0, 2)); + + if (PQgetisnull(res, 0, 2)) + { + node_info->upstream_node_id = NO_UPSTREAM_NODE; + } + else + { + node_info->upstream_node_id = atoi(PQgetvalue(res, 0, 2)); + } + strncpy(node_info->name, PQgetvalue(res, 0, 3), MAXLEN); strncpy(node_info->conninfo_str, PQgetvalue(res, 0, 4), MAXLEN); strncpy(node_info->slot_name, PQgetvalue(res, 0, 5), MAXLEN);