summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aef15b6)
raw | patch | inline | side by side (parent: aef15b6)
author | Pavel Rochnyack <pavel2000@ngs.ru> | |
Wed, 11 May 2016 16:41:27 +0000 (22:41 +0600) | ||
committer | Pavel Rochnyack <pavel2000@ngs.ru> | |
Thu, 12 May 2016 12:17:16 +0000 (18:17 +0600) |
src/utils_db_query.c | patch | blob | history |
diff --git a/src/utils_db_query.c b/src/utils_db_query.c
index 91fc1421860a03987104b2c89c456fabf0b01fda..f683fb5d2bd571d409192bbc70e41ab295d871ee 100644 (file)
--- a/src/utils_db_query.c
+++ b/src/utils_db_query.c
char *name;
char *statement;
void *user_data;
+ char *plugin_instance_from;
unsigned int min_version;
unsigned int max_version;
char **instances_buffer;
char **values_buffer;
char **metadata_buffer;
+ char *plugin_instance;
struct udb_result_preparation_area_s *next;
}; /* }}} */
struct udb_query_preparation_area_s /* {{{ */
{
size_t column_num;
+ size_t plugin_instance_pos;
char *host;
char *plugin;
char *db_name;
sstrncpy (vl.host, q_area->host, sizeof (vl.host));
sstrncpy (vl.plugin, q_area->plugin, sizeof (vl.plugin));
- sstrncpy (vl.plugin_instance, q_area->db_name, sizeof (vl.plugin_instance));
sstrncpy (vl.type, r->type, sizeof (vl.type));
+ /* Set vl.plugin_instance */
+ if (q->plugin_instance_from != NULL) {
+ sstrncpy (vl.plugin_instance, r_area->plugin_instance, sizeof (vl.plugin_instance));
+ }
+ else {
+ sstrncpy (vl.plugin_instance, q_area->db_name, sizeof (vl.plugin_instance));
+ }
+
/* Set vl.type_instance {{{ */
if (r->instances_num == 0)
{
for (i = 0; i < r->metadata_num; i++)
r_area->metadata_buffer[i] = column_values[r_area->metadata_pos[i]];
+ if (q->plugin_instance_from)
+ r_area->plugin_instance = column_values[q_area->plugin_instance_pos];
+
return udb_result_submit (r, r_area, q, q_area);
} /* }}} int udb_result_handle_result */
/* }}} */
- /* Determine the position of the instance columns {{{ */
+ /* Determine the position of the plugin instance column {{{ */
for (i = 0; i < r->instances_num; i++)
{
size_t j;
}
} /* }}} for (i = 0; i < r->instances_num; i++) */
+
/* Determine the position of the value columns {{{ */
for (i = 0; i < r->values_num; i++)
{
return;
sfree (r->type);
+ sfree (r->instance_prefix);
for (i = 0; i < r->instances_num; i++)
sfree (r->instances[i]);
sfree (q->name);
sfree (q->statement);
+ sfree (q->plugin_instance_from);
udb_result_free (q->results);
}
q->min_version = 0;
q->max_version = UINT_MAX;
+ q->statement = NULL;
+ q->results = NULL;
+ q->plugin_instance_from = NULL;
status = udb_config_set_string (&q->name, ci);
if (status != 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 if (strcasecmp ("PluginInstanceFrom", child->key) == 0)
+ status = udb_config_set_string (&q->plugin_instance_from, child);
/* Call custom callbacks */
else if (cb != NULL)
} while (0);
#endif
+ /* Determine the position of the PluginInstance column {{{ */
+ if (q->plugin_instance_from != NULL)
+ {
+ size_t i;
+
+ for (i = 0; i < column_num; i++)
+ {
+ if (strcasecmp (q->plugin_instance_from, column_names[i]) == 0)
+ {
+ prep_area->plugin_instance_pos = i;
+ break;
+ }
+ }
+
+ if (i >= column_num)
+ {
+ ERROR ("db query utils: udb_query_prepare_result: "
+ "Column `%s' from `PluginInstanceFrom' could not be found.",
+ q->plugin_instance_from);
+ udb_query_finish_result (q, prep_area);
+ return (-ENOENT);
+ }
+ }
+ /* }}} */
+
for (r = q->results, r_area = prep_area->result_prep_areas;
r != NULL; r = r->next, r_area = r_area->next)
{