static rasqal_query* check_query_init_query(rasqal_world *world, const char* ql_name, const unsigned char* query_string, raptor_uri* base_uri, raptor_sequence* data_graphs) { rasqal_query* rq; rq = rasqal_new_query(world, (const char*)ql_name, NULL); if(!rq) { fprintf(stderr, "%s: Failed to create query in language %s\n", program, ql_name); goto tidy_query; } if(rasqal_query_prepare(rq, (const unsigned char*)query_string, base_uri)) { fprintf(stderr, "%s: Parsing query failed\n", program); rasqal_free_query(rq); rq = NULL; goto tidy_query; } if(data_graphs) { rasqal_data_graph* dg; while((dg = (rasqal_data_graph*)raptor_sequence_pop(data_graphs))) { if(rasqal_query_add_data_graph(rq, dg)) { fprintf(stderr, "%s: Failed to add data graph to query\n", program); goto tidy_query; } } } tidy_query: return rq; }
static rasqal_query* roqet_init_query(rasqal_world *world, const char* ql_name, const char* ql_uri, const unsigned char* query_string, raptor_uri* base_uri, rasqal_feature query_feature, int query_feature_value, const unsigned char* query_feature_string_value, int store_results, raptor_sequence* data_graphs) { rasqal_query* rq; rq = rasqal_new_query(world, (const char*)ql_name, (const unsigned char*)ql_uri); if(!rq) { fprintf(stderr, "%s: Failed to create query name %s\n", program, ql_name); goto tidy_query; } if(query_feature_value >= 0) rasqal_query_set_feature(rq, query_feature, query_feature_value); if(query_feature_string_value) rasqal_query_set_feature_string(rq, query_feature, query_feature_string_value); #ifdef STORE_RESULTS_FLAG if(store_results >= 0) rasqal_query_set_store_results(rq, store_results); #endif if(data_graphs) { rasqal_data_graph* dg; while((dg = (rasqal_data_graph*)raptor_sequence_pop(data_graphs))) { if(rasqal_query_add_data_graph(rq, dg)) { fprintf(stderr, "%s: Failed to add data graph to query\n", program); goto tidy_query; } } } if(rasqal_query_prepare(rq, query_string, base_uri)) { size_t len = strlen((const char*)query_string); fprintf(stderr, "%s: Parsing query '", program); if(len > MAX_QUERY_ERROR_REPORT_LEN) { (void)fwrite(query_string, MAX_QUERY_ERROR_REPORT_LEN, sizeof(char), stderr); fprintf(stderr, "...' (%d bytes) failed\n", (int)len); } else { (void)fwrite(query_string, len, sizeof(char), stderr); fputs("' failed\n", stderr); } rasqal_free_query(rq); rq = NULL; goto tidy_query; } tidy_query: return rq; }
static int rasqal_redland_new_triples_source(rasqal_query* rdf_query, void *factory_user_data, void *user_data, rasqal_triples_source *rts) { librdf_world *world=(librdf_world*)factory_user_data; rasqal_redland_triples_source_user_data* rtsc=(rasqal_redland_triples_source_user_data*)user_data; raptor_sequence *seq; librdf_query_rasqal_context *context; librdf_iterator* cit; rtsc->world = world; rtsc->query = (librdf_query*)rasqal_query_get_user_data(rdf_query); context = (librdf_query_rasqal_context*)rtsc->query->context; rtsc->model = context->model; seq = rasqal_query_get_data_graph_sequence(rdf_query); /* FIXME: queries with data graphs in them (such as FROM in SPARQL) * are deleted, so that there are no unexpected data loads */ if(seq) { while(raptor_sequence_size(seq)) { rasqal_data_graph* dg=(rasqal_data_graph*)raptor_sequence_pop(seq); rasqal_free_data_graph(dg); } } if(librdf_model_supports_contexts(rtsc->model)) { /* Add all contexts (named graphs) to the query so Rasqal can bind them */ cit = librdf_model_get_contexts(rtsc->model); while(!librdf_iterator_end(cit)) { librdf_node* node = (librdf_node*)librdf_iterator_get_object(cit); librdf_uri* uri; raptor_uri* source_uri; rasqal_data_graph* dg; uri = librdf_node_get_uri(node); source_uri = (raptor_uri*)raptor_new_uri(world->raptor_world_ptr, librdf_uri_as_string(uri)); dg = rasqal_new_data_graph_from_uri(world->rasqal_world_ptr, source_uri, source_uri, RASQAL_DATA_GRAPH_NAMED, NULL, NULL, NULL); rasqal_query_add_data_graph(rdf_query, dg); raptor_free_uri(source_uri); librdf_iterator_next(cit); } librdf_free_iterator(cit); } #ifdef RASQAL_TRIPLES_SOURCE_MIN_VERSION rts->version = 1; #endif rts->init_triples_match=rasqal_redland_init_triples_match; rts->triple_present=rasqal_redland_triple_present; rts->free_triples_source=rasqal_redland_free_triples_source; return 0; }