Ejemplo n.º 1
0
 public function convertException(\PDOException $e)
 {
     $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
     if (in_array($code, array(1, 2299, 38911), TRUE)) {
         return Nette\Database\UniqueConstraintViolationException::from($e);
     } elseif (in_array($code, array(1400), TRUE)) {
         return Nette\Database\NotNullConstraintViolationException::from($e);
     } elseif (in_array($code, array(2266, 2291, 2292), TRUE)) {
         return Nette\Database\ForeignKeyConstraintViolationException::from($e);
     } else {
         return Nette\Database\DriverException::from($e);
     }
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
0
 public function convertException(\PDOException $e)
 {
     $code = isset($e->errorInfo[1]) ? $e->errorInfo[1] : NULL;
     $msg = $e->getMessage();
     if ($code !== 19) {
         return Nette\Database\DriverException::from($e);
     } elseif (strpos($msg, 'must be unique') !== FALSE || strpos($msg, 'is not unique') !== FALSE || strpos($msg, 'UNIQUE constraint failed') !== FALSE) {
         return Nette\Database\UniqueConstraintViolationException::from($e);
     } elseif (strpos($msg, 'may not be NULL') !== FALSE || strpos($msg, 'NOT NULL constraint failed') !== FALSE) {
         return Nette\Database\NotNullConstraintViolationException::from($e);
     } elseif (strpos($msg, 'foreign key constraint failed') !== FALSE || strpos($msg, 'FOREIGN KEY constraint failed') !== FALSE) {
         return Nette\Database\ForeignKeyConstraintViolationException::from($e);
     } else {
         return Nette\Database\ConstraintViolationException::from($e);
     }
 }
Ejemplo n.º 4
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);
     }
 }
Ejemplo n.º 5
0
 public function convertException(\PDOException $e)
 {
     return Nette\Database\DriverException::from($e);
 }
Ejemplo n.º 6
0
 /**
  * @param  string  string to be quoted
  * @param  int     data type hint
  * @return string
  */
 public function quote($string, $type = PDO::PARAM_STR)
 {
     try {
         return $this->getPdo()->quote($string, $type);
     } catch (PDOException $e) {
         throw DriverException::from($e);
     }
 }