zjh пре 3 недеља
родитељ
комит
5358dd7cf0
1 измењених фајлова са 7 додато и 2 уклоњено
  1. 7 2
      src/Driver/Traits/SQL.php

+ 7 - 2
src/Driver/Traits/SQL.php

@@ -38,6 +38,7 @@ trait SQL
     );
     private $condition = ['eq', 'neq', 'gt', 'lt', 'gte', 'lte', 'in', 'between', 'like', 'llike', 'rlike'];
     private $conditionFormatter = [
+        'null' => '%s IS NULL',
         'eq' => "%s = '%s'",
         'neq' => "%s != '%s'",
         'gt' => "%s > '%s'",
@@ -308,6 +309,9 @@ trait SQL
         $this->handleError(!$field, '字段名不能为空');
         $tmp = explode(':', $field);
         if(count($tmp) == 1) {
+            if(is_null($val)) {
+                return sprintf($this->conditionFormatter['null'], $this->handleFieldAlias($field));
+            }
             return sprintf($this->conditionFormatter['eq'], $this->handleFieldAlias($field), $this->setQuote($val));
         }
         $cond = array_pop($tmp);
@@ -345,7 +349,6 @@ trait SQL
      */
     private function handleSubWhere($where) {
         $arr = [];
-
         $count = count($where);
         // 多维数组处理
         if(count($where, 1) > $count) {
@@ -513,7 +516,9 @@ trait SQL
     final public function order($order){
         $this->handleError(!is_array($order) && !is_string($order), 'order 参数必须为字符串或数组, 获取到的是'. gettype($order));
 
-        if((is_array($order) && count($order) == 0) || preg_match('/(COUNT|SUM)\((.*)\)/', $this->fields)) {
+        //if((is_array($order) && count($order) == 0) || preg_match('/(COUNT|SUM)\((.*)\)/', $this->fields)) {
+        // 去掉限制
+        if((is_array($order) && count($order) == 0)) {
             return $this;
         }