Skip to content
Snippets Groups Projects
Commit 0fd91ff6 authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Markus Klein
Browse files

[FEATURE] Extbase: Add between() operator to Query object

Support for ``between`` has been added to the Extbase Query object.
As there is no performance advantage to using BETWEEN on the DBMS
side (the query optimizers converts it to `min <= expr AND expr <= max)`
this method replicates the DBMS behaviour by building a logical AND
condition that has the advantage of working on all DBMS.

Resolves: #47812
Releases: master
Change-Id: Ic3b416515eedc651faf69de1db21eab288a8ad33
Reviewed-on: http://review.typo3.org/42813


Reviewed-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: default avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: default avatarMarkus Klein <markus.klein@typo3.org>
parent 4bdc929b
Branches
Tags
No related merge requests found
=================================================
Feature: #47812 - Query support for BETWEEN added
=================================================
Description
===========
Support for ``between`` has been added to the Extbase ``Query`` object. As there is no performance
advantage to using BETWEEN on the DBMS side (the optimizer converts it to ``(min <= expr AND expr <= max)``
this function replicates the DBMS behaviour by building a logical AND condition that has the advantage
of working on all DBMS.
Example:
.. code-block:: php
$query->matching(
$query->between('uid', 3, 5)
);
......@@ -552,6 +552,23 @@ class Query implements QueryInterface {
return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand);
}
/**
* Returns a greater than or equal criterion used for matching objects against a query
*
* @param string $propertyName The name of the property to compare against
* @param $operandLower The value of the lower boundary to compare against
* @param $operandUpper The value of the upper boundary to compare against
* @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException
* @api
*/
public function between($propertyName, $operandLower, $operandUpper) {
return $this->logicalAnd(
$this->greaterThanOrEqual($propertyName, $operandLower),
$this->lessThanOrEqual($propertyName, $operandUpper)
);
}
/**
* @return void
*/
......
......@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
class OperatorTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
......@@ -87,4 +88,22 @@ class OperatorTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
$this->assertSame(2, $query->count());
}
/**
* @test
*/
public function betweenSetsBoundariesCorrectly() {
$query = $this->postRepository->createQuery();
$query->setOrderings(array('uid' => QueryInterface::ORDER_ASCENDING));
$query->matching(
$query->between('uid', 3, 5)
);
$result = array_map(
function($row) { return $row['uid']; },
$query->execute(TRUE)
);
$this->assertEquals(array(3,4,5), $result);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment