Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Integer limit, offset and column values raise TypeError in getSqlString() on a strict platform

未關閉
#205 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@simon-mundy 已經在處理了。

開始於 2026年10月5日。

  • #222 來自 @simon-mundy —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
php, sql
領域
database

研究方向

Start with the named call sites in src/Sql/Select.php and src/Sql/AbstractSql.php, then read test/unit/TestAsset/TrustingSql92Platform.php and the existing unit tests that exercise these paths. Check how the expression path handles values before quoting. Done means integer and boolean values are safely quoted and the strict test platform catches non-string arguments; the unit suite passes.

由索引模型根據 Issue 內容生成。

描述

bug
Package Version

0.6.x-dev @ e022af5c

Php Version

8.3, 8.4, 8.5

Database Engine

Any platform whose quoteValue() keeps the string type: Sql92, MySQL, SQLite and PostgreSQL (PDO::quote())

Basic Information

PlatformInterface::quoteValue() takes a string (PlatformInterface.php#L68). Three call sites in strict-typed files pass values that can be integers or booleans:

  • Select::processLimit() passes $this->limit (Select.php#L522), typed string|int|null.
  • Select::processOffset() passes $this->offset (Select.php#L540).
  • AbstractSql::resolveColumnValue() passes $column (AbstractSql.php#L445), which can be int or bool. Insert and Update values go through it.

The expression path in the same class already casts: quoteValue((string) $argument->getValue()) (AbstractSql.php#L242).

The unit suite does not catch this because TrustingSql92Platform::quoteValue($value) drops the string type (TrustingSql92Platform.php#L16), so it accepts integers.

Prepared statements are unaffected: those paths bind the value instead of quoting it. The MySQL and SQLite driver SelectDecorators render limit and offset without quoting, so only their non-decorated paths are affected.

Steps to Reproduce
  1. (new Select('t'))->limit(10)->getSqlString($platform) with the MySQL or SQLite driver's AdapterPlatform, or with PostgreSQL's (which has no SelectDecorator).
  2. (new Insert('t'))->values(['c' => 1]) rendered with buildSqlString() on the SQLite AdapterPlatform.
Expected Behavior

Scalars are cast to string before quoting, as the expression path already does: LIMIT '10' and VALUES ('1').

TrustingSql92Platform::quoteValue() should keep the string type, so the suite fails if a call site passes a non-string again. With that change alone, 6 existing tests error.

Actual behavior?
TypeError: PhpDb\Adapter\Platform\Sql92::quoteValue(): Argument #1 ($value) must be of type string, int given, called in src/Sql/Select.php on line 522

On phpdb-pgsql:

TypeError: PDO::quote(): Argument #1 ($string) must be of type string, int given
Additional Info

The same cast was made on the unmerged sql-platform-refactor branch (a0b63fa4, "Fixed small issue where limit/offset were not cast as strings").

主要語言
PHP
星號
18
分支
8
平均合併
6 天 11 小時
30 天內合併 PR
14

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

php-db/phpdb 的其他 Issue

查看 php-db/phpdb 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。