Skip to content

Comments

Add SQLite multi-query parser#48

Merged
JanTvrdik merged 3 commits intomainfrom
sqlite-multi-query-parser
Feb 24, 2026
Merged

Add SQLite multi-query parser#48
JanTvrdik merged 3 commits intomainfrom
sqlite-multi-query-parser

Conversation

@JanTvrdik
Copy link
Member

Summary

  • Add SqliteMultiQueryParser supporting all SQLite-specific SQL dialect features: three identifier quoting styles (double quotes, backticks, brackets), single-quoted strings with doubled-quote escaping, and non-nesting block comments
  • Handle BEGIN...END compound statements (for CREATE TRIGGER) while correctly treating BEGIN TRANSACTION/DEFERRED/IMMEDIATE/EXCLUSIVE and bare BEGIN; as simple statements
  • Include 62-query test data file and comprehensive test case covering edge cases, chunk boundary safety, and all identifier styles

Test plan

  • composer run phpstan passes with no errors
  • composer run tests passes all 72 tests including exhaustive two-chunk combinations and randomized chunking

Implement SqliteMultiQueryParser with support for all three SQLite
identifier quoting styles (double quotes, backticks, brackets),
single-quoted strings with doubled-quote escaping, non-nesting block
comments, and BEGIN...END compound statements for CREATE TRIGGER
while correctly treating BEGIN TRANSACTION as a simple statement.
Copilot AI review requested due to automatic review settings February 24, 2026 08:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a new SqliteMultiQueryParser class to parse SQLite SQL scripts that may contain multiple queries. The implementation correctly handles SQLite's dialect features including three identifier quoting styles (double quotes, backticks, and brackets), single-quoted strings with escaped quotes using doubled characters, non-nesting block comments, and compound BEGIN...END statements for triggers.

Changes:

  • Added SqliteMultiQueryParser class with comprehensive regex patterns for parsing SQLite-specific SQL syntax
  • Included test data file with 62 diverse queries covering tables, views, triggers, and various identifier quoting styles
  • Comprehensive test suite with 247 lines covering edge cases, chunk boundary safety, and randomized chunking scenarios

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/SqliteMultiQueryParser.php New parser implementation extending BaseMultiQueryParser with SQLite-specific regex patterns for handling identifiers, strings, comments, and BEGIN...END blocks
tests/cases/SqliteMultiQueryParserTest.phpt Comprehensive test suite with 72 tests covering superfluous semicolons, edge cases (identifiers, strings, comments, BEGIN variants), and chunk boundary scenarios
tests/data/sqlite.sql Test data file with 62 queries including CREATE TABLE/VIEW/TRIGGER/INDEX statements, PRAGMA, INSERT, DELETE, and SELECT queries demonstrating all SQLite identifier quoting styles and edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Factor out inner construct bodies (sqI, dqI, btI, bkI, bcI) and
reusable sub-patterns (skip, stmt, lc) into a DEFINE block, replacing
the $simpleQuery string concatenation hack with a single self-contained
pattern. (*PRUNE) remains inline at the call sites because PCRE confines
backtracking verbs to subroutine scope.
@JanTvrdik JanTvrdik merged commit c14813e into main Feb 24, 2026
12 checks passed
@JanTvrdik JanTvrdik deleted the sqlite-multi-query-parser branch February 24, 2026 08:54
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