cs

parent 4c6e6bbf
...@@ -3592,14 +3592,17 @@ abstract class AbstractPlatform ...@@ -3592,14 +3592,17 @@ abstract class AbstractPlatform
*/ */
final public function escapeStringForLike(string $inputString, string $escapeChar) : string final public function escapeStringForLike(string $inputString, string $escapeChar) : string
{ {
$replacePairs = [$escapeChar => $escapeChar.$escapeChar]; $replacePairs = [$escapeChar => $escapeChar . $escapeChar];
foreach ($this->getLikeWildcardCharacters() as $wildcardChar) { foreach ($this->getLikeWildcardCharacters() as $wildcardChar) {
$replacePairs[$wildcardChar] = $escapeChar.$wildcardChar; $replacePairs[$wildcardChar] = $escapeChar . $wildcardChar;
} }
return strtr($inputString, $replacePairs); return strtr($inputString, $replacePairs);
} }
/**
* @return string[]
*/
protected function getLikeWildcardCharacters() : iterable protected function getLikeWildcardCharacters() : iterable
{ {
return ['%', '_']; return ['%', '_'];
......
...@@ -117,6 +117,9 @@ class SQLServer2008Platform extends SQLServer2005Platform ...@@ -117,6 +117,9 @@ class SQLServer2008Platform extends SQLServer2005Platform
return Keywords\SQLServer2008Keywords::class; return Keywords\SQLServer2008Keywords::class;
} }
/**
* {@inheritDoc}
*/
protected function getLikeWildcardCharacters() : iterable protected function getLikeWildcardCharacters() : iterable
{ {
return array_merge(parent::getLikeWildcardCharacters(), ['[', ']', '^']); return array_merge(parent::getLikeWildcardCharacters(), ['[', ']', '^']);
......
...@@ -8,9 +8,9 @@ final class LikeWildcardsEscapingTest extends DbalFunctionalTestCase ...@@ -8,9 +8,9 @@ final class LikeWildcardsEscapingTest extends DbalFunctionalTestCase
{ {
public function testFetchLikeExpressionResult() : void public function testFetchLikeExpressionResult() : void
{ {
$string = '_25% off_ your next purchase \o/'; $string = '_25% off_ your next purchase \o/';
$escapeChar = '!'; $escapeChar = '!';
$stmt = $this->_conn->prepare(sprintf( $stmt = $this->_conn->prepare(sprintf(
"SELECT '%s' LIKE '%s' ESCAPE '%s' as it_matches", "SELECT '%s' LIKE '%s' ESCAPE '%s' as it_matches",
$string, $string,
$this->_conn->getDatabasePlatform()->escapeStringForLike($string, $escapeChar), $this->_conn->getDatabasePlatform()->escapeStringForLike($string, $escapeChar),
......
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