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


PHP SQLQuery::getFilter方法代码示例

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


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

示例1: sqlQueryToString

 /**
  * Convert a SQLQuery object into a SQL statement.
  */
 public function sqlQueryToString(SQLQuery $sqlQuery)
 {
     if (!$sqlQuery->from) {
         return '';
     }
     if ($sqlQuery->orderby && strtoupper(trim($sqlQuery->orderby)) == 'RAND()') {
         $sqlQuery->orderby = "NEWID()";
     }
     //Get the limit and offset
     $limit = '';
     $offset = '0';
     if (is_array($sqlQuery->limit)) {
         $limit = $sqlQuery->limit['limit'];
         if (isset($sqlQuery->limit['start'])) {
             $offset = $sqlQuery->limit['start'];
         }
     } else {
         if (preg_match('/^([0-9]+) offset ([0-9]+)$/i', trim($sqlQuery->limit), $matches)) {
             $limit = $matches[1];
             $offset = $matches[2];
         } else {
             //could be a comma delimited string
             $bits = explode(',', $sqlQuery->limit);
             if (sizeof($bits) > 1) {
                 list($offset, $limit) = $bits;
             } else {
                 $limit = $bits[0];
             }
         }
     }
     $text = '';
     $suffixText = '';
     $nestedQuery = false;
     // DELETE queries
     if ($sqlQuery->delete) {
         $text = 'DELETE ';
         // SELECT queries
     } else {
         $distinct = $sqlQuery->distinct ? "DISTINCT " : "";
         // If there's a limit but no offset, just use 'TOP X'
         // rather than the more complex sub-select method
         if ($limit != 0 && $offset == 0) {
             $text = "SELECT {$distinct} TOP {$limit}";
             // If there's a limit and an offset, then we need to do a subselect
         } else {
             if ($limit && $offset) {
                 if ($sqlQuery->orderby) {
                     $rowNumber = "ROW_NUMBER() OVER (ORDER BY {$sqlQuery->orderby}) AS Number";
                 } else {
                     $firstCol = reset($sqlQuery->select);
                     $rowNumber = "ROW_NUMBER() OVER (ORDER BY {$firstCol}) AS Number";
                 }
                 $text = "SELECT * FROM ( SELECT {$distinct}{$rowNumber}, ";
                 $suffixText .= ") AS Numbered WHERE Number BETWEEN " . ($offset + 1) . " AND " . ($offset + $limit) . " ORDER BY Number";
                 $nestedQuery = true;
                 // Otherwise a simple query
             } else {
                 $text = "SELECT {$distinct}";
             }
         }
         // Now add the columns to be selected
         $text .= implode(", ", $sqlQuery->select);
     }
     $text .= " FROM " . implode(" ", $sqlQuery->from);
     if ($sqlQuery->where) {
         $text .= " WHERE (" . $sqlQuery->getFilter() . ")";
     }
     if ($sqlQuery->groupby) {
         $text .= " GROUP BY " . implode(", ", $sqlQuery->groupby);
     }
     if ($sqlQuery->having) {
         $text .= " HAVING ( " . implode(" ) AND ( ", $sqlQuery->having) . " )";
     }
     if (!$nestedQuery && $sqlQuery->orderby) {
         $text .= " ORDER BY " . $sqlQuery->orderby;
     }
     // $suffixText is used by the nested queries to create an offset limit
     if ($suffixText) {
         $text .= $suffixText;
     }
     return $text;
 }
开发者ID:natmchugh,项目名称:silverstripe-mssql,代码行数:85,代码来源:MSSQLDatabase.php

示例2: sqlQueryToString

 /**
  * Convert a SQLQuery object into a SQL statement
  */
 public function sqlQueryToString(SQLQuery $sqlQuery)
 {
     $distinct = $sqlQuery->distinct ? "DISTINCT " : "";
     if ($sqlQuery->delete) {
         $text = "DELETE ";
     } else {
         if ($sqlQuery->select) {
             $text = "SELECT {$distinct}" . implode(", ", $sqlQuery->select);
         }
     }
     if ($sqlQuery->from) {
         $text .= " FROM " . implode(" ", $sqlQuery->from);
     }
     if ($sqlQuery->where) {
         $text .= " WHERE (" . $sqlQuery->getFilter() . ")";
     }
     if ($sqlQuery->groupby) {
         $text .= " GROUP BY " . implode(", ", $sqlQuery->groupby);
     }
     if ($sqlQuery->having) {
         $text .= " HAVING ( " . implode(" ) AND ( ", $sqlQuery->having) . " )";
     }
     if ($sqlQuery->orderby) {
         $text .= " ORDER BY " . $sqlQuery->orderby;
     }
     if ($sqlQuery->limit) {
         $limit = $sqlQuery->limit;
         // Pass limit as array or SQL string value
         if (is_array($limit)) {
             if (!array_key_exists('limit', $limit)) {
                 throw new InvalidArgumentException('SQLQuery::limit(): Wrong format for $limit: ' . var_export($limit, true));
             }
             if (isset($limit['start']) && is_numeric($limit['start']) && isset($limit['limit']) && is_numeric($limit['limit'])) {
                 $combinedLimit = $limit['start'] ? "{$limit['limit']} OFFSET {$limit['start']}" : "{$limit['limit']}";
             } elseif (isset($limit['limit']) && is_numeric($limit['limit'])) {
                 $combinedLimit = (int) $limit['limit'];
             } else {
                 $combinedLimit = false;
             }
             if (!empty($combinedLimit)) {
                 $text .= " LIMIT " . $combinedLimit;
             }
         } else {
             $text .= " LIMIT " . $sqlQuery->limit;
         }
     }
     return $text;
 }
