PgRest.SQL.Placeholders (PgRest v0.2.0)

Copy Markdown View Source

Shifts the $n placeholders of a SQL text by an offset.

This is a tokenizer, not a regex: it skips standard strings (doubled quotes), E'...' strings (backslash escapes), dollar quoting, -- and nested /* */ comments and quoted identifiers, and only renumbers placeholders found outside them.

It assumes standard_conforming_strings = on (the default), where a backslash is literal inside '...'. With it off the scan can disagree with the server about where a string ends, which fails closed: the placeholder check or a Postgres syntax error rejects the statement.

Summary

Functions

Adds offset to every placeholder in sql.

Functions

renumber(sql, offset, param_count)

@spec renumber(String.t(), non_neg_integer(), non_neg_integer()) :: String.t()

Adds offset to every placeholder in sql.

Raises ArgumentError unless the placeholders found are exactly $1..$param_count (each used at least once), or when a $ outside a token cannot be classified.