Skip to content

guard, deparser, dialect: names as the catalog has them, every clause checked, literals no value can end - #110

Merged
stbischof merged 1 commit into
eclipse-daanse:mainfrom
stbischof:fix/guard-hardening
Dec 1, 2026
Merged

stbischof merged 1 commit into
eclipse-daanse:mainfrom
stbischof:fix/guard-hardening

Conversation

@stbischof

Copy link
Copy Markdown
Contributor

The guard resolves each name against the catalog and writes it with its spelling: a quoted name matches exactly, an unquoted one as the dialect folds it. Every clause is walked and anything outside the catalog is refused, also in LIMIT, OFFSET, FETCH, QUALIFY, WINDOW, DISTINCT ON and behind a set operation, and a common table expression never hides a catalog table. Expressions are allowed by kind; syntax that calls a function or operator goes through the whitelist. String literals are read once and written by the dialect, casts name plain types only, and sequences, variables, parameters, database links, table hints, time travel and sampling are refused; the size of a statement is limited. The written text is read again as the database reads it and must hold what was checked. One guard serves statements from many threads.

The deparser quotes, through the dialect, an alias that is not a plain identifier and a qualifier that names it, and writes IS DISTINCT FROM, COLLATE, KEEP, the JSON operators, MATCH ... AGAINST and START WITH / CONNECT BY part by part, so that each name is quoted and each literal written by the dialect.

The dialects write a string literal that no quote or backslash of its value can end. LiteralQuoter.backslashEscapesInStringLiterals() says which databases read a backslash as an escape (MySQL, MariaDB, ClickHouse, Hive, Impala). Hive and Impala now escape a backslash and a quote of the value; PostgreSQL writes a value with a backslash as an escape string literal, read the same with standard_conforming_strings on or off. MySQL, MariaDB and PostgreSQL read every value back as one literal.

… checked, literals no value can end

The guard resolves each name against the catalog and writes it with its
spelling: a quoted name matches exactly, an unquoted one as the dialect
folds it. Every clause is walked and anything outside the catalog is
refused, also in LIMIT, OFFSET, FETCH, QUALIFY, WINDOW, DISTINCT ON and
behind a set operation, and a common table expression never hides a
catalog table. Expressions are allowed by kind; syntax that calls a
function or operator goes through the whitelist. String literals are
read once and written by the dialect. Casts name plain types only.
Sequences, variables, parameters, database links, table hints, time
travel and sampling are refused, and the size of a statement is limited.
The written text is read again as the database reads it and must hold
what was checked. One guard serves statements from many threads.

The deparser quotes, through the dialect, an alias that is not a plain
identifier and a qualifier that names it. IS DISTINCT FROM, COLLATE,
KEEP, the JSON operators, MATCH ... AGAINST and START WITH / CONNECT BY
are written part by part, so that each name is quoted and each literal
written by the dialect.

The dialects write a string literal that no quote or backslash of its
value can end. MySQL, MariaDB, ClickHouse, Hive and Impala read a
backslash in a string literal as an escape;
LiteralQuoter.backslashEscapesInStringLiterals() says so. Hive and Impala
now escape a backslash and a quote of the value (Impala wrote a quote as
\\', which ends the string). PostgreSQL writes a value with a backslash
as an escape string literal, read the same with
standard_conforming_strings on or off. MySQL, MariaDB and PostgreSQL read
every value back as one literal.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@stbischof
stbischof merged commit 7ddfda5 into eclipse-daanse:main Dec 1, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant