Skip to main content

Module translate

Module translate 

Source
Expand description

Dialect-aware placeholder translation (CONN-03).

Public surface lives at pmcp_server_toolkit::sql::translate_placeholders per D-05 — a free helper, not a trait method. Dialect-aware placeholder translation (CONN-03).

Translates canonical :name named placeholders in a SQL string into the positional form each backend dialect expects, while preserving the binding order so the per-backend execute() impl can build a positional argument list from the caller’s &[(String, serde_json::Value)].

The translation walks the SQL char-by-char with a small state machine ([SqlWalker]) that tracks string literals, line/block comments, and the placeholder substate so a :name inside '...', "...", -- ..., or /* ... */ is NEVER rewritten. Each helper stays under PMAT cog 25 via the split-helper form (PATTERNS Pattern G) — no cognitive-complexity allow attribute is needed anywhere in this module.

Placeholder-recognition rule (REVIEWS H7): in Normal state a : only begins a placeholder if the NEXT char is [A-Za-z_]. A :: is a Postgres cast (consumed verbatim, the following type identifier is swallowed by the transitional CastTypeName state), a := is a MySQL session-var assignment, and :1bad is malformed — all three emit the bare : verbatim and stay in Normal. This eliminates the ::text mis-translation regression class.

Public surface lives at pmcp_server_toolkit::sql::translate_placeholders (D-05): a free helper, NOT a trait method — every connector calls it the same way, so putting it on the trait would invite per-backend drift.

Structs§

TranslatedSql
Result of translating canonical :name placeholders into a dialect’s positional form, plus the binding order needed to bind values positionally.

Functions§

translate_placeholders
Translate canonical :name placeholders in sql into dialect’s positional form, returning the rewritten SQL plus the binding order.