Skip to content
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

Allow to specify arbitrary SQL expression in AbstractPlatform::getDummySelectSQL() #3109

Merged
merged 1 commit into from
May 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
use function array_values;
use function count;
use function explode;
use function func_get_arg;
use function func_get_args;
use function func_num_args;
use function get_class;
use function implode;
use function in_array;
Expand Down Expand Up @@ -3499,7 +3501,9 @@ public function getTruncateTableSQL($tableName, $cascade = false)
*/
public function getDummySelectSQL()
{
return 'SELECT 1';
$expression = func_num_args() > 0 ? func_get_arg(0) : '1';

return sprintf('SELECT %s', $expression);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/Doctrine/DBAL/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use function count;
use function current;
use function explode;
use function func_get_arg;
use function func_num_args;
use function implode;
use function sprintf;
use function strpos;
Expand Down Expand Up @@ -863,7 +865,9 @@ public function getForUpdateSQL()
*/
public function getDummySelectSQL()
{
return 'SELECT 1 FROM sysibm.sysdummy1';
$expression = func_num_args() > 0 ? func_get_arg(0) : '1';

return sprintf('SELECT %s FROM sysibm.sysdummy1', $expression);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use function array_merge;
use function count;
use function explode;
use function func_get_arg;
use function func_num_args;
use function implode;
use function preg_match;
use function sprintf;
Expand Down Expand Up @@ -1120,7 +1122,9 @@ public function getTruncateTableSQL($tableName, $cascade = false)
*/
public function getDummySelectSQL()
{
return 'SELECT 1 FROM DUAL';
$expression = func_num_args() > 0 ? func_get_arg(0) : '1';

return sprintf('SELECT %s FROM DUAL', $expression);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ 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 = $this->_conn->prepare(
$databasePlatform->getDummySelectSQL(
sprintf(
"(CASE WHEN '%s' LIKE '%s' ESCAPE '%s' THEN 1 ELSE 0 END)",
$string,
$databasePlatform->escapeStringForLike($string, $escapeChar),
$escapeChar
)
)
);
$stmt->execute();
$this->assertTrue((bool) $stmt->fetchColumn());
}
Expand Down