Top | ![]() |
![]() |
![]() |
![]() |
rasqal_query * rasqal_new_query (rasqal_world *world
,const char *name
,const char *uri
);
Constructor - create a new rasqal_query object.
A query language can be named or identified by a URI, either of which is optional. The default query language will be used if both are NULL. rasqal_world_get_query_language_description returns the description of the known names, labels, MIME types and URIs.
world |
rasqal_world object |
|
name |
the query language name (or NULL) |
|
uri |
raptor_uri language uri (or NULL) |
void
rasqal_free_query (rasqal_query *query
);
Destructor - destroy a rasqal_query object.
int rasqal_query_add_data_graph (rasqal_query *query
,rasqal_data_graph *data_graph
);
Add a data graph to the query.
int rasqal_query_add_data_graphs (rasqal_query *query
,raptor_sequence *data_graphs
);
Add a set of data graphs to the query.
The objects in the passed-in data_graphs
sequence becomes owne by the query.
The data_graphs
sequence itself is freed and must not be used after this call.
int rasqal_query_add_prefix (rasqal_query *query
,rasqal_prefix *prefix
);
Add a namespace prefix to the query.
If the prefix has already been used, the old URI will be overridden.
int rasqal_query_add_variable (rasqal_query *query
,rasqal_variable *var
);
Add a projected (named) variable to the query.
See also rasqal_query_set_variable()
which assigns or removes a value to
a previously added variable in the query.
int rasqal_query_dataset_contains_named_graph (rasqal_query *query
,raptor_uri *graph_uri
);
Test if the query dataset contains a named graph
rasqal_query_results *
rasqal_query_execute (rasqal_query *query
);
Excute a query - run and return results.
raptor_sequence *
rasqal_query_get_all_variable_sequence
(rasqal_query *query
);
Get the sequence of all variables mentioned in the query.
raptor_sequence *
rasqal_query_get_anonymous_variable_sequence
(rasqal_query *query
);
Get the sequence of anonymous variables mentioned in the query.
rasqal_row * rasqal_query_get_bindings_row (rasqal_query *query
,int idx
);
Get a rasqal_row* in the sequence of BINDINGS block result rows
raptor_sequence *
rasqal_query_get_bindings_rows_sequence
(rasqal_query *query
);
Get the sequence of BINDINGS block result rows
rasqal_variable * rasqal_query_get_bindings_variable (rasqal_query *query
,int idx
);
Get a rasqal_variable* in the sequence of BINDINGS block variables
raptor_sequence *
rasqal_query_get_bindings_variables_sequence
(rasqal_query *query
);
Get the sequence of BINDINGS block variables
raptor_sequence *
rasqal_query_get_bound_variable_sequence
(rasqal_query *query
);
Get the sequence of projected variables in the query.
This returns the sequence of variables that are explicitly chosen via SELECT in SPARQL. Or all variables mentioned with SELECT *
rasqal_triple * rasqal_query_get_construct_triple (rasqal_query *query
,int idx
);
Get a triple in the sequence of construct triples.
raptor_sequence *
rasqal_query_get_construct_triples_sequence
(rasqal_query *query
);
Get the sequence of triples for a construct.
rasqal_data_graph * rasqal_query_get_data_graph (rasqal_query *query
,int idx
);
Get a rasqal_data_graph* in the sequence of data_graphs.
raptor_sequence *
rasqal_query_get_data_graph_sequence (rasqal_query *query
);
Get the sequence of data_graph URIs.
raptor_sequence *
rasqal_query_get_describe_sequence (rasqal_query *query
);
Get the sequence of literals described in the query.
This returns the sequence of literals (constants or variables) that are explicitly chosen via DESCRIBE in SPARQL.
int
rasqal_query_get_distinct (rasqal_query *query
);
Get the query distinct mode
See rasqal_query_set_distinct()
for the distinct modes.
int
rasqal_query_get_explain (rasqal_query *query
);
Get the query explain results flag.
rasqal_expression * rasqal_query_get_group_condition (rasqal_query *query
,int idx
);
Get a query grouping expression in the sequence of query grouping conditions.
raptor_sequence *
rasqal_query_get_group_conditions_sequence
(rasqal_query *query
);
Get the sequence of query grouping conditions.
rasqal_graph_pattern * rasqal_query_get_graph_pattern (rasqal_query *query
,int idx
);
Get a graph_pattern in the sequence of graph_pattern expressions in the top query graph pattern.
raptor_sequence *
rasqal_query_get_graph_pattern_sequence
(rasqal_query *query
);
Get the sequence of graph_patterns expressions inside the top query graph pattern.
rasqal_expression * rasqal_query_get_having_condition (rasqal_query *query
,int idx
);
Get a query having expression in the sequence of query havinging conditions.
raptor_sequence *
rasqal_query_get_having_conditions_sequence
(rasqal_query *query
);
Get the sequence of query having conditions.
const char *
rasqal_query_get_label (rasqal_query *query
);
Get a readable label for the query language.
int
rasqal_query_get_limit (rasqal_query *query
);
Get the query-specified limit on results.
This is the limit given in the query on the number of results allowed.
const char *
rasqal_query_get_name (rasqal_query *query
);
Get a short name for the query language.
int
rasqal_query_get_offset (rasqal_query *query
);
Get the query-specified offset on results.
This is the offset given in the query on the number of results allowed. It is only guaranteed to work after the query is prepared and before it is executed.
rasqal_expression * rasqal_query_get_order_condition (rasqal_query *query
,int idx
);
Get a query ordering expression in the sequence of query ordering conditions.
raptor_sequence *
rasqal_query_get_order_conditions_sequence
(rasqal_query *query
);
Get the sequence of query ordering conditions.
rasqal_prefix * rasqal_query_get_prefix (rasqal_query *query
,int idx
);
Get a prefix in the sequence of namespsace prefixes in the query.
raptor_sequence *
rasqal_query_get_prefix_sequence (rasqal_query *query
);
Get the sequence of namespace prefixes in the query.
rasqal_graph_pattern *
rasqal_query_get_query_graph_pattern (rasqal_query *query
);
Get the top query graph pattern.
rasqal_triple * rasqal_query_get_triple (rasqal_query *query
,int idx
);
Get a triple in the sequence of matching triples in the query.
raptor_sequence *
rasqal_query_get_triple_sequence (rasqal_query *query
);
Get the sequence of matching triples in the query.
void *
rasqal_query_get_user_data (rasqal_query *query
);
Get query user data.
rasqal_variable * rasqal_query_get_variable (rasqal_query *query
,int idx
);
Get a variable in the query
rasqal_query_verb
rasqal_query_get_verb (rasqal_query *query
);
Get the query verb.
int
rasqal_query_get_wildcard (rasqal_query *query
);
Get the query verb is wildcard flag.
int rasqal_query_has_variable2 (rasqal_query *query
,rasqal_variable_type type
,const char *name
);
Find if the named variable of the given type is in the query
Note that looking up for any type RASQAL_VARIABLE_TYPE_UNKNOWN may a name match but for any type so in cases where the query has both a named and anonymous (extensional) variable, an arbitrary one will be returned.
query |
rasqal_query query object |
|
type |
the variable type to match or RASQAL_VARIABLE_TYPE_UNKNOWN for any. |
|
name |
variable name |
int rasqal_query_has_variable (rasqal_query *query
,const char *name
);
rasqal_query_has_variable
is deprecated and should not be used in newly-written code.
Find if the named variable is in the query (of any type)
Deprecated
: Use rasqal_query_has_variable2()
with the variable type arg
int rasqal_query_prepare (rasqal_query *query
,const char *query_string
,raptor_uri *base_uri
);
Prepare a query - typically parse it.
Some query languages may require a base URI to resolve any relative URIs in the query string. If this is not given, the current directory in the filesystem is used as the base URI.
The query string may be NULL in which case it is not parsed and the query parts may be created by API calls such as rasqal_query_add_source etc.
query |
the rasqal_query object |
|
query_string |
the query string (or NULL) |
|
base_uri |
base URI of query string (optional) |
int rasqal_query_print (rasqal_query *query
,FILE *fh
);
Print a query in a debug format.
int rasqal_query_graph_pattern_visit2 (rasqal_query *query
,rasqal_graph_pattern_visit_fn visit_fn
,void *data
);
Visit all graph patterns in a query with a user function visit_fn
.
See also rasqal_graph_pattern_visit()
.
void rasqal_query_graph_pattern_visit (rasqal_query *query
,rasqal_graph_pattern_visit_fn visit_fn
,void *data
);
rasqal_query_graph_pattern_visit
is deprecated and should not be used in newly-written code.
Visit all graph patterns in a query with a user function visit_fn
.
Deprecated
: use rasqal_query_graph_pattern_visit2()
that returns the visit_fn
status code.
See also rasqal_graph_pattern_visit()
.
void rasqal_query_set_distinct (rasqal_query *query
,int distinct_mode
);
Set the query distinct results mode.
The allowed distinct_mode
values are:
0 if not given
1 if DISTINCT: ensure solutions are unique
2 if SPARQL REDUCED: permit elimination of some non-unique solutions
void rasqal_query_set_explain (rasqal_query *query
,int is_explain
);
Set the query explain results flag.
void rasqal_query_set_limit (rasqal_query *query
,int limit
);
Set the query-specified limit on results.
This is the limit given in the query on the number of results allowed. It is only guaranteed to work after the query is prepared and before it is executed.
query |
rasqal_query query object |
|
limit |
the limit on results, >=0 to set a limit, <0 to have no limit |
void rasqal_query_set_offset (rasqal_query *query
,int offset
);
Set the query-specified offset on results.
This is the offset given in the query on the number of results allowed.
query |
rasqal_query query object |
|
offset |
offset for results, >=0 to set an offset, <0 to have no offset |
void rasqal_query_set_user_data (rasqal_query *query
,void *user_data
);
Set the query user data.
int rasqal_query_set_variable2 (rasqal_query *query
,rasqal_variable_type type
,const char *name
,rasqal_literal *value
);
Bind an existing typed variable to a value to the query.
See also rasqal_query_add_variable()
which adds a new binding variable
and must be called before this method is invoked.
query |
rasqal_query query object |
|
type |
the variable type to match or RASQAL_VARIABLE_TYPE_UNKNOWN for any. |
|
name |
rasqal_variable variable |
|
value |
rasqal_literal value to set or NULL |
int rasqal_query_set_variable (rasqal_query *query
,const char *name
,rasqal_literal *value
);
rasqal_query_set_variable
is deprecated and should not be used in newly-written code.
Bind an existing named (selected) variable to a value to the query.
Deprecated
for rasqal_query_set_variable2()
that includes a type
arg. This function only sets named variables of type
RASQAL_VARIABLE_TYPE_NORMAL
query |
rasqal_query query object |
|
name |
rasqal_variable variable |
|
value |
rasqal_literal value to set or NULL |
int rasqal_query_set_store_results (rasqal_query *query
,int store_results
);
Request that query results are stored during execution
When called after a rasqal_query_prepare()
, this tells
rasqal_query_execute()
to execute the entire query immediately
rather than generate them lazily, and store all the results in
memory. The results will then be available for reading multiple
times using rasqal_query_results_rewind()
to move back to the
start of the result object. If called after preparation, returns
failure.
void rasqal_query_set_wildcard (rasqal_query *query
,int wildcard
);
Set the query projection wildcard flag
const char *
rasqal_query_verb_as_string (rasqal_query_verb verb
);
Get a string for the query verb.
int rasqal_query_write (raptor_iostream *iostr
,rasqal_query *query
,raptor_uri *format_uri
,raptor_uri *base_uri
);
Write a query to an iostream in a specified format.
The supported URIs for the format_uri are:
Default: SPARQL Query Language 2006-04-06 http://www.w3.org/TR/2006/CR-rdf-sparql-query-20060406/
iostr |
raptor_iostream to write the query to |
|
query |
rasqal_query pointer. |
|
format_uri |
raptor_uri describing the format to write (or NULL for default) |
|
base_uri |
raptor_uri base URI of the output format |
int rasqal_query_iostream_write_escaped_counted_string (rasqal_query *query
,raptor_iostream *iostr
,const unsigned char *string
,size_t len
);
Write a string to an iostream in escaped form suitable for the query string.
query |
rasqal_query object |
|
iostr |
raptor_iostream to write the escaped string to |
|
string |
string to escape |
|
len |
Length of string to escape |
unsigned char * rasqal_query_escape_counted_string (rasqal_query *query
,const char *string
,size_t len
,size_t *output_len_p
);
Convert a string into an escaped form suitable for the query string.
The returned string must be freed by the caller with
rasqal_free_memory()
query |
rasqal_query object |
|
string |
string to escape |
|
len |
Length of string to escape |
|
output_len_p |
Pointer to store length of output string (or NULL) |
int rasqal_query_set_feature (rasqal_query *query
,rasqal_feature feature
,int value
);
Set various query features.
The allowed features are available via rasqal_features_enumerate()
.
query |
rasqal_query query object |
|
feature |
feature to set from enumerated rasqal_feature values |
|
value |
integer feature value |
int rasqal_query_set_feature_string (rasqal_query *query
,rasqal_feature feature
,const char *value
);
Set query features with string values.
The allowed features are available via rasqal_features_enumerate()
.
If the feature type is integer, the value is interpreted as an integer.
query |
rasqal_query query object |
|
feature |
feature to set from enumerated rasqal_feature values |
|
value |
feature value |
int rasqal_query_get_feature (rasqal_query *query
,rasqal_feature feature
);
Get various query features.
The allowed features are available via rasqal_features_enumerate()
.
Note: no feature value is negative
const unsigned char * rasqal_query_get_feature_string (rasqal_query *query
,rasqal_feature feature
);
Get query features with string values.
The allowed features are available via rasqal_features_enumerate()
.
If a string is returned, it must be freed by the caller.
rasqal_query_results_type
rasqal_query_get_result_type (rasqal_query *query
);
Get the result type expected from executing the query.
This function is only valid after rasqal_query_prepare()
has been
run on the query and will return RASQAL_QUERY_RESULTS_UNKNOWN if
called before preparation.
rasqal_update_operation * rasqal_query_get_update_operation (rasqal_query *query
,int idx
);
Get a query update operation in the sequence of update operations
raptor_sequence *
rasqal_query_get_update_operations_sequence
(rasqal_query *query
);
Get the sequence of update operations
Query main operation verbs describing the major type of query being performed.