vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php line 36

Open in your IDE?
  1. <?php
  2. namespace Doctrine\DBAL\Driver;
  3. use Doctrine\DBAL\Connection;
  4. use Doctrine\DBAL\Driver;
  5. use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException;
  6. use Doctrine\DBAL\Exception\ConnectionException;
  7. use Doctrine\DBAL\Exception\DriverException;
  8. use Doctrine\DBAL\Exception\InvalidFieldNameException;
  9. use Doctrine\DBAL\Exception\LockWaitTimeoutException;
  10. use Doctrine\DBAL\Exception\NonUniqueFieldNameException;
  11. use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
  12. use Doctrine\DBAL\Exception\ReadOnlyException;
  13. use Doctrine\DBAL\Exception\SyntaxErrorException;
  14. use Doctrine\DBAL\Exception\TableExistsException;
  15. use Doctrine\DBAL\Exception\TableNotFoundException;
  16. use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
  17. use Doctrine\DBAL\Platforms\SqlitePlatform;
  18. use Doctrine\DBAL\Schema\SqliteSchemaManager;
  19. use function strpos;
  20. /**
  21.  * Abstract base implementation of the {@link Driver} interface for SQLite based drivers.
  22.  */
  23. abstract class AbstractSQLiteDriver implements DriverExceptionConverterDriver
  24. {
  25.     /**
  26.      * {@inheritdoc}
  27.      *
  28.      * @deprecated
  29.      *
  30.      * @link http://www.sqlite.org/c3ref/c_abort.html
  31.      */
  32.     public function convertException($messageDeprecatedDriverException $exception)
  33.     {
  34.         if (strpos($exception->getMessage(), 'database is locked') !== false) {
  35.             return new LockWaitTimeoutException($message$exception);
  36.         }
  37.         if (
  38.             strpos($exception->getMessage(), 'must be unique') !== false ||
  39.             strpos($exception->getMessage(), 'is not unique') !== false ||
  40.             strpos($exception->getMessage(), 'are not unique') !== false ||
  41.             strpos($exception->getMessage(), 'UNIQUE constraint failed') !== false
  42.         ) {
  43.             return new UniqueConstraintViolationException($message$exception);
  44.         }
  45.         if (
  46.             strpos($exception->getMessage(), 'may not be NULL') !== false ||
  47.             strpos($exception->getMessage(), 'NOT NULL constraint failed') !== false
  48.         ) {
  49.             return new NotNullConstraintViolationException($message$exception);
  50.         }
  51.         if (strpos($exception->getMessage(), 'no such table:') !== false) {
  52.             return new TableNotFoundException($message$exception);
  53.         }
  54.         if (strpos($exception->getMessage(), 'already exists') !== false) {
  55.             return new TableExistsException($message$exception);
  56.         }
  57.         if (strpos($exception->getMessage(), 'has no column named') !== false) {
  58.             return new InvalidFieldNameException($message$exception);
  59.         }
  60.         if (strpos($exception->getMessage(), 'ambiguous column name') !== false) {
  61.             return new NonUniqueFieldNameException($message$exception);
  62.         }
  63.         if (strpos($exception->getMessage(), 'syntax error') !== false) {
  64.             return new SyntaxErrorException($message$exception);
  65.         }
  66.         if (strpos($exception->getMessage(), 'attempt to write a readonly database') !== false) {
  67.             return new ReadOnlyException($message$exception);
  68.         }
  69.         if (strpos($exception->getMessage(), 'unable to open database file') !== false) {
  70.             return new ConnectionException($message$exception);
  71.         }
  72.         return new DriverException($message$exception);
  73.     }
  74.     /**
  75.      * {@inheritdoc}
  76.      *
  77.      * @deprecated Use Connection::getDatabase() instead.
  78.      */
  79.     public function getDatabase(Connection $conn)
  80.     {
  81.         $params $conn->getParams();
  82.         return $params['path'] ?? null;
  83.     }
  84.     /**
  85.      * {@inheritdoc}
  86.      */
  87.     public function getDatabasePlatform()
  88.     {
  89.         return new SqlitePlatform();
  90.     }
  91.     /**
  92.      * {@inheritdoc}
  93.      */
  94.     public function getSchemaManager(Connection $conn)
  95.     {
  96.         return new SqliteSchemaManager($conn);
  97.     }
  98. }