Skip to content

Commit

Permalink
ZF2-514 Fixed fatal error when using expression in columns part of a …
Browse files Browse the repository at this point in the history
…join, Added unit test, fixed typo's in unit test
  • Loading branch information
Koen Pieters committed Sep 3, 2012
1 parent 3a4cee6 commit ca24ad1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion library/Zend/Db/Sql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ protected function processSelect(PlatformInterface $platform, Adapter $adapter =
$adapter,
$this->processInfo['paramPrefix'] . ((is_string($jKey)) ? $jKey : 'column')
);
$parameterContainer->merge($jColumnParts->getParameterContainer());
if ($parameterContainer) {
$parameterContainer->merge($jColumnParts->getParameterContainer());
}
$jColumns[] = $jColumnParts->getSql();
} else {
$name = (is_array($join['name'])) ? key($join['name']) : $name = $join['name'];
Expand Down
15 changes: 13 additions & 2 deletions tests/ZendTest/Db/Sql/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function testOrder()
}

/**
* @testdox unit test: Test join() returns same Select object (is chainable)
* @testdox unit test: Test having() returns same Select object (is chainable)
* @covers Zend\Db\Sql\Select::having
*/
public function testHaving()
Expand All @@ -275,7 +275,7 @@ public function testGetRawStateViaHaving(Select $select)
}

/**
* @testdox unit test: Test join() returns same Select object (is chainable)
* @testdox unit test: Test group() returns same Select object (is chainable)
* @covers Zend\Db\Sql\Select::group
*/
public function testGroup()
Expand Down Expand Up @@ -746,6 +746,16 @@ public function providerData()
'processOrder' => array(array(array('isnull("name") DESC'), array('"name"', Select::ORDER_ASCENDING)))
);

// join with expression in COLUMNS part (ZF2-514)
$select35 = new Select;
$select35->from('foo')->join('zac', 'm = n', array('bar' => new Expression("IF(foo.id = 1, NULL, foo.bar)")));
$sqlPrep35 = // same
$sqlStr35 = 'SELECT "foo".*, IF(foo.id = 1, NULL, foo.bar) AS "bar" FROM "foo" INNER JOIN "zac" ON "m" = "n"';
$internalTests35 = array(
'processSelect' => array(array(array('"foo".*'), array('IF(foo.id = 1, NULL, foo.bar)', '"bar"')), '"foo"'),
'processJoins' => array(array(array('INNER', '"zac"', '"m" = "n"')))
);

/**
* $select = the select object
* $sqlPrep = the sql as a result of preparation
Expand Down Expand Up @@ -790,6 +800,7 @@ public function providerData()
array($select32, $sqlPrep32, array(), $sqlStr32, $internalTests32),
array($select33, $sqlPrep33, array(), $sqlStr33, $internalTests33),
array($select34, $sqlPrep34, array(), $sqlStr34, $internalTests34),
array($select35, $sqlPrep35, array(), $sqlStr35, $internalTests35),
);
}

Expand Down

0 comments on commit ca24ad1

Please sign in to comment.