char *statement;
void *user_data;
+ unsigned int min_version;
+ unsigned int max_version;
+
/* Preparation area */
size_t column_num;
char *host;
return (0);
} /* }}} int udb_config_add_string */
+static int udb_config_set_uint (unsigned int *ret_value, /* {{{ */
+ oconfig_item_t *ci)
+{
+ double tmp;
+
+ if ((ci->values_num != 1)
+ || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+ {
+ WARNING ("db query utils: The `%s' config option "
+ "needs exactly one numeric argument.", ci->key);
+ return (-1);
+ }
+
+ tmp = ci->values[0].value.number;
+ if ((tmp < 0.0) || (tmp > ((double) UINT_MAX)))
+ return (-ERANGE);
+
+ *ret_value = (unsigned int) (tmp + .5);
+ return (0);
+} /* }}} int udb_config_set_uint */
+
/*
* Result private functions
*/
}
}
- vl.time = time (NULL);
sstrncpy (vl.host, q->host, sizeof (vl.host));
sstrncpy (vl.plugin, q->plugin, sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, q->db_name, sizeof (vl.type_instance));
* Query public functions
*/
int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */
- size_t *ret_query_list_len, oconfig_item_t *ci)
+ size_t *ret_query_list_len, oconfig_item_t *ci,
+ udb_query_create_callback_t cb)
{
udb_query_t **query_list;
size_t query_list_len;
return (-1);
}
memset (q, 0, sizeof (*q));
+ q->min_version = 0;
+ q->max_version = UINT_MAX;
status = udb_config_set_string (&q->name, ci);
if (status != 0)
status = udb_config_set_string (&q->statement, child);
else if (strcasecmp ("Result", child->key) == 0)
status = udb_result_create (q->name, &q->results, child);
+ else if (strcasecmp ("MinVersion", child->key) == 0)
+ status = udb_config_set_uint (&q->min_version, child);
+ else if (strcasecmp ("MaxVersion", child->key) == 0)
+ status = udb_config_set_uint (&q->max_version, child);
+ /* PostgreSQL compatibility code */
+ else if (strcasecmp ("MinPGVersion", child->key) == 0)
+ {
+ WARNING ("db query utils: Query `%s': The `MinPGVersion' option is "
+ "deprecated. Please use `MinVersion' instead.",
+ q->name);
+ status = udb_config_set_uint (&q->min_version, child);
+ }
+ else if (strcasecmp ("MaxPGVersion", child->key) == 0)
+ {
+ WARNING ("db query utils: Query `%s': The `MaxPGVersion' option is "
+ "deprecated. Please use `MaxVersion' instead.",
+ q->name);
+ status = udb_config_set_uint (&q->max_version, child);
+ }
+ else if (cb != NULL)
+ {
+ status = (*cb) (q, child);
+ if (status != 0)
+ {
+ WARNING ("db query utils: The configuration callback failed "
+ "to handle `%s'.", child->key);
+ }
+ }
else
{
WARNING ("db query utils: Query `%s': Option `%s' not allowed here.",
return (q->user_data);
} /* }}} void *udb_query_get_user_data */
+int udb_query_check_version (udb_query_t *q, unsigned int version) /* {{{ */
+{
+ if (q == NULL)
+ return (-EINVAL);
+
+ if ((version < q->min_version) || (version > q->max_version))
+ return (0);
+
+ return (1);
+} /* }}} int udb_query_check_version */
+
void udb_query_finish_result (udb_query_t *q) /* {{{ */
{
udb_result_t *r;