From: Florian Forster Date: Sat, 14 Feb 2009 17:31:49 +0000 (+0100) Subject: src/utils_db_query.c: udb_query_pick_from_list* should add *all* queries of the desir... X-Git-Tag: collectd-4.6.0~33 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=bcdb011cfc86a3a7317128a969bfe6fd57cd063b;p=collectd.git src/utils_db_query.c: udb_query_pick_from_list* should add *all* queries of the desired name. --- diff --git a/src/utils_db_query.c b/src/utils_db_query.c index 9389db65..33107649 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -922,10 +922,8 @@ int udb_query_pick_from_list_by_name (const char *name, /* {{{ */ udb_query_t **src_list, size_t src_list_len, udb_query_t ***dst_list, size_t *dst_list_len) { - udb_query_t *q; - udb_query_t **tmp_list; - size_t tmp_list_len; size_t i; + int num_added; if ((name == NULL) || (src_list == NULL) || (dst_list == NULL) || (dst_list_len == NULL)) @@ -935,35 +933,45 @@ int udb_query_pick_from_list_by_name (const char *name, /* {{{ */ return (-EINVAL); } - q = NULL; + num_added = 0; for (i = 0; i < src_list_len; i++) - if (strcasecmp (name, src_list[i]->name) == 0) + { + udb_query_t **tmp_list; + size_t tmp_list_len; + + if (strcasecmp (name, src_list[i]->name) != 0) + continue; + + tmp_list_len = *dst_list_len; + tmp_list = (udb_query_t **) realloc (*dst_list, (tmp_list_len + 1) + * sizeof (udb_query_t *)); + if (tmp_list == NULL) { - q = src_list[i]; - break; + ERROR ("db query utils: realloc failed."); + return (-ENOMEM); } - if (q == NULL) + tmp_list[tmp_list_len] = src_list[i]; + tmp_list_len++; + + *dst_list = tmp_list; + *dst_list_len = tmp_list_len; + + num_added++; + } /* for (i = 0; i < src_list_len; i++) */ + + if (num_added <= 0) { ERROR ("db query utils: Cannot find query `%s'. Make sure the " "block is above the database definition!", name); return (-ENOENT); } - - tmp_list_len = *dst_list_len; - tmp_list = (udb_query_t **) realloc (*dst_list, (tmp_list_len + 1) - * sizeof (udb_query_t *)); - if (tmp_list == NULL) + else { - ERROR ("db query utils: realloc failed."); - return (-ENOMEM); + DEBUG ("db query utils: Added %i versions of query `%s'.", + num_added, name); } - tmp_list[tmp_list_len] = q; - tmp_list_len++; - - *dst_list = tmp_list; - *dst_list_len = tmp_list_len; return (0); } /* }}} int udb_query_pick_from_list_by_name */ diff --git a/src/utils_db_query.h b/src/utils_db_query.h index 05513105..864b4204 100644 --- a/src/utils_db_query.h +++ b/src/utils_db_query.h @@ -54,6 +54,12 @@ const char *udb_query_get_statement (udb_query_t *q); void udb_query_set_user_data (udb_query_t *q, void *user_data); void *udb_query_get_user_data (udb_query_t *q); +/* + * db->proto_version + * + * Returns 0 if the query is NOT suitable for `version' and >0 if the + * query IS suitable. + */ int udb_query_check_version (udb_query_t *q, unsigned int version); int udb_query_prepare_result (udb_query_t *q,