コード例 #1
0
ファイル: RDF.c プロジェクト: Webo/DEFOREST
/**
 * @brief Executes the given query and returns the result in the given format.
 *
 *
 * @param query The query to execute.
 * @param format The format of the result.
 * 
 * @return The results.
 */
unsigned char* RDF_ExecQuery(unsigned char* query, unsigned char* format)
{   
    librdf_query* rdfquery;
    librdf_query_results* results;
           
    rdfquery = librdf_new_query(world, "sparql", NULL, query, NULL);
    results = librdf_model_query_execute(model, rdfquery);             
        
    librdf_serializer* serializer;
    librdf_stream* stream;

    serializer = librdf_new_serializer(world, format, NULL, NULL);
    
    if(!serializer) 
    {
      fprintf(stderr,
              "Failed to create triples serializer for format '%s'\n",
              format);
      return NULL;
    }

    stream = librdf_query_results_as_stream(results);
    unsigned char* result = librdf_serializer_serialize_stream_to_string(serializer,
               NULL, stream);    

    if(!result) 
    {
      fprintf(stderr, "Failed to turn query results to format '%s'\n",
              format);
      return NULL;
    }
    
    librdf_free_query(rdfquery);
    librdf_free_query_results(results);
    librdf_free_serializer(serializer);
    librdf_free_stream(stream);
    
    return result;
}
コード例 #2
0
ファイル: serializer.c プロジェクト: totesPferd/bagatellen
int
lua_bindings_redland_serializer_serialize_stream_to_string(lua_State *L) {
   librdf_serializer **pp_serializer
      =  (librdf_serializer **) luaL_checkudata(
            L
         ,  -4
         ,  serializer_userdata_type );
   librdf_stream **pp_stream
      =  (librdf_stream **) luaL_checkudata(
            L
         ,  -3
         ,  stream_userdata_type );

   librdf_uri *p_uri =  NULL;
   lua_getfield(L, -1, "base_uri");
   if (!lua_isnil(L, -1)) {
      librdf_uri **pp_uri
         =  (librdf_uri **) luaL_checkudata(
               L
            ,  -1
            ,  uri_userdata_type );
      p_uri =  *pp_uri;
   }
   lua_pop(L, 1);

   lua_pop(L, 3);

   unsigned char *result =  librdf_serializer_serialize_stream_to_string(
         *pp_serializer
      ,  p_uri
      ,  *pp_stream);
   if (result) {
      lua_pushstring(L, result);
      return 1;
   } else {
      return 0;
   }
}