8000 Utilize DBAL PDO Exception for table missing checks · symfony/symfony@35c9674 · GitHub
[go: up one dir, main page]

Skip to content

Commit 35c9674

Browse files
committed
Utilize DBAL PDO Exception for table missing checks
1 parent b6e958b commit 35c9674

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/Symfony/Component/Cache/Adapter/PdoAdapter.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Cache\Adapter;
1313

1414
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Driver\PDO\Exception;
1516
use Doctrine\DBAL\Schema\Schema;
1617
use Psr\Cache\CacheItemInterface;
1718
use Psr\Log\LoggerInterface;
@@ -599,15 +600,15 @@ private function getServerVersion(): string
599600

600601
private function isTableMissing(\PDOException $exception): bool
601602
{
603+
$exception = Exception::new($exception);
602604
$driver = $this->driver;
603-
$code = $exception->errorInfo ? $exception->errorInfo[1] : $exception->getCode();
604605

605606
switch (true) {
606-
case 'pgsql' === $driver && str_contains($exception->getMessage(), '42P01'):
607+
case 'pgsql' === $driver && '42P01' === $exception->getSQLState():
607608
case 'sqlite' === $driver && str_contains($exception->getMessage(), 'no such table:'):
608-
case 'oci' === $driver && 942 === $code:
609-
case 'sqlsrv' === $driver && 208 === $code:
610-
case 'mysql' === $driver && 1146 === $code:
609+
case 'oci' === $driver && 942 === $exception->getCode():
610+
case 'sqlsrv' === $driver && 208 === $exception->getCode():
611+
case 'mysql' === $driver && 1146 === $exception->getCode():
611612
return true;
612613
default:
613614
return false;

src/Symfony/Component/Lock/Store/PdoStore.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Lock\Store;
1313

1414
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Driver\PDO\Exception;
1516
use Doctrine\DBAL\Schema\Schema;
1617
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1718
use Symfony\Component\Lock\Exception\InvalidTtlException;
@@ -329,15 +330,15 @@ private function getCurrentTimestampStatement(): string
329330

330331
private function isTableMissing(\PDOException $exception): bool
331332
{
332-
$driver = $this->getDriver();
333-
$code = $exception->errorInfo ? $exception->errorInfo[1] : $exception->getCode();
333+
$exception = Exception::new($exception);
334+
$driver = $this->driver;
334335

335336
switch (true) {
336-
case 'pgsql' === $driver && str_contains($exception->getMessage(), '42P01'):
337+
case 'pgsql' === $driver && '42P01' === $exception->getSQLState():
337338
case 'sqlite' === $driver && str_contains($exception->getMessage(), 'no such table:'):
338-
case 'oci' === $driver && 942 === $code:
339-
case 'sqlsrv' === $driver && 208 === $code:
340-
case 'mysql' === $driver && 1146 === $code:
339+
case 'oci' === $driver && 942 === $exception->getCode():
340+
case 'sqlsrv' === $driver && 208 === $exception->getCode():
341+
case 'mysql' === $driver && 1146 === $exception->getCode():
341342
return true;
342343
default:
343344
return false;

0 commit comments

Comments
 (0)
0