This commit is contained in:
2021-02-25 17:25:30 +08:00
parent 2f1e4235c6
commit e1fa0a6b12
3 changed files with 16 additions and 19 deletions
+3 -3
View File
@@ -167,13 +167,13 @@ class ActiveRecord extends BaseActiveRecord
/**
* @param array $attributes
* @param array $fields
* @return ActiveRecord|bool
* @throws Exception
*/
public function update(array $attributes): static|bool
public function update(array $fields): static|bool
{
return $this->save($attributes);
return $this->save($fields);
}
/**
+3 -4
View File
@@ -190,10 +190,9 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
/**
* @throws Exception
*/
public function hasAutoIncrement(): bool
public function isAutoIncrement(): bool
{
$autoIncrement = $this->getAutoIncrement();
return $autoIncrement !== null;
return $this->getAutoIncrement() !== null;
}
/**
@@ -434,7 +433,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
*/
private function setPrimary($lastId, $param): static
{
if ($this->hasAutoIncrement()) {
if ($this->isAutoIncrement()) {
$this->setAttribute($this->getAutoIncrement(), (int)$lastId);
return $this;
}
+10 -12
View File
@@ -225,19 +225,17 @@ class Command extends Component
{
$connect = $this->db->getConnect($this->sql);
if (!($connect instanceof PDO)) {
return null;
return $this->addError('数据库繁忙, 请稍后再试.');
}
if (!($query = $connect->query($this->sql))) return null;
if ($type === static::ROW_COUNT) {
$result = $query->rowCount();
} else if ($type === static::FETCH_COLUMN) {
$result = $query->fetchColumn();
} else if ($type === static::FETCH_ALL) {
$result = $query->fetchAll(PDO::FETCH_ASSOC);
} else {
$result = $query->fetch(PDO::FETCH_ASSOC);
if (!($query = $connect->query($this->sql))) {
return $this->addError($connect->errorInfo()[2] ?? '数据库异常, 请稍后再试.');
}
return $result;
return match ($type) {
self::ROW_COUNT => $query->rowCount(),
self::FETCH_COLUMN => $query->fetchColumn(),
self::FETCH_ALL => $query->fetchAll(PDO::FETCH_ASSOC),
default => $query->fetch(PDO::FETCH_ASSOC)
};
}
/**
@@ -258,7 +256,7 @@ class Command extends Component
return true;
}
$result = $connection->lastInsertId();
if ($result == 0 && $hasAutoIncrement->hasAutoIncrement()) {
if ($result == 0 && $hasAutoIncrement->isAutoIncrement()) {
return $this->addError($connection->errorInfo()[2], 'mysql');
}
return $result == 0 ? true : $result;