/** * {@inheritdoc} * * @link http://www.sqlite.org/c3ref/c_abort.html */ public function convertException($message, DriverException $exception) { if (strpos($exception->getMessage(), 'must be unique') !== false) { return new Exception\UniqueConstraintViolationException($message, $exception); } if (strpos($exception->getMessage(), 'may not be NULL') !== false) { return new Exception\NotNullConstraintViolationException($message, $exception); } if (strpos($exception->getMessage(), 'is not unique') !== false) { return new Exception\UniqueConstraintViolationException($message, $exception); } if (strpos($exception->getMessage(), 'no such table:') !== false) { return new Exception\TableNotFoundException($message, $exception); } if (strpos($exception->getMessage(), 'already exists') !== false) { return new Exception\TableExistsException($message, $exception); } if (strpos($exception->getMessage(), 'has no column named') !== false) { return new Exception\InvalidFieldNameException($message, $exception); } if (strpos($exception->getMessage(), 'ambiguous column name') !== false) { return new Exception\NonUniqueFieldNameException($message, $exception); } if (strpos($exception->getMessage(), 'syntax error') !== false) { return new Exception\SyntaxErrorException($message, $exception); } if (strpos($exception->getMessage(), 'attempt to write a readonly database') !== false) { return new Exception\ReadOnlyException($message, $exception); } if (strpos($exception->getMessage(), 'unable to open database file') !== false) { return new Exception\ConnectionException($message, $exception); } return new Exception\DriverException($message, $exception); }
/** * {@inheritdoc} * * @link http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html */ public function convertException($message, DriverException $exception) { switch ($exception->getSQLState()) { case '23502': return new Exception\NotNullConstraintViolationException($message, $exception); case '23503': return new Exception\ForeignKeyConstraintViolationException($message, $exception); case '23505': return new Exception\UniqueConstraintViolationException($message, $exception); case '42601': return new Exception\SyntaxErrorException($message, $exception); case '42702': return new Exception\NonUniqueFieldNameException($message, $exception); case '42703': return new Exception\InvalidFieldNameException($message, $exception); case '42P01': return new Exception\TableNotFoundException($message, $exception); case '42P07': return new Exception\TableExistsException($message, $exception); case '7': // In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code. // The exception code is always set to 7 here. // We have to match against the SQLSTATE in the error message in these cases. if (strpos($exception->getMessage(), 'SQLSTATE[08006]') !== false) { return new Exception\ConnectionException($message, $exception); } break; } return new Exception\DriverException($message, $exception); }
/** * {@inheritdoc} */ public function convertException($message, DriverException $exception) { switch ($exception->getErrorCode()) { case '-239': case '-268': return new Exception\UniqueConstraintViolationException($message, $exception); case '-206': return new Exception\TableNotFoundException($message, $exception); case '-310': return new Exception\TableExistsException($message, $exception); case '-691': case '-692': case '-26018': return new Exception\ForeignKeyConstraintViolationException($message, $exception); case '-391': return new Exception\NotNullConstraintViolationException($message, $exception); case '-217': return new Exception\InvalidFieldNameException($message, $exception); case '-324': return new Exception\NonUniqueFieldNameException($message, $exception); case '-201': return new Exception\SyntaxErrorException($message, $exception); case '-908': case '-930': case '-951': return new Exception\ConnectionException($message, $exception); } // In some cases the exception doesn't have the driver-specific error code if (self::isErrorAccessDeniedMessage($exception->getMessage())) { return new Exception\ConnectionException($message, $exception); } return new Exception\DriverException($message, $exception); }