summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4c9b0f6)
raw | patch | inline | side by side (parent: 4c9b0f6)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 3 Feb 2009 20:34:36 +0000 (21:34 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 3 Feb 2009 20:34:36 +0000 (21:34 +0100) |
These settings can be used to check if a particular query is suited to the
database server version we're currently connected to.
database server version we're currently connected to.
src/utils_db_query.c | patch | blob | history | |
src/utils_db_query.h | patch | blob | history |
diff --git a/src/utils_db_query.c b/src/utils_db_query.c
index 27e8a55f9a94aeeb88758bacd007fb5bd8fe97eb..1bd5b21664d85653b5c427a36c5be70fe9208b30 100644 (file)
--- a/src/utils_db_query.c
+++ b/src/utils_db_query.c
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
*/
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);
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;
diff --git a/src/utils_db_query.h b/src/utils_db_query.h
index 87c3e4e44bb068f7938c1a53188398dc4610a9a8..4e12cedd0b7d99e487ce99ad03c02d73951c2eeb 100644 (file)
--- a/src/utils_db_query.h
+++ b/src/utils_db_query.h
void udb_query_set_user_data (udb_query_t *q, void *user_data);
void *udb_query_get_user_data (udb_query_t *q);
+int udb_query_check_version (udb_query_t *q, unsigned int version);
+
int udb_query_prepare_result (udb_query_t *q,
const char *host, const char *plugin, const char *db_name,
char **column_names, size_t column_num);