PDO::FETCH_COLUMN | PDO::FETCH_GROUP with column parameter behavior
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
I believe the current code behavior of FETCH_COLUMN | FETCH_GROUP when specifying the column parameter is non-sensical. I believe it was not originally designed to work this way.
(And does not match the current documentation ... but that seems to be part of the story to how it got broken - see timeline below)
To see what I'm talking about, please refer to https://github.com/AllenJB/sandbox/blob/main/php-docs/pdo/fetch-modes/column/group.phpt (3v4l version: https://3v4l.org/2f7aV )
When you use FETCH_COLUMN, you can specify the additional column parameter to fetchAll() to tell PDO which column to retrieve values from. However, when you combine it with FETCH_GROUP, the column number is used for the grouping key and the values returned are always the first column.
This does not match my personal expected behavior, especially given that the column parameter can only be used with the COLUMN fetch mode - no other fetch mode allows you to influence how GROUP works in this way.
It also does not match the current documentation for PDOStatement::fetchAll()
You can see from the 3v4l link above that COLUMN | GROUP works as I expected in PHP <5.2.6.
I could find no tests in php-src for the combination of COLUMN | GROUP and specifying the column parameter.
The following is a timeline I put together for this:
2005-08-31: PDOStatement::fetchAll docs updated to include FETCH_GROUP, but the behavior described does not match the then actual behavior
2008-05-01: PHP 5.2.6 changes the behavior to somewhat match the docs (I believe the bug that triggered this is https://bugs.php.net/bug.php?id=44362 ) (if you read it one way, but this just ends up confusing because if you read it this way to column parameter has 2 different purposes at the same time)
2024-10-06: PDOStatement::fetchAll docs changed to describe the original < 5.2.6 behavior
PHP Version
8.4.13
Operating System
n/a
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 php-docs/pdo/fetch-modes/column/group.phpt 中的复现开始,并将其输出与 3v4l 示例进行比较。阅读 PDOStatement::fetchAll() 文档,并检查 PDO 的 fetch 实现以及 FETCH_COLUMN 和 FETCH_GROUP 的现有测试。完成的标准是:列和分组的预期行为已达成一致、由回归测试覆盖,并且文档保持一致。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- databases
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100