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
6c9c6cb0
Unverified
Commit
6c9c6cb0
authored
May 20, 2018
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When building a limit query, zero offset without a limit should be ignored
parent
1f91c2d8
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
36 additions
and
26 deletions
+36
-26
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+15
-10
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+5
-10
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+1
-1
SQLServer2012Platform.php
lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php
+1
-1
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+1
-1
AbstractMySQLPlatformTestCase.php
...ne/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
+1
-1
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+10
-0
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+1
-1
SqlitePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
+1
-1
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
6c9c6cb0
...
...
@@ -3394,22 +3394,27 @@ abstract class AbstractPlatform
$limit
=
(
int
)
$limit
;
}
if
(
$offset
!==
null
)
{
$offset
=
(
int
)
$offset
;
$offset
=
(
int
)
$offset
;
if
(
$offset
<
0
)
{
throw
new
DBALException
(
"LIMIT argument offset=
$offset
is not valid"
);
}
if
(
$offset
>
0
&&
!
$this
->
supportsLimitOffset
())
{
throw
new
DBALException
(
sprintf
(
"Platform %s does not support offset values in limit queries."
,
$this
->
getName
()));
}
if
(
$offset
<
0
)
{
throw
new
DBALException
(
sprintf
(
'Offset must be a positive integer of zero, %d given'
,
$offset
));
}
if
(
$offset
>
0
&&
!
$this
->
supportsLimitOffset
())
{
throw
new
DBALException
(
sprintf
(
'Platform %s does not support offset values in limit queries.'
,
$this
->
getName
()
));
}
return
$this
->
doModifyLimitQuery
(
$query
,
$limit
,
$offset
);
}
/**
* Adds an
driver
-specific LIMIT clause to the query.
* Adds an
platform
-specific LIMIT clause to the query.
*
* @param string $query
* @param int|null $limit
...
...
@@ -3423,7 +3428,7 @@ abstract class AbstractPlatform
$query
.=
' LIMIT '
.
$limit
;
}
if
(
$offset
!==
null
)
{
if
(
$offset
>
0
)
{
$query
.=
' OFFSET '
.
$offset
;
}
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
6c9c6cb0
...
...
@@ -63,23 +63,18 @@ class MySqlPlatform extends AbstractPlatform
const
LENGTH_LIMIT_MEDIUMBLOB
=
16777215
;
/**
* Adds MySQL-specific LIMIT clause to the query
* 18446744073709551615 is 2^64-1 maximum of unsigned BIGINT the biggest limit possible
*
* @param string $query
* @param int $limit
* @param int $offset
*
* @return string
* {@inheritDoc}
*/
protected
function
doModifyLimitQuery
(
$query
,
$limit
,
$offset
)
{
if
(
$limit
!==
null
)
{
$query
.=
' LIMIT '
.
$limit
;
if
(
$offset
!==
null
)
{
if
(
$offset
>
0
)
{
$query
.=
' OFFSET '
.
$offset
;
}
}
elseif
(
$offset
!==
null
)
{
}
elseif
(
$offset
>
0
)
{
// 2^64-1 is the maximum of unsigned BIGINT, the biggest limit possible
$query
.=
' LIMIT 18446744073709551615 OFFSET '
.
$offset
;
}
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
6c9c6cb0
...
...
@@ -987,7 +987,7 @@ END;';
*/
protected
function
doModifyLimitQuery
(
$query
,
$limit
,
$offset
=
null
)
{
if
(
$limit
===
null
&&
$offset
===
null
)
{
if
(
$limit
===
null
&&
$offset
<=
0
)
{
return
$query
;
}
...
...
lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php
View file @
6c9c6cb0
...
...
@@ -113,7 +113,7 @@ class SQLServer2012Platform extends SQLServer2008Platform
*/
protected
function
doModifyLimitQuery
(
$query
,
$limit
,
$offset
=
null
)
{
if
(
$limit
===
null
&&
$offset
===
null
)
{
if
(
$limit
===
null
&&
$offset
<=
0
)
{
return
$query
;
}
...
...
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
6c9c6cb0
...
...
@@ -719,7 +719,7 @@ class SqlitePlatform extends AbstractPlatform
*/
protected
function
doModifyLimitQuery
(
$query
,
$limit
,
$offset
)
{
if
(
null
===
$limit
&&
null
!==
$offset
)
{
if
(
$limit
===
null
&&
$offset
>
0
)
{
return
$query
.
' LIMIT -1 OFFSET '
.
$offset
;
}
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
View file @
6c9c6cb0
...
...
@@ -179,7 +179,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
public
function
testModifyLimitQuery
()
{
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user'
,
10
,
0
);
self
::
assertEquals
(
'SELECT * FROM user LIMIT 10
OFFSET 0
'
,
$sql
);
self
::
assertEquals
(
'SELECT * FROM user LIMIT 10'
,
$sql
);
}
public
function
testModifyLimitQueryWithEmptyOffset
()
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
6c9c6cb0
...
...
@@ -1480,4 +1480,14 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this
->
_platform
->
escapeStringForLike
(
'_25% off_ your next purchase \o/'
,
'\\'
)
);
}
public
function
testZeroOffsetWithoutLimitIsIgnored
()
:
void
{
$query
=
'SELECT * FROM user'
;
self
::
assertSame
(
$query
,
$this
->
_platform
->
modifyLimitQuery
(
$query
,
null
,
0
)
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
6c9c6cb0
...
...
@@ -296,7 +296,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
public
function
testModifyLimitQuery
()
{
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user'
,
10
,
0
);
self
::
assertEquals
(
'SELECT * FROM user LIMIT 10
OFFSET 0
'
,
$sql
);
self
::
assertEquals
(
'SELECT * FROM user LIMIT 10'
,
$sql
);
}
public
function
testModifyLimitQueryWithEmptyOffset
()
...
...
tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
View file @
6c9c6cb0
...
...
@@ -280,7 +280,7 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
public
function
testModifyLimitQuery
()
{
$sql
=
$this
->
_platform
->
modifyLimitQuery
(
'SELECT * FROM user'
,
10
,
0
);
self
::
assertEquals
(
'SELECT * FROM user LIMIT 10
OFFSET 0
'
,
$sql
);
self
::
assertEquals
(
'SELECT * FROM user LIMIT 10'
,
$sql
);
}
public
function
testModifyLimitQueryWithEmptyOffset
()
...
...
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