[2.0] DDC-320 - Fixed Substring across all platforms using AbstractPlatform::getSubstringExpression() instead of the "hand-built" one.
This commit is contained in:
parent
d197c814f3
commit
8357289050
@ -321,10 +321,10 @@ abstract class AbstractPlatform
|
||||
*
|
||||
* SQLite only supports the 2 parameter variant of this function
|
||||
*
|
||||
* @param string $value an sql string literal or column name/alias
|
||||
* @param integer $position where to start the substring portion
|
||||
* @param integer $length the substring portion length
|
||||
* @return string SQL substring function with given parameters
|
||||
* @param string $value an sql string literal or column name/alias
|
||||
* @param integer $from where to start the substring portion
|
||||
* @param integer $len the substring portion length
|
||||
* @return string
|
||||
*/
|
||||
public function getSubstringExpression($value, $from, $len = null)
|
||||
{
|
||||
|
@ -38,21 +38,23 @@ class SubstringFunction extends FunctionNode
|
||||
{
|
||||
public $stringPrimary;
|
||||
public $firstSimpleArithmeticExpression;
|
||||
public $secondSimpleArithmeticExpression;
|
||||
public $secondSimpleArithmeticExpression = null;
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
|
||||
{
|
||||
//TODO: Use platform to get SQL
|
||||
return 'SUBSTRING('
|
||||
. $sqlWalker->walkStringPrimary($this->stringPrimary)
|
||||
. ', '
|
||||
. $sqlWalker->walkSimpleArithmeticExpression($this->firstSimpleArithmeticExpression)
|
||||
. ', '
|
||||
. $sqlWalker->walkSimpleArithmeticExpression($this->secondSimpleArithmeticExpression)
|
||||
. ')';
|
||||
$optionalSecondSimpleArithmeticExpression = null;
|
||||
if ($this->secondSimpleArithmeticExpression !== null) {
|
||||
$optionalSecondSimpleArithmeticExpression = $sqlWalker->walkSimpleArithmeticExpression($this->secondSimpleArithmeticExpression);
|
||||
}
|
||||
|
||||
return $sqlWalker->getConnection()->getDatabasePlatform()->getSubstringExpression(
|
||||
$sqlWalker->walkStringPrimary($this->stringPrimary),
|
||||
$sqlWalker->walkSimpleArithmeticExpression($this->firstSimpleArithmeticExpression),
|
||||
$optionalSecondSimpleArithmeticExpression
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,10 +72,12 @@ class SubstringFunction extends FunctionNode
|
||||
$parser->match(Lexer::T_COMMA);
|
||||
|
||||
$this->firstSimpleArithmeticExpression = $parser->SimpleArithmeticExpression();
|
||||
|
||||
if ($lexer->isNextToken(Lexer::T_COMMA)) {
|
||||
$parser->match(Lexer::T_COMMA);
|
||||
|
||||
$parser->match(Lexer::T_COMMA);
|
||||
|
||||
$this->secondSimpleArithmeticExpression = $parser->SimpleArithmeticExpression();
|
||||
$this->secondSimpleArithmeticExpression = $parser->SimpleArithmeticExpression();
|
||||
}
|
||||
|
||||
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
|
||||
}
|
||||
|
@ -165,9 +165,10 @@ class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
public function testFunctionSubstring()
|
||||
{
|
||||
$this->markTestSkipped('SUBSTRING does not exist on Oracle and Sqlite.');
|
||||
$dql = "SELECT m, SUBSTRING(m.name, 1, 3) AS str1, SUBSTRING(m.name, 5) AS str2 ".
|
||||
"FROM Doctrine\Tests\Models\Company\CompanyManager m";
|
||||
|
||||
$result = $this->_em->createQuery("SELECT m, SUBSTRING(m.name, 1, 3) AS str1 FROM Doctrine\Tests\Models\Company\CompanyManager m")
|
||||
$result = $this->_em->createQuery($dql)
|
||||
->getArrayResult();
|
||||
|
||||
$this->assertEquals(4, count($result));
|
||||
@ -175,6 +176,10 @@ class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals('Ben', $result[1]['str1']);
|
||||
$this->assertEquals('Gui', $result[2]['str1']);
|
||||
$this->assertEquals('Jon', $result[3]['str1']);
|
||||
$this->assertEquals('n B.', $result[0]['str2']);
|
||||
$this->assertEquals('amin E.', $result[1]['str2']);
|
||||
$this->assertEquals('herme B.', $result[2]['str2']);
|
||||
$this->assertEquals('than W.', $result[3]['str2']);
|
||||
}
|
||||
|
||||
public function testFunctionTrim()
|
||||
|
Loading…
Reference in New Issue
Block a user