-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Escape LIKE metacharacters #3013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+107
−4
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1bc0536
Escape LIKE metacharacters
greg0ire 3306fa7
Make building LIKE expression with escaping easier
greg0ire 1b21a84
Add more meta-characters for some MS platforms
greg0ire 4c6e6bb
Pick a more commonplace escape char for the test
greg0ire 3efabd4
cs
greg0ire 4aee7a4
use array as return type hint
greg0ire 20d07bf
Use fetch column to be independent from the alias
greg0ire de2bfb1
Provide FROM clause to Oracle
ccf6817
Prefer func_get_arg over func_get_args
greg0ire 44f7c13
Document the new parameter
greg0ire bcc9403
Let the caller do the quoting
greg0ire 35982f2
Use dummy SELECT SQL
greg0ire 7a92de7
Add SQL Server 2008 wildcard chars in test string
greg0ire a9e5e5a
Replace foreach and strtr with regex + addcslashes
greg0ire f397fe0
Use strings to represent wildcard characters
greg0ire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\DBAL\Functional; | ||
|
||
use Doctrine\Tests\DbalFunctionalTestCase; | ||
use function sprintf; | ||
use function str_replace; | ||
|
||
final class LikeWildcardsEscapingTest extends DbalFunctionalTestCase | ||
{ | ||
public function testFetchLikeExpressionResult() : void | ||
{ | ||
$string = '_25% off_ your next purchase \o/ [$̲̅(̲̅5̲̅)̲̅$̲̅] (^̮^)'; | ||
$escapeChar = '!'; | ||
$databasePlatform = $this->_conn->getDatabasePlatform(); | ||
$stmt = $this->_conn->prepare(str_replace( | ||
'1', | ||
sprintf( | ||
"(CASE WHEN '%s' LIKE '%s' ESCAPE '%s' THEN 1 ELSE 0 END)", | ||
$string, | ||
$databasePlatform->escapeStringForLike($string, $escapeChar), | ||
$escapeChar | ||
), | ||
$databasePlatform->getDummySelectSQL() | ||
)); | ||
$stmt->execute(); | ||
$this->assertTrue((bool) $stmt->fetchColumn()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Classy 💩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IKR?