1
0
mirror of synced 2025-01-22 08:11:40 +03:00

[DDC-1147] Allowed usage of 0-based input parameters in DQL.

This commit is contained in:
Guilherme Blanco 2011-05-11 17:30:42 -03:00
parent 0d0d61935f
commit 54a0109d5d
5 changed files with 21 additions and 17 deletions

View File

@ -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();

View File

@ -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,}'
);
}

View File

@ -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

View File

@ -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(

View File

@ -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");