Commit 22375235 authored by romanb's avatar romanb

[2.0][DDC-162][DDC-94] Fixed.

parent 69a0b597
...@@ -73,6 +73,13 @@ class StandardEntityPersister ...@@ -73,6 +73,13 @@ class StandardEntityPersister
*/ */
protected $_em; protected $_em;
/**
* The SqlLogger to use, if any.
*
* @var Doctrine\DBAL\Logging\SqlLogger
*/
protected $_sqlLogger;
/** /**
* Queued inserts. * Queued inserts.
* *
...@@ -92,6 +99,7 @@ class StandardEntityPersister ...@@ -92,6 +99,7 @@ class StandardEntityPersister
{ {
$this->_em = $em; $this->_em = $em;
$this->_conn = $em->getConnection(); $this->_conn = $em->getConnection();
$this->_sqlLogger = $em->getConfiguration()->getSqlLogger();
$this->_platform = $this->_conn->getDatabasePlatform(); $this->_platform = $this->_conn->getDatabasePlatform();
$this->_class = $class; $this->_class = $class;
} }
...@@ -405,8 +413,15 @@ class StandardEntityPersister ...@@ -405,8 +413,15 @@ class StandardEntityPersister
*/ */
public function load(array $criteria, $entity = null, $assoc = null, array $hints = array()) public function load(array $criteria, $entity = null, $assoc = null, array $hints = array())
{ {
$stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($criteria, $assoc)); $sql = $this->_getSelectEntitiesSql($criteria, $assoc);
$stmt->execute(array_values($criteria)); $params = array_values($criteria);
if ($this->_sqlLogger !== null) {
$this->_sqlLogger->logSql($sql, $params);
}
$stmt = $this->_conn->prepare($sql);
$stmt->execute($params);
$result = $stmt->fetch(Connection::FETCH_ASSOC); $result = $stmt->fetch(Connection::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -421,8 +436,15 @@ class StandardEntityPersister ...@@ -421,8 +436,15 @@ class StandardEntityPersister
*/ */
final public function refresh(array $id, $entity) final public function refresh(array $id, $entity)
{ {
$stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($id)); $sql = $this->_getSelectEntitiesSql($id);
$stmt->execute(array_values($id)); $params = array_values($id);
if ($this->_sqlLogger !== null) {
$this->_sqlLogger->logSql($sql, $params);
}
$stmt = $this->_conn->prepare($sql);
$stmt->execute($params);
$result = $stmt->fetch(Connection::FETCH_ASSOC); $result = $stmt->fetch(Connection::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -503,8 +525,15 @@ class StandardEntityPersister ...@@ -503,8 +525,15 @@ class StandardEntityPersister
{ {
$entities = array(); $entities = array();
$stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($criteria)); $sql = $this->_getSelectEntitiesSql($criteria);
$stmt->execute(array_values($criteria)); $params = array_values($criteria);
if ($this->_sqlLogger !== null) {
$this->_sqlLogger->logSql($sql, $params);
}
$stmt = $this->_conn->prepare($sql);
$stmt->execute($params);
$result = $stmt->fetchAll(Connection::FETCH_ASSOC); $result = $stmt->fetchAll(Connection::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -524,8 +553,16 @@ class StandardEntityPersister ...@@ -524,8 +553,16 @@ class StandardEntityPersister
public function loadOneToManyCollection(array $criteria, PersistentCollection $coll) public function loadOneToManyCollection(array $criteria, PersistentCollection $coll)
{ {
$owningAssoc = $this->_class->associationMappings[$coll->getMapping()->mappedByFieldName]; $owningAssoc = $this->_class->associationMappings[$coll->getMapping()->mappedByFieldName];
$stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($criteria, $owningAssoc));
$stmt->execute(array_values($criteria)); $sql = $this->_getSelectEntitiesSql($criteria, $owningAssoc);
$params = array_values($criteria);
if ($this->_sqlLogger !== null) {
$this->_sqlLogger->logSql($sql, $params);
}
$stmt = $this->_conn->prepare($sql);
$stmt->execute($params);
while ($result = $stmt->fetch(Connection::FETCH_ASSOC)) { while ($result = $stmt->fetch(Connection::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result)); $coll->hydrateAdd($this->_createEntity($result));
} }
...@@ -540,8 +577,15 @@ class StandardEntityPersister ...@@ -540,8 +577,15 @@ class StandardEntityPersister
*/ */
public function loadManyToManyCollection($assoc, array $criteria, PersistentCollection $coll) public function loadManyToManyCollection($assoc, array $criteria, PersistentCollection $coll)
{ {
$stmt = $this->_conn->prepare($this->_getSelectManyToManyEntityCollectionSql($assoc, $criteria)); $sql = $this->_getSelectManyToManyEntityCollectionSql($assoc, $criteria);
$stmt->execute(array_values($criteria)); $params = array_values($criteria);
if ($this->_sqlLogger !== null) {
$this->_sqlLogger->logSql($sql, $params);
}
$stmt = $this->_conn->prepare($sql);
$stmt->execute($params);
while ($result = $stmt->fetch(Connection::FETCH_ASSOC)) { while ($result = $stmt->fetch(Connection::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result)); $coll->hydrateAdd($this->_createEntity($result));
} }
......
...@@ -603,8 +603,7 @@ class ObjectHydratorTest extends HydrationTestCase ...@@ -603,8 +603,7 @@ class ObjectHydratorTest extends HydrationTestCase
* in the result set. * in the result set.
* *
* DQL: * DQL:
* select c.id, c.position, c.name, b.id, b.position * select c, b from Doctrine\Tests\Models\Forum\ForumCategory c inner join c.boards b
* from \Doctrine\Tests\Models\Forum\ForumCategory c inner join c.boards b
* order by c.position asc, b.position asc * order by c.position asc, b.position asc
* *
* Checks whether the boards are correctly assigned to the categories. * Checks whether the boards are correctly assigned to the categories.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment