Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
PSDI Army
yii2
Commits
0a5894fc
Commit
0a5894fc
authored
Jul 13, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #4299
parent
4fdfe7a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
8 deletions
+7
-8
QueryBuilder.php
framework/db/mssql/QueryBuilder.php
+7
-8
No files found.
framework/db/mssql/QueryBuilder.php
View file @
0a5894fc
...
...
@@ -135,13 +135,6 @@ class QueryBuilder extends \yii\db\QueryBuilder
$params
=
empty
(
$params
)
?
$query
->
params
:
array_merge
(
$params
,
$query
->
params
);
if
(
empty
(
$query
->
orderBy
)
&&
(
$this
->
hasLimit
(
$query
->
limit
)
||
$this
->
hasOffset
(
$query
->
offset
))
&&
$this
->
isOldMssql
())
{
// hack so LIMIT will work because ROW_NUMBER requires an ORDER BY clause
$orderBy
=
'ORDER BY (SELECT NULL)'
;
}
else
{
$orderBy
=
$this
->
buildOrderBy
(
$query
->
orderBy
);
}
$clauses
=
[
$this
->
buildSelect
(
$query
->
select
,
$params
,
$query
->
distinct
,
$query
->
selectOption
),
$this
->
buildFrom
(
$query
->
from
,
$params
),
...
...
@@ -149,7 +142,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
$this
->
buildWhere
(
$query
->
where
,
$params
),
$this
->
buildGroupBy
(
$query
->
groupBy
),
$this
->
buildHaving
(
$query
->
having
,
$params
),
$
orderBy
,
$
this
->
buildOrderBy
(
$query
->
orderBy
)
,
$this
->
isOldMssql
()
?
''
:
$this
->
buildLimit
(
$query
->
limit
,
$query
->
offset
),
];
...
...
@@ -209,6 +202,12 @@ class QueryBuilder extends \yii\db\QueryBuilder
}
}
$sql
=
str_replace
(
$originalOrdering
,
''
,
$sql
);
if
(
$originalOrdering
===
''
)
{
// hack so LIMIT will work because ROW_NUMBER requires an ORDER BY clause
$originalOrdering
=
'ORDER BY (SELECT NULL)'
;
}
$sql
=
preg_replace
(
'/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i'
,
"
\\
1SELECT
\\
2 rowNum = ROW_NUMBER() over (
{
$originalOrdering
}
),"
,
$sql
);
$sql
=
"SELECT TOP
{
$limit
}
{
$select
}
FROM (
$sql
) sub WHERE rowNum >
{
$offset
}
"
;
return
$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