Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

TableGateway delete(), insert() and update() raise TypeError for an aliased table

Fermée
#209 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

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
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
php, sql
Domaine
databases

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

bug
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
  1. 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

  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.

Autres issues de php-db/phpdb

Toutes les issues de php-db/phpdb

Issues similaires

Plus d'issues PHP

Recevez les nouvelles issues par e-mail

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