Skip to main content

Module sql

Module sql 

Source
Expand description

Statement analysis: the layer that decides whether a statement may be sent.

§The order is the whole design

  1. strip blanks comments, text literals and quoted identifiers. Every textual comparison in this layer runs over that output and never over the raw statement.
  2. parse reads the text into a syntax tree, inside a size ceiling and on a stack it owns, because the parser feature that guards recursion was switched off to keep the build free of a C toolchain.
  3. classify decides from that tree what the statement does, never from its first word.
  4. guard applies the structural refusals over the tree, falling back to the blanked text only where the tree cannot carry the answer.

A statement whose shape is not recognised is refused. It is never treated as a read, because that is the guess that lets a change through.

§The defects this replaces

Both reference implementations decide by prefix over raw text. That produces failures in both directions, and every one of them has a test here:

  • A legitimate query carrying a reserved word inside a literal is refused.
  • A statement whose first word is moved by a comment escapes the decision.
  • A text ending in a separator escapes the single-command refusal, so SELECT 1; SELECT 2; is admitted.

§The other two members

ident quotes an object name that introspection pastes into a statement, because a name cannot travel as a parameter. rewrite imposes this tool’s own row ceiling on a caller’s query without wrapping it in a derived table, which is what breaks an unnamed or a repeated column name.

Re-exports§

pub use classify::analyze;
pub use classify::classify;
pub use classify::Analysis;
pub use classify::Classification;
pub use guard::admit;
pub use guard::Admission;
pub use ident::quote;
pub use ident::quote_qualified;
pub use parse::parse;
pub use parse::ParseLimits;
pub use rewrite::with_limit;
pub use strip::strip;
pub use strip::Stripped;

Modules§

classify
Classification of a statement by its syntax tree.
guard
Structural refusals applied to a statement before it is sent.
ident
Safe quoting of an object name.
parse
Reading a statement into a syntax tree, inside bounds this module owns.
rewrite
Imposition of this tool’s own row ceiling on a caller’s query.
strip
Blanking of comments, text literals and quoted identifiers.