Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
9b5042c1
Commit
9b5042c1
authored
Mar 13, 2015
by
Alex Pott
Browse files
Issue
#2443657
by daffie, bzrudi71: PostgreSQL: Fix system\Tests\Entity\EntityQueryTest
parent
8d87a928
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/Database/Driver/pgsql/Select.php
View file @
9b5042c1
...
...
@@ -52,11 +52,15 @@ public function orderRandom() {
* directly in SelectQuery::orderBy().
*/
public
function
orderBy
(
$field
,
$direction
=
'ASC'
)
{
// Call parent function to order on this.
$return
=
parent
::
orderBy
(
$field
,
$direction
);
// Only allow ASC and DESC, default to ASC.
// Emulate MySQL default behavior to sort NULL values first for ascending,
// and last for descending.
// @see http://www.postgresql.org/docs/9.3/static/queries-order.html
$direction
=
strtoupper
(
$direction
)
==
'DESC'
?
'DESC NULLS LAST'
:
'ASC NULLS FIRST'
;
$this
->
order
[
$field
]
=
$direction
;
if
(
$this
->
hasTag
(
'entity_query'
))
{
return
$
return
;
return
$
this
;
}
// If there is a table alias specified, split it up.
...
...
@@ -68,14 +72,14 @@ public function orderBy($field, $direction = 'ASC') {
if
(
!
empty
(
$table
))
{
// If table alias is given, check if field and table exists.
if
(
$existing_field
[
'table'
]
==
$table
&&
$existing_field
[
'field'
]
==
$table_field
)
{
return
$
return
;
return
$
this
;
}
}
else
{
// If there is no table, simply check if the field exists as a field or
// an aliased field.
if
(
$existing_field
[
'alias'
]
==
$field
)
{
return
$
return
;
return
$
this
;
}
}
}
...
...
@@ -83,7 +87,7 @@ public function orderBy($field, $direction = 'ASC') {
// Also check expression aliases.
foreach
(
$this
->
expressions
as
$expression
)
{
if
(
$expression
[
'alias'
]
==
$this
->
connection
->
escapeAlias
(
$field
))
{
return
$
return
;
return
$
this
;
}
}
...
...
@@ -93,7 +97,7 @@ public function orderBy($field, $direction = 'ASC') {
// actually belongs to a different table, it must be added manually.
foreach
(
$this
->
tables
as
$table
)
{
if
(
!
empty
(
$table
[
'all_fields'
]))
{
return
$
return
;
return
$
this
;
}
}
...
...
@@ -101,12 +105,12 @@ public function orderBy($field, $direction = 'ASC') {
// it is considered an expression, these can't be handled automatically
// either.
if
(
$this
->
connection
->
escapeField
(
$field
)
!=
$field
)
{
return
$
return
;
return
$
this
;
}
// This is a case that can be handled automatically, add the field.
$this
->
addField
(
NULL
,
$field
);
return
$
return
;
return
$
this
;
}
/**
...
...
core/modules/system/src/Tests/Database/SelectComplexTest.php
View file @
9b5042c1
...
...
@@ -7,7 +7,8 @@
namespace
Drupal\system\Tests\Database
;
use
\
Drupal\Core\Database\RowCountException
;
use
Drupal\Core\Database\Database
;
use
Drupal\Core\Database\RowCountException
;
/**
* Tests the Select query builder with more complex queries.
...
...
@@ -220,7 +221,10 @@ function testCountQueryRemovals() {
// Check that the ordering clause is handled properly.
$orderby
=
$query
->
getOrderBy
();
$this
->
assertEqual
(
$orderby
[
'name'
],
'ASC'
,
'Query correctly sets ordering clause.'
);
// The orderby string is different for PostgreSQL.
// @see Drupal\Core\Database\Driver\pgsql\Select::orderBy()
$db_type
=
Database
::
getConnection
()
->
databaseType
();
$this
->
assertEqual
(
$orderby
[
'name'
],
(
$db_type
==
'pgsql'
?
'ASC NULLS FIRST'
:
'ASC'
),
'Query correctly sets ordering clause.'
);
$orderby
=
$count
->
getOrderBy
();
$this
->
assertFalse
(
isset
(
$orderby
[
'name'
]),
'Count query correctly unsets ordering caluse.'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment