mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fix bug: In addOrderBy method, _SortColumn will only keep the last one if there are more than 1 multi-word columns
This commit is contained in:
parent
20e486690c
commit
72b6fb49b6
@ -334,10 +334,12 @@ class SQLSelect extends SQLConditionalExpression {
|
|||||||
|
|
||||||
// Move the clause to the select fragment, substituting a placeholder column in the sort fragment.
|
// Move the clause to the select fragment, substituting a placeholder column in the sort fragment.
|
||||||
$clause = trim($clause);
|
$clause = trim($clause);
|
||||||
$column = "_SortColumn{$i}";
|
do {
|
||||||
|
$column = "_SortColumn{$i}";
|
||||||
|
$i++;
|
||||||
|
} while(array_key_exists('"' . $column . '"', $this->orderby));
|
||||||
$this->selectField($clause, $column);
|
$this->selectField($clause, $column);
|
||||||
$clause = '"' . $column . '"';
|
$clause = '"' . $column . '"';
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
$orderby[$clause] = $dir;
|
$orderby[$clause] = $dir;
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,18 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$this->assertTrue($query->canSortBy('Name'));
|
$this->assertTrue($query->canSortBy('Name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test multiple order by SQL clauses.
|
||||||
|
*/
|
||||||
|
public function testAddOrderBy() {
|
||||||
|
$query = new SQLQuery();
|
||||||
|
$query->setSelect('ID', "Title")->setFrom('Page')->addOrderBy('(ID % 2) = 0', 'ASC')->addOrderBy('ID > 50', 'ASC');
|
||||||
|
$this->assertSQLEquals(
|
||||||
|
'SELECT ID, Title, (ID % 2) = 0 AS "_SortColumn0", ID > 50 AS "_SortColumn1" FROM Page ORDER BY "_SortColumn0" ASC, "_SortColumn1" ASC',
|
||||||
|
$query->sql($parameters)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSelectWithChainedFilterParameters() {
|
public function testSelectWithChainedFilterParameters() {
|
||||||
$query = new SQLQuery();
|
$query = new SQLQuery();
|
||||||
$query->setSelect(array("Name","Meta"))->setFrom("MyTable");
|
$query->setSelect(array("Name","Meta"))->setFrom("MyTable");
|
||||||
|
Loading…
Reference in New Issue
Block a user