当前位置: 首页>>代码示例>>PHP>>正文


PHP SqlWalker::walkSelectStatement方法代码示例

本文整理汇总了PHP中Doctrine\ORM\Query\SqlWalker::walkSelectStatement方法的典型用法代码示例。如果您正苦于以下问题:PHP SqlWalker::walkSelectStatement方法的具体用法?PHP SqlWalker::walkSelectStatement怎么用?PHP SqlWalker::walkSelectStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\Query\SqlWalker的用法示例。


在下文中一共展示了SqlWalker::walkSelectStatement方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: walkSelectStatement

 /**
  * Walks down a SelectStatement AST node, wrapping it in a COUNT (SELECT DISTINCT)
  *
  * Note that the ORDER BY clause is not removed. Many SQL implementations (e.g. MySQL)
  * are able to cache subqueries. By keeping the ORDER BY clause intact, the limitSubQuery
  * that will most likely be executed next can be read from the native SQL cache.
  *
  * @param SelectStatement $AST
  * @return string
  */
 public function walkSelectStatement(SelectStatement $AST)
 {
     $sql = parent::walkSelectStatement($AST);
     // Find out the SQL alias of the identifier column of the root entity
     // It may be possible to make this work with multiple root entities but that
     // would probably require issuing multiple queries or doing a UNION SELECT
     // so for now, It's not supported.
     // Get the root entity and alias from the AST fromClause
     $from = $AST->fromClause->identificationVariableDeclarations;
     if (count($from) > 1) {
         throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
     }
     $rootClass = $from[0]->rangeVariableDeclaration->abstractSchemaName;
     $rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable;
     // Get the identity properties from the metadata
     $rootIdentifier = $this->queryComponents[$rootAlias]['metadata']->identifier;
     // For every identifier, find out the SQL alias by combing through the ResultSetMapping
     $sqlIdentifier = array();
     foreach ($rootIdentifier as $property) {
         foreach (array_keys($this->rsm->fieldMappings, $property) as $alias) {
             if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) {
                 $sqlIdentifier[$property] = $alias;
             }
         }
     }
     if (count($rootIdentifier) != count($sqlIdentifier)) {
         throw new \RuntimeException(sprintf('Not all identifier properties can be found in the ResultSetMapping: %s', implode(', ', array_diff($rootIdentifier, array_keys($sqlIdentifier)))));
     }
     // Build the counter query
     return sprintf('SELECT %s AS _dctrn_count FROM (SELECT DISTINCT %s FROM (%s) AS _dctrn_result) AS _dctrn_table', $this->platform->getCountExpression('*'), implode(', ', $sqlIdentifier), $sql);
 }
开发者ID:davidbui2,项目名称:doctrine2,代码行数:41,代码来源:CountOutputWalker.php

示例2: walkSelectStatement

 /**
  * Walks down a SelectStatement AST node, wrapping it in a SELECT DISTINCT
  *
  * @param SelectStatement $AST
  * @return string
  */
 public function walkSelectStatement(SelectStatement $AST)
 {
     $innerSql = parent::walkSelectStatement($AST);
     // Find out the SQL alias of the identifier column of the root entity
     // It may be possible to make this work with multiple root entities but that
     // would probably require issuing multiple queries or doing a UNION SELECT
     // so for now, It's not supported.
     // Get the root entity and alias from the AST fromClause
     $from = $AST->fromClause->identificationVariableDeclarations;
     if (count($from) !== 1) {
         throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
     }
     $rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable;
     $rootClass = $this->queryComponents[$rootAlias]['metadata'];
     $rootIdentifier = $rootClass->identifier;
     // For every identifier, find out the SQL alias by combing through the ResultSetMapping
     $sqlIdentifier = array();
     foreach ($rootIdentifier as $property) {
         if (isset($rootClass->fieldMappings[$property])) {
             foreach (array_keys($this->rsm->fieldMappings, $property) as $alias) {
                 if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) {
                     $sqlIdentifier[$property] = $alias;
                 }
             }
         }
         if (isset($rootClass->associationMappings[$property])) {
             $joinColumn = $rootClass->associationMappings[$property]['joinColumns'][0]['name'];
             foreach (array_keys($this->rsm->metaMappings, $joinColumn) as $alias) {
                 if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) {
                     $sqlIdentifier[$property] = $alias;
                 }
             }
         }
     }
     if (count($rootIdentifier) != count($sqlIdentifier)) {
         throw new \RuntimeException(sprintf('Not all identifier properties can be found in the ResultSetMapping: %s', implode(', ', array_diff($rootIdentifier, array_keys($sqlIdentifier)))));
     }
     // Build the counter query
     $sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', implode(', ', $sqlIdentifier), $innerSql);
     if ($this->platform instanceof PostgreSqlPlatform) {
         //http://www.doctrine-project.org/jira/browse/DDC-1958
         $this->getPostgresqlSql($AST, $sqlIdentifier, $innerSql, $sql);
     }
     // Apply the limit and offset
     $sql = $this->platform->modifyLimitQuery($sql, $this->maxResults, $this->firstResult);
     // Add the columns to the ResultSetMapping. It's not really nice but
     // it works. Preferably I'd clear the RSM or simply create a new one
     // but that is not possible from inside the output walker, so we dirty
     // up the one we have.
     foreach ($sqlIdentifier as $property => $alias) {
         $this->rsm->addScalarResult($alias, $property);
     }
     return $sql;
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:60,代码来源:LimitSubqueryOutputWalker.php

