TableGateway delete(), insert() and update() raise TypeError for an aliased table
Les mainteneurs répondent en général sous 2 jours
Une pull request liée a déjà été fusionnée.
- #225 par @simon-mundy — fusionnée
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 30/100
Piste de recherche
Start with TableGateway's delete(), insert(), and update() methods, then compare them with executeDelete(), executeInsert(), and executeUpdate() in AbstractTableGateway.php. Read the referenced Sql.php and Delete.php, Insert.php, and Update.php constructors and setters; the existing gateway alias tests mock Sql and miss this path. Add coverage using an aliased TableGateway and verify the generated data-changing statements target the bare table; also check the open linked pull request before starting.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Package Version
0.6.x-dev @ e022af5c
Php Version
8.3, 8.4, 8.5
Database Engine
Any
Basic Information
TableGateway supports an aliased table (['u' => 'users'] or ['u' => new TableIdentifier(...)]). Its executeDelete(), executeInsert() and executeUpdate() swap in the bare table before rendering, then restore the array, because most databases reject aliases in INSERT, UPDATE and DELETE (AbstractTableGateway.php#L276-L292; laminas zf2#7311, PR #342).
That swap is never reached through the gateway's own methods. delete(), insert() and update() call Sql::delete() / insert() / update() (Sql.php#L49, #L78, #L124). Those pass the aliased array to the Delete, Insert and Update constructors, which accept only string|TableIdentifier|null (Delete.php#L48, Insert.php#L54, Update.php#L70). Their setters from(), into() and table() do accept arrays.
Rendering a statement that holds an aliased array also raises a TypeError, since AbstractSql::resolveTable() takes no arrays.
The constructors were narrowed in 4807d3c9 ("Strong typing and rector improvements"). The gateway's alias tests mock Sql, so they do not exercise this path.
Steps to Reproduce
new TableGateway(['u' => 'users'], $adapter), then->delete(['id' => 5]),->insert(['id' => 5])or->update(['n' => 'x'], ['id' => 5]).
Expected Behavior
DELETE FROM "users" WHERE "id" = ? and the equivalent INSERT and UPDATE against the bare table, matching what executeDelete() and friends intend. select() keeps the alias.
Actual behavior?
TypeError: PhpDb\Sql\Delete::__construct(): Argument #1 ($table) must be of type PhpDb\Sql\TableIdentifier|string|null, array given
Additional Info
The unmerged sql-platform-refactor branch removes the gateway's unaliasing and renders aliases in data-changing statements (b4180743). That is the opposite of the expected behaviour above, and it would need reconciling if revived.
- Langage dominant
- PHP
- Étoiles
- 18
- Forks
- 8
- Merge moyen
- 2 j 14 h
- PR mergées (30 j)
- 26
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Aucun modèle de pull request
- Aucun guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de php-db/phpdb
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 2 jours
-
RFC
Difficulté 3/5 1-2 jours Accessibilité débutants 66/100
Les mainteneurs répondent en général sous 2 jours
-
RFC
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
Les mainteneurs répondent en général sous 2 jours
-
RFC
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 2 jours
-
RFC
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de php-db/phpdb
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
components-web-app/api-components-bundle#403 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
mollie/PrestaShop#1566 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
components-web-app/docs#193 ·
-
Python 3.15 supportPeut-être pris @amnesiaof l’a pris aujourd’hui. OuverteL: python L: python:uv
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
dependabot/dependabot-core#16524 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
crazy-goat/rabbit-stream#830 ·
Les mainteneurs répondent en général sous 1 jour