[redland-dev] Re: rasqal_query_results_get_bindings

Dave Beckett dave at dajobe.org
Tue May 22 05:58:45 BST 2007


Jagdev Bhogal wrote:
> Hi
> 
>  
> 
> I am trying to use rasqal_query_results_get_bindings function to see if
> I can iterate through each binding value in the results set returned
> from a query.
> 
> 
> The code compiles ok but when I run it I get segmentation fault, there
> is something wrong with the way I am using the
> rasqal_query_results_get_bindings function.
> 
> I would be very grateful if you could help me out with this.
> 
>  
> 
> To be honest I understand the use of a single * to declare a pointer but
> I am not sure why 3 asterisks are used in the
> rasqal_query_results_get_bindings function.


It's a C thing, the variable stores a pointer (*) to array of binding names
or, in this case, values.

This is all explained in the API docs:
http://librdf.org/rasqal/docs/api/rasqal-section-query-results.html#rasqal-query-results-get-bindings

[[[

If values is not NULL, it is set to the address of a shared array of
rasqal_literal* binding values. These values are shaerd and must not be
freed by the caller.
]]

which despite the typo, points out your error.

You need to point varvalues at a pre-declared array, large enough
to store the result values.

const char **names=NULL;
rasqal_value* varvalues[10];

rasqal_query_results_get_bindings(results, &names, values)) ...



>  
> 
>  rasqal_literal ***varvalues;
> 
> .
> 
> ./* other lines of code */
> 
> .
> 
> i=rasqal_query_results_get_bindings(results,NULL,varvalues);
> 
>  
> 
> Thanking you in anticipation


There's more about this in the redland API docs:
http://librdf.org/docs/api/redland-query-results.html#librdf-query-results-get-bindings


Dave



More information about the redland-dev mailing list