示例3: walkSelectStatement

 /**
  * {@inheritDoc}
  */
 public function walkSelectStatement(SelectStatement $AST)
 {
     $result = parent::walkSelectStatement($AST);
     if (!count($this->translatedComponents)) {
         return $result;
     }
     $hydrationMode = $this->getQuery()->getHydrationMode();
     if ($hydrationMode === Query::HYDRATE_OBJECT) {
         $this->getQuery()->setHydrationMode(self::HYDRATE_OBJECT_TRANSLATION);
         $this->getEntityManager()->getConfiguration()->addCustomHydrationMode(self::HYDRATE_OBJECT_TRANSLATION, 'Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator');
         $this->getQuery()->setHint(Query::HINT_REFRESH, true);
     } elseif ($hydrationMode === Query::HYDRATE_SIMPLEOBJECT) {
         $this->getQuery()->setHydrationMode(self::HYDRATE_SIMPLE_OBJECT_TRANSLATION);
         $this->getEntityManager()->getConfiguration()->addCustomHydrationMode(self::HYDRATE_SIMPLE_OBJECT_TRANSLATION, 'Gedmo\\Translatable\\Hydrator\\ORM\\SimpleObjectHydrator');
         $this->getQuery()->setHint(Query::HINT_REFRESH, true);
     }
     return $result;
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:21,代码来源:TranslationWalker.php

示例4: __construct

 public function __construct(SelectStatement $AST, SqlWalker $sqlWalker)
 {
     $this->_sqlStatements = $sqlWalker->walkSelectStatement($AST);
 }
开发者ID:relo-san,项目名称:doctrine2,代码行数:4,代码来源:SingleSelectExecutor.php

示例5: walkSelectStatement

 public function walkSelectStatement(Query\AST\SelectStatement $selectStatement)
 {
     parent::walkSelectStatement($selectStatement);
     $this->setQueryComponent('x', array());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:5,代码来源:CustomTreeWalkersTest.php

示例6: getInnerSQL

 /**
  * @param SelectStatement $AST
  *
  * @return string
  *
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\Query\QueryException
  */
 private function getInnerSQL(SelectStatement $AST)
 {
     // Set every select expression as visible(hidden = false) to
     // make $AST have scalar mappings properly - this is relevant for referencing selected
     // fields from outside the subquery, for example in the ORDER BY segment
     $hiddens = [];
     foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
         $hiddens[$idx] = $expr->hiddenAliasResultVariable;
         $expr->hiddenAliasResultVariable = false;
     }
     $innerSql = parent::walkSelectStatement($AST);
     // Restore hiddens
     foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
         $expr->hiddenAliasResultVariable = $hiddens[$idx];
     }
     return $innerSql;
 }
开发者ID:AlexanderForks,项目名称:doctrine2,代码行数:25,代码来源:LimitSubqueryOutputWalker.php

示例7: walkSelectStatement

 /**
  * {@inheritDoc}
  */
 public function walkSelectStatement(SelectStatement $AST)
 {
     $result = parent::walkSelectStatement($AST);
     if (!count($this->translatedComponents)) {
         return $result;
     }
     $hydrationMode = $this->getQuery()->getHydrationMode();
     if ($this->needsFallback()) {
         // in case if fallback is used and hydration is array, it needs custom hydrator
         if ($hydrationMode === Query::HYDRATE_ARRAY) {
             $this->getQuery()->setHydrationMode(self::HYDRATE_ARRAY_TRANSLATION);
             $this->getEntityManager()->getConfiguration()->addCustomHydrationMode(self::HYDRATE_ARRAY_TRANSLATION, 'Gedmo\\Translatable\\Hydrator\\ORM\\ArrayHydrator');
         }
     }
     $this->getQuery()->setHint(self::HINT_TRANSLATION_LISTENER, $this->listener);
     if ($hydrationMode === Query::HYDRATE_OBJECT) {
         $this->getQuery()->setHydrationMode(self::HYDRATE_OBJECT_TRANSLATION);
         $this->getEntityManager()->getConfiguration()->addCustomHydrationMode(self::HYDRATE_OBJECT_TRANSLATION, 'Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator');
         $this->getQuery()->setHint(Query::HINT_REFRESH, true);
     } elseif ($hydrationMode === Query::HYDRATE_SIMPLEOBJECT) {
         $this->getQuery()->setHydrationMode(self::HYDRATE_SIMPLE_OBJECT_TRANSLATION);
         $this->getEntityManager()->getConfiguration()->addCustomHydrationMode(self::HYDRATE_SIMPLE_OBJECT_TRANSLATION, 'Gedmo\\Translatable\\Hydrator\\ORM\\SimpleObjectHydrator');
         $this->getQuery()->setHint(Query::HINT_REFRESH, true);
     }
     return $result;
 }
