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

Oracle incorrect SELECT FROM decoration with table alias when using nested selects #5794

Merged
merged 1 commit into from
Apr 16, 2014
Merged

Oracle incorrect SELECT FROM decoration with table alias when using nested selects #5794

merged 1 commit into from
Apr 16, 2014

Conversation

ralphschindler
Copy link
Member

Using the Oracle adapter, creating a SELECT query with more than 1 nested sub-select, like this:

$sql = new \Zend\Db\Sql\Sql($adapter);

$select = $sql->select()
    ->from('test');

$select = $sql->select()
    ->from(array('a' => $select));

$select = $sql->select()
    ->from(array('b' => $select));

$sql->prepareStatementForSqlObject($select);

results in the following SQL:

SELECT "b".* FROM (SELECT "a".* FROM (SELECT "test".* FROM "test") AS "a") "b"

The expected SQL for Oracle is:

SELECT "b".* FROM (SELECT "a".* FROM (SELECT "test".* FROM "test") "a") "b"

Oracle only allows the use of AS for aliasing columns - not tables.

This bug is similar to #4069.

@samsonasik
Copy link
Contributor

@KGrey PR #4070 is merged, so it can be closed? if yes, please close it.

@ghost
Copy link
Author

ghost commented Apr 14, 2014

@samsonasik #4070 does not resolve the issue where more than 1 nested sub-select is concerned.

@ralphschindler
Copy link
Member

I think #5392 might fix your issue with nested sub-selects, which is in the latest version of ZF2 (2.3.1), could you try that?

@ghost
Copy link
Author

ghost commented Apr 16, 2014

@ralphschindler Have just updated to 2.3.1 and still seeing the same output.

@ralphschindler
Copy link
Member

I have a fix for this, I"ll turn this issue into a PR and have someone merge it today.

@ralphschindler
Copy link
Member

Actually- my tests show your example above works in 2.3.1, but does not work for the method getSqlString(). I can push a fix for the getSqlString fix, but prepareStatementForSqlObject() should actually already be producing your output expected above.

- Fixed AbstractSql's processSubSelect to use decorators when calling getSqlString()
@ghost
Copy link
Author

ghost commented Apr 16, 2014

@ralphschindler Yes, my testing this morning was using getSqlString(). I probably should have mentioned that!

@ralphschindler ralphschindler self-assigned this Apr 16, 2014
@ralphschindler ralphschindler added this to the 2.3.2 milestone Apr 16, 2014
@ezimuel ezimuel merged commit 82820ed into zendframework:master Apr 16, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants