- if (PGRES_TUPLES_OK != PQresultStatus (res)) {
- log_err ("Failed to execute SQL query: %s",
- PQerrorMessage (db->conn));
- log_info ("SQL query was: %s", query->query);
- PQclear (res);
- return -1;
- }
-
- rows = PQntuples (res);
- if (1 > rows)
- 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);
- return -1;
- }
-
- for (i = 0; i < rows; ++i) {
- int j;
-
- for (j = 0; j < cols; ++j) {
- c_psql_col_t col = query->cols[j];
-
- char *value = PQgetvalue (res, i, j);
-
- if (col.ds_type == DS_TYPE_COUNTER)
- submit_counter (db, col.type, col.type_instance, value);
- else if (col.ds_type == DS_TYPE_GAUGE)
- submit_gauge (db, col.type, col.type_instance, value);
- }
- }
- return 0;
-} /* c_psql_exec_query */
-
-static int c_psql_read (void)