This commit is contained in:
2023-08-17 10:16:08 +08:00
parent 37abaa8035
commit ccacfcbc02
+5 -21
View File
@@ -13,11 +13,8 @@ namespace Database;
use Exception;
use Kiri\Abstracts\Component;
use Kiri\Di\Container;
use Kiri\Di\Context;
use Kiri\Exception\ConfigException;
use PDO;
use PDOStatement;
use ReflectionException;
use Throwable;
/**
@@ -89,7 +86,7 @@ class Command extends Component
return $prepare->fetchAll(PDO::FETCH_ASSOC);
} catch (Throwable $throwable) {
$result = $this->error($throwable);
if (str_contains($throwable->getMessage(), 'MySQL server has gone away') && $this->retry()) {
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
return $this->all();
}
return $result;
@@ -113,7 +110,7 @@ class Command extends Component
return $prepare->fetch(PDO::FETCH_ASSOC);
} catch (Throwable $throwable) {
$result = $this->error($throwable);
if (str_contains($throwable->getMessage(), 'MySQL server has gone away') && $this->retry()) {
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
return $this->one();
}
return $result;
@@ -137,7 +134,7 @@ class Command extends Component
return $prepare->fetchColumn(PDO::FETCH_ASSOC);
} catch (Throwable $throwable) {
$result = $this->error($throwable);
if (str_contains($throwable->getMessage(), 'MySQL server has gone away') && $this->retry()) {
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
return $this->fetchColumn();
}
return $result;
@@ -161,7 +158,7 @@ class Command extends Component
return $prepare->rowCount();
} catch (Throwable $throwable) {
$result = $this->error($throwable);
if (str_contains($throwable->getMessage(), 'MySQL server has gone away') && $this->retry()) {
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
return $this->rowCount();
}
return $result;
@@ -171,19 +168,6 @@ class Command extends Component
}
/**
* @return bool
*/
protected function retry(): bool
{
if (Context::increment(self::RETRY_NAME) < 3) {
return true;
}
Context::remove(self::RETRY_NAME);
return false;
}
/**
* @return int|bool
* @throws Exception
@@ -215,7 +199,7 @@ class Command extends Component
return $result == 0 ? true : (int)$result;
} catch (Throwable $throwable) {
$result = $this->error($throwable);
if (str_contains($throwable->getMessage(), 'MySQL server has gone away') && $this->retry()) {
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
return $this->_execute();
}
return $result;