コード例 #1
0
 /**
  * @param Query                              $query
  * @param array                              $paramMappings
  * @return array
  * @throws \Doctrine\ORM\Query\QueryException
  */
 protected function processParameterMappings(Query $query, $paramMappings)
 {
     $sqlParams = array();
     $types = array();
     /** @var Parameter $parameter */
     foreach ($query->getParameters() as $parameter) {
         $key = $parameter->getName();
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         $value = $query->processParameterValue($parameter->getValue());
         $type = $parameter->getValue() === $value ? $parameter->getType() : Query\ParameterTypeInferer::inferType($value);
         foreach ($paramMappings[$key] as $position) {
             $types[$position] = $type;
         }
         $sqlPositions = $paramMappings[$key];
         $value = array($value);
         $countValue = count($value);
         for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
             $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
         }
     }
     if (count($sqlParams) != count($types)) {
         throw QueryException::parameterTypeMissmatch();
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
         ksort($types);
         $types = array_values($types);
     }
     return array($sqlParams, $types);
 }
コード例 #2
0
 /**
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * Copy of Doctrine\ORM\Query::processParameterMappings
  *
  * @param Query $query
  * @return array
  * @throws QueryException
  */
 public function processParameterMappings(Query $query)
 {
     $parser = new Parser($query);
     $parseResult = $parser->parse();
     $paramMappings = $parseResult->getParameterMappings();
     $resultSetMapping = $parseResult->getResultSetMapping();
     $paramCount = count($query->getParameters());
     $mappingCount = count($paramMappings);
     if ($paramCount > $mappingCount) {
         throw QueryException::tooManyParameters($mappingCount, $paramCount);
     } elseif ($paramCount < $mappingCount) {
         throw QueryException::tooFewParameters($mappingCount, $paramCount);
     }
     $sqlParams = [];
     $types = [];
     foreach ($query->getParameters() as $parameter) {
         $key = $parameter->getName();
         $value = $parameter->getValue();
         $rsm = $resultSetMapping;
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         if (isset($rsm->metadataParameterMapping[$key]) && $value instanceof ClassMetadata) {
             $value = $value->getMetadataValue($rsm->metadataParameterMapping[$key]);
         }
         $value = $query->processParameterValue($value);
         $type = $parameter->getValue() === $value ? $parameter->getType() : Query\ParameterTypeInferer::inferType($value);
         foreach ($paramMappings[$key] as $position) {
             $types[$position] = $type;
         }
         $sqlPositions = $paramMappings[$key];
         // optimized multi value sql positions away for now,
         // they are not allowed in DQL anyways.
         $value = [$value];
         $countValue = count($value);
         for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
             $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
         }
     }
     if (count($sqlParams) !== count($types)) {
         throw QueryException::parameterTypeMismatch();
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
         ksort($types);
         $types = array_values($types);
     }
     return [$sqlParams, $types];
 }
コード例 #3
0
ファイル: Query.php プロジェクト: davidbui2/doctrine2
 /**
  * Processes query parameter mappings
  *
  * @param array $paramMappings
  * @return array
  */
 private function processParameterMappings($paramMappings)
 {
     $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];
             }
         }
         $sqlPositions = $paramMappings[$key];
         // optimized multi value sql positions away for now,
         // they are not allowed in DQL anyways.
         $value = array($value);
         $countValue = count($value);
         for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
             $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
         }
     }
     if (count($sqlParams) != count($types)) {
         throw QueryException::parameterTypeMissmatch();
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
         ksort($types);
         $types = array_values($types);
     }
     return array($sqlParams, $types);
 }
コード例 #4
0
ファイル: Query.php プロジェクト: Dren-x/mobit
 /**
  * Processes query parameter mappings.
  *
  * @param array $paramMappings
  *
  * @return array
  *
  * @throws Query\QueryException
  */
 private function processParameterMappings($paramMappings)
 {
     $sqlParams = array();
     $types = array();
     foreach ($this->parameters as $parameter) {
         $key = $parameter->getName();
         $value = $parameter->getValue();
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         if (isset($this->_resultSetMapping->metadataParameterMapping[$key]) && $value instanceof ClassMetadata) {
             $value = $value->getMetadataValue($this->_resultSetMapping->metadataParameterMapping[$key]);
         }
         $value = $this->processParameterValue($value);
         $type = $parameter->getValue() === $value ? $parameter->getType() : ParameterTypeInferer::inferType($value);
         foreach ($paramMappings[$key] as $position) {
             $types[$position] = $type;
         }
         $sqlPositions = $paramMappings[$key];
         // optimized multi value sql positions away for now,
         // they are not allowed in DQL anyways.
         $value = array($value);
         $countValue = count($value);
         for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
             $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
         }
     }
     if (count($sqlParams) != count($types)) {
         throw QueryException::parameterTypeMismatch();
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
         ksort($types);
         $types = array_values($types);
     }
     return array($sqlParams, $types);
 }
コード例 #5
0
ファイル: Query.php プロジェクト: poulikov/readlater
 /**
  * {@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);
 }
コード例 #6
0
ファイル: Query.php プロジェクト: krishcdbry/z-zangura
 /**
  * {@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);
 }
コード例 #7
0
ファイル: Query.php プロジェクト: andreia/doctrine
 /**
  * {@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);
 }
コード例 #8
0
ファイル: Query.php プロジェクト: ramonornela/doctrine2
 /**
  * Processes query parameter mappings
  * 
  * @param array $paramMappings
  * @return array
  */
 private function processParameterMappings($paramMappings)
 {
     $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];
             }
         }
         $sqlPositions = $paramMappings[$key];
         $value = array_values($this->processParameterValue($value));
         $countValue = count($value);
         for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
             $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
         }
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
     }
     return array($sqlParams, $types);
 }