Skip to content

State each platform's value quoting, and render limit and offset as integers - #259

Open
tyrsson wants to merge 1 commit into
rfc/256-statement-factoryfrom
rfc/256-platform-value-quoting
Open

tyrsson wants to merge 1 commit into
rfc/256-statement-factoryfrom
rfc/256-platform-value-quoting

Conversation

@tyrsson

@tyrsson tyrsson commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Makes value quoting a decision each platform states, and stops quoting limit and offset.

  • AbstractPlatform no longer declares quoteValue(). The base carried no driver property, only a @property claim, and the method's guard tested for a driver object rather than for a driver that can quote. PlatformInterface already requires the method, so every platform now states its own policy: the drivers ask their driver, Sql92 throws.
  • Select::processLimit() and processOffset() render the bare integer instead of passing it through quoteValue().

Why the limit change is not cosmetic: a limit is a non-negative integer, not a value. LIMIT '10' is accepted by MySQL, PostgreSQL and SQLite only because they coerce an unknown literal, and rejected by SQL Server's OFFSET n ROWS and Oracle's OFFSET/FETCH, which take an integer constant or a bind parameter. The prepared path already binds these as ParameterContainer::TYPE_INTEGER, so the unprepared path was the only place they were treated as strings. The defect is old and recorded: zendframework/zendframework#6221, where ralphschindler noted LIMIT '1' is invalid on some servers.

Why the guard removal matters: with no driver, quoteValue() fell back to dialect-agnostic backslash escaping rather than refusing. A platform with an idle connection hits exactly that path, so an untrusted value silently received the weaker treatment. Rendering a statement that carries values against a connection that is not open now throws instead.

Depends on #258, which is where the statement factory and the Sql92 @internal tag landed. The three driver packages follow in referencing pull requests.

Existing drivers (mysql, pgsql, sqlite) pass their suites apart from the sqlite fixes tracked in phpdb-sqlite#45.

Tracked in #260.

…ntegers

AbstractPlatform no longer declares quoteValue(), so the base carries no driver concept and
cannot pretend a driver may be absent. PlatformInterface already requires the method, so every
platform states its own policy: the three drivers ask their driver, Sql92 states that it cannot
quote and throws.

That also removes the guard's real defect. quoteValue() fell back to dialect-agnostic backslash
escaping whenever the driver could not answer, which is what happens before a connection is
opened, so an untrusted value silently received the weaker treatment.

Select rendered limit and offset through quoteValue(), producing LIMIT '10'. A limit is a
non-negative integer, not a value: MySQL, PostgreSQL and SQLite accept the quoted form only by
coercing an unknown literal, while SQL Server's OFFSET and Oracle's OFFSET and FETCH take an
integer constant or bind parameter and reject a string. The prepared path already binds them as
integers, so the unprepared path now renders the same integer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant