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
b9a3b087
Commit
b9a3b087
authored
Sep 15, 2016
by
Sergei Morozov
Committed by
Steve Müller
Jan 16, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Oracle platform ignores OFFSET in case if LIMIT is not specified
parent
3a351369
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
13 deletions
+31
-13
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+18
-13
ModifyLimitQueryTest.php
...s/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php
+1
-0
OraclePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
+12
-0
No files found.
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
b9a3b087
...
...
@@ -974,24 +974,29 @@ LEFT JOIN user_cons_columns r_cols
*/
protected
function
doModifyLimitQuery
(
$query
,
$limit
,
$offset
=
null
)
{
$limit
=
(
int
)
$limit
;
$offset
=
(
int
)
$offset
;
if
(
$limit
===
null
&&
$offset
===
null
)
{
return
$query
;
}
if
(
preg_match
(
'/^\s*SELECT/i'
,
$query
))
{
if
(
!
preg_match
(
'/\sFROM\s/i'
,
$query
))
{
$query
.=
" FROM dual"
;
}
if
(
$limit
>
0
)
{
$max
=
$offset
+
$limit
;
$column
=
'*'
;
$columns
=
array
(
'a.*'
)
;
if
(
$offset
>
0
)
{
$min
=
$offset
+
1
;
$query
=
'SELECT * FROM (SELECT a.'
.
$column
.
', rownum AS doctrine_rownum FROM ('
.
$query
.
') a WHERE rownum <= '
.
$max
.
') WHERE doctrine_rownum >= '
.
$min
;
}
else
{
$query
=
'SELECT a.'
.
$column
.
' FROM ('
.
$query
.
') a WHERE ROWNUM <= '
.
$max
;
$columns
[]
=
'ROWNUM AS doctrine_rownum'
;
}
$query
=
sprintf
(
'SELECT %s FROM (%s) a'
,
implode
(
', '
,
$columns
),
$query
);
if
(
$limit
!==
null
)
{
$query
.=
sprintf
(
' WHERE ROWNUM <= %d'
,
$offset
+
$limit
);
}
if
(
$offset
>
0
)
{
$query
=
sprintf
(
'SELECT * FROM (%s) WHERE doctrine_rownum >= %d'
,
$query
,
$offset
+
1
);
}
}
...
...
tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php
View file @
b9a3b087
...
...
@@ -44,6 +44,7 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
assertLimitResult
(
array
(
1
,
2
,
3
,
4
),
$sql
,
10
,
0
);
$this
->
assertLimitResult
(
array
(
1
,
2
),
$sql
,
2
,
0
);
$this
->
assertLimitResult
(
array
(
3
,
4
),
$sql
,
2
,
2
);
$this
->
assertLimitResult
(
array
(
2
,
3
,
4
),
$sql
,
null
,
1
);
}
public
function
testModifyLimitQueryJoinQuery
()
...
...
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
View file @
b9a3b087
...
...
@@ -265,6 +265,18 @@ class OraclePlatformTest extends AbstractPlatformTestCase
$this
->
assertEquals
(
'SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10'
,
$sql
);
}
public
function
testModifyLimitQueryWithNonEmptyOffset
()
{
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user'
,
10
,
10
);
$this
->
assertEquals
(
'SELECT * FROM (SELECT a.*, ROWNUM AS doctrine_rownum FROM (SELECT * FROM user) a WHERE ROWNUM <= 20) WHERE doctrine_rownum >= 11'
,
$sql
);
}
public
function
testModifyLimitQueryWithEmptyLimit
()
{
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user'
,
null
,
10
);
$this
->
assertEquals
(
'SELECT * FROM (SELECT a.*, ROWNUM AS doctrine_rownum FROM (SELECT * FROM user) a) WHERE doctrine_rownum >= 11'
,
$sql
);
}
public
function
testModifyLimitQueryWithAscOrderBy
()
{
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user ORDER BY username ASC'
,
10
);
...
...
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