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 */
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,