From 4cd4d2f6231728cab739f1f614de0a19ecf733d7 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 14 Feb 2009 14:04:02 +0100 Subject: [PATCH] src/utils_db_query.[ch]: Introduces a ``legacy mode''. When passing `1' as `legacy mode' to `udb_query_create', compatibility with the postgresql plugin in version 4.5 is enabled. This means that the options `Query', `MinPGVersion' and `MaxPGVersion' are understood in the blocks. Yet to do is support for the `Column' options. The `Param' option should probably be implemented using the already existing callback function. --- src/dbi.c | 2 +- src/oracle.c | 2 +- src/utils_db_query.c | 22 +++++++++++++++++++--- src/utils_db_query.h | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/dbi.c b/src/dbi.c index d970938e..5be9cae4 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -357,7 +357,7 @@ static int cdbi_config (oconfig_item_t *ci) /* {{{ */ oconfig_item_t *child = ci->children + i; if (strcasecmp ("Query", child->key) == 0) udb_query_create (&queries, &queries_num, child, - /* callback = */ NULL); + /* callback = */ NULL, /* legacy mode = */ 0); else if (strcasecmp ("Database", child->key) == 0) cdbi_config_add_database (child); else diff --git a/src/oracle.c b/src/oracle.c index b008e5c5..324dd4b4 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -295,7 +295,7 @@ static int o_config (oconfig_item_t *ci) /* {{{ */ oconfig_item_t *child = ci->children + i; if (strcasecmp ("Query", child->key) == 0) udb_query_create (&queries, &queries_num, child, - /* callback = */ NULL); + /* callback = */ NULL, /* legacy mode = */ 0); else if (strcasecmp ("Database", child->key) == 0) o_config_add_database (child); else diff --git a/src/utils_db_query.c b/src/utils_db_query.c index eb001dee..e50bc584 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -55,6 +55,8 @@ struct udb_query_s /* {{{ */ char *statement; void *user_data; + int legacy_mode; + unsigned int min_version; unsigned int max_version; @@ -540,7 +542,7 @@ void udb_query_free_one (udb_query_t *q) /* {{{ */ */ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ size_t *ret_query_list_len, oconfig_item_t *ci, - udb_query_create_callback_t cb) + udb_query_create_callback_t cb, int legacy_mode) { udb_query_t **query_list; size_t query_list_len; @@ -569,6 +571,7 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ return (-1); } memset (q, 0, sizeof (*q)); + q->legacy_mode = legacy_mode; q->min_version = 0; q->max_version = UINT_MAX; @@ -592,21 +595,34 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ 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) + else if ((strcasecmp ("Query", child->key) == 0) + && (q->legacy_mode == 1)) + { + WARNING ("db query utils: Query `%s': The `Query' option is " + "deprecated. Please use `Statement' instead.", + q->name); + status = udb_config_set_string (&q->statement, child); + } + else if ((strcasecmp ("MinPGVersion", child->key) == 0) + && (q->legacy_mode == 1)) { 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) + else if ((strcasecmp ("MaxPGVersion", child->key) == 0) + && (q->legacy_mode == 1)) { 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); } + + /* Call custom callbacks */ else if (cb != NULL) { status = (*cb) (q, child); diff --git a/src/utils_db_query.h b/src/utils_db_query.h index 3959e882..36da9e3d 100644 --- a/src/utils_db_query.h +++ b/src/utils_db_query.h @@ -38,7 +38,7 @@ typedef int (*udb_query_create_callback_t) (udb_query_t *q, */ int udb_query_create (udb_query_t ***ret_query_list, size_t *ret_query_list_len, oconfig_item_t *ci, - udb_query_create_callback_t cb); + udb_query_create_callback_t cb, int legacy_mode); void udb_query_free (udb_query_t **query_list, size_t query_list_len); int udb_query_pick_from_list (oconfig_item_t *ci, -- 2.11.0