Parameterization and identifiers
Overview
Bind untrusted data values using the driver API instead of building SQL by concatenating input. Identifiers such as table names and sort columns are syntax, not bound values. Map requested identifiers to a fixed allowlist; when necessary use the engine or driver identifier-quoting API. Objective: distinguish literal values from identifiers.
First example
SELECT tenant,id FROM sec_doc WHERE title='O''Brien';Observed SQLite result (rows in JSON):
[ [ 1, 1 ]]How it works
A harmless apostrophe illustrates literal quoting; the SQL example is a fixed literal, not a recommended way to handle user input. The host lab binds O’Brien using a placeholder and tests a fixed sort allowlist. Binding does not implement authorization, and LIKE patterns still have wildcard semantics. Never put secrets into SQL logs.
Practical example
SELECT 'title' AS literal_value, title AS column_value FROM sec_doc WHERE tenant=1 AND id=1;Observed SQLite result (rows in JSON):
[ [ "title", "O'Brien" ]]Practice and mistakes
Practice: query the title containing an apostrophe with a bound value in host-lab.py. Hint 1: use a question-mark placeholder. Hint 2: supply a one-element tuple. Check: the exact single matching row. Mistake: treating ORDER BY ? as dynamic column selection.
PostgreSQL 17 example — NOT RUN
PREPARE sec_title(text) AS SELECT $1 AS title;EXECUTE sec_title('O''Brien');DEALLOCATE sec_title;Expected result, not executed: "Returns literal O’Brien; application code should bind via its driver."