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


PHP SQLQuery::getOrderBy方法代码示例

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


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

示例1: ensureSelectContainsOrderbyColumns

 /**
  * Ensure that if a query has an order by clause, those columns are present in the select.
  * 
  * @param SQLQuery $query
  * @return null
  */
 protected function ensureSelectContainsOrderbyColumns($query, $originalSelect = array())
 {
     $tableClasses = ClassInfo::dataClassesFor($this->dataClass);
     $baseClass = array_shift($tableClasses);
     if ($orderby = $query->getOrderBy()) {
         $newOrderby = array();
         $i = 0;
         foreach ($orderby as $k => $dir) {
             $newOrderby[$k] = $dir;
             // don't touch functions in the ORDER BY or public function calls
             // selected as fields
             if (strpos($k, '(') !== false) {
                 continue;
             }
             $col = str_replace('"', '', trim($k));
             $parts = explode('.', $col);
             // Pull through SortColumn references from the originalSelect variables
             if (preg_match('/_SortColumn/', $col)) {
                 if (isset($originalSelect[$col])) {
                     $query->selectField($originalSelect[$col], $col);
                 }
                 continue;
             }
             if (count($parts) == 1) {
                 $databaseFields = DataObject::database_fields($baseClass);
                 // database_fields() doesn't return ID, so we need to
                 // manually add it here
                 $databaseFields['ID'] = true;
                 if (isset($databaseFields[$parts[0]])) {
                     $qualCol = "\"{$baseClass}\".\"{$parts[0]}\"";
                 } else {
                     $qualCol = "\"{$parts['0']}\"";
                 }
                 // remove original sort
                 unset($newOrderby[$k]);
                 // add new columns sort
                 $newOrderby[$qualCol] = $dir;
                 // To-do: Remove this if block once SQLQuery::$select has been refactored to store getSelect()
                 // format internally; then this check can be part of selectField()
                 $selects = $query->getSelect();
                 if (!isset($selects[$col]) && !in_array($qualCol, $selects)) {
                     $query->selectField($qualCol);
                 }
             } else {
                 $qualCol = '"' . implode('"."', $parts) . '"';
                 if (!in_array($qualCol, $query->getSelect())) {
                     unset($newOrderby[$k]);
                     $newOrderby["\"_SortColumn{$i}\""] = $dir;
                     $query->selectField($qualCol, "_SortColumn{$i}");
                     $i++;
                 }
             }
         }
         $query->setOrderBy($newOrderby);
     }
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:62,代码来源:DataQuery.php

示例2: ensureSelectContainsOrderbyColumns

	/**
	 * Ensure that if a query has an order by clause, those columns are present in the select.
	 * 
	 * @param SQLQuery $query
	 * @return null
	 */
	protected function ensureSelectContainsOrderbyColumns($query) {
		$tableClasses = ClassInfo::dataClassesFor($this->dataClass);
		$baseClass = array_shift($tableClasses);

		if($query->orderby) {
			$orderby = $query->getOrderBy();

			foreach($orderby as $k => $dir) {
				// don't touch functions in the ORDER BY or function calls 
				// selected as fields
				if(strpos($k, '(') !== false || preg_match('/_SortColumn/', $k)) 
					continue;
				
				$col = str_replace('"', '', trim($k));
				$parts = explode('.', $col);

				if(count($parts) == 1) {
					$databaseFields = DataObject::database_fields($baseClass);
	
					// database_fields() doesn't return ID, so we need to 
					// manually add it here
					$databaseFields['ID'] = true;
				
					if(isset($databaseFields[$parts[0]])) {
						$qualCol = "\"$baseClass\".\"{$parts[0]}\"";
						
						// remove original sort
						unset($orderby[$k]);
						
						// add new columns sort
						$orderby[$qualCol] = $dir;
							
					} else {
						$qualCol = "\"$parts[0]\"";
					}
					
					if(!isset($query->select[$col]) && !in_array($qualCol, $query->select)) {
						$query->select[] = $qualCol;
					}
				} else {
					$qualCol = '"' . implode('"."', $parts) . '"';
					
					if(!in_array($qualCol, $query->select)) {
						$query->select[] = $qualCol;
					}
				}
			}

			$query->orderby = $orderby;
		}
	}
开发者ID:redema,项目名称:sapphire,代码行数:57,代码来源:DataQuery.php

示例3: sqlQueryToString

 /**
  * Convert a SQLQuery object into a SQL statement
  * @param $query SQLQuery
  */
 public function sqlQueryToString(SQLQuery $query)
 {
     if ($query->getDelete()) {
         $text = 'DELETE ';
     } else {
         $text = $this->sqlSelectToString($query->getSelect(), $query->getDistinct());
     }
     if ($query->getFrom()) {
         $text .= $this->sqlFromToString($query->getFrom());
     }
     if ($query->getWhere()) {
         $text .= $this->sqlWhereToString($query->getWhere(), $query->getConnective());
     }
     // these clauses only make sense in SELECT queries, not DELETE
     if (!$query->getDelete()) {
         if ($query->getGroupBy()) {
             $text .= $this->sqlGroupByToString($query->getGroupBy());
         }
         if ($query->getHaving()) {
             $text .= $this->sqlHavingToString($query->getHaving());
         }
         if ($query->getOrderBy()) {
             $text .= $this->sqlOrderByToString($query->getOrderBy());
         }
         if ($query->getLimit()) {
             $text .= $this->sqlLimitToString($query->getLimit());
         }
     }
     return $text;
 }
开发者ID:nzjoel,项目名称:sapphire,代码行数:34,代码来源:Database.php

示例4: sqlQueryToString

 /**
  * Convert a SQLQuery object into a SQL statement
  * Caution: Expects correctly quoted and escaped SQL fragments.
  * 
  * @param $query SQLQuery
  */
 public function sqlQueryToString(SQLQuery $query)
 {
     if ($query->getDelete()) {
         //Appended space at the end of string causing an issue but this might not be the best solution
         //@see sqlSelectToString() sqlFromToString
         $text = 'DELETE';
     } else {
         if ($traverse = $query->getTraverse()) {
             //Build the traverse string here
             $text = $this->sqlTraverseToString($traverse);
         } else {
             $text = $this->sqlSelectToString($query->getSelect(), $query->getDistinct());
         }
     }
     if ($query->getFrom()) {
         $text .= $this->sqlFromToString($query->getFrom());
     }
     if ($query->getWhere()) {
         $text .= $this->sqlWhereToString($query->getWhere(), $query->getConnective());
     }
     // these clauses only make sense in SELECT queries, not DELETE
     if (!$query->getDelete()) {
         if ($query->getGroupBy()) {
             $text .= $this->sqlGroupByToString($query->getGroupBy());
         }
         if ($query->getHaving()) {
             $text .= $this->sqlHavingToString($query->getHaving());
         }
         if ($query->getOrderBy()) {
             $text .= $this->sqlOrderByToString($query->getOrderBy());
         }
         if ($query->getLimit()) {
             $text .= $this->sqlLimitToString($query->getLimit());
         }
     }
     // SS_Log::log(new Exception(print_r($text, true)), SS_Log::NOTICE);
     return $text;
 }
开发者ID:Cumquat,项目名称:silverstripe-orientdb-poc,代码行数:44,代码来源:OrientDatabase.php


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