Models a SELECT statement in SPARQL. More...
Public Member Functions | |
Select () | |
Constructs an empty SELECT statement. | |
Select (const Select &other) | |
Select & | operator= (const Select &other) |
bool | operator== (const Select &other) const |
bool | operator!= (const Select &other) const |
void | addProjection (const Projection &projection) |
Adds a new projection to the statement's projections. | |
void | addProjection (const Variable &variable) |
Adds a new variable to the statement's projections. | |
void | addProjection (const Function &function, const Variable &alias=Variable::invalid()) |
Adds a new predicate function to the statement's projections. | |
void | addProjection (const Select &select, const Variable &alias=Variable::invalid()) |
Adds an inner select to the statement's projections. | |
void | addProjection (const LiteralValue &literalValue) |
Adds a literal value to the statement's projections. | |
void | addRestriction (const PatternBase &pattern) |
Adds a new restriction to the statement. | |
void | addRestriction (const Value &s, const Value &p, const Value &o) |
Adds a new triple to the statement's restrictions. | |
void | addRestriction (const Value &s, const ValueChain &chain, const Value &o) |
Adds a triple chain to the statement's restrictions. | |
Filter | filter () const |
Returns the current statement's restriction filter, or an invalid Filter if there is none. | |
void | setFilter (const Filter &filter) |
Sets a global filter on the statement's restrictions. | |
void | setLimit (long limit) |
Sets the maximum number of results to return. | |
void | setOffset (long offset) |
Set number of results to skip at the beginning of the result set. | |
void | setOrderBy (const Value &order) |
Sets the expression used to order the results in the result set. | |
bool | isEmpty () const |
Returns true if there are no projections, no restrictions and no filter set. | |
QList< Projection > | projections () const |
Returns all the projections of this statement. | |
QList< PatternBase > | restrictions () const |
Returns all the restrictions of this statement. | |
long | limit () const |
Returns the current results limit of this statement, or -1 if there is no limit set. | |
long | offset () const |
Returns the current results offset of this statement, or -1 if there is no offset set. | |
Value | orderBy () const |
Returns the expression used to sort the results, or an invalid Value if none is set. | |
QString | sparql (Options::SparqlOptions options=Options::DefaultSparqlOptions) const |
Returns the Sparql query corresponding to this statement. |
Models a SELECT statement in SPARQL.
That class can be used for both "normal" and nested SELECTs.
A Select statement has projections and restrictions. The projections are the variables you want to get in the result set, and the restrictions are the graph patterns that must be satisfied by the triples returned in the result set.
Let's consider the following query:
SELECT ?c WHERE {?c a nco:PersonContact}
In this query, The ?c variable is a projection, and the only retriction is the graph pattern in the curly braces.
Select::Select | ( | ) |
Constructs an empty SELECT statement.
The returned statement has no projections, no restrictions, no results limit and no results offset.
void Select::addProjection | ( | const LiteralValue & | literalValue | ) |
Adds a literal value to the statement's projections.
This adds a constant column to the results.
void Select::addProjection | ( | const Function & | function, | |
const Variable & | alias = Variable::invalid() | |||
) |
Adds a new predicate function to the statement's projections.
The function must have previously been applied to another projection using Function::apply(), this will not be checked by the library.
An optional alias can be defined for the projection using the alias
parameter.
Adds an inner select to the statement's projections.
The inner select must have one single projection, and return 0 or 1 results for the query to work.
An optional alias can be defined for the projection using the alias
parameter.
void Select::addRestriction | ( | const PatternBase & | pattern | ) |
Adds a new restriction to the statement.
You will probably use this function to add a PatternGroup to the statement's restrictions.
The user keeps ownership of the pattern and must free it.
Adds a new triple to the statement's restrictions.
The user keeps the ownership of the variables and must free them.
Adds a triple chain to the statement's restrictions.
The user keeps the ownership of the variables and must free them.
QList< PatternBase > Select::restrictions | ( | ) | const |
Returns all the restrictions of this statement.
Note that this list is actually a tree, since it can contain PatternGroup instances, that contains restrictions themselves.
void Select::setFilter | ( | const Filter & | filter | ) |
Sets a global filter on the statement's restrictions.
More specific filters applying only to a subset of the restrictions can be done setting filters on PatternGroup instances and adding those instances to the restrictions.
void Select::setLimit | ( | long | limit | ) |
Sets the maximum number of results to return.
-1 can be passed to disable this feature.
void Select::setOffset | ( | long | offset | ) |
Set number of results to skip at the beginning of the result set.
-1 can be passed to disable this feature.