Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Change "new line" char on space char instead of blank char to preserv…
Browse files Browse the repository at this point in the history
…e a very rare case with raw subquery with "new line" chars inside
  • Loading branch information
erdraug committed Oct 13, 2015
1 parent 1396c59 commit d4887a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library/Zend/Db/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ protected function _tableCols($correlationName, $cols, $afterCorrelationName = n
$currentCorrelationName = $correlationName;
if (is_string($col)) {
// Check for a column matching "<column> AS <alias>" and extract the alias name
$col = str_replace("\n",'',$col);
$col = str_replace("\n",' ',$col);
if (preg_match('/^(.+)\s+' . self::SQL_AS . '\s+(.+)$/i', $col, $m)) {
$col = $m[1];
$alias = $m[2];
Expand Down
14 changes: 13 additions & 1 deletion tests/Zend/Db/Select/StaticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,22 @@ public function testAssembleQueryWithSubqueryInSelectBlock() {
$select = $this->_db->select();
$select->from(array('t' => 'table1'), $columns);

$expected = 'SELECT (SELECT "st1"."col1", "st2"."col2" FROM "subTable1" AS "st1" INNER JOIN "subTable2" AS "st2" ON st1.fk_id=st2.fk_id) AS "subInSelect" FROM "table1" AS "t"';
$expected = 'SELECT (SELECT "st1"."col1", "st2"."col2" FROM "subTable1" AS "st1" INNER JOIN "subTable2" AS "st2" ON st1.fk_id=st2.fk_id) AS "subInSelect" FROM "table1" AS "t"';

$this->assertEquals($expected, $select->assemble(),
'Assembling query with subquery with join failed');
}

public function testAssembleQueryWithRawSubqueryInSelectBlock() {
$columns[] = '(SELECT *
FROM tb2) as subInSelect2';
$select = $this->_db->select();
$select->from(array('t' => 'table1'), $columns);

$expected = 'SELECT (SELECT * FROM tb2) AS "subInSelect2" FROM "table1" AS "t"';

$this->assertEquals($expected, $select->assemble(),
'Assembling query with raw subquery with "new line" char failed');
}

}

0 comments on commit d4887a0

Please sign in to comment.