-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DibiPostgreDriver: use 'E' prefix in escapeLike() [Closes dg#159]
- Loading branch information
Showing
2 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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,42 @@ | ||
<?php | ||
|
||
/** | ||
* @dataProvider ../databases.ini pgsql | ||
*/ | ||
|
||
use Tester\Assert; | ||
|
||
require __DIR__ . '/bootstrap.php'; | ||
|
||
|
||
$danger = '_ % \\'; | ||
|
||
test(function() use ($config, $danger) { | ||
$conn = new DibiConnection($config); | ||
$conn->query('SET standard_conforming_strings = on'); | ||
Assert::false($conn->query("SELECT 'ROLEX' LIKE %~like~", 'ROLE_')->fetchSingle()); | ||
Assert::true($conn->query("SELECT 'ROLE_X' LIKE %~like~", 'ROLE_')->fetchSingle()); | ||
|
||
Assert::same("E'%\\\\_ \\\\% \\%'", $conn->getDriver()->escapeLike($danger, 0)); | ||
}); | ||
|
||
|
||
test(function() use ($config, $danger) { | ||
$conn = new DibiConnection($config); | ||
$conn->query('SET standard_conforming_strings = off'); | ||
$conn->query('SET escape_string_warning = off'); // do not write into PostgreSQL log | ||
|
||
Assert::false($conn->query("SELECT 'ROLEX' LIKE %~like~", 'ROLE_')->fetchSingle()); | ||
Assert::true($conn->query("SELECT 'ROLE_X' LIKE %~like~", 'ROLE_')->fetchSingle()); | ||
|
||
Assert::same("E'%\\\\_ \\\\% \\\\%'", $conn->getDriver()->escapeLike($danger, 0)); | ||
}); | ||
|
||
|
||
test(function() use ($config) { | ||
$conn = new DibiConnection($config); | ||
|
||
Assert::same("E'%A'", $conn->getDriver()->escapeLike('A', -1)); | ||
Assert::same("E'%A%'", $conn->getDriver()->escapeLike('A', 0)); | ||
Assert::same("E'A%'", $conn->getDriver()->escapeLike('A', 1)); | ||
}); |