Click or drag to resize

SparqlParameterizedString Class

A SPARQL Parameterized String is a String that can contain parameters in the same fashion as a SQL command string.
Inheritance Hierarchy
SystemObject
  VDS.RDF.QuerySparqlParameterizedString

Namespace:  VDS.RDF.Query
Assembly:  dotNetRDF (in dotNetRDF.dll) Version:
Syntax
public class SparqlParameterizedString

The SparqlParameterizedString type exposes the following members.

Constructors
  NameDescription
Public methodSparqlParameterizedString
Creates a new empty parameterized String.
Public methodSparqlParameterizedString(String)
Creates a new parameterized String.
Top
Properties
  NameDescription
Public propertyBaseUri
Gets/Sets the Base URI which will be used to prepend BASE declarations to the command.
Public propertyCommandText
Gets/Sets the parameterized Command Text.
Public propertyNamespaces
Gets/Sets the Namespace Map that is used to prepend PREFIX declarations to the command.
Public propertyParameters
Gets an enumeration of the Parameters for which Values have been set.
Public propertyQueryProcessor
Gets/Sets the Query processor which is used when you call the ExecuteQuery() method.
Public propertyUpdateProcessor
Gets/Sets the Query processor which is used when you call the ExecuteUpdate() method.
Public propertyVariables
Gets an enumeration of the Variables for which Values have been set.
Top
Methods
  NameDescription
Public methodAppend(String)
Appends the given text to the existing command text, any prefixes in the command are moved to the parent query.
Public methodAppend(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.
Public methodAppendSubQuery(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.
Public methodAppendSubQuery(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.
Public methodClear
Clears all set Parameters and Variables.
Public methodClearParameters
Clears all set Parameters.
Public methodClearVariables
Clears all set Variables.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodExecuteQuery
Executes this command as a query.
Public methodExecuteQuery(IRdfHandler, ISparqlResultsHandler)
Executes this command as a query.
Public methodExecuteUpdate
Executes this command as an update.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodSetBlankNode(String)
Sets the Parameter to be a new anonymous Blank Node.
Public methodSetBlankNode(String, String)
Sets the Parameter to be a Blank Node with the given ID.
Public methodSetLiteral(String, Boolean)
Sets the Parameter to a Boolean Literal.
Public methodSetLiteral(String, DateTime)
Sets the Parameter to a Date Time Literal.
Public methodSetLiteral(String, DateTimeOffset)
Sets the Parameter to a Date Time Literal.
Public methodSetLiteral(String, Decimal)
Sets the Parameter to a Decimal Literal.
Public methodSetLiteral(String, Double)
Sets the Parameter to a Double Literal.
Public methodSetLiteral(String, Int16)
Sets the Parameter to an Integer Literal.
Public methodSetLiteral(String, Int32)
Sets the Parameter to an Integer Literal.
Public methodSetLiteral(String, Int64)
Sets the Parameter to an Integer Literal.
Public methodSetLiteral(String, Single)
Sets the Parameter to a Float Literal.
Public methodSetLiteral(String, String)
Sets the Parameter to an Untyped Literal.
Public methodSetLiteral(String, TimeSpan)
Sets the Parameter to a Duration Literal.
Public methodSetLiteral(String, DateTime, Boolean)
Sets the Parameter to a Date Time Literal.
Public methodSetLiteral(String, DateTimeOffset, Boolean)
Sets the Parameter to a Date Time Literal.
Public methodSetLiteral(String, String, String)
Sets the Parameter to a Literal with a Language Specifier.
Public methodSetLiteral(String, String, Uri)
Sets the Parameter to a Typed Literal.
Public methodSetParameter
Sets the Value of a Parameter.
Public methodSetUri
Sets the Parameter to a URI.
Public methodSetVariable
Sets the Value of a Variable.
Public methodToString
Returns the actual Query/Update String with parameter and variable values inserted.
(Overrides ObjectToString.)
Public methodUnsetParameter
Removes a previously set value for a Parameter.
Public methodUnsetVariable
Removes a previously set value for a Variable.
Top
Remarks

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.

See Also