SQLParser
South Ural State University / March 2001
Goals
- Parse arbitrary SQL queries into a structured internal representation so the system could reliably analyze and transform them.
- Support the generation of paginated SQL queries by breaking down the original statement into its logical components.
- Handle a wide range of SQL constructs and dialect variations to ensure pagination could be applied consistently, regardless of query complexity.
- Provide a stable, programmatic interface that allowed other parts of the application to inspect, modify, or regenerate SQL statements as needed.
The SQLParser was implemented in C++ as a standalone component responsible for interpreting SQL queries and converting them into a structured internal representation suitable for downstream processing. At its core, the system used a YACC‑generated grammar to define the syntactic rules of the SQL dialects we needed to support. This grammar, expressed in a BNF‑like notation, captured the structure of statements such as `SELECT`, `INSERT`, `UPDATE`, `DELETE`, joins, expressions, and nested subqueries. A custom lexical analyzer complemented the grammar by tokenizing the raw SQL input stream into keywords, identifiers, operators, literals, and punctuation symbols. Once tokenized and parsed, the system constructed an abstract syntax tree (AST) that represented the logical hierarchy of each SQL statement. This AST served as the canonical form for further analysis, validation, and transformation. As the application requirements evolved, the parser was extended to handle additional SQL constructs, vendor‑specific extensions, and more complex expression patterns, ensuring compatibility with the query shapes produced by the rest of the system. To integrate with the broader application stack, the parser was packaged as a COM/ActiveX component, exposing automation‑friendly interfaces that allowed Visual Basic and other COM‑aware environments to instantiate and interact with it. This approach provided a clean separation between the high‑performance C++ parsing engine and the higher‑level business logic, while maintaining a stable contract for query inspection and manipulation.
Outcomes
- The application could automatically generate paginated SQL queries from any incoming statement, eliminating fragile hand‑written pagination logic in the classic ASP and Visual Basic layers.
- By exposing the parser through COM, the ASP/VB components gained reliable access to a structured representation of SQL statements, improving stability and reducing errors caused by manual string manipulation.
- - Centralizing SQL interpretation in a dedicated C++ parser improved maintainability across the system, ensuring consistent behavior even as query complexity and SQL dialect variations increased.