[DDC-1147] Allowed usage of 0-based input parameters in DQL.
This commit is contained in:
parent
0d0d61935f
commit
54a0109d5d
@ -558,10 +558,6 @@ abstract class AbstractQuery
|
||||
$this->setParameters($params);
|
||||
}
|
||||
|
||||
if (isset($this->_params[0])) {
|
||||
throw QueryException::invalidParameterPosition(0);
|
||||
}
|
||||
|
||||
// Check result cache
|
||||
if ($this->_useResultCache && $cacheDriver = $this->getResultCacheDriver()) {
|
||||
list($key, $hash) = $this->getResultCacheId();
|
||||
@ -572,8 +568,8 @@ abstract class AbstractQuery
|
||||
$stmt = $this->_doExecute();
|
||||
|
||||
$result = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll(
|
||||
$stmt, $this->_resultSetMapping, $this->_hints
|
||||
);
|
||||
$stmt, $this->_resultSetMapping, $this->_hints
|
||||
);
|
||||
|
||||
$cacheDriver->save($hash, array($key => $result), $this->_resultCacheTTL);
|
||||
|
||||
|
@ -126,7 +126,7 @@ class Lexer extends \Doctrine\Common\Lexer
|
||||
'[a-z_\\\][a-z0-9_\:\\\]*[a-z0-9_]{1}',
|
||||
'(?:[0-9]+(?:[\.][0-9]+)*)(?:e[+-]?[0-9]+)?',
|
||||
"'(?:[^']|'')*'",
|
||||
'\?[1-9][0-9]*|:[a-z]{1}[a-z0-9_]{0,}'
|
||||
'\?[0-9]*|:[a-z]{1}[a-z0-9_]{0,}'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class SqlWalker implements TreeWalker
|
||||
private $_aliasCounter = 0;
|
||||
private $_tableAliasCounter = 0;
|
||||
private $_scalarResultCounter = 1;
|
||||
private $_sqlParamIndex = 1;
|
||||
private $_sqlParamIndex = 0;
|
||||
|
||||
/**
|
||||
* @var ParserResult
|
||||
|
@ -95,6 +95,23 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals('Symfony 2', $users[0]->articles[1]->topic);
|
||||
}
|
||||
|
||||
public function testUsingZeroBasedQueryParameterShouldWork()
|
||||
{
|
||||
$user = new CmsUser;
|
||||
$user->name = 'Jonathan';
|
||||
$user->username = 'jwage';
|
||||
$user->status = 'developer';
|
||||
$this->_em->persist($user);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?0');
|
||||
$q->setParameter(0, 'jwage');
|
||||
$user = $q->getSingleResult();
|
||||
|
||||
$this->assertNotNull($user);
|
||||
}
|
||||
|
||||
public function testUsingUnknownQueryParameterShouldThrowException()
|
||||
{
|
||||
$this->setExpectedException(
|
||||
|
@ -13,15 +13,6 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->_em = $this->_getTestEntityManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Doctrine\ORM\Query\QueryException
|
||||
*/
|
||||
public function testParameterIndexZeroThrowsException()
|
||||
{
|
||||
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
|
||||
$query->execute(array(42)); // same as array(0 => 42), 0 is invalid parameter position
|
||||
}
|
||||
|
||||
public function testGetParameters()
|
||||
{
|
||||
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
|
||||
|
Loading…
x
Reference in New Issue
Block a user