本文整理汇总了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":
//.........这里部分代码省略.........