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


PHP SQLQuery::setLimit方法代码示例

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


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

示例1: testSelectWithLimitClause

 function testSelectWithLimitClause()
 {
     if (!(DB::getConn() instanceof MySQLDatabase || DB::getConn() instanceof SQLite3Database || DB::getConn() instanceof PostgreSQLDatabase)) {
         $this->markTestIncomplete();
     }
     $query = new SQLQuery();
     $query->setFrom("MyTable");
     $query->setLimit(99);
     $this->assertEquals("SELECT * FROM MyTable LIMIT 99", $query->sql());
     // array limit with start (MySQL specific)
     $query = new SQLQuery();
     $query->setFrom("MyTable");
     $query->setLimit(99, 97);
     $this->assertEquals("SELECT * FROM MyTable LIMIT 99 OFFSET 97", $query->sql());
 }
开发者ID:nzjoel,项目名称:sapphire,代码行数:15,代码来源:SQLQueryTest.php

示例2: Tags

 public function Tags()
 {
     $select = array('Title');
     $query = new SQLQuery($select, 'PostTag');
     $query->selectField('count(PostTag.ID)', 'Number');
     $query->selectField('PostTag.ID');
     $query->addInnerjoin('MicroPost_Tags', 'PostTag.ID = MicroPost_Tags.PostTagID');
     $date = date('Y-m-d H:i:s', strtotime('-1 month'));
     $query->addWhere("MicroPost_Tags.Tagged > '{$date}'");
     $query->addWhere('"PostTag"."Title" NOT LIKE \'SELF_TAG%\'');
     $query->addGroupBy('PostTag.ID');
     $query->setLimit(20);
     $rows = $query->execute();
     $tags = ArrayList::create();
     foreach ($rows as $row) {
         $data = new ArrayData($row);
         $data->Link = Controller::join_links(TimelineController::URL_SEGMENT, '?tags=' . urlencode($data->Title));
         $tags->push($data);
     }
     return $tags;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-microblog,代码行数:21,代码来源:TagsDashlet.php

示例3: limit

 /**
  * Set the limit of this query.
  * 
  * @param int $limit
  * @param int $offset
  */
 public function limit($limit, $offset = 0)
 {
     $this->query->setLimit($limit, $offset);
     return $this;
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:11,代码来源:DataQuery.php

示例4: Elements

 /**
  * Returns a number of topseller products.
  * 
  * @return ArrayList
  * 
  * @author Sebastian Diel <sdiel@pixeltricks.de>,
  *         Sascha Koehler <skoehler@pixeltricks.de>
  * @since 03.02.2015
  */
 public function Elements()
 {
     if (!$this->numberOfProductsToShow) {
         $this->numberOfProductsToShow = SilvercartTopsellerProductsWidget::$defaults['numberOfProductsToShow'];
     }
     $cachekey = 'TopsellerProducts' . $this->numberOfProductsToShow;
     $cache = SS_Cache::factory($cachekey);
     $cachedResult = $cache->load($cachekey);
     if ($cachedResult) {
         $result = unserialize($result);
     } else {
         $products = array();
         $sqlQuery = new SQLQuery();
         $sqlQuery->selectField('SOP.SilvercartProductID');
         $sqlQuery->selectField('SUM(SOP.Quantity) AS OrderedQuantity');
         $sqlQuery->addFrom('SilvercartOrderPosition SOP');
         $sqlQuery->addLeftJoin('SilvercartProduct', 'SP.ID = SOP.SilvercartProductID', 'SP');
         $sqlQuery->addWhere('SP.isActive = 1');
         $sqlQuery->addGroupBy('SOP.SilvercartProductID');
         $sqlQuery->addOrderBy('OrderedQuantity', 'DESC');
         $sqlQuery->setLimit($this->numberOfProductsToShow);
         $sqlResult = $sqlQuery->execute();
         foreach ($sqlResult as $row) {
             $product = DataObject::get_by_id('SilvercartProduct', $row['SilvercartProductID']);
             $product->addCartFormIdentifier = $this->ID . '_' . $product->ID;
             $products[] = $product;
         }
         $result = new ArrayList($products);
     }
     return $result;
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:40,代码来源:SilvercartTopsellerProductsWidget.php

示例5: testLimitSetFromClauseString

 /**
  * Test passing in a LIMIT with OFFSET clause string.
  */
 public function testLimitSetFromClauseString()
 {
     $query = new SQLQuery();
     $query->setSelect('*');
     $query->setFrom('"SQLQueryTest_DO"');
     $query->setLimit('20 OFFSET 10');
     $limit = $query->getLimit();
     $this->assertEquals(20, $limit['limit']);
     $this->assertEquals(10, $limit['start']);
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:13,代码来源:SQLQueryTest.php

示例6: getLocationSQLResultsByLatLong

 /**
  * Retrieves Locations by lat, long, distance, and optionally a limit.
  */
 public function getLocationSQLResultsByLatLong($lat = 37, $long = -122, $distance = 25, $limit = null)
 {
     //$data = DB::query('SELECT "ID" FROM "Marker" LIMIT 0 , '.$limit.';')->value();
     //$query = 'SELECT "ID", ( 3959 * acos( cos( radians('.$lat.') ) * cos( radians( Latitude ) ) * cos( radians( Longitude ) - radians('.$long.') ) + sin( radians('.$lat.') ) * sin( radians( Latitude ) ) ) ) AS "Distance" FROM "Marker" HAVING "Distance" < '.$distance.' ORDER BY "Distance" LIMIT 0 , '.$limit.';';
     $markerClass = StoreFinder::$MarkerClass;
     $sqlQuery = new SQLQuery();
     $sqlQuery->setFrom($markerClass);
     $sqlQuery->selectField('*');
     $sqlQuery->selectField('( 3959 * acos( cos( radians(' . $lat . ') ) * cos( radians( Latitude ) ) * cos( radians( Longitude ) - radians(' . $long . ') ) + sin( radians(' . $lat . ') ) * sin( radians( Latitude ) ) ) )', 'Distance');
     $sqlQuery->setHaving("Distance < " . $distance);
     $sqlQuery->setOrderBy('Distance');
     $sqlQuery->setLimit($limit);
     if ($markerClass != 'Marker') {
         $sqlQuery->addLeftJoin("Marker", 'Marker.ID = ' . $markerClass . '.ID');
     }
     $this->extraSQL($sqlQuery);
     // Execute and return a Query object
     $result = $sqlQuery->execute();
     return $result;
 }
开发者ID:helpfulrobot,项目名称:cbryer-silverstripe-google-store-finder,代码行数:23,代码来源:StoreFinder.php

示例7: queryList

 /**
  * Perform a search against the data table.
  *
  * @param array $where Array of strings to add into the WHERE clause
  * @param array $orderby Array of column as key, to direction as value to add into the ORDER BY clause
  * @param string|int $start Record to start at (for paging)
  * @param string|int $pageLength Number of results per page (for paging)
  * @param boolean $paged Paged results or not?
  * @return ArrayList|PaginatedList
  */
 protected function queryList($where = array(), $orderby = array(), $start, $pageLength, $paged = true)
 {
     $dataClass = $this->dataRecord->getDataClass();
     if (!$dataClass) {
         return new PaginatedList(new ArrayList());
     }
     $resultColumns = $this->dataRecord->getDataSingleton()->summaryFields();
     $resultColumns['ID'] = 'ID';
     $results = new ArrayList();
     $query = new SQLQuery();
     $query->setSelect($this->escapeSelect(array_keys($resultColumns)))->setFrom("\"{$dataClass}\"");
     $query->addWhere($where);
     $query->addOrderBy($orderby);
     $query->setConnective('AND');
     if ($paged) {
         $query->setLimit($pageLength, $start);
     }
     foreach ($query->execute() as $record) {
         $result = new $dataClass($record);
         $result->Columns = $this->Columns($result);
         // we attach Columns here so the template can loop through them on each result
         $results->push($result);
     }
     if ($paged) {
         $list = new PaginatedList($results);
         $list->setPageStart($start);
         $list->setPageLength($pageLength);
         $list->setTotalItems($query->unlimitedRowCount());
         $list->setLimitItems(false);
     } else {
         $list = $results;
     }
     return $list;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-registry,代码行数:44,代码来源:RegistryPage.php

示例8: testNegativeOffsetAndLimit

 /**
  * @expectedException InvalidArgumentException
  */
 public function testNegativeOffsetAndLimit()
 {
     $query = new SQLQuery();
     $query->setLimit(-10, -10);
 }
开发者ID:nomidi,项目名称:sapphire,代码行数:8,代码来源:SQLQueryTest.php

示例9: modify

 /**
  * @param \SQLQuery $query
  * @param array $data
  * @return \SQLQuery
  */
 public function modify(\SQLQuery $query, array $data, QueryBuilderInterface $queryBuilder)
 {
     $query->setLimit($this->getLimit());
     return $query;
 }
开发者ID:helpfulrobot,项目名称:heyday-silverstripe-querybuilder,代码行数:10,代码来源:PaginationQueryModifier.php


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