Class SimpleStatement
A simple IStatement implementation built directly from a query string.
Implements
Inherited Members
Namespace: Dse
Assembly: Dse.dll
Syntax
public class SimpleStatement : RegularStatement, IStatement
Constructors
SimpleStatement()
Creates a new instance of SimpleStatement without any query string or parameters.
Declaration
public SimpleStatement()
SimpleStatement(IDictionary<String, Object>, String)
Creates a new instance of SimpleStatement using a dictionary of parameters and a query with named parameters.
Declaration
public SimpleStatement(IDictionary<string, object> valuesDictionary, string query)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<System.String, System.Object> | valuesDictionary | A dictionary containing the query parameters values using the parameter name as keys. |
System.String | query | The cql query string. |
Remarks
This constructor is valid for dynamically-sized named parameters, consider using anonymous types for fixed-size named parameters.
Examples
const string query = "INSERT INTO users (id, name, email) VALUES (:id, :name, :email)";
var parameters = new Dictionary<string, object>
{
{ "id", id },
{ "name", name },
{ "email", email },
};
var statement = new SimpleStatement(parameters, query);
See Also
SimpleStatement(String)
Creates a new instance of SimpleStatement with the provided CQL query.
Declaration
public SimpleStatement(string query)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | The cql query string. |
SimpleStatement(String, Object[])
Creates a new instance of SimpleStatement with the provided CQL query and values provided.
Declaration
public SimpleStatement(string query, params object[] values)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | The cql query string. |
System.Object[] | values | Parameter values required for the execution of |
Examples
Using positional parameters:
const string query = "INSERT INTO users (id, name, email) VALUES (?, ?, ?)";
var statement = new SimpleStatement(query, id, name, email);
Using named parameters (using anonymous objects):
const string query = "INSERT INTO users (id, name, email) VALUES (:id, :name, :email)";
var statement = new SimpleStatement(query, new { id, name, email } );
Properties
Keyspace
Returns the keyspace this query operates on, as set using SetKeyspace(String)
The keyspace returned is used as a hint for token-aware routing.
Declaration
public override string Keyspace { get; }
Property Value
Type | Description |
---|---|
System.String |
Overrides
Remarks
Consider using a ISession connected to single keyspace using Connect(String).
QueryString
Gets the query string.
Declaration
public override string QueryString { get; }
Property Value
Type | Description |
---|---|
System.String |
Overrides
RoutingKey
Gets the routing key for the query.
Routing key can be provided using the SetRoutingValues(Object[]) method.
Declaration
public override RoutingKey RoutingKey { get; }
Property Value
Type | Description |
---|---|
RoutingKey |
Overrides
Methods
Bind(Object[])
Sets the parameter values for the query.
The same amount of values must be provided as parameter markers in the query.
Specify the parameter values by the position of the markers in the query or by name, using a single instance of an anonymous type, with property names as parameter names.
Declaration
[Obsolete("The method Bind() is deprecated, use SimpleStatement constructor parameters to provide query values")]
public SimpleStatement Bind(params object[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | values |
Returns
Type | Description |
---|---|
SimpleStatement |
BindObjects(Object[])
Declaration
[Obsolete("The method BindObject() is deprecated, use SimpleStatement constructor parameters to provide query values")]
public SimpleStatement BindObjects(object[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | values |
Returns
Type | Description |
---|---|
SimpleStatement |
SetKeyspace(String)
Sets the keyspace this Statement operates on. The keyspace should only be set when the IStatement applies to a different keyspace to the logged keyspace of the ISession.
Declaration
public SimpleStatement SetKeyspace(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The keyspace name. |
Returns
Type | Description |
---|---|
SimpleStatement |
SetQueryString(String)
Declaration
public SimpleStatement SetQueryString(string queryString)
Parameters
Type | Name | Description |
---|---|---|
System.String | queryString |
Returns
Type | Description |
---|---|
SimpleStatement |
SetRoutingKey(RoutingKey[])
Set the routing key for this query.
This method allows to manually provide a routing key for this query. It is thus optional since the routing key is only an hint for token aware load balancing policy but is never mandatory.
If the partition key for the query is composite, use the
#setRoutingKey(ByteBuffer...) method instead to build the routing key.Declaration
public SimpleStatement SetRoutingKey(params RoutingKey[] routingKeyComponents)
Parameters
Type | Name | Description |
---|---|---|
RoutingKey[] | routingKeyComponents | the raw (binary) values to compose to obtain the routing key. |
Returns
Type | Description |
---|---|
SimpleStatement | this |
SetRoutingValues(Object[])
Sets the partition key values in order to route the query to the correct replicas.
For simple partition keys, set the partition key value.
For composite partition keys, set the multiple the partition key values in correct order.
Declaration
public SimpleStatement SetRoutingValues(params object[] keys)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | keys |
Returns
Type | Description |
---|---|
SimpleStatement |