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


PHP Query::decorateResults方法代码示例

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


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

示例1: testDecorateResults

 /**
  * Tests stacking decorators for results and resetting the list of decorators
  *
  * @return void
  */
 public function testDecorateResults()
 {
     $query = new Query($this->connection);
     $result = $query->select(['id', 'title'])->from('articles')->order(['id' => 'ASC'])->decorateResults(function ($row) {
         $row['modified_id'] = $row['id'] + 1;
         return $row;
     })->execute();
     while ($row = $result->fetch('assoc')) {
         $this->assertEquals($row['id'] + 1, $row['modified_id']);
     }
     $result = $query->decorateResults(function ($row) {
         $row['modified_id']--;
         return $row;
     })->execute();
     while ($row = $result->fetch('assoc')) {
         $this->assertEquals($row['id'], $row['modified_id']);
     }
     $result = $query->decorateResults(function ($row) {
         $row['foo'] = 'bar';
         return $row;
     }, true)->execute();
     while ($row = $result->fetch('assoc')) {
         $this->assertEquals('bar', $row['foo']);
         $this->assertArrayNotHasKey('modified_id', $row);
     }
     $results = $query->decorateResults(null, true)->execute();
     while ($row = $result->fetch('assoc')) {
         $this->assertArrayNotHasKey('foo', $row);
         $this->assertArrayNotHasKey('modified_id', $row);
     }
 }
开发者ID:KarimaLadhani,项目名称:cakephp,代码行数:36,代码来源:QueryTest.php

示例2: _pagingSubquery

 /**
  * Generate a paging subquery for older versions of Oracle Server.
  *
  * Prior to Oracle 12 there was no equivalent to LIMIT OFFSET,
  * so a subquery must be used.
  *
  * @param \Cake\Database\Query $original The query to wrap in a subquery.
  * @param int $limit The number of rows to fetch.
  * @param int $offset The number of rows to offset.
  * @return \Cake\Database\Query Modified query object.
  */
 protected function _pagingSubquery($original, $limit, $offset)
 {
     $field = 'cake_paging_out."_cake_page_rownum_"';
     $query = clone $original;
     $query->limit(null)->offset(null);
     $outer = new Query($query->connection());
     $outer->select(['cake_paging.*', '_cake_page_rownum_' => new SimpleExpression('ROWNUM')])->from(['cake_paging' => $query]);
     $outer2 = new Query($query->connection());
     $outer2->select('*')->from(['cake_paging_out' => $outer]);
     if ($offset) {
         $outer2->where(["{$field} > " . (int) $offset]);
     }
     if ($limit) {
         $value = (int) $offset + (int) $limit;
         $outer2->where(["{$field} <= {$value}"]);
     }
     $original->decorateResults(function ($row) {
         if (isset($row['_cake_page_rownum_'])) {
             unset($row['_cake_page_rownum_']);
         }
         return $row;
     });
     return $outer2;
 }
开发者ID:cakedc,项目名称:cakephp-oracle-driver,代码行数:35,代码来源:OracleDialectTrait.php

示例3: _transformDistinct

 /**
  * Returns the passed query after rewriting the DISTINCT clause, so that drivers
  * that do not support the "ON" part can provide the actual way it should be done
  *
  * @param \Cake\Database\Query $original The query to be transformed
  * @return \Cake\Database\Query
  */
 protected function _transformDistinct($original)
 {
     if (!is_array($original->clause('distinct'))) {
         return $original;
     }
     $query = clone $original;
     $distinct = $query->clause('distinct');
     $query->distinct(false);
     $order = new OrderByExpression($distinct);
     $query->select(function ($q) use($distinct, $order) {
         $over = $q->newExpr('ROW_NUMBER() OVER')->add('(PARTITION BY')->add($q->newExpr()->add($distinct)->tieWith(','))->add($order)->add(')')->tieWith(' ');
         return ['_cake_distinct_pivot_' => $over];
     })->limit(null)->offset(null)->order([], true);
     $outer = new Query($query->connection());
     $outer->select('*')->from(['_cake_distinct_' => $query])->where(['_cake_distinct_pivot_' => 1]);
     // Decorate the original query as that is what the
     // end developer will be calling execute() on originally.
     $original->decorateResults(function ($row) {
         if (isset($row['_cake_distinct_pivot_'])) {
             unset($row['_cake_distinct_pivot_']);
         }
         return $row;
     });
     return $outer;
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:32,代码来源:SqlserverDialectTrait.php

示例4: _pagingSubquery

 /**
  * Generate a paging subquery for older versions of SQLserver.
  *
  * Prior to SQLServer 2012 there was no equivalent to LIMIT OFFSET, so a subquery must
  * be used.
  *
  * @param \Cake\Database\Query $original The query to wrap in a subquery.
  * @param int $limit The number of rows to fetch.
  * @param int $offset The number of rows to offset.
  * @return \Cake\Database\Query Modified query object.
  */
 protected function _pagingSubquery($original, $limit, $offset)
 {
     $field = '_cake_paging_._cake_page_rownum_';
     $query = clone $original;
     $order = $query->clause('order') ?: new OrderByExpression('NULL');
     $query->select(['_cake_page_rownum_' => new UnaryExpression('ROW_NUMBER() OVER', $order)])->limit(null)->offset(null)->order([], true);
     $outer = new Query($query->connection());
     $outer->select('*')->from(['_cake_paging_' => $query]);
     if ($offset) {
         $outer->where(["{$field} >" => $offset]);
     }
     if ($limit) {
         $outer->where(["{$field} <=" => (int) $offset + (int) $limit]);
     }
     // Decorate the original query as that is what the
     // end developer will be calling execute() on originally.
     $original->decorateResults(function ($row) {
         if (isset($row['_cake_page_rownum_'])) {
             unset($row['_cake_page_rownum_']);
         }
         return $row;
     });
     return $outer;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:35,代码来源:SqlserverDialectTrait.php


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