php / php/php-src

PDO::FETCH_COLUMN | PDO::FETCH_GROUP with column parameter behavior

Đang mở
#20,215 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Extension: pdo (core) Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với việc tái hiện trong php-docs/pdo/fetch-modes/column/group.phpt và so sánh kết quả của nó với ví dụ 3v4l. Đọc tài liệu về PDOStatement::fetchAll() và kiểm tra phần triển khai fetch của PDO cùng các bài kiểm thử hiện có cho FETCH_COLUMN và FETCH_GROUP. Công việc được xem là hoàn tất khi hành vi dự kiến của cột và việc nhóm đã được thống nhất, được bao phủ bằng một bài kiểm thử hồi quy và được ghi tài liệu nhất quán.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
php
Lĩnh vực
databases
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.