Skip to content
Permalink
Browse files

Ensure that fields in orderAsc/orderDesc are quoted.

String fields should be quoted when used with orderDesc/orderAsc.
  • Loading branch information...
markstory committed Aug 8, 2015
1 parent f65eddd commit 80908ec77831ce09965859fa143b2131e4bc921a
Showing with 17 additions and 7 deletions.
  1. +4 −7 src/Database/Expression/OrderClauseExpression.php
  2. +13 −0 tests/TestCase/Database/QueryTest.php
@@ -15,21 +15,18 @@
namespace Cake\Database\Expression;
use Cake\Database\ExpressionInterface;
use Cake\Database\Expression\FieldInterface;
use Cake\Database\Expression\FieldTrait;
use Cake\Database\ValueBinder;
/**
* An expression object for complex ORDER BY clauses
*
* @internal
*/
class OrderClauseExpression implements ExpressionInterface
class OrderClauseExpression implements ExpressionInterface, FieldInterface
{
/**
* The field being sorted on.
*
* @var \Cake\Database\ExpressionInterface|string
*/
protected $_field;
use FieldTrait;
/**
* The direction of sorting.
@@ -1504,13 +1504,20 @@ public function testSelectOrderAsc()
$query->select(['id'])
->from('articles')
->orderAsc('id');
$sql = $query->sql();
$result = $query->execute()->fetchAll('assoc');
$expected = [
['id' => 1],
['id' => 2],
['id' => 3],
];
$this->assertEquals($expected, $result);
$this->assertQuotedQuery(
'SELECT <id> FROM <articles> ORDER BY <id> ASC',
$sql,
!$this->autoQuote
);
$query = new Query($this->connection);
$query->select(['id'])
@@ -1537,13 +1544,19 @@ public function testSelectOrderDesc()
$query->select(['id'])
->from('articles')
->orderDesc('id');
$sql = $query->sql();
$result = $query->execute()->fetchAll('assoc');
$expected = [
['id' => 3],
['id' => 2],
['id' => 1],
];
$this->assertEquals($expected, $result);
$this->assertQuotedQuery(
'SELECT <id> FROM <articles> ORDER BY <id> DESC',
$sql,
!$this->autoQuote
);
$query = new Query($this->connection);
$query->select(['id'])

0 comments on commit 80908ec

Please sign in to comment.
You can’t perform that action at this time.