8000 Extract from PDOException instead of DBAL exception for table missing… · symfony/symfony@1120396 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1120396

Browse files
committed
Extract from PDOException instead of DBAL exception for table missing checks
1 parent 35c9674 commit 1120396

File tree

3 files changed

+13
-15
lines changed

3< 8000 !-- --> files changed

+13
-15
lines changed

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

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

1414
use Doctrine\DBAL\Connection;
15-
use Doctrine\DBAL\Driver\PDO\Exception;
1615
use Doctrine\DBAL\Schema\Schema;
1716
use Psr\Cache\CacheItemInterface;
1817
use Psr\Log\LoggerInterface;
@@ -600,15 +599,15 @@ private function getServerVersion(): string
600599

601600
private function isTableMissing(\PDOException $exception): bool
602601
{
603-
$exception = Exception::new($exception);
604602
$driver = $this->driver;
603+
[$sqlState, $code] = $exception->errorInfo ?? [null, $exception->getCode()];
605604

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

src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ public static function provideDsnSQLite()
9595
/**
9696
* @requires extension pdo_pgsql
9797
*
98-
* @group integration
98+
* @group szn
9999
*/
100100
public function testDsnWithPostgreSQL()
101101
{
102-
if (!$host = getenv('POSTGRES_HOST')) {
102+
if (!$host = 'localhost') {
103103
$this->markTestSkipped('Missing POSTGRES_HOST env variable');
104104
}
105105

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

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

1414
use Doctrine\DBAL\Connection;
15-
use Doctrine\DBAL\Driver\PDO\Exception;
1615
use Doctrine\DBAL\Schema\Schema;
1716
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1817
use Symfony\Component\Lock\Exception\InvalidTtlException;
@@ -330,15 +329,15 @@ private function getCurrentTimestampStatement(): string
330329

331330
private function isTableMissing(\PDOException $exception): bool
332331
{
333-
$exception = Exception::new($exception);
334-
$driver = $this->driver;
332+
$driver = $this->getDriver();
333+
[$sqlState, $code] = $exception->errorInfo ?? [null, $exception->getCode()];
335334

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

0 commit comments

Comments
 (0)
0