Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 2dc5433

Browse files
committed
Solve problem with detection of expressions in column if there are additional space chars in it.
1 parent f2d3686 commit 2dc5433

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

library/Zend/Db/Select.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Zend_Db_Select
8181
const SQL_ASC = 'ASC';
8282
const SQL_DESC = 'DESC';
8383

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

8686
/**
8787
* Bind variables for query
@@ -940,7 +940,7 @@ protected function _tableCols($correlationName, $cols, $afterCorrelationName = n
940940
$currentCorrelationName = $correlationName;
941941
if (is_string($col)) {
942942
// Check for a column matching "<column> AS <alias>" and extract the alias name
943-
$col = str_replace("\n",' ',$col);
943+
$col = trim(str_replace("\n",' ',$col));
944944
if (preg_match('/^(.+)\s+' . self::SQL_AS . '\s+(.+)$/i', $col, $m)) {
945945
$col = $m[1];
946946
$alias = $m[2];

tests/Zend/Db/Select/StaticTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,4 +1041,15 @@ public function testAssembleQueryWithRawSubqueryInSelectBlock() {
10411041
'Assembling query with raw subquery with "new line" char failed');
10421042
}
10431043

1044+
public function testAssembleQueryWithExpressionInSelectBlock() {
1045+
$columns[] = ' DISTINCT (*) as expr';
1046+
$select = $this->_db->select();
1047+
$select->from(array('t' => 'table1'), $columns);
1048+
1049+
$expected = 'SELECT DISTINCT (*) AS "expr" FROM "table1" AS "t"';
1050+
1051+
$this->assertEquals($expected, $select->assemble(),
1052+
'Assembling query with raw subquery with "new line" char failed');
1053+
}
1054+
10441055
}

0 commit comments

Comments
 (0)