Skip to content

Split Adapter::query() into prepareQuery() and executeQuery() - #172

Merged
simon-mundy merged 6 commits into
php-db:0.6.xfrom
simon-mundy:171-rfc-split-adapter-query
Aug 12, 2026
Merged

Split Adapter::query() into prepareQuery() and executeQuery()#172
simon-mundy merged 6 commits into
php-db:0.6.xfrom
simon-mundy:171-rfc-split-adapter-query

Conversation

@simon-mundy

@simon-mundy simon-mundy commented Aug 11, 2026

Copy link
Copy Markdown
Member

Summary

Implements #171: splits Adapter::query() into two single-purpose methods, deprecating query() as a BC-preserving proxy.

  • prepareQuery(string $sql, ParameterContainer|array $parameters = []): Driver\StatementInterface — always prepares (and binds if parameters are given), never executes.
  • executeQuery(string|Driver\StatementInterface $sql): Driver\ResultInterface — executes raw SQL or a prepared statement and returns a deterministic Driver\ResultInterface. Callers check isQueryResult() and call getQueryResult() themselves if they want a ResultSet.
  • query() is now @deprecated, proxying to the two new methods internally, preserving all prior behavior.
  • AdapterInterface now also declares prepareQuery() and executeQuery(). This supersedes the RFC's original BC-avoidance stance of landing the new methods on Adapter only — external implementors of AdapterInterface will need to add both methods to stay compatible.
  • Added Driver\ResultInterface::getQueryResult(?ResultSetInterface $resultPrototype = null): ResultSetInterface, implemented in Pdo\Result, replacing the clone/initialize logic previously duplicated in Adapter.

Test plan

Added coverage for prepareQuery(), executeQuery(), and getQueryResult(); updated existing query() tests for the new delegated architecture

Adapter::query() conflated preparing a statement and executing SQL
behind a stringly-typed second argument and a three-way union return
type. prepareQuery() always prepares (and binds if parameters are
given) without executing; executeQuery() executes raw SQL or a
prepared statement and returns a deterministic Driver\ResultInterface.

query() is now deprecated and proxies to the two new methods for
backwards compatibility. AdapterInterface is left untouched to avoid
breaking external implementors mid-0.x.

Also adds Driver\ResultInterface::getQueryResult(), which clones and
initializes a ResultSet from a query result, replacing the
clone/initialize logic previously duplicated in Adapter.
@simon-mundy
simon-mundy requested a review from tyrsson August 11, 2026 02:55
@simon-mundy simon-mundy self-assigned this Aug 11, 2026
@simon-mundy simon-mundy added enhancement New feature or request qa Improvements in quality assurance of the project next minor Target next minor release. labels Aug 11, 2026
@github-project-automation github-project-automation Bot moved this to Todo in @phpdb Aug 11, 2026
@simon-mundy simon-mundy added this to the 0.6.0 milestone Aug 11, 2026
The docblock claimed array{0: string, 1: string}, but the first
element is genuinely nullable for table-less selects (e.g. selecting
bare function expressions with no FROM clause), a case already
covered by SelectTest. A newer PHPStan release trusts the inaccurate
annotation and flags the isset() null-check in processSelect() as
dead code; correcting the annotation fixes the false positive without
touching runtime behavior.
Supersedes the RFC's original decision to leave AdapterInterface
untouched for 0.x BC. External implementors will need to add both
methods to remain compatible.
Collapses the mode-detection branching into a single match expression
and a guard-clause early return for the prepare-only case, relying on
the declared parameter type to distinguish array/ParameterContainer
from an invalid string without extra type checks.
The message only needs to flag that the mode string was wrong; it
doesn't need to enumerate the other accepted parameter types.
AdapterInterface declared string|Driver\StatementInterface, putting
the scalar before the object type and diverging from the codebase's
convention (and from Adapter's own implementation signature).

@tyrsson tyrsson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending all test are passing (unit / integration). As long as test are passing local as I know there is issues with action runs prior to the mago migration.

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in @phpdb Aug 12, 2026
@simon-mundy
simon-mundy merged commit 5c561a6 into php-db:0.6.x Aug 12, 2026
16 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in @phpdb Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request next minor Target next minor release. qa Improvements in quality assurance of the project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants