变更
This commit is contained in:
+27
-23
@@ -28,19 +28,19 @@ class Command extends Component
|
|||||||
const FETCH_ALL = 'fetchAll';
|
const FETCH_ALL = 'fetchAll';
|
||||||
const EXECUTE = 'execute';
|
const EXECUTE = 'execute';
|
||||||
const FETCH_COLUMN = 'fetchColumn';
|
const FETCH_COLUMN = 'fetchColumn';
|
||||||
|
|
||||||
const DB_ERROR_MESSAGE = 'The system is busy, please try again later.';
|
const DB_ERROR_MESSAGE = 'The system is busy, please try again later.';
|
||||||
|
|
||||||
/** @var Connection */
|
/** @var Connection */
|
||||||
public Connection $connection;
|
public Connection $connection;
|
||||||
|
|
||||||
/** @var ?string */
|
/** @var ?string */
|
||||||
public ?string $sql = '';
|
public ?string $sql = '';
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
public array $params = [];
|
public array $params = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int|bool
|
* @return int|bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -49,7 +49,7 @@ class Command extends Component
|
|||||||
{
|
{
|
||||||
return $this->_execute();
|
return $this->_execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int|bool
|
* @return int|bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -58,8 +58,8 @@ class Command extends Component
|
|||||||
{
|
{
|
||||||
return $this->_execute();
|
return $this->_execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool|array|null
|
* @return bool|array|null
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -82,7 +82,7 @@ class Command extends Component
|
|||||||
$this->connection->release($pdo ?? null);
|
$this->connection->release($pdo ?? null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool|array|null
|
* @return bool|array|null
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -105,7 +105,7 @@ class Command extends Component
|
|||||||
$this->connection->release($client ?? null);
|
$this->connection->release($client ?? null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool|array|null
|
* @return bool|array|null
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -128,7 +128,7 @@ class Command extends Component
|
|||||||
$this->connection->release($client ?? null);
|
$this->connection->release($client ?? null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int|bool
|
* @return int|bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -151,8 +151,8 @@ class Command extends Component
|
|||||||
$this->connection->release($client ?? null);
|
$this->connection->release($client ?? null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int|bool
|
* @return int|bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -161,7 +161,7 @@ class Command extends Component
|
|||||||
{
|
{
|
||||||
return $this->_execute();
|
return $this->_execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool|int
|
* @return bool|int
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
@@ -179,6 +179,10 @@ class Command extends Component
|
|||||||
}
|
}
|
||||||
$result = $client->lastInsertId();
|
$result = $client->lastInsertId();
|
||||||
$prepare->closeCursor();
|
$prepare->closeCursor();
|
||||||
|
|
||||||
|
if (!$client->inTransaction()) {
|
||||||
|
$this->connection->release($client);
|
||||||
|
}
|
||||||
return $result == 0 ? true : $result;
|
return $result == 0 ? true : $result;
|
||||||
} catch (\Throwable $throwable) {
|
} catch (\Throwable $throwable) {
|
||||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
||||||
@@ -187,8 +191,8 @@ class Command extends Component
|
|||||||
return $this->error($throwable);
|
return $this->error($throwable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Throwable $throwable
|
* @param \Throwable $throwable
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -198,8 +202,8 @@ class Command extends Component
|
|||||||
$message = $this->sql . '(' . json_encode($this->params, JSON_UNESCAPED_UNICODE) . ');';
|
$message = $this->sql . '(' . json_encode($this->params, JSON_UNESCAPED_UNICODE) . ');';
|
||||||
return $this->logger->addError($message . $throwable->getMessage(), 'mysql');
|
return $this->logger->addError($message . $throwable->getMessage(), 'mysql');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int|bool
|
* @return int|bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -208,7 +212,7 @@ class Command extends Component
|
|||||||
{
|
{
|
||||||
return $this->_execute();
|
return $this->_execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int|bool
|
* @return int|bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -217,7 +221,7 @@ class Command extends Component
|
|||||||
{
|
{
|
||||||
return $this->_execute();
|
return $this->_execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return $this
|
* @return $this
|
||||||
@@ -229,7 +233,7 @@ class Command extends Component
|
|||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $sql
|
* @param $sql
|
||||||
* @return $this
|
* @return $this
|
||||||
@@ -240,5 +244,5 @@ class Command extends Component
|
|||||||
$this->sql = $sql;
|
$this->sql = $sql;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user