Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Using TableGateway::update() or TableGateway::delete() fails when table has an alias #128

Open
GeeH opened this issue Jun 28, 2016 · 1 comment

Comments

@GeeH
Copy link
Contributor

GeeH commented Jun 28, 2016

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7430
User: @mirfilip
Created On: 2015-04-07T13:57:06Z
Updated At: 2015-11-06T21:16:13Z
Body
This is a continuation of #7311, I should have been more precise with previous bug description for Insert.

For technical background please refer to #7311. I've verified the fix and it was correct for Insert, however, for Update and Delete - the behaviour is still buggy.

As @weierophinney investigated in #7311 Zend\Db\Sql\Sql::prepareStatementForSqlObject() should get unaliased table name from Zend\Db\TableGateway\AbstractTableGateway::executeUpdate()/executeDelete().

Technically, there are two approaches to the problem. While no flavour of SQL allows aliases for insert (at least AFAIK), some platforms do allow aliases in update and delete. It has a different syntax, but it works.
Example for SQL Server:
DELETE U FROM Users AS U WHERE id = 1
or
UPDATE U SET U.Name = 'Any' FROM Users U WHERE U.ID = 1

So, first and easy approach is to pass unaliased table (as done in Insert). Second is to use alternative syntax but it's not platfiorm agnostic (and I believe ZF2 maintains compatibility in DBAL).


@michalbundyra
Copy link
Member

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#120.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants