public function resolveException($e, $query = NULL, $params = [])
{
if ($this->throwOldKdybyExceptions !== TRUE) {
return $e;
}
if ($e instanceof Doctrine\DBAL\DBALException && ($pe = $e->getPrevious()) instanceof \PDOException) {
$info = $pe->errorInfo;
} elseif ($e instanceof \PDOException) {
$info = $e->errorInfo;
} else {
return new DBALException($e, $query, $params, $this);
}
if ($this->getDriver() instanceof Doctrine\DBAL\Driver\PDOMySql\Driver) {
if ($info[0] == 23000 && $info[1] == self::MYSQL_ERR_UNIQUE) {
// unique fail
$columns = [];
try {
if (preg_match('~Duplicate entry .*? for key \'([^\']+)\'~', $info[2], $m) && ($table = self::resolveExceptionTable($e)) && ($indexes = $this->getSchemaManager()->listTableIndexes($table)) && isset($indexes[$m[1]])) {
$columns[$m[1]] = $indexes[$m[1]]->getColumns();
}
} catch (\Exception $e) {
}
return new DuplicateEntryException($e, $columns, $query, $params, $this);
} elseif ($info[0] == 23000 && $info[1] == self::MYSQL_ERR_NOT_NULL) {
// notnull fail
$column = NULL;
if (preg_match('~Column \'([^\']+)\'~', $info[2], $m)) {
$column = $m[1];
}
return new EmptyValueException($e, $column, $query, $params, $this);
}
}
$raw = $e;
do {
$raw = $raw->getPrevious();
} while ($raw && !$raw instanceof \PDOException);
return new DBALException($e, $query, $params, $this, $raw ? $raw->getMessage() : $e->getMessage());
}