1
This commit is contained in:
+1
-1
@@ -269,7 +269,7 @@ class ActiveQuery extends Component implements ISqlBuilder
|
||||
[$sql, $params] = $this->builder->insert($data, true);
|
||||
|
||||
|
||||
return $this->execute($sql, $params)->exec(null, true);
|
||||
return $this->execute($sql, $params)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -540,7 +540,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
||||
{
|
||||
[$sql, $param] = SqlBuilder::builder(static::query())->insert($param);
|
||||
$dbConnection = $this->getConnection()->createCommand($sql, $param);
|
||||
if (!($lastId = $dbConnection->save(true, $this->getAutoIncrement()))) {
|
||||
if (!($lastId = $dbConnection->save(true))) {
|
||||
throw new Exception('保存失败.');
|
||||
}
|
||||
$lastId = $this->setPrimary((int)$lastId, $param);
|
||||
|
||||
+7
-17
@@ -60,7 +60,7 @@ class Command extends Component
|
||||
*/
|
||||
public function save(bool $isInsert = TRUE, mixed $hasAutoIncrement = null): int|bool|array|string|null
|
||||
{
|
||||
return $this->execute(static::EXECUTE, $isInsert, $hasAutoIncrement);
|
||||
return $this->execute(static::EXECUTE);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,17 +111,15 @@ class Command extends Component
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @param null $isInsert
|
||||
* @param bool|null $hasAutoIncrement
|
||||
* @return int|bool|array|string|null
|
||||
* @throws Exception
|
||||
*/
|
||||
private function execute($type, $isInsert = null, mixed $hasAutoIncrement = null): int|bool|array|string|null
|
||||
private function execute($type): int|bool|array|string|null
|
||||
{
|
||||
try {
|
||||
$time = microtime(true);
|
||||
if ($type === static::EXECUTE) {
|
||||
$result = $this->insert_or_change($isInsert, $hasAutoIncrement);
|
||||
$result = $this->insert_or_change();
|
||||
} else {
|
||||
$result = $this->search($type);
|
||||
}
|
||||
@@ -159,19 +157,13 @@ class Command extends Component
|
||||
|
||||
|
||||
/**
|
||||
* @param $isInsert
|
||||
* @param $hasAutoIncrement
|
||||
* @return bool|int
|
||||
* @throws Exception
|
||||
*/
|
||||
private function insert_or_change($isInsert, $hasAutoIncrement): bool|int
|
||||
private function insert_or_change(): bool|int
|
||||
{
|
||||
$pdo = $this->db->getConnect($this->sql);
|
||||
$result = $pdo->execute($this->sql, $isInsert, $this->params);
|
||||
if (!is_null($hasAutoIncrement) && $result == 0) {
|
||||
return false;
|
||||
}
|
||||
return $result;
|
||||
return $pdo->execute($this->sql,$this->params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,14 +176,12 @@ class Command extends Component
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $scope
|
||||
* @param bool $insert
|
||||
* @return int|bool|array|string|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function exec($scope = null, bool $insert = false): int|bool|array|string|null
|
||||
public function exec(): int|bool|array|string|null
|
||||
{
|
||||
return $this->execute(static::EXECUTE, $insert, $scope);
|
||||
return $this->execute(static::EXECUTE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-6
@@ -242,12 +242,11 @@ class PDO implements StopHeartbeatCheck
|
||||
|
||||
/**
|
||||
* @param string $sql
|
||||
* @param $isInsert
|
||||
* @param array $params
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(string $sql, $isInsert, array $params = []): int
|
||||
public function execute(string $sql, array $params = []): int
|
||||
{
|
||||
$this->_last = time();
|
||||
$pdo = $this->_pdo();
|
||||
@@ -257,10 +256,7 @@ class PDO implements StopHeartbeatCheck
|
||||
if ($prepare->execute($params) === false) {
|
||||
throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
|
||||
}
|
||||
$result = 1;
|
||||
if ($isInsert) {
|
||||
$result = (int)$pdo->lastInsertId();
|
||||
}
|
||||
$result = (int)$pdo->lastInsertId();
|
||||
$prepare->closeCursor();
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user