开发者ID:rdohms,项目名称:DoctrineExtensions,代码行数:29,代码来源:TranslationWalker.php

示例8: walkSelectStatement

 /**
  * Walks down a SelectStatement AST node, wrapping it in a SELECT DISTINCT.
  *
  * @param SelectStatement $AST
  * @param bool $addMissingItemsFromOrderByToSelect
  *
  * @return string
  *
  * @throws \RuntimeException
  */
 public function walkSelectStatement(SelectStatement $AST, $addMissingItemsFromOrderByToSelect = true)
 {
     // We don't want to call this recursively!
     if ($AST->orderByClause instanceof OrderByClause && $addMissingItemsFromOrderByToSelect) {
         // In the case of ordering a query by columns from joined tables, we
         // must add those columns to the select clause of the query BEFORE
         // the SQL is generated.
         $this->addMissingItemsFromOrderByToSelect($AST);
     }
     // Remove order by clause from the inner query
     // It will be re-appended in the outer select generated by this method
     $orderByClause = $AST->orderByClause;
     $AST->orderByClause = null;
     // Set every select expression as visible(hidden = false) to
     // make $AST have scalar mappings properly - this is relevant for referencing selected
     // fields from outside the subquery, for example in the ORDER BY segment
     $hiddens = array();
     foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
         $hiddens[$idx] = $expr->hiddenAliasResultVariable;
         $expr->hiddenAliasResultVariable = false;
     }
     $innerSql = parent::walkSelectStatement($AST);
     // Restore orderByClause
     $AST->orderByClause = $orderByClause;
     // Restore hiddens
     foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
         $expr->hiddenAliasResultVariable = $hiddens[$idx];
     }
     // Find out the SQL alias of the identifier column of the root entity.
     // It may be possible to make this work with multiple root entities but that
     // would probably require issuing multiple queries or doing a UNION SELECT.
     // So for now, it's not supported.
     // Get the root entity and alias from the AST fromClause.
     $from = $AST->fromClause->identificationVariableDeclarations;
     if (count($from) !== 1) {
         throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
     }
     $fromRoot = reset($from);
     $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable;
     $rootClass = $this->queryComponents[$rootAlias]['metadata'];
     $rootIdentifier = $rootClass->identifier;
     // For every identifier, find out the SQL alias by combing through the ResultSetMapping
     $sqlIdentifier = array();
     foreach ($rootIdentifier as $property) {
         if (isset($rootClass->fieldMappings[$property])) {
             foreach (array_keys($this->rsm->fieldMappings, $property) as $alias) {
                 if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) {
                     $sqlIdentifier[$property] = $alias;
                 }
             }
         }
         if (isset($rootClass->associationMappings[$property])) {
             $joinColumn = $rootClass->associationMappings[$property]['joinColumns'][0]['name'];
             foreach (array_keys($this->rsm->metaMappings, $joinColumn) as $alias) {
                 if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) {
                     $sqlIdentifier[$property] = $alias;
                 }
             }
         }
     }
     if (count($sqlIdentifier) === 0) {
         throw new \RuntimeException('The Paginator does not support Queries which only yield ScalarResults.');
     }
     if (count($rootIdentifier) != count($sqlIdentifier)) {
         throw new \RuntimeException(sprintf('Not all identifier properties can be found in the ResultSetMapping: %s', implode(', ', array_diff($rootIdentifier, array_keys($sqlIdentifier)))));
     }
     // Build the counter query
     $sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', implode(', ', $sqlIdentifier), $innerSql);
     // http://www.doctrine-project.org/jira/browse/DDC-1958
     $sql = $this->preserveSqlOrdering($sqlIdentifier, $innerSql, $sql, $orderByClause);
     // Apply the limit and offset.
     $sql = $this->platform->modifyLimitQuery($sql, $this->maxResults, $this->firstResult);
     // Add the columns to the ResultSetMapping. It's not really nice but
     // it works. Preferably I'd clear the RSM or simply create a new one
     // but that is not possible from inside the output walker, so we dirty
     // up the one we have.
     foreach ($sqlIdentifier as $property => $alias) {
         $this->rsm->addScalarResult($alias, $property);
     }
     return $sql;
 }
开发者ID:ismael-rivera,项目名称:project-manati,代码行数:91,代码来源:LimitSubqueryOutputWalker.php


注:本文中的Doctrine\ORM\Query\SqlWalker::walkSelectStatement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。