The `pgsql_have_schemas` of `struct pgsql_instance` is never used. The `pgres` member is always assigned and cleared in the same function. Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx> --- output/pgsql/ulogd_output_PGSQL.c | 46 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/output/pgsql/ulogd_output_PGSQL.c b/output/pgsql/ulogd_output_PGSQL.c index 9dfef7946775..70bfbee7f565 100644 --- a/output/pgsql/ulogd_output_PGSQL.c +++ b/output/pgsql/ulogd_output_PGSQL.c @@ -31,8 +31,6 @@ struct pgsql_instance { struct db_instance db_inst; PGconn *dbh; - PGresult *pgres; - unsigned char pgsql_have_schemas; }; /* our configuration directives */ @@ -90,6 +88,7 @@ static int pgsql_namespace(struct ulogd_pluginstance *upi) struct pgsql_instance *pi = (struct pgsql_instance *) upi->private; char pgbuf[strlen(PGSQL_HAVE_NAMESPACE_TEMPLATE) + strlen(schema_ce(upi->config_kset).u.string) + 1]; + PGresult *pgres; if (!pi->dbh) return -1; @@ -98,28 +97,28 @@ static int pgsql_namespace(struct ulogd_pluginstance *upi) schema_ce(upi->config_kset).u.string); ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf); - pi->pgres = PQexec(pi->dbh, pgbuf); - if (!pi->pgres) { + pgres = PQexec(pi->dbh, pgbuf); + if (!pgres) { ulogd_log(ULOGD_DEBUG, "\n result false"); return -1; } - if (PQresultStatus(pi->pgres) == PGRES_TUPLES_OK) { - if (PQntuples(pi->pgres)) { + if (PQresultStatus(pgres) == PGRES_TUPLES_OK) { + if (PQntuples(pgres)) { ulogd_log(ULOGD_DEBUG, "using schema %s\n", schema_ce(upi->config_kset).u.string); pi->db_inst.schema = schema_ce(upi->config_kset).u.string; } else { ulogd_log(ULOGD_ERROR, "schema %s not found: %s\n", schema_ce(upi->config_kset).u.string, PQerrorMessage(pi->dbh)); - PQclear(pi->pgres); + PQclear(pgres); return -1; } } else { pi->db_inst.schema = NULL; } - PQclear(pi->pgres); + PQclear(pgres); return 0; } @@ -137,6 +136,7 @@ static int get_columns_pgsql(struct ulogd_pluginstance *upi) char pgbuf[strlen(PGSQL_GETCOLUMN_TEMPLATE_SCHEMA) + strlen(table_ce(upi->config_kset).u.string) + strlen(pi->db_inst.schema) + 2]; + PGresult *pgres; int rv; if (!pi->dbh) { @@ -156,27 +156,27 @@ static int get_columns_pgsql(struct ulogd_pluginstance *upi) ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf); - pi->pgres = PQexec(pi->dbh, pgbuf); - if (!pi->pgres) { + pgres = PQexec(pi->dbh, pgbuf); + if (!pgres) { ulogd_log(ULOGD_DEBUG, "result false (%s)", PQerrorMessage(pi->dbh)); return -1; } - if (PQresultStatus(pi->pgres) != PGRES_TUPLES_OK) { + if (PQresultStatus(pgres) != PGRES_TUPLES_OK) { ulogd_log(ULOGD_DEBUG, "pres_command_not_ok (%s)", PQerrorMessage(pi->dbh)); - PQclear(pi->pgres); + PQclear(pgres); return -1; } - rv = ulogd_db_alloc_input_keys(upi, PQntuples(pi->pgres), pi->pgres); + rv = ulogd_db_alloc_input_keys(upi, PQntuples(pgres), pgres); /* ID (starting by '.') is a sequence */ if (!rv && upi->input.keys[0].name[0] == '.') upi->input.keys[0].flags |= ULOGD_KEYF_INACTIVE; - PQclear(pi->pgres); + PQclear(pgres); return rv; } @@ -207,6 +207,7 @@ static int open_db_pgsql(struct ulogd_pluginstance *upi) char *connstr = connstr_ce(upi->config_kset).u.string; char *schema = NULL; char pgbuf[128]; + PGresult *pgres; if (!connstr[0]) { char *server = host_ce(upi->config_kset).u.string; @@ -260,13 +261,13 @@ static int open_db_pgsql(struct ulogd_pluginstance *upi) if (!(schema == NULL) && (strcmp(schema,"public"))) { snprintf(pgbuf, 128, "SET search_path='%.63s', \"$user\", 'public'", schema); - pi->pgres = PQexec(pi->dbh, pgbuf); - if ((PQresultStatus(pi->pgres) == PGRES_COMMAND_OK)) { - PQclear(pi->pgres); + pgres = PQexec(pi->dbh, pgbuf); + if ((PQresultStatus(pgres) == PGRES_COMMAND_OK)) { + PQclear(pgres); } else { ulogd_log(ULOGD_ERROR, "could not set search path to (%s): %s\n", schema, PQerrorMessage(pi->dbh)); - PQclear(pi->pgres); + PQclear(pgres); close_db_pgsql(upi); return -1; } @@ -286,16 +287,17 @@ static int execute_pgsql(struct ulogd_pluginstance *upi, const struct db_stmt *stmt) { struct pgsql_instance *pi = (struct pgsql_instance *) upi->private; + PGresult *pgres; - pi->pgres = PQexec(pi->dbh, stmt->sql); - if (!(pi->pgres && ((PQresultStatus(pi->pgres) == PGRES_COMMAND_OK) - || (PQresultStatus(pi->pgres) == PGRES_TUPLES_OK)))) { + pgres = PQexec(pi->dbh, stmt->sql); + if (!(pgres && ((PQresultStatus(pgres) == PGRES_COMMAND_OK) + || (PQresultStatus(pgres) == PGRES_TUPLES_OK)))) { ulogd_log(ULOGD_ERROR, "execute failed (%s)\n", PQerrorMessage(pi->dbh)); return -1; } - PQclear(pi->pgres); + PQclear(pgres); return 0; } -- 2.35.1