Skip to main content

validate_read_only

Function validate_read_only 

Source
pub fn validate_read_only(
    sql: &str,
    dialect: &impl Dialect,
) -> Result<StatementKind, SqlError>
Expand description

Validates that a SQL query is read-only and classifies it for pagination.

Parses the query using the given dialect and checks:

  1. Exactly one statement (multi-statement injection blocked)
  2. Statement type is read-only (SELECT, SHOW, DESCRIBE, USE, EXPLAIN)
  3. The statement wrapped by EXPLAIN is itself read-only
  4. No data-modifying CTEs or SELECT ... INTO inside queries
  5. No dangerous functions (file access, large objects, sequences, extensions)
  6. No INTO OUTFILE/DUMPFILE clauses

Returns the classified StatementKind on success so callers that paginate can dispatch Select to a subquery-wrapped fetch and route NonSelect through a single-page pass-through.

ยงErrors

Returns SqlError if the query is not allowed in read-only mode.