Unverified Commit 5c4c2b76 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3109 from morozov/dummy-sql-expression

Allow to specify arbitrary SQL expression in AbstractPlatform::getDummySelectSQL()
parents 755c99e3 8c41da97
......@@ -49,7 +49,9 @@ use function array_unique;
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;
......@@ -3499,7 +3501,9 @@ abstract class AbstractPlatform
*/
public function getDummySelectSQL()
{
return 'SELECT 1';
$expression = func_num_args() > 0 ? func_get_arg(0) : '1';
return sprintf('SELECT %s', $expression);
}
/**
......
......@@ -30,6 +30,8 @@ use function array_merge;
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;
......@@ -863,7 +865,9 @@ class DB2Platform extends AbstractPlatform
*/
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);
}
/**
......
......@@ -31,6 +31,8 @@ use Doctrine\DBAL\Types\BinaryType;
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;
......@@ -1116,7 +1118,9 @@ END;';
*/
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);
}
/**
......
......@@ -13,16 +13,16 @@ final class LikeWildcardsEscapingTest extends DbalFunctionalTestCase
$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());
}
......
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