function BasicSyntaxTest::testLikeEscape
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php \Drupal\KernelTests\Core\Database\BasicSyntaxTest::testLikeEscape()
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php \Drupal\KernelTests\Core\Database\BasicSyntaxTest::testLikeEscape()
- 10 core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php \Drupal\KernelTests\Core\Database\BasicSyntaxTest::testLikeEscape()
Tests escaping of LIKE wildcards.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ BasicSyntaxTest.php, line 80
Class
- BasicSyntaxTest
- Tests SQL syntax interpretation.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testLikeEscape() : void {
$this->connection
->insert('test')
->fields([
'name' => 'Ring_',
])
->execute();
// Match both "Ringo" and "Ring_".
$num_matches = $this->connection
->select('test', 't')
->condition('name', 'Ring_', 'LIKE')
->countQuery()
->execute()
->fetchField();
$this->assertSame('2', $num_matches, 'Found 2 records.');
// Match only "Ring_" using a LIKE expression with no wildcards.
$num_matches = $this->connection
->select('test', 't')
->condition('name', $this->connection
->escapeLike('Ring_'), 'LIKE')
->countQuery()
->execute()
->fetchField();
$this->assertSame('1', $num_matches, 'Found 1 record.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.