mini\Parsing\SQL\SqlParser class

Documentation

SQL Parser - Recursive Descent Implementation

Features:

  • Generates an AST (Abstract Syntax Tree)
  • Supports SELECT, INSERT, UPDATE, DELETE
  • Supports WHERE, ORDER BY, LIMIT
  • Supports IN (LIST) and IN (SELECT ...) recursively
  • Supports Function Calls (e.g. COUNT(*), MAX(col))
  • Supports dotted identifiers (table.column)
  • Supports Placeholders (? and :name)
  • Supports Negative Numbers (-5)
  • Rich Error Reporting (Line numbers + Visual pointers)

Constants (3)

Name Value
CACHE_MAX_SIZE 256
COMPARISON_OPS array ( 0 => '=', 1 => '!=', 2 => '<>', 3 => '<', 4 => '<=', 5 => '>', 6 => '>=', )
JOIN_TYPE_TOKENS array ( 0 => 'JOIN', 1 => 'LEFT', 2 => 'RIGHT', 3 => 'INNER', 4 => 'FULL', 5 => 'CROSS', )

Properties (4)

private string $sql
private array $tokens
private int $pos
private static array $astCache

Methods (56)

Parse SQL string into AST

Parse a SQL expression fragment into AST

Parse an ORDER BY clause fragment into AST

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Parse a query that may start with WITH or SELECT, and may include UNION/INTERSECT/EXCEPT

Parse WITH statement body (CTEs + main query) without EOF validation

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Parse WITH statement at top level (with EOF validation)

Parse a single CTE definition: name [(columns)] AS (query)

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Parse a derived table: (SELECT ...) in FROM position

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Parse a number or placeholder (for LIMIT/OFFSET/FETCH)

Documentation missing

Parse OVER (PARTITION BY ... ORDER BY ...) clause

Parse CASE expression

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Parse SQL and bind parameters, returning the AST

Parse SQL with caching - returns AST from cache (possibly shared)

Clear the AST cache (for testing or memory management)

Parse CREATE statement (TABLE, INDEX, VIEW)

Parse CREATE TABLE statement

Parse column definition

Parse a single column constraint

Parse default value expression

Parse table-level constraint

Parse (col1, col2, ...) list for constraints

Parse referential action (CASCADE, RESTRICT, SET NULL, etc.)

Parse CREATE INDEX statement

Parse DROP statement (TABLE, INDEX)

Parse DROP TABLE statement

Parse DROP INDEX statement

Expect a specific keyword (may be token or identifier)

Expect an identifier token and return its name

Bind parameter values to PlaceholderNodes in an AST

Source

src/Parsing/SQL/SqlParser.php:50-1877