Skip to content

Commit

Permalink
rethrow the original exception and augment the message with schema@ho…
Browse files Browse the repository at this point in the history
…stname details
  • Loading branch information
dland committed Feb 24, 2012
1 parent d84f088 commit b6b3b26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 10 additions & 3 deletions MyDBD.php
Expand Up @@ -298,11 +298,16 @@ protected function link($autoconnect = true)
return $this->link;
}

protected function dbName ()
{
return sprintf("%s@%s", $this->connectionInfo['database'], $this->connectionInfo['hostname']);
}

protected function handleErrors($query = null)
{
if ($this->link->errno)
{
MyDBD_Error::throwError($this->link->errno, $this->link->error . ' /*@' . $this->link->host_info . '*/', $this->link->sqlstate, $query);
MyDBD_Error::throwError($this->link->errno, $this->link->error . ' /* ' . $this->dbName() . ' */', $this->link->sqlstate, $query);
}
}

Expand Down Expand Up @@ -421,7 +426,8 @@ public function prepare()
}
catch (SQLException $e)
{
throw new Exception($e->getMessage() . ' /*@' . $this->link->host_info . '*/', $e->getCode(), $e);
$e->appendMessage('/* ' . $this->dbName() . ' */');
throw $e;
}

return $sth;
Expand Down Expand Up @@ -907,7 +913,8 @@ public function execute(MyDBD_PreparedStatement $statement, $params = null)
}
catch (SQLException $e)
{
throw new Exception($e->getMessage() . ' /*@' . $this->link->host_info . '*/', $e->getCode(), $e);
$e->appendMessage('/* ' . $this->dbName() . ' */');
throw $e;
}
return $res;
}
Expand Down
6 changes: 6 additions & 0 deletions MyDBD/Error.php
Expand Up @@ -79,7 +79,13 @@ public function __construct($message = null, $code = null, $sqlstate = null)
$this->code = $code;
$this->sqlstate = $sqlstate;
}

public function appendMessage ($m)
{
$this->message .= " $m";
}
}

class SQLUnknownException extends SQLException {}
class SQLSyntaxException extends SQLException {}
class SQLConstraintException extends SQLException {}
Expand Down

0 comments on commit b6b3b26

Please sign in to comment.