diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin.c | 1 | ||||
-rw-r--r-- | src/port.c | 1 | ||||
-rw-r--r-- | src/query.c | 177 | ||||
-rw-r--r-- | src/slv2_internal.h | 5 |
4 files changed, 0 insertions, 184 deletions
diff --git a/src/plugin.c b/src/plugin.c index a7e211e..6f68102 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -30,7 +30,6 @@ #include "slv2/collections.h" #include "slv2/plugin.h" #include "slv2/pluginclass.h" -#include "slv2/query.h" #include "slv2/util.h" #include "slv2_internal.h" @@ -25,7 +25,6 @@ #include "slv2/types.h" #include "slv2/collections.h" #include "slv2/port.h" -#include "slv2/query.h" #include "slv2/util.h" #include "slv2_internal.h" diff --git a/src/query.c b/src/query.c index 3fb0ce9..187bf5d 100644 --- a/src/query.c +++ b/src/query.c @@ -25,187 +25,10 @@ #include "slv2/types.h" #include "slv2/collections.h" #include "slv2/plugin.h" -#include "slv2/query.h" #include "slv2/util.h" #include "slv2_internal.h" -static const char* slv2_query_prefixes = - "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" - "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" - "PREFIX doap: <http://usefulinc.com/ns/doap#>\n" - "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" - "PREFIX lv2: <http://lv2plug.in/ns/lv2core#>\n" - "PREFIX lv2ev: <http://lv2plug.in/ns/ext/event#>\n"; - - -SLV2Values -slv2_query_get_variable_bindings(SLV2World world, - SLV2Results results, - int variable) -{ - SLV2Values result = NULL; - - if (!librdf_query_results_finished(results->rdf_results)) - result = slv2_values_new(); - - while (!librdf_query_results_finished(results->rdf_results)) { - librdf_node* node = librdf_query_results_get_binding_value(results->rdf_results, variable); - - if (node == NULL) { - SLV2_ERRORF("Variable %d bound to NULL.\n", variable); - librdf_query_results_next(results->rdf_results); - continue; - } - - SLV2Value val = slv2_value_new_librdf_node(world, node); - if (val) - raptor_sequence_push(result, val); - - librdf_free_node(node); - librdf_query_results_next(results->rdf_results); - } - - return result; -} - - -unsigned -slv2_results_size(SLV2Results results) -{ - size_t count = 0; - - while (!slv2_results_finished(results)) { - ++count; - slv2_results_next(results); - } - - return count; -} - - -SLV2Results -slv2_plugin_query_sparql(SLV2Plugin plugin, - const char* sparql_str) -{ - slv2_plugin_load_if_necessary(plugin); - - librdf_uri* base_uri = slv2_value_as_librdf_uri(plugin->plugin_uri); - - char* query_str = slv2_strjoin(slv2_query_prefixes, sparql_str, NULL); - - librdf_query* query = librdf_new_query(plugin->world->world, "sparql", NULL, - (const uint8_t*)query_str, base_uri); - - if (!query) { - SLV2_ERRORF("Failed to create query:\n%s", query_str); - return NULL; - } - - librdf_query_results* results = librdf_query_execute(query, plugin->rdf); - - librdf_free_query(query); - free(query_str); - - SLV2Results ret = (SLV2Results)malloc(sizeof(struct _SLV2Results)); - ret->world = plugin->world; - ret->rdf_results = results; - - return ret; -} - - -void -slv2_results_free(SLV2Results results) -{ - librdf_free_query_results(results->rdf_results); - free(results); -} - - -bool -slv2_results_finished(SLV2Results results) -{ - return librdf_query_results_finished(results->rdf_results); -} - - -SLV2Value -slv2_results_get_binding_value(SLV2Results results, unsigned index) -{ - return slv2_value_new_librdf_node(results->world, - librdf_query_results_get_binding_value( - results->rdf_results, index)); -} - - -SLV2Value -slv2_results_get_binding_value_by_name(SLV2Results results, const char* name) -{ - return slv2_value_new_librdf_node(results->world, - librdf_query_results_get_binding_value_by_name( - results->rdf_results, name)); -} - - -const char* -slv2_results_get_binding_name(SLV2Results results, unsigned index) -{ - return librdf_query_results_get_binding_name(results->rdf_results, index); -} - - -void -slv2_results_next(SLV2Results results) -{ - librdf_query_results_next(results->rdf_results); -} - - -/** Query a single variable */ -SLV2Values -slv2_plugin_query_variable(SLV2Plugin plugin, - const char* sparql_str, - unsigned variable) -{ - assert(variable < INT_MAX); - - SLV2Results results = slv2_plugin_query_sparql(plugin, sparql_str); - - SLV2Values ret = slv2_query_get_variable_bindings(plugin->world, - results, (int)variable); - - slv2_results_free(results); - - return ret; -} - - -/** Run a query and count number of matches. - * - * More efficient than slv2_plugin_simple_query if you're only interested - * in the number of results (ie slv2_plugin_num_ports). - * - * Note the result of this function is probably meaningless unless the query - * is a SELECT DISTINCT. - */ -unsigned -slv2_plugin_query_count(SLV2Plugin plugin, - const char* sparql_str) -{ - SLV2Results results = slv2_plugin_query_sparql(plugin, sparql_str); - - unsigned ret = 0; - - if (results) { - ret = slv2_results_size(results); - slv2_results_free(results); - } - - return ret; -} - - librdf_stream* slv2_plugin_find_statements(SLV2Plugin plugin, librdf_node* subject, diff --git a/src/slv2_internal.h b/src/slv2_internal.h index af748bb..35a8f12 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -279,11 +279,6 @@ void slv2_scale_point_free(SLV2ScalePoint point); /* ********* Query Results********* */ -struct _SLV2Results { - SLV2World world; - librdf_query_results* rdf_results; -}; - SLV2Values slv2_values_from_stream_i18n(SLV2Plugin p, librdf_stream* stream); |