1
0
mirror of synced 2024-12-14 15:16:04 +03:00

Merge branch 'DDC-949'

This commit is contained in:
Benjamin Eberlei 2011-01-02 09:42:15 +01:00
commit ed7ec261d0
2 changed files with 76 additions and 8 deletions

View File

@ -525,7 +525,8 @@ class BasicEntityPersister
public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = 0)
{
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc, $lockMode);
$stmt = $this->_conn->executeQuery($sql, array_values($criteria));
list($params, $types) = $this->expandParameters($criteria);
$stmt = $this->_conn->executeQuery($sql, $params, $types);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
@ -608,7 +609,8 @@ class BasicEntityPersister
public function refresh(array $id, $entity)
{
$sql = $this->_getSelectEntitiesSQL($id);
$stmt = $this->_conn->executeQuery($sql, array_values($id));
list($params, $types) = $this->expandParameters($id);
$stmt = $this->_conn->executeQuery($sql, $params, $types);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
@ -694,7 +696,8 @@ class BasicEntityPersister
{
$entities = array();
$sql = $this->_getSelectEntitiesSQL($criteria);
$stmt = $this->_conn->executeQuery($sql, array_values($criteria));
list($params, $types) = $this->expandParameters($criteria);
$stmt = $this->_conn->executeQuery($sql, $params, $types);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
@ -742,7 +745,8 @@ class BasicEntityPersister
}
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
$stmt = $this->_conn->executeQuery($sql, array_values($criteria));
list($params, $types) = $this->expandParameters($criteria);
$stmt = $this->_conn->executeQuery($sql, $params, $types);
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result));
}
@ -1084,8 +1088,8 @@ class BasicEntityPersister
$sql = 'SELECT 1 '
. $this->_platform->appendLockHint($this->getLockTablesSql(), $lockMode)
. ($conditionSql ? ' WHERE ' . $conditionSql : '') . ' ' . $lockSql;
$params = array_values($criteria);
$this->_conn->executeQuery($sql, $params);
list($params, $types) = $this->expandParameters($criteria);
$stmt = $this->_conn->executeQuery($sql, $params, $types);
}
/**
@ -1169,14 +1173,35 @@ class BasicEntityPersister
}
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
$params = array_values($criteria);
$stmt = $this->_conn->executeQuery($sql, $params);
list($params, $types) = $this->expandParameters($criteria);
$stmt = $this->_conn->executeQuery($sql, $params, $types);
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result));
}
$stmt->closeCursor();
}
/**
* Expand the parameters from the given criteria and use the correct binding types if found.
*
* @param array $criteria
* @return array
*/
private function expandParameters($criteria)
{
$params = $types = array();
foreach ($criteria AS $field => $value) {
$type = null;
if (isset($this->_class->fieldMappings[$field])) {
$type = Type::getType($this->_class->fieldMappings[$field]['type'])->getBindingType();
}
$params[] = $value;
$types[] = $type;
}
return array($params, $types);
}
/**
* Checks whether the given managed entity exists in the database.
*

View File

@ -0,0 +1,43 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Tests\Models\Generic\BooleanModel;
require_once __DIR__ . '/../../../TestInit.php';
class DDC949Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('generic');
parent::setUp();
}
/**
* @group DDC-949
*/
public function testBooleanThroughRepository()
{
$true = new BooleanModel();
$true->booleanField = true;
$false = new BooleanModel();
$false->booleanField = false;
$this->_em->persist($true);
$this->_em->persist($false);
$this->_em->flush();
$this->_em->clear();
$true = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy(array('booleanField' => true));
$false = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy(array('booleanField' => false));
$this->assertType('Doctrine\Tests\Models\Generic\BooleanModel', $true);
$this->assertTrue($true->booleanField, "True Boolean Model should be true.");
$this->assertType('Doctrine\Tests\Models\Generic\BooleanModel', $false);
$this->assertFalse($false->booleanField, "False Boolean Model should be false.");
}
}