Exemple #1
0
 /**
  * {@inheritdoc}
  */
 protected function _doExecute()
 {
     $parameters = array();
     $types = array();
     foreach ($this->getParameters() as $parameter) {
         $name = $parameter->getName();
         $value = $this->processParameterValue($parameter->getValue());
         $type = $parameter->getValue() === $value ? $parameter->getType() : Query\ParameterTypeInferer::inferType($value);
         $parameters[$name] = $value;
         $types[$name] = $type;
     }
     if ($parameters && is_int(key($parameters))) {
         ksort($parameters);
         ksort($types);
         $parameters = array_values($parameters);
         $types = array_values($types);
     }
     return $this->_em->getConnection()->executeQuery($this->_sql, $parameters, $types, $this->_queryCacheProfile);
 }
 /**
  * Sets a query parameter for the query being constructed.
  *
  * <code>
  *     $qb = $em->createQueryBuilder()
  *         ->select('u')
  *         ->from('User', 'u')
  *         ->where('u.id = :user_id')
  *         ->setParameter('user_id', 1);
  * </code>
  *
  * @param string|integer $key The parameter position or name.
  * @param mixed $value The parameter value.
  * @param string|null $type PDO::PARAM_* or \Doctrine\DBAL\Types\Type::* constant
  * @return QueryBuilder This QueryBuilder instance.
  */
 public function setParameter($key, $value, $type = null)
 {
     $key = trim($key, ':');
     if ($type === null) {
         $type = Query\ParameterTypeInferer::inferType($value);
     }
     $this->_paramTypes[$key] = $type;
     $this->_params[$key] = $value;
     return $this;
 }