|
@@ -188,6 +188,26 @@ class Base
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 格式化插入值,新增null值插入
|
|
|
+ *
|
|
|
+ * @param $arr
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ protected function formatInsertObject($arr) {
|
|
|
+ if(is_array($arr)) {
|
|
|
+ $values = array();
|
|
|
+ foreach ($arr as $v) {
|
|
|
+ if(strtoupper(gettype($val)) == 'NULL') {
|
|
|
+ $values[] = 'null';
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $values[] = "'". $val . "'";
|
|
|
+ }
|
|
|
+ return $values;
|
|
|
+ }
|
|
|
+ return $arr;
|
|
|
+ }
|
|
|
+ /**
|
|
|
* 插入数据
|
|
|
* @param $table
|
|
|
* @param $dataArray
|
|
@@ -204,7 +224,10 @@ class Base
|
|
|
{
|
|
|
throw new Variable(_i('Invalid %s format', 'data'), __LINE__);
|
|
|
}
|
|
|
- $this->executeSQL = $this->modelSQL = $sql = "INSERT INTO " . $this->getTable($table) . "(`" . join("`, `", $replaceObj['fields']) . "`) VALUES('" . join("', '", $replaceObj['values']) . "')";
|
|
|
+ // 针对 null 值单独处理,并将值的两端加上单引号 '
|
|
|
+ $values = $this->formatInsertObject($replaceObj['values']);
|
|
|
+ $this->executeSQL = $this->modelSQL = $sql = "INSERT INTO " . $this->getTable($table) . "(`" . join("`, `", $replaceObj['fields']) . "`) VALUES(". join(',', $values) . ")";
|
|
|
+
|
|
|
$this->setQuery($sql);
|
|
|
$this->setError();
|
|
|
return $this->lastInsertId();
|
|
@@ -225,7 +248,10 @@ class Base
|
|
|
{
|
|
|
throw new Variable(_i('Invalid %s format', 'data'), __LINE__);
|
|
|
}
|
|
|
- $this->executeSQL = $this->modelSQL = $sql = "REPLACE INTO " . $this->getTable($table) . "(`" . join("`, `", $replaceObj['fields']) . "`) VALUES('" . join("', '", $replaceObj['values']) . "')";
|
|
|
+ // 针对 null 值单独处理,并将值的两端加上单引号 '
|
|
|
+ $values = $this->formatInsertObject($replaceObj['values']);
|
|
|
+
|
|
|
+ $this->executeSQL = $this->modelSQL = $sql = "REPLACE INTO " . $this->getTable($table) . "(`" . join("`, `", $replaceObj['fields']) . "`) VALUES(". join(',', $values) . ")";
|
|
|
$rs = $this->setQuery($sql);
|
|
|
$this->setError();
|
|
|
return $this->AffectedRows($rs);
|
|
@@ -251,7 +277,11 @@ class Base
|
|
|
if (is_array($value)) {
|
|
|
throw new InvalidFormat(_i('Invalid %s format', $key), __LINE__);
|
|
|
}
|
|
|
- $values[] = $this->setQuote($value);
|
|
|
+ if(strtoupper(gettype($value)) == 'NULL') {
|
|
|
+ $values[] = null;
|
|
|
+ }else{
|
|
|
+ $values[] = $this->setQuote($value);
|
|
|
+ }
|
|
|
}
|
|
|
return array('fields' => $keys, 'values' => $values);
|
|
|
}
|