Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/e8377649146f9ddfdcac to your computer and use it in GitHub Desktop.
Save doctrinebot/e8377649146f9ddfdcac to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-162 - https://github.com/doctrine/doctrine2/issues/2260
index cec6d51..d3dd1a3 100644
--- lib/Doctrine/ORM/Persisters/StandardEntityPersister.php
+++ lib/Doctrine/ORM/Persisters/StandardEntityPersister.php
@@ -405,7 +405,13 @@ class StandardEntityPersister
*/
public function load(array $criteria, $entity = null, $assoc = null, array $hints = array())
{
- $stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($criteria, $assoc));
+ $sqlLogger = $this->_conn->getConfiguration()->getSqlLogger();
+ $sql = $this->_getSelectEntitiesSql($criteria, $assoc);
+ if ($sqlLogger) {
+ $sqlLogger->logSql($sql, array_values($criteria));
+ }
+
+ $stmt = $this->_conn->prepare($sql);
$stmt->execute(array_values($criteria));
$result = $stmt->fetch(Connection::FETCH_ASSOC);
$stmt->closeCursor();
@@ -421,7 +427,13 @@ class StandardEntityPersister
*/
final public function refresh(array $id, $entity)
{
- $stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($id));
+ $sqlLogger = $this->_conn->getConfiguration()->getSqlLogger();
+ $sql = $this->_getSelectEntitiesSql($id);
+ if ($sqlLogger) {
+ $sqlLogger->logSql($sql, array_values($id));
+ }
+
+ $stmt = $this->_conn->prepare($sql);
$stmt->execute(array_values($id));
$result = $stmt->fetch(Connection::FETCH_ASSOC);
$stmt->closeCursor();
@@ -503,7 +515,13 @@ class StandardEntityPersister
{
$entities = array();
- $stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($criteria));
+ $sqlLogger = $this->_conn->getConfiguration()->getSqlLogger();
+ $sql = $this->_getSelectEntitiesSql($criteria);
+ if ($sqlLogger) {
+ $sqlLogger->logSql($sql, array_values($criteria));
+ }
+
+ $stmt = $this->_conn->prepare($sql);
$stmt->execute(array_values($criteria));
$result = $stmt->fetchAll(Connection::FETCH_ASSOC);
$stmt->closeCursor();
@@ -523,8 +541,14 @@ class StandardEntityPersister
*/
public function loadOneToManyCollection(array $criteria, PersistentCollection $coll)
{
+ $sqlLogger = $this->_conn->getConfiguration()->getSqlLogger();
+ $sql = $this->_getSelectEntitiesSql($criteria, $owningAssoc);
+ if ($sqlLogger) {
+ $sqlLogger->logSql($sql, array_values($criteria));
+ }
+
$owningAssoc = $this->_class->associationMappings[$coll->getMapping()->mappedByFieldName];
- $stmt = $this->_conn->prepare($this->_getSelectEntitiesSql($criteria, $owningAssoc));
+ $stmt = $this->_conn->prepare($sql);
$stmt->execute(array_values($criteria));
while ($result = $stmt->fetch(Connection::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result));
@@ -540,7 +564,13 @@ class StandardEntityPersister
*/
public function loadManyToManyCollection($assoc, array $criteria, PersistentCollection $coll)
{
- $stmt = $this->_conn->prepare($this->_getSelectManyToManyEntityCollectionSql($assoc, $criteria));
+ $sqlLogger = $this->_conn->getConfiguration()->getSqlLogger();
+ $sql = $this->_getSelectManyToManyEntityCollectionSql($assoc, $criteria);
+ if ($sqlLogger) {
+ $sqlLogger->logSql($sql, array_values($criteria));
+ }
+
+ $stmt = $this->_conn->prepare($sql);
$stmt->execute(array_values($criteria));
while ($result = $stmt->fetch(Connection::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment