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

Commit

Permalink
Merge branch 'hotfix/3641'
Browse files Browse the repository at this point in the history
Close #3641
Fixes #3629
  • Loading branch information
weierophinney committed Feb 5, 2013
2 parents 585a1eb + ec3caff commit 0d37980
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/Zend/Db/Sql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,12 @@ protected function processSelect(PlatformInterface $platform, DriverInterface $d
$jColumns[] = $jColumnParts->getSql();
} else {
$name = (is_array($join['name'])) ? key($join['name']) : $name = $join['name'];
$jColumns[] = $platform->quoteIdentifier($name) . $separator . $platform->quoteIdentifierInFragment($jColumn);
if ($name instanceof TableIdentifier) {
$name = $platform->quoteIdentifier($name->getSchema()) . $separator . $platform->quoteIdentifier($name->getTable());
} else {
$name = $platform->quoteIdentifier($name);
}
$jColumns[] = $name . $separator . $platform->quoteIdentifierInFragment($jColumn);
}
if (is_string($jKey)) {
$jColumns[] = $platform->quoteIdentifier($jKey);
Expand All @@ -631,6 +636,8 @@ protected function processJoins(PlatformInterface $platform, DriverInterface $dr
$joinSpecArgArray = array();
foreach ($this->joins as $j => $join) {
$joinSpecArgArray[$j] = array();
$joinName = null;
$joinAs = null;

// type
$joinSpecArgArray[$j][] = strtoupper($join['type']);
Expand Down
19 changes: 19 additions & 0 deletions tests/ZendTest/Db/Sql/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,24 @@ public function providerData()
'processJoins' => array(array(array('INNER', '(SELECT "bar".* FROM "bar" WHERE "y" LIKE ?) AS "z"', '"z"."foo" = "bar"."id"')))
);

// @link https://github.com/zendframework/zf2/issues/3294
// Test TableIdentifier In Joins, with multiple joins
$select40 = new Select;
$select40->from('foo')
->join(array('a' => new TableIdentifier('another_foo', 'another_schema')), 'a.x = foo.foo_column')
->join('bar', 'foo.colx = bar.colx');
$sqlPrep40 = // same
$sqlStr40 = 'SELECT "foo".*, "a".*, "bar".* FROM "foo"'
. ' INNER JOIN "another_schema"."another_foo" AS "a" ON "a"."x" = "foo"."foo_column"'
. ' INNER JOIN "bar" ON "foo"."colx" = "bar"."colx"';
$internalTests40 = array(
'processSelect' => array(array(array('"foo".*'), array('"a".*'), array('"bar".*')), '"foo"'),
'processJoins' => array(array(
array('INNER', '"another_schema"."another_foo" AS "a"', '"a"."x" = "foo"."foo_column"'),
array('INNER', '"bar"', '"foo"."colx" = "bar"."colx"')
))
);

/**
* $select = the select object
* $sqlPrep = the sql as a result of preparation
Expand Down Expand Up @@ -1011,6 +1029,7 @@ public function providerData()
array($select37, $sqlPrep37, array(), $sqlStr37, $internalTests37),
array($select38, $sqlPrep38, array(), $sqlStr38, $internalTests38),
array($select39, $sqlPrep39, array(), $sqlStr39, $internalTests39),
array($select40, $sqlPrep40, array(), $sqlStr40, $internalTests40),
);
}
}

0 comments on commit 0d37980

Please sign in to comment.