Overview of CG/SQL and the CQL Compiler
CG/SQL is a code generation system for SQLite that enables developers to write stored procedures using a variant of Transact-SQL (T-SQL). These procedures are compiled into C code that interacts with SQLite's C API.
Key components include:
- CQL Compiler: The core engine that reads schemas and procedures. It provides a strongly typed language that catches hundreds of potential runtime SQL issues at compile time, such as data type inconsistencies (e.g., assigning nullable columns to non-nullable variables).
- Generated C Code: Automatically handles return code checks and ensures correct column ordinals and types during data binding and reading.
- Schema Management: Uses schema annotations to automatically generate stored procedures for upgrading databases between versions.
- Testing & Analysis: Supports the creation of unit test code and the generation of query plans at compile time via procedure annotations.