示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function _doExecute()
 {
     $executor = $this->_parse()->getSqlExecutor();
     if ($this->_queryCacheProfile) {
         $executor->setQueryCacheProfile($this->_queryCacheProfile);
     }
     // Prepare parameters
     $paramMappings = $this->_parserResult->getParameterMappings();
     if (count($paramMappings) != count($this->_params)) {
         throw QueryException::invalidParameterNumber();
     }
     list($sqlParams, $types) = $this->processParameterMappings($paramMappings);
     if ($this->_resultSetMapping === null) {
         $this->_resultSetMapping = $this->_parserResult->getResultSetMapping();
     }
     return $executor->execute($this->_em->getConnection(), $sqlParams, $types);
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 protected function _doExecute()
 {
     $executor = $this->_parse()->getSqlExecutor();
     // Prepare parameters
     $paramMappings = $this->_parserResult->getParameterMappings();
     if (count($paramMappings) != count($this->_params)) {
         throw QueryException::invalidParameterNumber();
     }
     $sqlParams = $types = array();
     foreach ($this->_params as $key => $value) {
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         if (isset($this->_paramTypes[$key])) {
             foreach ($paramMappings[$key] as $position) {
                 $types[$position] = $this->_paramTypes[$key];
             }
         }
         if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value))) {
             $values = $this->_em->getUnitOfWork()->getEntityIdentifier($value);
             $sqlPositions = $paramMappings[$key];
             $sqlParams = array_merge($sqlParams, array_combine((array) $sqlPositions, $values));
         } else {
             foreach ($paramMappings[$key] as $position) {
                 $sqlParams[$position] = $value;
             }
         }
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
     }
     if ($this->_resultSetMapping === null) {
         $this->_resultSetMapping = $this->_parserResult->getResultSetMapping();
     }
     return $executor->execute($this->_em->getConnection(), $sqlParams, $types);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 protected function _doExecute()
 {
     $executor = $this->_parse()->getSqlExecutor();
     // Prepare parameters
     $paramMappings = $this->_parserResult->getParameterMappings();
     if (count($paramMappings) != count($this->_params)) {
         throw QueryException::invalidParameterNumber();
     }
     $sqlParams = $types = array();
     foreach ($this->_params as $key => $value) {
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         if (isset($this->_paramTypes[$key])) {
             foreach ($paramMappings[$key] as $position) {
                 $types[$position] = $this->_paramTypes[$key];
             }
         }
         if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value))) {
             if ($this->_em->getUnitOfWork()->getEntityState($value) == UnitOfWork::STATE_MANAGED) {
                 $idValues = $this->_em->getUnitOfWork()->getEntityIdentifier($value);
             } else {
                 $class = $this->_em->getClassMetadata(get_class($value));
                 $idValues = $class->getIdentifierValues($value);
             }
             $sqlPositions = $paramMappings[$key];
             $cSqlPos = count($sqlPositions);
             $cIdValues = count($idValues);
             $idValues = array_values($idValues);
             for ($i = 0; $i < $cSqlPos; $i++) {
                 $sqlParams[$sqlPositions[$i]] = $idValues[$i % $cIdValues];
             }
         } else {
             foreach ($paramMappings[$key] as $position) {
                 $sqlParams[$position] = $value;
             }
         }
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
     }
     if ($this->_resultSetMapping === null) {
         $this->_resultSetMapping = $this->_parserResult->getResultSetMapping();
     }
     return $executor->execute($this->_em->getConnection(), $sqlParams, $types);
 }
示例#4
0
文件: Query.php 项目: josercl/forum
 /**
  * {@inheritdoc}
  */
 protected function _doExecute()
 {
     $executor = $this->_parse()->getSqlExecutor();
     if ($this->_queryCacheProfile) {
         $executor->setQueryCacheProfile($this->_queryCacheProfile);
     }
     if ($this->_resultSetMapping === null) {
         $this->_resultSetMapping = $this->_parserResult->getResultSetMapping();
     }
     // Prepare parameters
     $paramMappings = $this->_parserResult->getParameterMappings();
     if (count($paramMappings) != count($this->parameters)) {
         throw QueryException::invalidParameterNumber();
     }
     // evict all cache for the entity region
     if ($this->hasCache && isset($this->_hints[self::HINT_CACHE_EVICT]) && $this->_hints[self::HINT_CACHE_EVICT]) {
         $this->evictEntityCacheRegion();
     }
     list($sqlParams, $types) = $this->processParameterMappings($paramMappings);
     return $executor->execute($this->_em->getConnection(), $sqlParams, $types);
 }
示例#5
0
 /**
  * {@inheritdoc}
  *
  * @override
  */
 protected function _prepareParams(array $params)
 {
     $sqlParams = array();
     $paramMappings = $this->_parserResult->getParameterMappings();
     if (count($paramMappings) != count($params)) {
         throw QueryException::invalidParameterNumber();
     }
     foreach ($params as $key => $value) {
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         if (is_object($value)) {
             //$values = $this->_em->getClassMetadata(get_class($value))->getIdentifierValues($value);
             $values = $this->_em->getUnitOfWork()->getEntityIdentifier($value);
             //var_dump($this->_em->getUnitOfWork()->getEntityIdentifier($value));
             $sqlPositions = $paramMappings[$key];
             $sqlParams = array_merge($sqlParams, array_combine((array) $sqlPositions, $values));
         } else {
             if (is_bool($value)) {
                 $boolValue = $this->_em->getConnection()->getDatabasePlatform()->convertBooleans($value);
                 foreach ($paramMappings[$key] as $position) {
                     $sqlParams[$position] = $boolValue;
                 }
             } else {
                 foreach ($paramMappings[$key] as $position) {
                     $sqlParams[$position] = $value;
                 }
             }
         }
     }
     ksort($sqlParams);
     return array_values($sqlParams);
 }