Commit 408a967d authored by Kim Hemsø Rasmussen's avatar Kim Hemsø Rasmussen

Updated to use switch case.

parent 8fd22324
...@@ -108,38 +108,35 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver ...@@ -108,38 +108,35 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver
*/ */
public function convertExceptionCode(\Exception $exception) public function convertExceptionCode(\Exception $exception)
{ {
if ($exception->getCode() === "42000") { switch ($exception->getCode()) {
return DBALException::ERROR_SYNTAX; case "42000":
} return DBALException::ERROR_SYNTAX;
if ($exception->getCode() === "42S02") { case "42S02":
return DBALException::ERROR_UNKNOWN_TABLE; return DBALException::ERROR_UNKNOWN_TABLE;
}
if ($exception->getCode() === "42S01") { case "42S01":
return DBALException::ERROR_TABLE_ALREADY_EXISTS; return DBALException::ERROR_TABLE_ALREADY_EXISTS;
}
if ($exception->getCode() === "42S22") { case "42S22":
return DBALException::ERROR_BAD_FIELD_NAME; return DBALException::ERROR_BAD_FIELD_NAME;
}
if ($exception->getCode() === "23000") { case "23000":
if (strpos($exception->getMessage(), 'Duplicate entry') !== false) { if (strpos($exception->getMessage(), 'Duplicate entry') !== false) {
return DBALException::ERROR_DUPLICATE_KEY; return DBALException::ERROR_DUPLICATE_KEY;
} }
if (strpos($exception->getMessage(), 'Cannot delete or update a parent row: a foreign key constraint fails') !== false) { if (strpos($exception->getMessage(), 'Cannot delete or update a parent row: a foreign key constraint fails') !== false) {
return DBALException::ERROR_FOREIGN_KEY_CONSTRAINT; return DBALException::ERROR_FOREIGN_KEY_CONSTRAINT;
} }
if (strpos($exception->getMessage(), ' cannot be null')) { if (strpos($exception->getMessage(), ' cannot be null')) {
return DBALException::ERROR_NOT_NULL; return DBALException::ERROR_NOT_NULL;
} }
if (strpos($exception->getMessage(), 'in field list is ambiguous') !== false) { if (strpos($exception->getMessage(), 'in field list is ambiguous') !== false) {
return DBALException::ERROR_NON_UNIQUE_FIELD_NAME; return DBALException::ERROR_NON_UNIQUE_FIELD_NAME;
} }
} }
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment