Skip to content

Commit

Permalink
better document what to do when mysql named zones are not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Mar 12, 2024
1 parent ddf0578 commit 647db40
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Drivers/Exception/UnknownMysqlTimezone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types = 1);

namespace Nextras\Dbal\Drivers\Exception;


use Exception;


class UnknownMysqlTimezone extends QueryException
{
public function __construct(
string $message,
int $errorCode = 0,
string $errorSqlState = '',
Exception $previousException = null,
?string $sqlQuery = null,
)
{
parent::__construct(
$message . "\nSee how to solve the issue: https://nextras.org/dbal/docs/main/timezones-mysql-support",
$errorCode,
$errorSqlState,
$previousException,
$sqlQuery,
);
}
}
3 changes: 3 additions & 0 deletions src/Drivers/Mysqli/MysqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Nextras\Dbal\Drivers\Exception\NotNullConstraintViolationException;
use Nextras\Dbal\Drivers\Exception\QueryException;
use Nextras\Dbal\Drivers\Exception\UniqueConstraintViolationException;
use Nextras\Dbal\Drivers\Exception\UnknownMysqlTimezone;
use Nextras\Dbal\Drivers\IDriver;
use Nextras\Dbal\Exception\InvalidStateException;
use Nextras\Dbal\Exception\NotSupportedException;
Expand Down Expand Up @@ -368,6 +369,8 @@ protected function createException(string $error, int $errorNo, string $sqlState
return new ConnectionException($error, $errorNo, $sqlState);
} elseif (in_array($errorNo, [1048, 1121, 1138, 1171, 1252, 1263, 1566], true)) {
return new NotNullConstraintViolationException($error, $errorNo, $sqlState, null, $query);
} elseif ($errorNo === 1298) {
return new UnknownMysqlTimezone($error, $errorNo, $sqlState, null, $query);
} elseif ($query !== null) {
return new QueryException($error, $errorNo, $sqlState, null, $query);
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/Drivers/PdoMysql/PdoMysqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Nextras\Dbal\Drivers\Exception\NotNullConstraintViolationException;
use Nextras\Dbal\Drivers\Exception\QueryException;
use Nextras\Dbal\Drivers\Exception\UniqueConstraintViolationException;
use Nextras\Dbal\Drivers\Exception\UnknownMysqlTimezone;
use Nextras\Dbal\Drivers\IDriver;
use Nextras\Dbal\Drivers\Pdo\PdoDriver;
use Nextras\Dbal\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -153,6 +154,8 @@ protected function createException(string $error, int $errorNo, string $sqlState
return new ConnectionException($error, $errorNo, $sqlState);
} elseif (in_array($errorNo, [1048, 1121, 1138, 1171, 1252, 1263, 1566], true)) {
return new NotNullConstraintViolationException($error, $errorNo, $sqlState, null, $query);
} elseif ($errorNo === 1298) {
return new UnknownMysqlTimezone($error, $errorNo, $sqlState, null, $query);
} elseif ($query !== null) {
return new QueryException($error, $errorNo, $sqlState, null, $query);
} else {
Expand Down

0 comments on commit 647db40

Please sign in to comment.