瀏覽代碼

Update:更新deleteObject和updateObject,以支持where条件

Zhu Jinhui 7 年之前
父節點
當前提交
045252acc1
共有 1 個文件被更改,包括 11 次插入3 次删除
  1. 11 3
      src/Driver/Base.php

+ 11 - 3
src/Driver/Base.php

@@ -451,7 +451,11 @@ class Base
 					$where[] = "`{$key}` = '" . $value . "'";
 				}
 			}
-			$this->modelSQL = $sql = "UPDATE ". $this->getTable($table) ." SET " . join(", ", $values) . (sizeof($where) > 0 ? " WHERE " . join(" AND ", $where) : '');
+			$whereSQL = $this->where;
+			if(sizeof($where) > 0) {
+				$whereSQL = $this->where ? $this->where . " AND (". join(" AND ", $where) .")" : " WHERE ". join(" AND ", $where);
+			}
+			$this->modelSQL = $sql = "UPDATE ". $this->getTable($table) ." SET " . join(", ", $values) . $whereSQL;
 			$rs = $this->setQuery($sql);
 			$this->cleanData();
 			$this->setError();
@@ -472,12 +476,16 @@ class Base
 			return -1;
 		}
 		$where = array();
-		if (sizeof($keys) > 0 || get_object_vars($keys)) {
+		if (sizeof($keys) > 0 || (is_a($keys, 'stdclass') && get_object_vars($keys))) {
 			foreach ($keys AS $k => $v) {
 				$where[] = "`{$k}` = '" . $this->setQuote($v) . "'";
 			}
 		}
-		$this->modelSQL = $sql = "DELETE FROM ". $this->getTable($table) ." " . (sizeof($where) > 0 ? " WHERE " . join(" AND ", $where) : '');
+		$whereSQL = $this->where;
+		if(sizeof($where) > 0) {
+			$whereSQL = $this->where ? $this->where . " AND (". join(" AND ", $where) .")" : " WHERE ". join(" AND ", $where);
+		}
+		$this->modelSQL = $sql = "DELETE FROM ". $this->getTable($table) ." " . $whereSQL;
 		$rs = $this->query($sql);
 		$this->cleanData();
 		$this->setError();