static int
rasqal_graph_rowsource_init(rasqal_rowsource* rowsource, void *user_data)
{
  rasqal_graph_rowsource_context *con;
  raptor_sequence* seq;

  con = (rasqal_graph_rowsource_context*)user_data;
  
  seq = rasqal_query_get_data_graph_sequence(rowsource->query);
  if(!seq)
    return 1;

  con->dg_size = raptor_sequence_size(seq);
  
  con->finished = 0;
  con->dg_offset = -1;
  con->offset = 0;

  /* Do not care if finished at this stage (it is not an
   * error). rasqal_graph_rowsource_read_row() will deal with
   * returning NULL for an empty result.
   */
  rasqal_graph_next_dg(con);

  return 0;
}
Beispiel #2
0
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;
}