php / php/php-src

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

Ouverte
#20,215 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Bug Extension: pdo (core) Status: Needs Triage
Langage dominant
C
Étoiles
40.4k
Forks
8.2k
Merge moyen
2 j 13 h
PR mergées (30 j)
96

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la reproduction dans php-docs/pdo/fetch-modes/column/group.phpt et comparez sa sortie avec l’exemple 3v4l. Lisez la documentation de PDOStatement::fetchAll() et examinez l’implémentation de fetch de PDO ainsi que les tests existants pour FETCH_COLUMN et FETCH_GROUP. Le travail est terminé lorsque le comportement attendu des colonnes et du groupement est défini d’un commun accord, couvert par un test de régression et documenté de manière cohérente.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
php
Domaine
databases
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.