+ c_psql_result_t *res;
+
+ int status = 0, i;
+
+ if (0 != ci->values_num) {
+ log_err ("<Result> does not expect any arguments.");
+ return 1;
+ }
+
+ res = c_psql_result_new (query);
+
+ for (i = 0; i < ci->children_num; ++i) {
+ oconfig_item_t *c = ci->children + i;
+
+ if (0 == strcasecmp (c->key, "Type"))
+ config_set_s ("Type", &res->type, c);
+ else if (0 == strcasecmp (c->key, "InstancePrefix"))
+ config_set_s ("InstancePrefix", &res->instance_prefix, c);
+ else if (0 == strcasecmp (c->key, "InstancesFrom"))
+ config_append_array_s ("InstancesFrom",
+ &res->instances_str, &res->instances_num, c);
+ else if (0 == strcasecmp (c->key, "ValuesFrom"))
+ config_append_array_s ("ValuesFrom",
+ &res->values_str, &res->values_num, c);
+ else
+ log_warn ("Ignoring unknown config key \"%s\".", c->key);
+ }
+
+ if (NULL == res->type) {
+ log_warn ("Query \"%s\": Missing Type option in <Result> block.",
+ query->name);
+ status = 1;
+ }
+
+ if (NULL == res->values_str) {
+ log_warn ("Query \"%s\": Missing ValuesFrom option in <Result> block.",
+ query->name);
+ status = 1;
+ }
+
+ if (0 != status) {
+ c_psql_result_delete (res);
+ --query->results_num;
+ return status;
+ }
+
+ /* preallocate memory to cache the column numbers and data types */
+ res->values = (int *)smalloc (res->values_num * sizeof (*res->values));
+ for (i = 0; i < res->values_num; ++i)
+ res->values[i] = -1;
+
+ res->instances = (int *)smalloc (res->instances_num
+ * sizeof (*res->instances));
+ for (i = 0; i < res->instances_num; ++i)
+ res->instances[i] = -1;
+
+ res->ds_types = (int *)smalloc (res->values_num
+ * sizeof (*res->ds_types));
+ for (i = 0; i < res->values_num; ++i)
+ res->ds_types[i] = -1;
+ return 0;
+} /* config_set_result */
+
+static int config_set_column (c_psql_query_t *query, int col_num,
+ const oconfig_item_t *ci)
+{
+ c_psql_result_t *res;