示例#1
0
 /**
  * Walks down an InstanceOfExpression AST node, thereby generating the appropriate SQL.
  *
  * @param InstanceOfExpression
  * @return string The SQL.
  */
 public function walkInstanceOfExpression($instanceOfExpr)
 {
     $sql = '';
     $dqlAlias = $instanceOfExpr->identificationVariable;
     $discrClass = $class = $this->queryComponents[$dqlAlias]['metadata'];
     if ($class->discriminatorColumn) {
         $discrClass = $this->em->getClassMetadata($class->rootEntityName);
     }
     if ($this->useSqlTableAliases) {
         $sql .= $this->getSQLTableAlias($discrClass->getTableName(), $dqlAlias) . '.';
     }
     $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' NOT IN ' : ' IN ');
     $sqlParameterList = array();
     foreach ($instanceOfExpr->value as $parameter) {
         if ($parameter instanceof AST\InputParameter) {
             $sqlParameterList[] = $this->walkInputParameter($parameter);
         } else {
             // Get name from ClassMetadata to resolve aliases.
             $entityClassName = $this->em->getClassMetadata($parameter)->name;
             if ($entityClassName == $class->name) {
                 $sqlParameterList[] = $this->conn->quote($class->discriminatorValue);
             } else {
                 $discrMap = array_flip($class->discriminatorMap);
                 if (!isset($discrMap[$entityClassName])) {
                     throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName);
                 }
                 $sqlParameterList[] = $this->conn->quote($discrMap[$entityClassName]);
             }
         }
     }
     $sql .= '(' . implode(', ', $sqlParameterList) . ')';
     return $sql;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function walkInstanceOfExpression($instanceOfExpr)
 {
     $sql = '';
     $dqlAlias = $instanceOfExpr->identificationVariable;
     $discrClass = $class = $this->queryComponents[$dqlAlias]['metadata'];
     if ($class->discriminatorColumn) {
         $discrClass = $this->em->getClassMetadata($class->rootEntityName);
     }
     if ($this->useSqlTableAliases) {
         $sql .= $this->getSQLTableAlias($discrClass->getTableName(), $dqlAlias) . '.';
     }
     $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' NOT IN ' : ' IN ');
     $sqlParameterList = array();
     foreach ($instanceOfExpr->value as $parameter) {
         if ($parameter instanceof AST\InputParameter) {
             // We need to modify the parameter value to be its correspondent mapped value
             $dqlParamKey = $parameter->name;
             $dqlParam = $this->query->getParameter($dqlParamKey);
             $paramValue = $this->query->processParameterValue($dqlParam->getValue());
             if (!$paramValue instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
                 throw QueryException::invalidParameterType('ClassMetadata', get_class($paramValue));
             }
             $entityClassName = $paramValue->name;
         } else {
             // Get name from ClassMetadata to resolve aliases.
             $entityClassName = $this->em->getClassMetadata($parameter)->name;
         }
         if ($entityClassName == $class->name) {
             $sqlParameterList[] = $this->conn->quote($class->discriminatorValue);
         } else {
             $discrMap = array_flip($class->discriminatorMap);
             if (!isset($discrMap[$entityClassName])) {
                 throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName);
             }
             $sqlParameterList[] = $this->conn->quote($discrMap[$entityClassName]);
         }
     }
     $sql .= '(' . implode(', ', $sqlParameterList) . ')';
     return $sql;
 }
示例#3
0
 /**
  * Walks down an InstanceOfExpression AST node, thereby generating the appropriate SQL.
  *
  * @param InstanceOfExpression
  * @return string The SQL.
  */
 public function walkInstanceOfExpression($instanceOfExpr)
 {
     $sql = '';
     $dqlAlias = $instanceOfExpr->identificationVariable;
     $discrClass = $class = $this->_queryComponents[$dqlAlias]['metadata'];
     $fieldName = null;
     if ($class->discriminatorColumn) {
         $discrClass = $this->_em->getClassMetadata($class->rootEntityName);
     }
     if ($this->_useSqlTableAliases) {
         $sql .= $this->getSQLTableAlias($discrClass->table['name'], $dqlAlias) . '.';
     }
     $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' <> ' : ' = ');
     if ($instanceOfExpr->value instanceof AST\InputParameter) {
         // We need to modify the parameter value to be its correspondent mapped value
         $dqlParamKey = $instanceOfExpr->value->name;
         $paramValue = $this->_query->getParameter($dqlParamKey);
         if (!$paramValue instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
             throw QueryException::invalidParameterType('ClassMetadata', get_class($paramValue));
         }
         $entityClassName = $paramValue->name;
     } else {
         // Get name from ClassMetadata to resolve aliases.
         $entityClassName = $this->_em->getClassMetadata($instanceOfExpr->value)->name;
     }
     if ($entityClassName == $class->name) {
         $sql .= $this->_conn->quote($class->discriminatorValue);
     } else {
         $discrMap = array_flip($class->discriminatorMap);
         if (!isset($discrMap[$entityClassName])) {
             throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName);
         }
         $sql .= $this->_conn->quote($discrMap[$entityClassName]);
     }
     return $sql;
 }