liveBook · Manning

Parameterized query

As explained in ScyllaDB in Action

A pre-parsed database statement whose structure is cached so that it can be executed repeatedly with separately bound parameter values.

A parameterized query separates a CQL statement’s fixed structure from the values supplied for each execution. Prepare the statement once; the driver caches its parsed form, then bind values to its ? placeholders when running it again. This avoids repeated parsing and sanitizes supplied inputs, preventing CQL injection. section 10.3.1 section 10.7

Use parameterized queries as a small repeatable workflow:

  • Write CQL with ? for every value that will vary. section 10.3.1 section 10.4.2
  • Prepare it through the database session and retain the resulting statement under a descriptive key. section 10.3.2 section 10.4.2
  • Bind application values with the database types the query expects, then execute the statement. section 10.3.2
  • Set a default consistency level on the prepared statement when all uses share it; bind first to override one execution. section 10.5.1

Read one article by ID

Prepare SELECT id, author_id, date, restaurant_name, review, score, title FROM articles WHERE id = ?. A Flask route receives the ID, converts it to a UUID, and executes the stored statement with that UUID in a one-item list. The result is then adapted for the API response, including date serialization. section 10.3.2

Writes use the same mechanism. An article insert and its summary-table inserts each have a prepared statement, with one placeholder per inserted value. Preparing the database operation is straightforward; validating request data, retrieving related data, and organizing batch writes add most of the surrounding work. section 10.4 section 10.4.2

Figure 10.3 Using prepared statements in your application lets you reuse queries across requests, binding parameters for each use.
figure

Trace how one prepared query is reused across requests while each execution receives separately bound values. section 10.3.1

How ScyllaDB in Action covers it

How deep it goes
Explains preparation, placeholders, binding, caching, sanitization, and statement-level consistency overrides without driver internals.
Examples
Demonstrates article lookup by UUID, author retrieval, article inserts, summary-table inserts, and a curl API response.
What it assumes
Introduces binding from Flask route values and teaches UUID conversion required by the article query.
What you can do after
Apply it via the Scylla Python driver to reuse CQL safely and configure default or per-execution consistency.
How it connects
Connects prepared statements to CQL injection, consistency levels, batch statements, UUIDs, and Flask routes.

Also explained in

Compare how 8 books explain parameterized query →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.