SparqlParameterizedString Class |
Namespace: VDS.RDF.Query
The SparqlParameterizedString type exposes the following members.
Name | Description | |
---|---|---|
SparqlParameterizedString |
Creates a new empty parameterized String.
| |
SparqlParameterizedString(String) |
Creates a new parameterized String.
|
Name | Description | |
---|---|---|
BaseUri |
Gets/Sets the Base URI which will be used to prepend BASE declarations to the command.
| |
CommandText |
Gets/Sets the parameterized Command Text.
| |
Namespaces |
Gets/Sets the Namespace Map that is used to prepend PREFIX declarations to the command.
| |
Parameters |
Gets an enumeration of the Parameters for which Values have been set.
| |
QueryProcessor |
Gets/Sets the Query processor which is used when you call the ExecuteQuery() method.
| |
UpdateProcessor |
Gets/Sets the Query processor which is used when you call the ExecuteUpdate() method.
| |
Variables |
Gets an enumeration of the Variables for which Values have been set.
|
Name | Description | |
---|---|---|
Append(String) |
Appends the given text to the existing command text, any prefixes in the command are moved to the parent query.
| |
Append(SparqlParameterizedString) |
Appends the given text to the existing command text, any prefixes in the sub-query are moved to the parent query but any parameter/variable assignments will be lost.
| |
AppendSubQuery(SparqlParameterizedString) |
Appends the given query as a sub-query to the existing command text, any prefixes in the sub-query are moved to the parent query but any parameter/variable assignments will be lost.
| |
AppendSubQuery(SparqlQuery) |
Appends the given query as a sub-query to the existing command text, any prefixes in the sub-query are moved to the parent query.
| |
Clear |
Clears all set Parameters and Variables.
| |
ClearParameters |
Clears all set Parameters.
| |
ClearVariables |
Clears all set Variables.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
ExecuteQuery |
Executes this command as a query.
| |
ExecuteQuery(IRdfHandler, ISparqlResultsHandler) |
Executes this command as a query.
| |
ExecuteUpdate |
Executes this command as an update.
| |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
SetBlankNode(String) |
Sets the Parameter to be a new anonymous Blank Node.
| |
SetBlankNode(String, String) |
Sets the Parameter to be a Blank Node with the given ID.
| |
SetLiteral(String, Boolean) |
Sets the Parameter to a Boolean Literal.
| |
SetLiteral(String, DateTime) |
Sets the Parameter to a Date Time Literal.
| |
SetLiteral(String, DateTimeOffset) |
Sets the Parameter to a Date Time Literal.
| |
SetLiteral(String, Decimal) |
Sets the Parameter to a Decimal Literal.
| |
SetLiteral(String, Double) |
Sets the Parameter to a Double Literal.
| |
SetLiteral(String, Int16) |
Sets the Parameter to an Integer Literal.
| |
SetLiteral(String, Int32) |
Sets the Parameter to an Integer Literal.
| |
SetLiteral(String, Int64) |
Sets the Parameter to an Integer Literal.
| |
SetLiteral(String, Single) |
Sets the Parameter to a Float Literal.
| |
SetLiteral(String, String) |
Sets the Parameter to an Untyped Literal.
| |
SetLiteral(String, TimeSpan) |
Sets the Parameter to a Duration Literal.
| |
SetLiteral(String, DateTime, Boolean) |
Sets the Parameter to a Date Time Literal.
| |
SetLiteral(String, DateTimeOffset, Boolean) |
Sets the Parameter to a Date Time Literal.
| |
SetLiteral(String, String, String) |
Sets the Parameter to a Literal with a Language Specifier.
| |
SetLiteral(String, String, Uri) |
Sets the Parameter to a Typed Literal.
| |
SetParameter |
Sets the Value of a Parameter.
| |
SetUri |
Sets the Parameter to a URI.
| |
SetVariable |
Sets the Value of a Variable.
| |
ToString |
Returns the actual Query/Update String with parameter and variable values inserted.
(Overrides ObjectToString.) | |
UnsetParameter |
Removes a previously set value for a Parameter.
| |
UnsetVariable |
Removes a previously set value for a Variable.
|
This is intended for use in applications which may want to dynamically build SPARQL queries/updates where user input may comprise individual values in the triples patterns and the applications want to avoid SPARQL injection attacks which change the meaning of the query/update.
It works broadly in the same way as a SqlCommand would in that you specify a string with paramters specified in the form @name and then use various set methods to set the actual values that should be used. The values are only substituted for parameters when you actually call the ToString() method to get the final string representation of the command. E.g.
SparqlParameterizedString queryString = new SparqlParameterizedString(); queryString.CommandText = @"SELECT * WHERE { ?s a @type . }"; queryString.SetUri("type", new Uri("http://example.org/myType")); Console.WriteLine(queryString.ToString());
Would result in the following being printed to the Console:
SELECT * WHERE
{
?s a <http://example.org/myType>
}
Calling a Set method to set a parameter that has already been set changes that value and the new value will be used next time you call ToString() - this may be useful if you plan to execute a series of queries/updates using a series of values since you need not instantiate a completely new parameterized string each time.
This class was added to a library based on a suggestion by Alexander Sidorov and ideas from slides from Slideshare by Almedia et al.
PERFORMANCE TIPS: if building the command text incrementally, avoid using CommandText += and use the AppendSubQuery or Append methods instead.