function ReservedWordTest::testGroupBy
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/ReservedWordTest.php \Drupal\KernelTests\Core\Database\ReservedWordTest::testGroupBy()
- 11.x core/tests/Drupal/KernelTests/Core/Database/ReservedWordTest.php \Drupal\KernelTests\Core\Database\ReservedWordTest::testGroupBy()
Tests SELECT query with GROUP BY clauses on fields with reserved names.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ ReservedWordTest.php, line 88
Class
- ReservedWordTest
- Tests queries that include reserved words.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testGroupBy() : void {
$this->connection
->insert('select')
->fields([
'id' => 2,
'update' => 'Update value 1',
])
->execute();
// Using aliases.
$query = $this->connection
->select('select', 's');
$query->addExpression('COUNT([id])', 'num');
$query->addField('s', 'update');
$query->groupBy('s.update');
$this->assertSame('2', $query->execute()
->fetchAssoc()['num']);
// Not using aliases.
$query = $this->connection
->select('select');
$query->addExpression('COUNT([id])', 'num');
$query->addField('select', 'update');
$query->groupBy('update');
$this->assertSame('2', $query->execute()
->fetchAssoc()['num']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.