function BasicSyntaxTest::testConcatFields
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php \Drupal\KernelTests\Core\Database\BasicSyntaxTest::testConcatFields()
- 10 core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php \Drupal\KernelTests\Core\Database\BasicSyntaxTest::testConcatFields()
- 11.x core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php \Drupal\KernelTests\Core\Database\BasicSyntaxTest::testConcatFields()
Tests string concatenation with field values.
We use 'job' and 'age' fields from the {test} table. Using the 'name' field for concatenation causes issues with custom or contrib database drivers, since its type 'varchar_ascii' may lead to using field-level collations not compatible with the other fields.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ BasicSyntaxTest.php, line 38
Class
- BasicSyntaxTest
- Tests SQL syntax interpretation.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testConcatFields() {
$result = $this->connection
->query('SELECT CONCAT(:a1, CONCAT(job, CONCAT(:a2, CONCAT(age, :a3)))) FROM {test} WHERE age = :age', [
':a1' => 'The age of ',
':a2' => ' is ',
':a3' => '.',
':age' => 25,
]);
$this->assertSame('The age of Singer is 25.', $result->fetchField(), 'Field CONCAT works.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.