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


PHP QueryBuilder::getConnection方法代码示例

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


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

示例1: run

 /**
  * @param QueryBuilder $queryBuilder
  * @param $callback
  * @param int|null $limit
  * @param int $maxAttempts
  * @throws DBALWalkerException
  * @throws DBALException
  */
 public function run(QueryBuilder $queryBuilder, $callback, $limit = null, $maxAttempts = 10)
 {
     if (!is_callable($callback)) {
         throw new DBALWalkerException('$callback is not callable');
     }
     if (!is_null($limit)) {
         $queryBuilder->setMaxResults($limit);
     } else {
         $limit = $queryBuilder->getMaxResults();
     }
     if (is_null($limit)) {
         $limit = PHP_INT_MAX;
     }
     $offset = 0;
     do {
         $rows = [];
         $errors = $maxAttempts;
         while (true) {
             try {
                 $rows = $queryBuilder->setFirstResult($offset)->execute()->fetchAll();
                 break;
             } catch (DBALException $e) {
                 if ($errors-- == 0) {
                     throw $e;
                 }
                 $queryBuilder->getConnection()->connect();
             }
         }
         call_user_func($callback, $rows, $offset, $limit);
         $offset += $limit;
     } while (count($rows) >= $limit);
 }
开发者ID:octava,项目名称:replication,代码行数:40,代码来源:Walker.php

示例2: incorporateDbalQueryBuilder

 /**
  * @internal
  */
 private function incorporateDbalQueryBuilder(QueryBuilder $qb, FilterInterface $filter)
 {
     $criteria = $this->getFilteringCriteria($filter);
     // extraindo os rootAliases, pois o DBAL\QueryBuilder não tem
     $fromPart = $qb->getQueryPart('from');
     $rootAliases = array();
     foreach ($fromPart as $part) {
         $rootAliases[] = $part['alias'];
     }
     $visitor = new DbalQueryExpressionVisitor($qb->getConnection(), $rootAliases, $this->fieldMap);
     if ($whereExpression = $criteria->getWhereExpression()) {
         $qb->andWhere($visitor->dispatch($whereExpression));
         $qb->setParameters($visitor->getParameters());
     }
     if ($criteria->getOrderings()) {
         foreach ($criteria->getOrderings() as $sort => $order) {
             $qb->addOrderBy($visitor->getFieldName($sort), $order);
         }
     }
     if (($firstResult = $criteria->getFirstResult()) !== null) {
         $qb->setFirstResult($firstResult);
     }
     if (($maxResults = $criteria->getMaxResults()) !== null) {
         $qb->setMaxResults($maxResults);
     }
 }
开发者ID:brodaproject,项目名称:broda,代码行数:29,代码来源:DbalQueryBuilderIncorporator.php

示例3: getPlatformGroupConcat

 /**
  * Get platform specific group_concat token for provided column
  *
  * @param string       $alias
  * @param QueryBuilder $query
  *
  * @return string
  */
 protected function getPlatformGroupConcat($alias, QueryBuilder $query)
 {
     $platform = $query->getConnection()->getDatabasePlatform()->getName();
     $field = $this->mapping['fieldname'];
     $dummy = 'f_' . $field;
     switch ($platform) {
         case 'mysql':
             return "GROUP_CONCAT(DISTINCT CONCAT_WS('_', " . $dummy . '.name, ' . $dummy . '.grouping, ' . $dummy . ".id)) as {$alias}";
         case 'sqlite':
             return 'GROUP_CONCAT(DISTINCT ' . $dummy . ".name||'_'||" . $dummy . ".grouping||'_'||" . $dummy . ".id) as {$alias}";
         case 'postgresql':
             return 'string_agg(DISTINCT ' . $dummy . ".name||'_'||" . $dummy . ".grouping||'_'||" . $dummy . ".id) as {$alias}";
     }
 }
开发者ID:robbert-vdh,项目名称:bolt,代码行数:22,代码来源:RepeaterType.php

