改名
This commit is contained in:
@@ -167,13 +167,13 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $attributes
|
* @param array $fields
|
||||||
* @return ActiveRecord|bool
|
* @return ActiveRecord|bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function update(array $attributes): static|bool
|
public function update(array $fields): static|bool
|
||||||
{
|
{
|
||||||
return $this->save($attributes);
|
return $this->save($fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -190,10 +190,9 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function hasAutoIncrement(): bool
|
public function isAutoIncrement(): bool
|
||||||
{
|
{
|
||||||
$autoIncrement = $this->getAutoIncrement();
|
return $this->getAutoIncrement() !== null;
|
||||||
return $autoIncrement !== null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -434,7 +433,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
*/
|
*/
|
||||||
private function setPrimary($lastId, $param): static
|
private function setPrimary($lastId, $param): static
|
||||||
{
|
{
|
||||||
if ($this->hasAutoIncrement()) {
|
if ($this->isAutoIncrement()) {
|
||||||
$this->setAttribute($this->getAutoIncrement(), (int)$lastId);
|
$this->setAttribute($this->getAutoIncrement(), (int)$lastId);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-12
@@ -225,19 +225,17 @@ class Command extends Component
|
|||||||
{
|
{
|
||||||
$connect = $this->db->getConnect($this->sql);
|
$connect = $this->db->getConnect($this->sql);
|
||||||
if (!($connect instanceof PDO)) {
|
if (!($connect instanceof PDO)) {
|
||||||
return null;
|
return $this->addError('数据库繁忙, 请稍后再试.');
|
||||||
}
|
}
|
||||||
if (!($query = $connect->query($this->sql))) return null;
|
if (!($query = $connect->query($this->sql))) {
|
||||||
if ($type === static::ROW_COUNT) {
|
return $this->addError($connect->errorInfo()[2] ?? '数据库异常, 请稍后再试.');
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
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;
|
return true;
|
||||||
}
|
}
|
||||||
$result = $connection->lastInsertId();
|
$result = $connection->lastInsertId();
|
||||||
if ($result == 0 && $hasAutoIncrement->hasAutoIncrement()) {
|
if ($result == 0 && $hasAutoIncrement->isAutoIncrement()) {
|
||||||
return $this->addError($connection->errorInfo()[2], 'mysql');
|
return $this->addError($connection->errorInfo()[2], 'mysql');
|
||||||
}
|
}
|
||||||
return $result == 0 ? true : $result;
|
return $result == 0 ? true : $result;
|
||||||
|
|||||||
Reference in New Issue
Block a user