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
9c97fe11
Commit
9c97fe11
authored
Jan 24, 2014
by
Anatoliy Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue #1659: released buildLimitOffset() for MSSQL
parent
4fe0eeb1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
4 deletions
+77
-4
QueryBuilder.php
framework/db/mssql/QueryBuilder.php
+16
-4
MssqlQueryBuilderTest.php
tests/unit/framework/db/mssql/MssqlQueryBuilderTest.php
+61
-0
No files found.
framework/db/mssql/QueryBuilder.php
View file @
9c97fe11
...
...
@@ -49,10 +49,22 @@ class QueryBuilder extends \yii\db\QueryBuilder
// return '';
// }
// public function buildLimit($limit, $offset)
// {
// return '';
// }
/**
* @param integer $limit
* @param integer $offset
* @return string the LIMIT and OFFSET clauses built from [[query]].
*/
public
function
buildLimit
(
$limit
,
$offset
=
0
)
{
$sql
=
''
;
if
(
$offset
!==
null
&&
$offset
>=
0
)
{
$sql
=
'OFFSET '
.
(
int
)
$offset
.
' ROWS'
;
if
(
$limit
!==
null
&&
$limit
>=
0
)
{
$sql
.=
' FETCH NEXT '
.
(
int
)
$limit
.
' ROWS ONLY'
;
}
}
return
$sql
;
}
// public function resetSequence($table, $value = null)
// {
...
...
tests/unit/framework/db/mssql/MssqlQueryBuilderTest.php
0 → 100644
View file @
9c97fe11
<?php
namespace
yiiunit\framework\db\mssql
;
use
yiiunit\framework\db\QueryBuilderTest
;
use
yii\db\Query
;
/**
* @group db
* @group mssql
*/
class
MSSQLQueryBuilderTest
extends
QueryBuilderTest
{
public
$driverName
=
'sqlsrv'
;
public
function
testOffsetLimit
()
{
$expectedQuerySql
=
'SELECT `id` FROM `exapmle` OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY'
;
$expectedQueryParams
=
null
;
$query
=
new
Query
();
$query
->
select
(
'id'
)
->
from
(
'example'
)
->
limit
(
10
)
->
offset
(
5
);
list
(
$actualQuerySql
,
$actualQueryParams
)
=
$this
->
getQueryBuilder
()
->
build
(
$query
);
$this
->
assertEquals
(
$expectedQuerySql
,
$actualQuerySql
);
$this
->
assertEquals
(
$expectedQueryParams
,
$actualQueryParams
);
}
public
function
testLimit
()
{
$expectedQuerySql
=
'SELECT `id` FROM `exapmle` OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'
;
$expectedQueryParams
=
null
;
$query
=
new
Query
();
$query
->
select
(
'id'
)
->
from
(
'example'
)
->
limit
(
10
);
list
(
$actualQuerySql
,
$actualQueryParams
)
=
$this
->
getQueryBuilder
()
->
build
(
$query
);
$this
->
assertEquals
(
$expectedQuerySql
,
$actualQuerySql
);
$this
->
assertEquals
(
$expectedQueryParams
,
$actualQueryParams
);
}
public
function
testOffset
()
{
$expectedQuerySql
=
'SELECT `id` FROM `exapmle` OFFSET 10 ROWS'
;
$expectedQueryParams
=
null
;
$query
=
new
Query
();
$query
->
select
(
'id'
)
->
from
(
'example'
)
->
offset
(
10
);
list
(
$actualQuerySql
,
$actualQueryParams
)
=
$this
->
getQueryBuilder
()
->
build
(
$query
);
$this
->
assertEquals
(
$expectedQuerySql
,
$actualQuerySql
);
$this
->
assertEquals
(
$expectedQueryParams
,
$actualQueryParams
);
}
}
\ No newline at end of file
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