DDC-770 - Cleanup Query instance when its cloned
This commit is contained in:
parent
241e4d2f53
commit
8a21ab4755
@ -138,10 +138,16 @@ abstract class AbstractQuery
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees the resources used by the query object.
|
* Frees the resources used by the query object.
|
||||||
|
*
|
||||||
|
* Resets Parameters, Parameter Types and Query Hints.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function free()
|
public function free()
|
||||||
{
|
{
|
||||||
$this->_params = array();
|
$this->_params = array();
|
||||||
|
$this->_paramTypes = array();
|
||||||
|
$this->_hints = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -569,4 +575,14 @@ abstract class AbstractQuery
|
|||||||
* @return Doctrine\DBAL\Driver\Statement The executed database statement that holds the results.
|
* @return Doctrine\DBAL\Driver\Statement The executed database statement that holds the results.
|
||||||
*/
|
*/
|
||||||
abstract protected function _doExecute();
|
abstract protected function _doExecute();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup Query resource when clone is called.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __clone()
|
||||||
|
{
|
||||||
|
$this->free();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,28 +20,6 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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");
|
|
||||||
$this->assertEquals(array(), $query->getParameters());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetParameters_HasSomeAlready()
|
|
||||||
{
|
|
||||||
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
|
|
||||||
$query->setParameter(2, 84);
|
|
||||||
$this->assertEquals(array(2 => 84), $query->getParameters());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSimpleQueries()
|
public function testSimpleQueries()
|
||||||
{
|
{
|
||||||
$user = new CmsUser;
|
$user = new CmsUser;
|
||||||
|
@ -26,6 +26,7 @@ class AllTests
|
|||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Query\UpdateSqlGenerationTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Query\UpdateSqlGenerationTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Query\ExprTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Query\ExprTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Query\ParserResultTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Query\ParserResultTest');
|
||||||
|
$suite->addTestSuite('Doctrine\Tests\ORM\Query\QueryTest');
|
||||||
|
|
||||||
return $suite;
|
return $suite;
|
||||||
}
|
}
|
||||||
|
47
tests/Doctrine/Tests/ORM/Query/QueryTest.php
Normal file
47
tests/Doctrine/Tests/ORM/Query/QueryTest.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Query;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../TestInit.php';
|
||||||
|
|
||||||
|
class QueryTest extends \Doctrine\Tests\OrmTestCase
|
||||||
|
{
|
||||||
|
protected $_em = null;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$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");
|
||||||
|
$this->assertEquals(array(), $query->getParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetParameters_HasSomeAlready()
|
||||||
|
{
|
||||||
|
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
|
||||||
|
$query->setParameter(2, 84);
|
||||||
|
$this->assertEquals(array(2 => 84), $query->getParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFree()
|
||||||
|
{
|
||||||
|
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
|
||||||
|
$query->setParameter(2, 84, \PDO::PARAM_INT);
|
||||||
|
|
||||||
|
$query->free();
|
||||||
|
|
||||||
|
$this->assertEquals(array(), $query->getParameters());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user