Skip to content

Render ExpressionInterface check expressions and default the name - #184

Open
simon-mundy wants to merge 2 commits into
php-db:0.6.xfrom
simon-mundy:fix/177-check-constraint-expression
Open

Render ExpressionInterface check expressions and default the name#184
simon-mundy wants to merge 2 commits into
php-db:0.6.xfrom
simon-mundy:fix/177-check-constraint-expression

Conversation

@simon-mundy

@simon-mundy simon-mundy commented Sep 7, 2026

Copy link
Copy Markdown
Member
Q A
Documentation yes
Bugfix yes
BC Break no
New Feature no
RFC no
QA yes
House Keeping no

Check now takes string|ExpressionInterface $expression, ?string $name = null. An ExpressionInterface expression merges its own getExpressionData() into the check — spec CHECK (<inner spec>), values appended — so identifiers and values inside it are quoted by the platform instead of being flattened into a Literal and failing with a TypeError. Renders CHECK (a > '1') and CHECK ("a" > "b"). A plain string stays a Literal; it is an expression slot by design and the docs now say so.

An empty string throws Sql\Exception\InvalidArgumentException at construction, the same exception Expression::setExpression() throws, rather than rendering a bare CONSTRAINT header with no CHECK clause. $name defaults to null in line with PrimaryKey and UniqueKey.

Values are always inlined: DDL extends AbstractSql, not AbstractPreparableSql, and MySQL rejects a parameter marker inside a CHECK anyway (3815).

CheckTest covers the merged expression data, quoted values and identifiers via getSqlString(), % inside an Expression with and without a name, an unnamed check, the column-level inline form ("age" INTEGER NOT NULL CONSTRAINT "chk_age" CHECK (age >= 0)), and the empty-string exception.

Fixes #177

Check documented its expression as string|ExpressionInterface but always
wrapped it in a Literal, so an Expression was accepted at construction
and threw a TypeError at render. An empty string rendered a bare
CONSTRAINT header with no CHECK clause, and the name argument had no
default.

An ExpressionInterface expression now contributes its own specification
and values to the check, so its identifiers and values are quoted by the
platform. A plain string stays a literal SQL fragment by design. An empty
string throws InvalidArgumentException at construction, matching
Expression::setExpression(), and the name defaults to null like
PrimaryKey and UniqueKey.

Fixes php-db#177

Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@simon-mundy simon-mundy self-assigned this Sep 7, 2026
@github-project-automation github-project-automation Bot moved this to Todo in @phpdb Sep 7, 2026
@simon-mundy simon-mundy added this to the 0.6.0 milestone Sep 7, 2026
@simon-mundy simon-mundy added bug Something isn't working enhancement New feature or request qa Improvements in quality assurance of the project labels Sep 7, 2026
CI installs the newest Mago, and 1.47.5 changed how the analyzer handles
nested array shapes: prepareDataHierarchy() re-binds a reference into the
MetadataData shape on every loop iteration, which no longer completes in
useful time. Re-type the reference as a plain array so the shape is not
re-derived per iteration, and adjust the expected findings accordingly.

Regenerate the analyzer baseline for the reworded findings in Select,
PredicateSet, Profiler and AbstractSql (the issues are unchanged, the
messages are not), and reduce the continuation indent of two multi-line
conditions in AbstractTableGateway to match the 1.47.4+ formatter.

Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
@simon-mundy
simon-mundy requested a review from tyrsson September 7, 2026 11:36
@simon-mundy simon-mundy added the documentation Improvements or additions to documentation label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request qa Improvements in quality assurance of the project

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Check constraint: ExpressionInterface expressions throw TypeError, empty expressions render invalid SQL, name argument has no default

1 participant