Repository navigation
guard, deparser, dialect: names as the catalog has them, every clause checked, literals no value can end - #110
Merged
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ONand 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 ... AGAINSTandSTART WITH/CONNECT BYpart 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 withstandard_conforming_stringson or off. MySQL, MariaDB and PostgreSQL read every value back as one literal.