Commit 5601e988 authored by alexpott's avatar alexpott

Issue #2686483 by stBorchert, daffie: Add support for database condition operator "NOT BETWEEN"

parent 9cae5235
......@@ -300,6 +300,7 @@ protected function mapConditionOperator($operator) {
// $specials does not use drupal_static as its value never changes.
static $specials = array(
'BETWEEN' => array('delimiter' => ' AND '),
'NOT BETWEEN' => array('delimiter' => ' AND '),
'IN' => array('delimiter' => ', ', 'prefix' => ' (', 'postfix' => ')'),
'NOT IN' => array('delimiter' => ', ', 'prefix' => ' (', 'postfix' => ')'),
'EXISTS' => array('prefix' => ' (', 'postfix' => ')'),
......
......@@ -136,7 +136,8 @@ protected function _testBetween() {
$view->initHandlers();
$view->filter[$field]->operator = 'not between';
$view->filter[$field]->value['min'] = '2001-01-01';
$view->filter[$field]->value['max'] = '2002-01-01';
// Set maximum date to date of node 1 to test range borders.
$view->filter[$field]->value['max'] = '2001-10-10T12:12:12';
$view->setDisplay('default');
$this->executeView($view);
$expected_result = [
......
......@@ -28,7 +28,7 @@ protected function opBetween($field) {
$this->query->addHavingExpression($this->options['group'], "$field <= $placeholder_max", array($placeholder_max => $this->value['max']));
}
else {
$this->query->addHavingExpression($this->options['group'], "$field <= $placeholder_min OR $field >= $placeholder_max", array($placeholder_min => $this->value['min'], $placeholder_max => $this->value['max']));
$this->query->addHavingExpression($this->options['group'], "$field < $placeholder_min OR $field > $placeholder_max", array($placeholder_min => $this->value['min'], $placeholder_max => $this->value['max']));
}
}
......
......@@ -248,7 +248,7 @@ protected function opBetween($field) {
$this->query->addWhere($this->options['group'], $field, array($this->value['min'], $this->value['max']), 'BETWEEN');
}
else {
$this->query->addWhere($this->options['group'], db_or()->condition($field, $this->value['min'], '<=')->condition($field, $this->value['max'], '>='));
$this->query->addWhere($this->options['group'], $field, array($this->value['min'], $this->value['max']), 'NOT BETWEEN');
}
}
......
......@@ -88,8 +88,8 @@ protected function _testBetween() {
// Test between with min and max.
$view->initHandlers();
$view->filter['created']->operator = 'between';
$view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:s');
$view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
$view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:i:s');
$view->filter['created']->value['max'] = format_date(200000, 'custom', 'Y-m-d H:i:s');
$view->executeDisplay('default');
$expected_result = array(
array('nid' => $this->nodes[1]->id()),
......@@ -100,7 +100,7 @@ protected function _testBetween() {
// Test between with just max.
$view->initHandlers();
$view->filter['created']->operator = 'between';
$view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
$view->filter['created']->value['max'] = format_date(200000, 'custom', 'Y-m-d H:i:s');
$view->executeDisplay('default');
$expected_result = array(
array('nid' => $this->nodes[0]->id()),
......@@ -112,11 +112,11 @@ protected function _testBetween() {
// Test not between with min and max.
$view->initHandlers();
$view->filter['created']->operator = 'not between';
$view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:s');
$view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
$view->filter['created']->value['min'] = format_date(100000, 'custom', 'Y-m-d H:i:s');
$view->filter['created']->value['max'] = format_date(200000, 'custom', 'Y-m-d H:i:s');
$view->executeDisplay('default');
$expected_result = array(
array('nid' => $this->nodes[0]->id()),
array('nid' => $this->nodes[2]->id()),
array('nid' => $this->nodes[3]->id()),
);
......@@ -126,10 +126,9 @@ protected function _testBetween() {
// Test not between with just max.
$view->initHandlers();
$view->filter['created']->operator = 'not between';
$view->filter['created']->value['max'] = format_date(150000, 'custom', 'Y-m-d H:s');
$view->filter['created']->value['max'] = format_date(200000, 'custom', 'Y-m-d H:i:s');
$view->executeDisplay('default');
$expected_result = array(
array('nid' => $this->nodes[1]->id()),
array('nid' => $this->nodes[2]->id()),
array('nid' => $this->nodes[3]->id()),
);
......
......@@ -148,10 +148,6 @@ public function testFilterNumericBetween() {
'name' => 'John',
'age' => 25,
),
array(
'name' => 'Paul',
'age' => 26,
),
array(
'name' => 'Meredith',
'age' => 30,
......@@ -208,10 +204,6 @@ public function testFilterNumericExposedGroupedNotBetween() {
'name' => 'John',
'age' => 25,
),
array(
'name' => 'Paul',
'age' => 26,
),
array(
'name' => 'Meredith',
'age' => 30,
......
......@@ -114,7 +114,7 @@ public function dataProviderTestCompileWithKnownOperators() {
$data[] = [" (name LIKE :db_condition_placeholder_0 ESCAPE '\\\\') ", 'name', '%muh%', 'LIKE', [':db_condition_placeholder_0' => '%muh%']];
$data[] = [" (name NOT LIKE :db_condition_placeholder_0 ESCAPE '\\\\') ", 'name', '%muh%', 'NOT LIKE', [':db_condition_placeholder_0' => '%muh%']];
$data[] = [" (name BETWEEN :db_condition_placeholder_0 AND :db_condition_placeholder_1) ", 'name', [1, 2], 'BETWEEN', [':db_condition_placeholder_0' => 1, ':db_condition_placeholder_1' => 2]];
// $data[] = [" (name NOT BETWEEN :db_condition_placeholder_0 AND :db_condition_placeholder_1) ", 'name', [1, 2], 'NOT BETWEEN', [':db_condition_placeholder_0' => 1, ':db_condition_placeholder_1' => 2]];
$data[] = [" (name NOT BETWEEN :db_condition_placeholder_0 AND :db_condition_placeholder_1) ", 'name', [1, 2], 'NOT BETWEEN', [':db_condition_placeholder_0' => 1, ':db_condition_placeholder_1' => 2]];
// $data[] = [' ( STRCMP (name, :db_condition_placeholder_0) ) ', '', ['test-string'], 'STRCMP', [':db_condition_placeholder_0' => 'test-string']];
// $data[] = [' (EXISTS ) ', '', NULL, 'EXISTS'];
// $data[] = [' (name NOT EXISTS ) ', 'name', NULL, 'NOT EXISTS'];
......
Markdown is supported
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