示例4: getPlatformGroupConcat

 /**
  * Get platform specific group_concat token for provided column
  *
  * @param string       $column
  * @param string       $alias
  * @param QueryBuilder $query
  *
  * @return string
  */
 protected function getPlatformGroupConcat($column, $alias, QueryBuilder $query)
 {
     $platform = $query->getConnection()->getDatabasePlatform()->getName();
     switch ($platform) {
         case 'mysql':
             return "GROUP_CONCAT(DISTINCT {$column}) as {$alias}";
         case 'sqlite':
             return "GROUP_CONCAT(DISTINCT {$column}) as {$alias}";
         case 'postgresql':
             return "string_agg(distinct {$column}, ',') as {$alias}";
     }
 }
开发者ID:nuffer,项目名称:bolt,代码行数:21,代码来源:RelationType.php

示例5: make

 /**
  * @param array $request
  * @return array
  */
 public function make(array $request)
 {
     $output = ['data' => [], 'draw' => $request['draw'], 'recordsFiltered' => 0, 'recordsTotal' => 0];
     /**
      * Order By
      */
     if (isset($request['order'])) {
         for ($i = 0; $i < count($request['order']); ++$i) {
             $j = intval($request['order'][$i]['column']);
             if ($request['columns'][$j]['orderable'] != 'true') {
                 continue;
             }
             $column = $request['columns'][$j]['data'];
             $sort = $request['order'][$i]['dir'];
             $this->query->addOrderBy($column, $sort);
         }
     }
     /**
      * Count All
      */
     $temp = clone $this->query;
     $temp->resetQueryPart('select');
     $temp->resetQueryPart('orderBy');
     $temp->select("COUNT(*)");
     $output['recordsTotal'] = $temp->execute()->fetchColumn(0);
     /**
      * Filter
      */
     for ($i = 0; $i < count($request['columns']); ++$i) {
         if ($request['columns'][$i]['searchable'] != 'true') {
             continue;
         }
         $value = $request['columns'][$i]['search']['value'];
         if (strlen($value) > 0) {
             $column = $request['columns'][$i]['data'];
             $value = $this->query->getConnection()->quote("{$value}%");
             $this->query->andHaving($this->query->expr()->like($column, $value));
         }
     }
     /**
      * Search
      */
     if (isset($request['search'])) {
         $value = $request['search']['value'];
         if (strlen($value) > 0) {
             for ($i = 0; $i < count($request['columns']); ++$i) {
                 if ($request['columns'][$i]['searchable'] != 'true') {
                     continue;
                 }
                 $column = $request['columns'][$i]['data'];
                 $this->query->orHaving($this->query->expr()->like($column, ':search'));
             }
             $this->query->setParameter('search', "%{$value}%");
         }
     }
     /**
      * Count Filtered
      */
     $temp = clone $this->query;
     $temp->resetQueryPart('orderBy');
     $output['recordsFiltered'] = $temp->execute()->rowCount();
     /**
      * Limit
      */
     if (isset($request['start'])) {
         $this->query->setFirstResult($request['start']);
     }
     if (isset($request['length'])) {
         $this->query->setMaxResults($request['length']);
     }
     /**
      * Fetch Results
      */
     $output['data'] = $this->query->execute()->fetchAll(\PDO::FETCH_ASSOC);
     /**
      * Add Filter
      */
     return $output;
 }
开发者ID:vaibhavpandeyvpz,项目名称:acraviz,代码行数:83,代码来源:Datatables.php

