Class SimpleStatement
A simple IStatement implementation built directly from a query string.
Implements
Inherited Members
Namespace: Cassandra
Assembly: Cassandra.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 |
---|---|---|
IDictionary<string, object> | valuesDictionary | A dictionary containing the query parameters values using the parameter name as keys. |
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 |
---|---|---|
string | query | The cql query string. |
SimpleStatement(string, params 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 |
---|---|---|
string | query | The cql query string. |
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 |
---|---|
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 |
---|---|
string |
Overrides
RoutingKey
Gets the routing key for the query.
Routing key can be provided using the SetRoutingValues(params object[]) method.
Declaration
public override RoutingKey RoutingKey { get; }
Property Value
Type | Description |
---|---|
RoutingKey |
Overrides
Methods
Bind(params 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 |
---|---|---|
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 |
---|---|---|
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 |
---|---|---|
string | name | The keyspace name. |
Returns
Type | Description |
---|---|
SimpleStatement |
SetQueryString(string)
Declaration
public SimpleStatement SetQueryString(string queryString)
Parameters
Type | Name | Description |
---|---|---|
string | queryString |
Returns
Type | Description |
---|---|
SimpleStatement |
SetRoutingKey(params 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(params 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 |
---|---|---|
object[] | keys |
Returns
Type | Description |
---|---|
SimpleStatement |