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


PHP SQLSelect::addFrom方法代码示例

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


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

示例1: testSelectWithOrderbyClause

 public function testSelectWithOrderbyClause()
 {
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->setOrderBy('MyName');
     $this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName ASC', $query->sql($parameters));
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->setOrderBy('MyName desc');
     $this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName DESC', $query->sql($parameters));
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->setOrderBy('MyName ASC, Color DESC');
     $this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName ASC, Color DESC', $query->sql($parameters));
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->setOrderBy('MyName ASC, Color');
     $this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName ASC, Color ASC', $query->sql($parameters));
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->setOrderBy(array('MyName' => 'desc'));
     $this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName DESC', $query->sql($parameters));
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->setOrderBy(array('MyName' => 'desc', 'Color'));
     $this->assertSQLEquals('SELECT * FROM MyTable ORDER BY MyName DESC, Color ASC', $query->sql($parameters));
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->setOrderBy('implode("MyName","Color")');
     $this->assertSQLEquals('SELECT *, implode("MyName","Color") AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" ASC', $query->sql($parameters));
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->setOrderBy('implode("MyName","Color") DESC');
     $this->assertSQLEquals('SELECT *, implode("MyName","Color") AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" DESC', $query->sql($parameters));
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->setOrderBy('RAND()');
     $this->assertSQLEquals('SELECT *, RAND() AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" ASC', $query->sql($parameters));
     $query = new SQLSelect();
     $query->setFrom("MyTable");
     $query->addFrom('INNER JOIN SecondTable USING (ID)');
     $query->addFrom('INNER JOIN ThirdTable USING (ID)');
     $query->setOrderBy('MyName');
     $this->assertSQLEquals('SELECT * FROM MyTable ' . 'INNER JOIN SecondTable USING (ID) ' . 'INNER JOIN ThirdTable USING (ID) ' . 'ORDER BY MyName ASC', $query->sql($parameters));
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:45,代码来源:SQLSelectTest.php

示例2: unlimitedRowCount

 /**
  * Return the number of rows in this query if the limit were removed.  Useful in paged data sets.
  *
  * @param string $column
  * @return int
  */
 public function unlimitedRowCount($column = null)
 {
     // we can't clear the select if we're relying on its output by a HAVING clause
     if (count($this->having)) {
         $records = $this->execute();
         return $records->numRecords();
     }
     $clone = clone $this;
     $clone->limit = null;
     $clone->orderby = null;
     // Choose a default column
     if ($column == null) {
         if ($this->groupby) {
             // @todo Test case required here
             $countQuery = new SQLSelect();
             $countQuery->select("count(*)");
             $countQuery->addFrom(array('(' . $clone->sql($innerParameters) . ') all_distinct'));
             $sql = $countQuery->sql($parameters);
             // $parameters should be empty
             $result = DB::prepared_query($sql, $innerParameters);
             return $result->value();
         } else {
             $clone->setSelect(array("count(*)"));
         }
     } else {
         $clone->setSelect(array("count({$column})"));
     }
     $clone->setGroupBy(array());
     return $clone->execute()->value();
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:36,代码来源:SQLSelect.php


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