Пример #1
0
static int
print_graph_result(rasqal_query* rq,
                   rasqal_query_results *results,
                   raptor_world* raptor_world_ptr,
                   FILE* output,
                   const char* serializer_syntax_name, raptor_uri* base_uri,
                   int quiet)
{
    int triple_count = 0;
    rasqal_prefix* prefix;
    int i;
    raptor_serializer* serializer = NULL;

    if(!quiet)
        fprintf(stderr, "%s: Query has a graph result:\n", program);

    if(!raptor_world_is_serializer_name(raptor_world_ptr, serializer_syntax_name)) {
        fprintf(stderr,
                "%s: invalid query result serializer name `%s' for `" HELP_ARG(r, results) "'\n",
                program, serializer_syntax_name);
        return 1;
    }

    serializer = raptor_new_serializer(raptor_world_ptr,
                                       serializer_syntax_name);
    if(!serializer) {
        fprintf(stderr, "%s: Failed to create raptor serializer type %s\n",
                program, serializer_syntax_name);
        return(1);
    }

    /* Declare any query namespaces in the output serializer */
    for(i = 0; (prefix = rasqal_query_get_prefix(rq, i)); i++)
        raptor_serializer_set_namespace(serializer, prefix->uri, prefix->prefix);
    raptor_serializer_start_to_file_handle(serializer, base_uri, output);

    while(1) {
        raptor_statement *rs = rasqal_query_results_get_triple(results);
        if(!rs)
            break;

        raptor_serializer_serialize_statement(serializer, rs);
        triple_count++;

        if(rasqal_query_results_next_triple(results))
            break;
    }

    raptor_serializer_serialize_end(serializer);
    raptor_free_serializer(serializer);

    if(!quiet)
        fprintf(stderr, "%s: Total %d triples\n", program, triple_count);

    return 0;
}
Пример #2
0
static int
librdf_query_rasqal_query_results_next_statement(void* context)
{
  librdf_query_rasqal_stream_context* scontext=(librdf_query_rasqal_stream_context*)context;

  if(scontext->finished)
    return 1;
  
  if(scontext->statement) {
    librdf_free_statement(scontext->statement);
    scontext->statement=NULL;
  }

  scontext->finished = !scontext->qcontext->results;
  if(!scontext->finished)
    scontext->finished=rasqal_query_results_next_triple(scontext->qcontext->results);
  if(!scontext->finished)
    librdf_query_rasqal_query_results_update_statement(scontext);
  
  return scontext->finished;
}