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
842bbb91
Commit
842bbb91
authored
Jun 29, 2016
by
stchr
Committed by
Marco Pivetta
Jul 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Modify Limit Query with newline before ORDER BY
parent
69b57859
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
SQLServer2012Platform.php
lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php
+7
-1
SQLServer2012PlatformTest.php
...ctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php
+8
-0
No files found.
lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php
View file @
842bbb91
...
...
@@ -115,7 +115,13 @@ class SQLServer2012Platform extends SQLServer2008Platform
// Queries using OFFSET... FETCH MUST have an ORDER BY clause
// Find the position of the last instance of ORDER BY and ensure it is not within a parenthetical statement
$orderByPos
=
strripos
(
$query
,
" ORDER BY "
);
// but can be in a newline
$matches
=
array
();
$matchesCount
=
preg_match_all
(
"/[
\\
s]+order by /i"
,
$query
,
$matches
,
PREG_OFFSET_CAPTURE
);
$orderByPos
=
false
;
if
(
$matchesCount
>
0
)
{
$orderByPos
=
$matches
[
0
][(
$matchesCount
-
1
)][
1
];
}
if
(
$orderByPos
===
false
||
substr_count
(
$query
,
"("
,
$orderByPos
)
-
substr_count
(
$query
,
")"
,
$orderByPos
)
...
...
tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php
View file @
842bbb91
...
...
@@ -363,4 +363,12 @@ class SQLServer2012PlatformTest extends AbstractSQLServerPlatformTestCase
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
$querySql
,
10
);
$this
->
assertEquals
(
$expectedSql
,
$sql
);
}
public
function
testModifyLimitQueryWithNewlineBeforeOrderBy
()
{
$querySql
=
"SELECT * FROM test
\n
ORDER BY col DESC"
;
$expectedSql
=
"SELECT * FROM test
\n
ORDER BY col DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"
;
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
$querySql
,
10
);
$this
->
assertEquals
(
$expectedSql
,
$sql
);
}
}
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