示例6: testGetConnection

 public function testGetConnection()
 {
     $qb = new QueryBuilder($this->conn);
     $this->assertSame($this->conn, $qb->getConnection());
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:5,代码来源:QueryBuilderTest.php

示例7: getPlatformGroupConcat

 /**
  * Get platform specific group_concat token for provided column
  *
  * @param string       $alias
  * @param QueryBuilder $query
  *
  * @return string
  */
 protected function getPlatformGroupConcat($alias, QueryBuilder $query)
 {
     $platform = $query->getConnection()->getDatabasePlatform()->getName();
     switch ($platform) {
         case 'mysql':
             return "GROUP_CONCAT(DISTINCT CONCAT_WS('_', f.name, f.grouping, f.id)) as {$alias}";
         case 'sqlite':
             return "GROUP_CONCAT(DISTINCT f.name||'_'||f.grouping||'_'||f.id) as {$alias}";
         case 'postgresql':
             return "string_agg(DISTINCT f.name||'_'||f.grouping||'_'||f.id) as {$alias}";
     }
 }
开发者ID:MenZil-Team,项目名称:bolt,代码行数:20,代码来源:RepeaterType.php

示例8: getConnection

 /**
  * Gets the associated DBAL Connection for this query builder.
  *
  * @return \Doctrine\DBAL\Connection
  */
 public function getConnection()
 {
     return $this->qb->getConnection();
 }
开发者ID:Maksold,项目名称:platform,代码行数:9,代码来源:SqlQueryBuilder.php

示例9: getPlatformGroupConcat

 /**
  * Get platform specific group_concat token for provided column.
  *
  * @param string       $column
  * @param string       $order
  * @param string       $alias
  * @param QueryBuilder $query
  *
  * @return string
  */
 protected function getPlatformGroupConcat($column, $order, $alias, QueryBuilder $query)
 {
     $platform = $query->getConnection()->getDatabasePlatform()->getName();
     switch ($platform) {
         case 'mysql':
             return "GROUP_CONCAT({$column} ORDER BY {$order} ASC) as {$alias}";
         case 'sqlite':
             return "GROUP_CONCAT({$column}) as {$alias}";
         case 'postgresql':
             return "string_agg({$column}" . "::character varying, ',' ORDER BY {$order}) as {$alias}";
     }
 }
开发者ID:bolt,项目名称:bolt,代码行数:22,代码来源:TaxonomyType.php

示例10: __construct

 /**
  * @param QueryBuilder $queryBuilder
  */
 public function __construct(QueryBuilder $queryBuilder)
 {
     $this->connection = $queryBuilder->getConnection();
     $this->queryBuilder = $queryBuilder;
 }
开发者ID:alexdpy,项目名称:acl,代码行数:8,代码来源:DoctrineDbalAclFilter.php

示例11: setLastInsertId

 /**
  * @TODO Temporary workaround for PostgreSQL databases that don't use a sequence.
  *
  * @param QueryBuilder $query
  */
 private function setLastInsertId(QueryBuilder $query)
 {
     $seq = null;
     if ($query->getConnection()->getDatabasePlatform()->getName() === 'postgresql') {
         $sequences = $query->getConnection()->getSchemaManager()->listSequences();
         $desiredSeq = $query->getQueryPart('from')['table'] . '_id_seq';
         foreach ($sequences as $sequence) {
             if ($desiredSeq === $sequence->getName()) {
                 $seq = $desiredSeq;
                 break;
             }
         }
     }
     $this->lastInsertId = $query->getConnection()->lastInsertId($seq);
 }
开发者ID:gandalf3,项目名称:bolt,代码行数:20,代码来源:QuerySet.php

示例12: fetchCollection

 /**
  * @param QueryBuilder $builder
  * @param string       $class
  * @param int          $limit
  * @param int          $offset
  *
  * @return array
  */
 protected function fetchCollection(QueryBuilder $builder, $class, $limit, $offset)
 {
     $statement = $builder->execute();
     $statement->setFetchMode(PDOConnection::FETCH_ASSOC);
     $platform = $builder->getConnection()->getDatabasePlatform();
     $types = $this->getModelSchemes()->getAttributeTypeInstances($class);
     $models = [];
     while (($attributes = $statement->fetch()) !== false) {
         $models[] = $this->readInstanceFromAssoc($class, $attributes, $types, $platform);
     }
     return $this->normalizePagingParams($models, $limit, $offset);
 }
开发者ID:limoncello-php,项目名称:json-api,代码行数:20,代码来源:Crud.php


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