开发者ID:,项目名称:,代码行数:51,代码来源:

示例3: augmentSQL

 /**
  * Changes any SELECT query thats not filtering on an ID
  * to limit by the current language defined in {@link get_current_locale()}.
  * It falls back to "Locale='' OR Lang IS NULL" and assumes that
  * this implies querying for the default language.
  * 
  * Use {@link disable_locale_filter()} to temporarily disable this "auto-filtering".
  */
 function augmentSQL(SQLQuery &$query)
 {
     // If the record is saved (and not a singleton), and has a locale,
     // limit the current call to its locale. This fixes a lot of problems
     // with other extensions like Versioned
     $locale = $this->owner->ID && $this->owner->Locale ? $this->owner->Locale : Translatable::get_current_locale();
     $baseTable = ClassInfo::baseDataClass($this->owner->class);
     $where = $query->where;
     if ($locale && self::locale_filter_enabled() && !$query->filtersOnID() && array_search($baseTable, array_keys($query->from)) !== false && !preg_match('/("|\'|`)Locale("|\'|`)/', $query->getFilter())) {
         $qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, Convert::raw2sql($locale));
         $query->where[] = $qry;
     }
 }
开发者ID:eLBirador,项目名称:AllAboutCity,代码行数:21,代码来源:Translatable.php

示例4: sqlQueryToString

 /**
  * Convert a SQLQuery object into a SQL statement
  */
 public function sqlQueryToString(SQLQuery $sqlQuery)
 {
     if (!$sqlQuery->from) {
         return '';
     }
     $distinct = $sqlQuery->distinct ? "DISTINCT " : "";
     if ($sqlQuery->delete) {
         $text = "DELETE ";
     } else {
         if ($sqlQuery->select) {
             $text = "SELECT {$distinct}" . implode(", ", $sqlQuery->select);
         }
     }
     if ($sqlQuery->from) {
         $text .= " FROM " . implode(" ", $sqlQuery->from);
     }
     if ($sqlQuery->where) {
         $text .= " WHERE (" . $sqlQuery->getFilter() . ")";
     }
     if ($sqlQuery->groupby) {
         $text .= " GROUP BY " . implode(", ", $sqlQuery->groupby);
     }
     if ($sqlQuery->having) {
         $text .= " HAVING ( " . implode(" ) AND ( ", $sqlQuery->having) . " )";
     }
     if ($sqlQuery->orderby) {
         $text .= " ORDER BY " . $this->orderMoreSpecifically($sqlQuery->select, $sqlQuery->orderby);
     }
     if ($sqlQuery->limit) {
         $limit = $sqlQuery->limit;
         // Pass limit as array or SQL string value
         if (is_array($limit)) {
             if (!array_key_exists('limit', $limit)) {
                 user_error('SQLQuery::limit(): Wrong format for $limit', E_USER_ERROR);
             }
             if (isset($limit['start']) && is_numeric($limit['start']) && isset($limit['limit']) && is_numeric($limit['limit'])) {
                 $combinedLimit = "{$limit['limit']} OFFSET {$limit['start']}";
             } elseif (isset($limit['limit']) && is_numeric($limit['limit'])) {
                 $combinedLimit = (int) $limit['limit'];
             } else {
                 $combinedLimit = false;
             }
             if (!empty($combinedLimit)) {
                 $text .= " LIMIT " . $combinedLimit;
             }
         } else {
             $text .= " LIMIT " . $sqlQuery->limit;
         }
     }
     return $text;
 }
开发者ID:rodneyway,项目名称:front-end-workflow-testing,代码行数:54,代码来源:SQLite3Database.php


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