summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/public/appframework/db/mapper.php29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/public/appframework/db/mapper.php b/lib/public/appframework/db/mapper.php
index 3bc9fbcefc6..2e97b06802a 100644
--- a/lib/public/appframework/db/mapper.php
+++ b/lib/public/appframework/db/mapper.php
@@ -282,18 +282,43 @@ abstract class Mapper {
if($row === false || $row === null){
$stmt->closeCursor();
- throw new DoesNotExistException('No matching entry found');
+ $msg = $this->buildDebugMessage(
+ 'Did expect one result but found none when executing', $sql, $params, $limit, $offset
+ );
+ throw new DoesNotExistException($msg);
}
$row2 = $stmt->fetch();
$stmt->closeCursor();
//MDB2 returns null, PDO and doctrine false when no row is available
if( ! ($row2 === false || $row2 === null )) {
- throw new MultipleObjectsReturnedException('More than one result');
+ $msg = $this->buildDebugMessage(
+ 'Did not expect more than one result when executing', $sql, $params, $limit, $offset
+ );
+ throw new MultipleObjectsReturnedException($msg);
} else {
return $row;
}
}
+ /**
+ * Builds an error message by prepending the $msg to an error message which
+ * has the parameters
+ * @see findEntity
+ * @param string $sql the sql query
+ * @param array $params the parameters of the sql query
+ * @param int $limit the maximum number of rows
+ * @param int $offset from which row we want to start
+ * @return string formatted error message string
+ * @since 9.1.0
+ */
+ private function buildDebugMessage($msg, $sql, array $params=[], $limit=null, $offset=null) {
+ return $msg .
+ ': query "' . $sql . '"; ' .
+ 'parameters ' . print_r($params, true) . '; ' .
+ 'limit "' . $limit . '"; '.
+ 'offset "' . $offset . '"';
+ }
+
/**
* Creates an entity from a row. Automatically determines the entity class