summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4d380d9)
raw | patch | inline | side by side (parent: 4d380d9)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 14 Feb 2009 17:31:49 +0000 (18:31 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 14 Feb 2009 17:31:49 +0000 (18:31 +0100) |
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 9389db65d8fb86b6fe3eedf5ddb72ccbf0b338b5..33107649f1f7be1b298b6f49c4c5084534530c7e 100644 (file)
--- a/src/utils_db_query.c
+++ b/src/utils_db_query.c
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))
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 <Query> "
"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 0551310573dfe608c45d5a67efea8d221b96fd54..864b4204dfb6b9873d09ae368dfbe70ad2f27781 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);
+/*
+ * 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,