The Game Panel specification

ADR-0017: SQL is produced by a compiler, not by the query objects

Context

Every object in the query and schema builders produces its own SQL, per RFC-0003. Thirty-two classes each write their own, interpolating names straight into the string and returning their bound values separately.

Two consequences follow from that shape rather than from any one class. Names are written unquoted in some places and quoted in others, because each class decides for itself. And an insert computes its column list once for its SQL and again for its bound values, so the two can disagree and bind values to the wrong columns.

Fixing either one class by class means fixing it thirty-two times and trusting whoever writes the thirty-third.

Decision

SQL is produced by a compiler rather than by the objects being compiled. A query or schema object is a node describing what is wanted, and a compiler resolved by node class turns it into SQL. Compilation returns the SQL and its bound values together, produced by the same pass, and every name written into SQL goes through one identifier value object that quotes and escapes it.

Alternatives

An identifier value object alone. Quoting was originally to be fixed by introducing that object and using it throughout. The object survives as part of this decision, but on its own it leaves thirty-two classes each choosing whether to use it, and does nothing about SQL and bound values being produced separately.

Retrofitting quoting across the self-compiling classes, then dismantling it once a compiler arrived anyway.

Consequences

Easier:

Harder:

Constrained:

Sources