SQLite reports an unnamed failed CHECK constraint with the expression's
source text exactly as written between the parentheses, whitespace-trimmed:
CHECK(x<5) fails with `CHECK constraint failed: x<5`. Turso re-rendered
the parsed expression, producing `x < 5`. SQLite also dequotes the
captured text, so a constraint whose text starts with a quoted token is
reported by that token alone (`CHECK("x" < +5)` fails with just `x`).
Capture the between-parentheses text in the CHECK AST and carry it through
schema::CheckConstraint to the constraint-failure description. Turso stores
canonically re-rendered SQL in sqlite_schema, unlike SQLite, which stores the
user's text, so both the canonical formatter and schema rebuilding preserve
the captured text inside CHECK(...). Closed block comments remain intact. If
the source contains a line-comment marker, place the generated closing
parenthesis on a new line so the comment cannot swallow it.
Every path that rewrites a CHECK expression in place, including ALTER TABLE
renames of tables and columns, clears the captured text so stale spelling is
never reported or stored. Those paths fall back to pretty-printing, matching
the re-rendered SQL they store.
The PostgreSQL frontend builds these AST nodes from its own AST without Turso
SQL source text and keeps its pretty-printed messages.
Tests: check_constraint.sqltest covers verbatim text, reopen, names, dequoting,
comments, and ALTER TABLE rewrites.
Standalone turso_parser_pg crate wrapping pg_query: parses PostgreSQL
SQL and translates it to the SQLite AST used by the engine.
Co-authored-by: Pekka Enberg <penberg@iki.fi>