Skip to content

Commit

Permalink
Optimize Row Limiting Clause in Oracle Database 12c doctrine#2649
Browse files Browse the repository at this point in the history
  • Loading branch information
stchr authored and stchr committed Feb 8, 2017
1 parent e001419 commit 84cf3d8
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/Doctrine/DBAL/Platforms/Oracle12c1Platform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\DBAL\Platforms;

/**
* Oracle12c1Platform.
*/
class Oracle12c1Platform extends OraclePlatform
{

/**
* {@inheritDoc}
*/
protected function doModifyLimitQuery($query, $limit, $offset = null)
{
if ($limit === null) {
return $query;
}
$limit = (int)$limit;
$offset = (int)$offset;

if (preg_match('/^\s*SELECT/i', $query)) {
if (!preg_match('/\sFROM\s/i', $query)) {
$query .= ' FROM dual';
}
if ($limit > 0) {
$query .= ' OFFSET ' . $offset . ' ROWS FETCH NEXT ' . $limit . ' ROWS ONLY';
}
}

return $query;
}
}

0 comments on commit 84cf3d8

Please sign in to comment.