Skip to main content

Module params

Module params 

Source
Expand description

Prepared-statement parameter binding (SQLR-23).

Two responsibilities:

  1. Placeholder rewriting at prepare time. The user writes ? in the SQL; sqlparser parses each as Expr::Value(Placeholder("?")). We walk the parsed AST left-to-right and rewrite each bare ? to ?N (1-indexed source order) so the later substitution pass knows which slot to bind. The rewritten AST is what Statement caches.

  2. Substitution at execute time. Given the cached AST and a &[Value] slice, walk a clone of the AST and replace every Expr::Value(Placeholder("?N")) with the matching params[N-1].

Substitution lowers the bound value into a node shape the rest of the pipeline already understands:

  • Scalars (Integer, Real, Text, Bool, Null) become Expr::Value(...) literals — same shape an inline literal would parse to. Existing executor / parser arms handle them unchanged.
  • Vectors become Expr::Identifier { quote_style: Some('['), value: "<csv>" }, which is the in-band form sqlparser produces for inline bracket-array literals like [0.1, 0.2, ...]. The INSERT parser, the executor’s eval_expr_scope, and the HNSW probe optimizer all already recognize that shape, so a bound Value::Vector(...) flows through every path that an inline [...] literal does — including the HNSW shortcut.

Doing it as an AST-rewrite (rather than threading &[Value] through the executor) keeps the diff focused: every existing executor arm sees concrete literals, exactly as it does today on inline-params SQL.

Functions§

rewrite_placeholders
Walks every expression in stmt and rewrites bare ? placeholders to ?N (1-indexed source order). Returns the total parameter count.
substitute_params
Substitutes every ?N placeholder in stmt with the matching value from params. Mutates the AST in place — callers should clone first if they want the original back.