改名
This commit is contained in:
+12
-17
@@ -28,6 +28,8 @@ class Command extends Component
|
|||||||
const EXECUTE = 'EXECUTE';
|
const EXECUTE = 'EXECUTE';
|
||||||
const FETCH_COLUMN = 'FETCH_COLUMN';
|
const FETCH_COLUMN = 'FETCH_COLUMN';
|
||||||
|
|
||||||
|
const DB_ERROR_MESSAGE = 'The system is busy, please try again later.';
|
||||||
|
|
||||||
/** @var Connection */
|
/** @var Connection */
|
||||||
public Connection $db;
|
public Connection $db;
|
||||||
|
|
||||||
@@ -128,9 +130,6 @@ class Command extends Component
|
|||||||
if (microtime(true) - $time >= 0.03) {
|
if (microtime(true) - $time >= 0.03) {
|
||||||
$this->warning('execute sql `' . $this->sql . '` use time ' . (microtime(true) - $time));
|
$this->warning('execute sql `' . $this->sql . '` use time ' . (microtime(true) - $time));
|
||||||
}
|
}
|
||||||
if ($this->prepare) {
|
|
||||||
$this->prepare->closeCursor();
|
|
||||||
}
|
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
$message = $this->sql . '. error: ' . $exception->getMessage();
|
$message = $this->sql . '. error: ' . $exception->getMessage();
|
||||||
|
|
||||||
@@ -175,6 +174,9 @@ class Command extends Component
|
|||||||
if (!($query = $connect->query($this->sql))) {
|
if (!($query = $connect->query($this->sql))) {
|
||||||
return $this->addError($connect->errorInfo()[2] ?? '数据库异常, 请稍后再试.');
|
return $this->addError($connect->errorInfo()[2] ?? '数据库异常, 请稍后再试.');
|
||||||
}
|
}
|
||||||
|
defer(function () use ($query) {
|
||||||
|
$query->closeCursor();
|
||||||
|
});
|
||||||
if ($type === static::FETCH_COLUMN) {
|
if ($type === static::FETCH_COLUMN) {
|
||||||
return $query->fetchAll(PDO::FETCH_ASSOC);
|
return $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
} else if ($type === static::ROW_COUNT) {
|
} else if ($type === static::ROW_COUNT) {
|
||||||
@@ -201,7 +203,7 @@ class Command extends Component
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ($result == 0 && $hasAutoIncrement->isAutoIncrement()) {
|
if ($result == 0 && $hasAutoIncrement->isAutoIncrement()) {
|
||||||
return $this->addError('The system is busy, please try again later.', 'mysql');
|
return $this->addError(static::DB_ERROR_MESSAGE, 'mysql');
|
||||||
}
|
}
|
||||||
return $result == 0 ? true : $result;
|
return $result == 0 ? true : $result;
|
||||||
}
|
}
|
||||||
@@ -219,12 +221,13 @@ class Command extends Component
|
|||||||
if (!(($connect = $this->db->getConnect($this->sql)) instanceof PDO)) {
|
if (!(($connect = $this->db->getConnect($this->sql)) instanceof PDO)) {
|
||||||
return $this->addError('get client error.', 'mysql');
|
return $this->addError('get client error.', 'mysql');
|
||||||
}
|
}
|
||||||
$this->prepare = $connect->prepare($this->sql);
|
if (!(($prepare = $connect->prepare($this->sql)) instanceof PDOStatement)) {
|
||||||
if (!($this->prepare instanceof PDOStatement)) {
|
$error = $prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE;
|
||||||
return $this->addError($this->sql . ':' . $this->getError(), 'mysql');
|
|
||||||
|
return $this->addError($this->sql . ':' . $error, 'mysql');
|
||||||
}
|
}
|
||||||
$result = $this->prepare->execute($this->params);
|
$result = $prepare->execute($this->params);
|
||||||
$this->prepare->closeCursor();
|
$prepare->closeCursor();
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
return $this->addError($connect->errorInfo()[2], 'mysql');
|
return $this->addError($connect->errorInfo()[2], 'mysql');
|
||||||
}
|
}
|
||||||
@@ -295,12 +298,4 @@ class Command extends Component
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getError(): string
|
|
||||||
{
|
|
||||||
return $this->prepare->errorInfo()[2] ?? 'Db 驱动错误.';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user