Define the real wpdb query contract - #41
Draft
alexstandiford wants to merge 6 commits into
Draft
alexstandiford wants to merge 6 commits into
alexstandiford wants to merge 6 commits into
Conversation
alexstandiford
force-pushed
the
codex/real-wpdb-query-contract-tests
branch
2 times, most recently
from
September 20, 2026 16:53
d56e364 to
a43199e
Compare
alexstandiford
force-pushed
the
codex/real-wpdb-query-contract-tests
branch
from
September 20, 2026 17:06
a43199e to
7df38e0
Compare
alexstandiford
force-pushed
the
codex/real-wpdb-query-contract-tests
branch
from
September 20, 2026 17:24
d803c3f to
21b25c4
Compare
alexstandiford
force-pushed
the
codex/real-wpdb-query-contract-tests
branch
from
September 20, 2026 17:25
21b25c4 to
111135d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contract
The WordPress query adapter must preserve scalar, null, range, list, tuple, and grouped predicate meaning through real WordPress wpdb preparation. Invalid fields, operators, arity, and group logic must raise QueryBuilderException without changing builder state.
QueryStrategy must translate builder failures and wpdb SQL failures to DatastoreErrorException. It must preserve the builder exception as the cause when one exists. A genuine empty result remains RecordNotFoundException.
Compound insert, update, and delete must preserve full identities. Placeholder-like and subquery-marker text must remain data.
Architecture
This PR adds a separate integration bootstrap that loads official WordPress core from WORDPRESS_ROOT and connects to real MySQL through wpdb. The fixture uses connection-local TEMPORARY tables. It does not install WordPress, mock wpdb, or touch a persistent table.
The public surface already exists, so this packet adds no production signatures. The implementation keeps protected generatePlaceholder as the per-condition right-hand-side template seam. Every non-null value uses %s, null values render as SQL NULL, and each complete condition is prepared exactly once before it is stored. Build only concatenates prepared fragments.
Protected addCondition normalizes non-null logic to AND or OR before changing builder state. Invalid logic, invalid operators, invalid tuple widths, and preparation failures leave existing state unchanged.
Implementation
The implementation restores the condition placeholder seam without marker substitution or a printf parser. It flattens non-null scalar and tuple values in placeholder order, prepares one condition once through wpdb, and stores the prepared condition. The implementation also removes the old PHP-type placeholder selection that rounded floats and coerced values used against VARCHAR columns.
The existing CanGetDataFormats trait remains attached so subclasses retain inherited protected getFieldSprintfType and getFormats methods. Assertions introduced in the architecture commits are unchanged. Existing implementation-added unit expectations were updated only to reflect quoted non-null values returned by real wpdb preparation.
Verification
Unit suite:
Result: 74 tests, 124 assertions, no failures or errors.
Required real wpdb suite:
Result: 59 tests, 106 assertions, no failures, errors, or skips.
Full dependency comparison matrix:
Result: 439 of 439 cases passed with WordPress 6.8.3, MySQL 8.0.45, the merged database and MySQL repair trees, and this branch.
Separate-process reflection comparison against released main bce8152 found identical public and protected ClauseBuilder method sets, including trait-provided methods. The focused ClauseBuilder unit suite remains green at 4 tests and 6 assertions, and the required real wpdb suite remains green after the compatibility correction.
Target-file PHP CS Fixer dry runs report no changes for ClauseBuilder.php and ClauseBuilderTest.php. GitHub CI runs the PHP 8.3 unit suite on push.
The defect evidence is recorded in Retrospective audit: PHPNomad database consumer compatibility (Source 9959).