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


PHP DataFilter::toSQLStr方法代码示例

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


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

示例1: buildSingleParam

 protected static function buildSingleParam($paramName, $column, $filter)
 {
     $sql = "";
     $param = "";
     $pcolumn = preg_replace('/[^\\da-z]/i', '_', $column);
     $driver = Setting::get('db.driver');
     $column = ActiveRecord::formatSingleCriteria($column, $driver);
     ## quote field if it is containing illegal char
     if (!preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*\$/", str_replace(".", "", $column))) {
         $column = "{$column}";
     }
     switch ($filter['type']) {
         case "string":
             if ($filter['value'] != "" || $filter['operator'] == 'Is Empty') {
                 $sCol = DataFilter::toSQLStr("{$column}", $driver);
                 $spCol = DataFilter::toSQLStr(":{$paramName}_{$pcolumn}", $driver);
                 switch ($filter['operator']) {
                     case "Contains":
                         $sql = "{$sCol} LIKE {$spCol}";
                         $param = "%{$filter['value']}%";
                         break;
                     case "Does Not Contain":
                         $sql = "{$sCol} NOT LIKE {$spCol}";
                         $param = "%{$filter['value']}%";
                         break;
                     case "Is Equal To":
                         $sql = "{$sCol} LIKE {$spCol}";
                         $param = "{$filter['value']}";
                         break;
                     case "Starts With":
                         $sql = "{$sCol} LIKE {$spCol}";
                         $param = "{$filter['value']}%";
                         break;
                     case "Ends With":
                         $sql = "{$sCol} LIKE {$spCol}";
                         $param = "%{$filter['value']}";
                         break;
                     case "Is Any Of":
                         $param_raw = preg_split('/\\s+/', trim($filter['value']));
                         $param = [];
                         $psql = [];
                         foreach ($param_raw as $k => $p) {
                             $param[":{$paramName}_{$pcolumn}_{$k}"] = "%{$p}%";
                             $spCol = DataFilter::toSQLStr(":{$paramName}_{$pcolumn}_{$k}", $driver);
                             $psql[] = "{$sCol} LIKE {$spCol}";
                         }
                         $sql = "(" . implode(" OR ", $psql) . ")";
                         break;
                     case "Is Not Any Of":
                         $param_raw = preg_split('/\\s+/', trim($filter['value']));
                         $param = [];
                         $psql = [];
                         foreach ($param_raw as $k => $p) {
                             $param[":{$paramName}_{$pcolumn}_{$k}"] = "%{$p}%";
                             $spCol = DataFilter::toSQLStr(":{$paramName}_{$pcolumn}_{$k}", $driver);
                             $psql[] = "{$sCol} LIKE {$spCol}";
                         }
                         $sql = "(" . implode(" AND ", $psql) . ")";
                         break;
                     case "Is Empty":
                         $sql = "({$column} LIKE '' OR {$column} IS NULL)";
                         break;
                 }
             }
             break;
         case "number":
             if ($filter['value'] != "" || $filter['operator'] == 'Is Empty') {
                 switch ($filter['operator']) {
                     case "=":
                     case "<>":
                     case ">":
                     case '>':
                     case '>=':
                     case '<=':
                     case '<':
                         $sql = "{$column} {$filter['operator']} :{$paramName}_{$pcolumn}";
                         $param = "{$filter['value']}";
                         break;
                     case "Is Empty":
                         $sql = "({$column} IS NULL)";
                         break;
                 }
             }
             break;
         case "date":
             switch ($filter['operator']) {
                 case "Between":
                 case "Weekly":
                 case "Monthly":
                 case "Yearly":
                     if (@$filter['value']['from'] != '' && @$filter['value']['to'] != '') {
                         $a = self::toSQLDateTime(":{$paramName}_{$pcolumn}_from", $driver);
                         $b = self::toSQLDateTime(":{$paramName}_{$pcolumn}_to", $driver);
                         $sql = "({$column} BETWEEN {$a} AND {$b})";
                         $fromStartHour = date('Y-m-d 23:59:00', strtotime('-1 day', strtotime(@$filter['value']['from'])));
                         $toLastHour = date('Y-m-d 23:59:00', strtotime(@$filter['value']['to']));
                         $param = [":{$paramName}_{$pcolumn}_from" => $fromStartHour, ":{$paramName}_{$pcolumn}_to" => $toLastHour];
                     }
                     break;
                 case "Not Between":
//.........这里部分代码省略.........
开发者ID:rizabudi,项目名称:plansys,代码行数:101,代码来源:DataFilter.php


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