Unverified Commit 5c72f9f0 authored by alexpott's avatar alexpott

Issue #3131379 by daffie, Beakerboy, Lendude, alexpott: CONCAT_WS requires at least 3 arguments

parent 4d49b849
......@@ -76,17 +76,21 @@ public function query() {
}
}
if ($fields) {
$count = count($fields);
$separated_fields = [];
foreach ($fields as $key => $field) {
$separated_fields[] = $field;
if ($key < $count - 1) {
$separated_fields[] = "' '";
}
// We do not use the CONCAT_WS operator when there is only a single field.
// Using the CONCAT_WS operator with a single field is not a problem for
// the by core supported databases. Only the MS SQL Server requires the
// CONCAT_WS operator to be used with at least three arguments.
if (count($fields) == 1) {
$expression = reset($fields);
}
else {
// Multiple fields are separated by 3 spaces so that so that search
// strings that contain spaces are still only matched to single field
// values and not to multi-field values that exist only because we do
// the concatenation/LIKE trick.
$expression = implode(", ' ', ", $fields);
$expression = "CONCAT_WS(' ', $expression)";
}
$expression = implode(', ', $separated_fields);
$expression = "CONCAT_WS(' ', $expression)";
$info = $this->operators();
if (!empty($info[$this->operator]['method'])) {
$this->{$info[$this->operator]['method']}($expression);
......
......@@ -188,6 +188,10 @@ public function testFilterCombineAllWords() {
],
];
$this->assertIdenticalResultset($view, $resultset, $this->columnMap);
// Confirm that the query with multiple filters used the "CONCAT_WS"
// operator.
$this->assertStringContainsString('CONCAT_WS(', $view->query->query());
}
/**
......@@ -271,6 +275,10 @@ public function testNonFieldsRow() {
$errors = $view->validate();
// Check that the right error is shown.
$this->assertEquals(t('%display: %filter can only be used on displays that use fields. Set the style or row format for that display to one using fields to use the combine field filter.', ['%filter' => 'Global: Combine fields filter', '%display' => 'Master']), reset($errors['default']));
// Confirm that the query with single filter does not use the "CONCAT_WS"
// operator.
$this->assertStringNotContainsString('CONCAT_WS(', $view->query->query());
}
/**
......
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