Commit 12d16838 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Database: sql() accepts a 'specificMessage', shown if there is an exception

parent 23e8fa90
...@@ -178,12 +178,14 @@ class Database { ...@@ -178,12 +178,14 @@ class Database {
* @param $sql * @param $sql
* @param $mode * @param $mode
*/ */
public function sql($sql, $mode = ROW_REGULAR, array $parameterArray = array()) { public function sql($sql, $mode = ROW_REGULAR, array $parameterArray = array(), $specificMessage='') {
// for error reporting in exception // for error reporting in exception
if($specificMessage)
$specificMessage .= " ";
$count = $this->prepareExecute($sql, $parameterArray); $count = $this->prepareExecute($sql, $parameterArray);
if ($count === false) { if ($count === false) {
throw new DbException("No idea why this error happens - please take some time and check this: $sql", ERROR_DB_GENERIC_CHECK); throw new DbException($specificMessage . "No idea why this error happens - please take some time and check this: $sql", ERROR_DB_GENERIC_CHECK);
} }
if ($mode === ROW_IMPLODE_ALL) { if ($mode === ROW_IMPLODE_ALL) {
...@@ -199,11 +201,11 @@ class Database { ...@@ -199,11 +201,11 @@ class Database {
return array(); return array();
} }
throw new DbException("Expected one row, got nothing: $sql", ERROR_DB_TOO_FEW_ROWS); throw new DbException($specificMessage . "Expected one row, got nothing: $sql", ERROR_DB_TOO_FEW_ROWS);
} }
if ($count > 1) { if ($count > 1) {
throw new DbException("Expected one row, got $count rows: $sql", ERROR_DB_TOO_MANY_ROWS); throw new DbException($specificMessage ."Expected one row, got $count rows: $sql", ERROR_DB_TOO_MANY_ROWS);
} }
return $this->fetchOne(); return $this->fetchOne();
......
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