Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
9902f9b7
Commit
9902f9b7
authored
Apr 23, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix order by with aggregate function(s) for limit/offset queries on SQL Server
parent
d3322550
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
3 deletions
+34
-3
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+5
-3
AbstractSQLServerPlatformTestCase.php
...ests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
+29
-0
No files found.
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
9902f9b7
...
...
@@ -1149,7 +1149,10 @@ class SQLServerPlatform extends AbstractPlatform
$start
=
$offset
+
1
;
$end
=
$offset
+
$limit
;
$orderBy
=
stristr
(
$query
,
'ORDER BY'
);
$query
=
preg_replace
(
'/\s+ORDER\s+BY\s+([^\)]*)/i'
,
''
,
$query
);
//Remove ORDER BY from $query
//Remove ORDER BY from $query (including nested parentheses in order by list).
$query
=
preg_replace
(
'/\s+ORDER\s+BY\s+([^()]+|\((?:(?:(?>[^()]+)|(?R))*)\))+/i'
,
''
,
$query
);
$format
=
'SELECT * FROM (%s) AS doctrine_tbl WHERE doctrine_rownum BETWEEN %d AND %d'
;
// Pattern to match "main" SELECT ... FROM clause (including nested parentheses in select list).
...
...
@@ -1168,7 +1171,7 @@ class SQLServerPlatform extends AbstractPlatform
}
//Clear ORDER BY
$orderBy
=
preg_replace
(
'/ORDER\s+BY\s+(
[^\)]*)(
.*)/i'
,
'$1'
,
$orderBy
);
$orderBy
=
preg_replace
(
'/ORDER\s+BY\s+(.*)/i'
,
'$1'
,
$orderBy
);
$orderByParts
=
explode
(
','
,
$orderBy
);
$orderbyColumns
=
array
();
...
...
@@ -1190,7 +1193,6 @@ class SQLServerPlatform extends AbstractPlatform
//Find alias for each colum used in ORDER BY
if
(
!
empty
(
$orderbyColumns
))
{
foreach
(
$orderbyColumns
as
$column
)
{
$pattern
=
sprintf
(
'/%s\.%s\s+(?:AS\s+)?([^,\s)]+)/i'
,
$column
[
'table'
],
$column
[
'column'
]);
if
(
$isWrapped
)
{
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
View file @
9902f9b7
...
...
@@ -330,6 +330,35 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
);
}
/**
* @group DBAL-834
*/
public
function
testModifyLimitQueryWithAggregateFunctionInOrderByClause
()
{
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
"SELECT "
.
"MAX(heading_id) aliased, "
.
"code "
.
"FROM operator_model_operator "
.
"GROUP BY code "
.
"ORDER BY MAX(heading_id) DESC"
,
1
,
0
);
$this
->
assertEquals
(
"SELECT * FROM ("
.
"SELECT "
.
"MAX(heading_id) aliased, "
.
"code, "
.
"ROW_NUMBER() OVER (ORDER BY MAX(heading_id) DESC) AS doctrine_rownum "
.
"FROM operator_model_operator "
.
"GROUP BY code"
.
") AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 1"
,
$sql
);
}
/**
* @group DDC-1360
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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