Skip to content

Render aliased tables in data-changing statements as the bare table - #225

Merged
simon-mundy merged 5 commits into
php-db:0.6.xfrom
simon-mundy:fix/209-aliased-dml-tables
Oct 9, 2026
Merged

simon-mundy merged 5 commits into
php-db:0.6.xfrom
simon-mundy:fix/209-aliased-dml-tables

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Fixes #209.

TableGateway::delete(), insert() and update() raised a TypeError for an aliased table. Sql passed the aliased array to the Delete, Insert and Update constructors, which only accepted string|TableIdentifier|null, and rendering an aliased array failed in AbstractSql::resolveTable().

Changes

  • The Delete, Insert and Update constructors accept an aliased table array, as their from(), into() and table() setters already do.
  • The new AbstractPreparableSql::unaliasTable() returns the bare table, and data-changing statements render it without the alias, since alias syntax in INSERT, UPDATE and DELETE is not portable. getRawState('table') still returns the array, so TableGateway's swap-and-restore keeps working.
  • A TableGateway test drives delete(), insert() and update() through a real Sql and Adapter and checks the SQL that reaches the driver. DeleteTest, InsertTest, UpdateTest and SqlTest cover the aliased forms.

Breaking changes

None.

mago format, mago lint, mago analyze and the unit tests pass.

TableGateway keeps an aliased table array on Delete, Update and Insert,
but its delete(), insert() and update() raised a TypeError: Sql passed
the array to constructors that only accepted string|TableIdentifier,
and rendering an array failed in resolveTable(). The constructors now
accept the array the setters already took, and rendering drops the
alias, since alias syntax in these statements is not portable.

A TableGateway test drives each call through a real Sql and Adapter
and checks the SQL that reaches the driver.

Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
@simon-mundy simon-mundy added documentation Improvements or additions to documentation qa Improvements in quality assurance of the project Lang Feature Refactor Refactoring to new language features labels Oct 5, 2026
@simon-mundy simon-mundy added this to the 0.6.0 milestone Oct 5, 2026
@simon-mundy simon-mundy self-assigned this Oct 5, 2026
@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…dml-tables

# Conflicts:
#	analyzer-baseline.toml
@simon-mundy
simon-mundy requested a review from tyrsson October 6, 2026 02:22
@simon-mundy
simon-mundy merged commit ee34eae into php-db:0.6.x Oct 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Lang Feature Refactor Refactoring to new language features qa Improvements in quality assurance of the project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

2 participants