Example #1
0
 /**
  * @return Nette\Database\DriverException
  */
 public function convertException(\PDOException $e)
 {
     $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
     if (in_array($code, [1216, 1217, 1451, 1452, 1701], TRUE)) {
         return Nette\Database\ForeignKeyConstraintViolationException::from($e);
     } elseif (in_array($code, [1062, 1557, 1569, 1586], TRUE)) {
         return Nette\Database\UniqueConstraintViolationException::from($e);
     } elseif ($code >= 2001 && $code <= 2028) {
         return Nette\Database\ConnectionException::from($e);
     } elseif (in_array($code, [1048, 1121, 1138, 1171, 1252, 1263, 1566], TRUE)) {
         return Nette\Database\NotNullConstraintViolationException::from($e);
     } else {
         return Nette\Database\DriverException::from($e);
     }
 }
Example #2
0
 public function convertException(\PDOException $e)
 {
     $code = isset($e->errorInfo[0]) ? $e->errorInfo[0] : NULL;
     if ($code === '0A000' && strpos($e->getMessage(), 'truncate') !== FALSE) {
         return Nette\Database\ForeignKeyConstraintViolationException::from($e);
     } elseif ($code === '23502') {
         return Nette\Database\NotNullConstraintViolationException::from($e);
     } elseif ($code === '23503') {
         return Nette\Database\ForeignKeyConstraintViolationException::from($e);
     } elseif ($code === '23505') {
         return Nette\Database\UniqueConstraintViolationException::from($e);
     } elseif ($code === '08006') {
         return Nette\Database\ConnectionException::from($e);
     } else {
         return Nette\Database\DriverException::from($e);
     }
 }