static void c_psql_database_delete (c_psql_database_t *db)
{
PQfinish (db->conn);
+ db->conn = NULL;
sfree (db->queries);
db->queries_num = 0;
}
rows = PQntuples (res);
- if (1 > rows)
+ if (1 > rows) {
+ PQclear (res);
return 0;
+ }
cols = PQnfields (res);
if (query->cols_num != cols) {
log_err ("SQL query returned wrong number of fields "
"(expected: %i, got: %i)", query->cols_num, cols);
log_info ("SQL query was: %s", query->query);
+ PQclear (res);
return -1;
}
submit_gauge (db, col.type, col.type_instance, value);
}
}
+ PQclear (res);
return 0;
} /* c_psql_exec_query */
int j;
+ /* this will happen during reinitialization */
+ if (NULL != db->conn) {
+ c_psql_check_connection (db);
+ continue;
+ }
+
status = ssnprintf (buf, buf_len, "dbname = '%s'", db->database);
if (0 < status) {
buf += status;
log_warn ("Ignoring unknown config key \"%s\".", c->key);
}
+ for (i = 0; i < queries_num - 1; ++i) {
+ c_psql_query_t *q = queries + i;
+
+ if ((0 == strcasecmp (q->name, query->name))
+ && (q->min_pg_version <= query->max_pg_version)
+ && (query->min_pg_version <= q->max_pg_version)) {
+ log_err ("Ignoring redefinition (with overlapping version ranges) "
+ "of query \"%s\".", query->name);
+ c_psql_query_delete (query);
+ --queries_num;
+ return 1;
+ }
+ }
+
+ if (query->min_pg_version > query->max_pg_version) {
+ log_err ("Query \"%s\": MinPGVersion > MaxPGVersion.",
+ query->name);
+ c_psql_query_delete (query);
+ --queries_num;
+ return 1;
+ }
+
if (NULL == query->query) {
log_err ("Query \"%s\" does not include an SQL query string - "
"please check your configuration.", query->name);