X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdbi.c;h=899c802c4eb1fbd8d64b8c3b8073faa853f1c28b;hb=711f5b6c86f51061c21bedcaa46214a01de0125c;hp=4ef9f8c59f3fe5f08fb39b714366ae4ab37cf630;hpb=d486225f89ea52d8ed2b4242eba2ad94c409f837;p=collectd.git diff --git a/src/dbi.c b/src/dbi.c index 4ef9f8c5..899c802c 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -64,8 +64,6 @@ struct cdbi_database_s /* {{{ */ char *select_db; char *plugin_name; - cdtime_t interval; - char *driver; char *host; cdbi_driver_option_t *driver_options; @@ -267,6 +265,7 @@ static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ { + cdtime_t interval = 0; cdbi_database_t *db; int status; @@ -304,7 +303,7 @@ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ else if (strcasecmp("Host", child->key) == 0) status = cf_util_get_string(child, &db->host); else if (strcasecmp("Interval", child->key) == 0) - status = cf_util_get_cdtime(child, &db->interval); + status = cf_util_get_cdtime(child, &interval); else if (strcasecmp("Plugin", child->key) == 0) status = cf_util_get_string(child, &db->plugin_name); else { @@ -370,7 +369,7 @@ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ /* group = */ NULL, /* name = */ name ? name : db->name, /* callback = */ cdbi_read_database, - /* interval = */ (db->interval > 0) ? db->interval : 0, + /* interval = */ interval, &(user_data_t){ .data = db, }); @@ -547,11 +546,16 @@ static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */ sstrncpy(column_names[i], column_name, DATA_MAX_NAME_LEN); } /* }}} for (i = 0; i < column_num; i++) */ - udb_query_prepare_result( + status = udb_query_prepare_result( q, prep_area, (db->host ? db->host : hostname_g), /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "dbi", - db->name, column_names, column_num, - /* interval = */ (db->interval > 0) ? db->interval : 0); + db->name, column_names, column_num); + + if (status != 0) { + ERROR("dbi plugin: udb_query_prepare_result failed with status %i.", + status); + BAIL_OUT(-1); + } /* 0 = error; 1 = success; */ status = dbi_result_first_row(res); /* {{{ */ @@ -599,15 +603,16 @@ static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */ } /* }}} */ /* Get the next row from the database. */ + if (!dbi_result_has_next_row(res)) + break; + status = dbi_result_next_row(res); /* {{{ */ if (status != 1) { - if (dbi_conn_error(db->connection, NULL) != 0) { - char errbuf[1024]; - WARNING("dbi plugin: cdbi_read_database_query (%s, %s): " - "dbi_result_next_row failed: %s.", - db->name, udb_query_get_name(q), - cdbi_strerror(db->connection, errbuf, sizeof(errbuf))); - } + char errbuf[1024]; + WARNING("dbi plugin: cdbi_read_database_query (%s, %s): " + "dbi_result_next_row failed: %s.", + db->name, udb_query_get_name(q), + cdbi_strerror(db->connection, errbuf, sizeof(errbuf))); break; } /* }}} */ } /* }}} while (42) */