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

Commit

Permalink
Solve problem with detection of expressions in column if there are ad…
Browse files Browse the repository at this point in the history
…ditional space chars in it.
  • Loading branch information
erdraug committed Nov 18, 2015
1 parent f2d3686 commit 2dc5433
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/Zend/Db/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Zend_Db_Select
const SQL_ASC = 'ASC';
const SQL_DESC = 'DESC';

const REGEX_COLUMN_EXPR = '/^([\w]*\(([^\(\)]|(?1))*\))$/';
const REGEX_COLUMN_EXPR = '/^([\w]*\s*\(([^\(\)]|(?1))*\))$/';

/**
* Bind variables for query
Expand Down 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 = trim(str_replace("\n",' ',$col));
if (preg_match('/^(.+)\s+' . self::SQL_AS . '\s+(.+)$/i', $col, $m)) {
$col = $m[1];
$alias = $m[2];
Expand Down
11 changes: 11 additions & 0 deletions tests/Zend/Db/Select/StaticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,4 +1041,15 @@ public function testAssembleQueryWithRawSubqueryInSelectBlock() {
'Assembling query with raw subquery with "new line" char failed');
}

public function testAssembleQueryWithExpressionInSelectBlock() {
$columns[] = ' DISTINCT (*) as expr';
$select = $this->_db->select();
$select->from(array('t' => 'table1'), $columns);

$expected = 'SELECT DISTINCT (*) AS "expr" FROM "table1" AS "t"';

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

}

0 comments on commit 2dc5433

Please sign in to comment.