ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Server
  • Cloud
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Download
ScyllaDB Docs ScyllaDB C# driver Features Driver components Core component Statements Simple statements

Simple statements¶

Use SimpleStatement for queries that will be executed only once (or just a few times):

var statement =
    new SimpleStatement(
        "SELECT value FROM application_params WHERE name = 'greeting_message'");
session.Execute(statement);

Each time you execute a simple statement, Cassandra parses the query string again; nothing is cached (neither on the client nor on the server):

client                             driver                Cassandra
--+----------------------------------+---------------------+------
  |                                  |                     |
  | Session.Execute(SimpleStatement) |                     |
  |--------------------------------->|                     |
  |                                  | QUERY(query_string) |
  |                                  |-------------------->|
  |                                  |                     |
  |                                  |                     |
  |                                  |                     | - parse query string
  |                                  |                     | - execute query
  |                                  |                     |
  |                                  |       ROWS          |
  |                                  |<--------------------|
  |                                  |                     |
  |<---------------------------------|                     |

If you execute the same query often (or a similar query with different column values), consider a prepared statement instead.

Using values¶

Instead of hard-coding everything in the query string, you can use bind markers and provide values separately:

  • by position:

    new SimpleStatement(
      "SELECT value FROM application_params WHERE name = ?", 
      "greeting_message");
    
  • by name:

    var values = new Dictionary<string, object>
    {
        {"n", "greeting_message"}
    };
    session.Execute(
      new SimpleStatement(
        values,
        "SELECT value FROM application_params WHERE name = :n"));
    

This syntax has a few advantages:

  • if the values come from some other part of your code, it is safer and looks cleaner than doing the concatenation yourself;

  • you don’t need to translate the values to their string representation. The driver will send them alongside the query, in their serialized binary form.

The number of values must match the number of placeholders in the query string, and their types must match the database schema. Note that the driver does not parse simple statements, so it cannot perform those checks on the client side; if you make a mistake, the query will be sent anyway, and the server will reply with an error, that gets translated into a driver exception.

Type inference¶

Another consequence of not parsing query strings is that the driver has to guess how to serialize values, based on their .NET type (see the default type mappings). This can be tricky, in particular for numeric types:

// schema: create table bigints(b bigint primary key)
session.Execute(
    new SimpleStatement(
      "INSERT INTO bigints (b) VALUES (?)",
      1));
// InvalidQueryException

The problem here is that the literal 1 has the .NET type int. So the driver serializes it as a CQL int (4 bytes), but the server expects a CQL bigint (8 bytes). The fix is to specify the correct .NET type:

// schema: create table bigints(b bigint primary key)
session.Execute(
    new SimpleStatement(
      "INSERT INTO bigints (b) VALUES (?)",
      1L)); // long literal

You could also use prepared statements, which don’t have this limitation since parameter types are known in advance.

Was this page helpful?

PREVIOUS
Prepared statements
NEXT
Linq component
  • Create an issue
  • Edit this page

On this page

  • Simple statements
    • Using values
      • Type inference
ScyllaDB C# driver
  • master
    • master
  • Features
    • Address resolution
    • Authentication and Authorization
    • Automatic failover
    • Column Encryption
    • Driver components
      • ADO.NET
      • Core component
        • Statements
          • Batch statements
          • Per-query keyspace
          • Prepared statements
          • Simple statements
      • Linq component
        • Batch statements with LINQ
      • Mapper component
        • Batch statements with the Mapper
    • Connection heartbeat
    • Connection pooling
    • CQL data types to C# types
      • Date and time representation
      • Nulls and unset
    • Execution Profiles
    • Graph support
    • Cluster and schema metadata
    • Metrics
      • App.Metrics Provider
      • List of metrics
    • Native protocol
    • OpenTelemetry
    • Result paging
    • Parameterized queries
    • Query timestamps
    • Query warnings
    • Request Tracker
    • Routing queries
    • Speculative query execution
    • TLS/SSL
    • Tuning policies
    • User-defined functions and aggregates
    • User-defined types
    • Vector support
  • FAQ
  • Upgrade Guide
  • Examples
  • API Reference
Docs Tutorials University Contact Us About Us
© 2025 ScyllaDB | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 01 Aug 2025.
Powered by Sphinx 7.4.7 & ScyllaDB Theme 1.8.7
Ask AI