Skip to content

Commit

Permalink
Extract from PDOException instead of DBAL exception for table missing…
Browse files Browse the repository at this point in the history
… checks
  • Loading branch information
arifszn committed Mar 15, 2024
1 parent 35c9674 commit 1120396
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
11 changes: 5 additions & 6 deletions src/Symfony/Component/Cache/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Cache\Adapter;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PDO\Exception;
use Doctrine\DBAL\Schema\Schema;
use Psr\Cache\CacheItemInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -600,15 +599,15 @@ private function getServerVersion(): string

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

switch (true) {
case 'pgsql' === $driver && '42P01' === $exception->getSQLState():
case 'pgsql' === $driver && '42P01' === $sqlState:
case 'sqlite' === $driver && str_contains($exception->getMessage(), 'no such table:'):
case 'oci' === $driver && 942 === $exception->getCode():
case 'sqlsrv' === $driver && 208 === $exception->getCode():
case 'mysql' === $driver && 1146 === $exception->getCode():
case 'oci' === $driver && 942 === $code:
case 'sqlsrv' === $driver && 208 === $code:
case 'mysql' === $driver && 1146 === $code:
return true;
default:
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public static function provideDsnSQLite()
/**
* @requires extension pdo_pgsql
*
* @group integration
* @group szn
*/
public function testDsnWithPostgreSQL()
{
if (!$host = getenv('POSTGRES_HOST')) {
if (!$host = 'localhost') {
$this->markTestSkipped('Missing POSTGRES_HOST env variable');
}

Expand Down
13 changes: 6 additions & 7 deletions src/Symfony/Component/Lock/Store/PdoStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Lock\Store;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PDO\Exception;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Exception\InvalidTtlException;
Expand Down Expand Up @@ -330,15 +329,15 @@ private function getCurrentTimestampStatement(): string

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

switch (true) {
case 'pgsql' === $driver && '42P01' === $exception->getSQLState():
case 'pgsql' === $driver && '42P01' === $sqlState:
case 'sqlite' === $driver && str_contains($exception->getMessage(), 'no such table:'):
case 'oci' === $driver && 942 === $exception->getCode():
case 'sqlsrv' === $driver && 208 === $exception->getCode():
case 'mysql' === $driver && 1146 === $exception->getCode():
case 'oci' === $driver && 942 === $code:
case 'sqlsrv' === $driver && 208 === $code:
case 'mysql' === $driver && 1146 === $code:
return true;
default:
return false;
Expand Down

0 comments on commit 1120396

Please sign in to comment.