Skip to content

Commit 9c41e15

Browse files
committed
Releasing 1.2.3
2 parents d9dbc6a + aa85ca3 commit 9c41e15

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/TgDatabase/Criterion/CriteriaImpl.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,27 @@ public function addCriteria(Criteria $criteria, $joinCriterion) {
9494
/**
9595
* Queries the database and returns all defined rows.
9696
*/
97-
public function list() {
97+
public function list($throwException = FALSE) {
9898
$sql = $this->toSqlString();
9999
\TgLog\Log::debug('criteriaQuery: '.$sql);
100-
return $this->database->queryList($sql, $this->resultClassName);
100+
$rc = $this->database->queryList($sql, $this->resultClassName);
101+
if ($this->hasError() && $throwException) {
102+
throw new \Exception('Database error when querying: '.$this->error());
103+
}
104+
return $rc;
101105
}
102106

103107
/**
104108
* Queries the database and returns only the first row.
105109
*/
106-
public function first() {
110+
public function first($throwException = FALSE) {
107111
$sql = $this->toSqlString();
108112
\TgLog\Log::debug('criteriaQuery: '.$sql);
109-
return $this->database->querySingle($sql, $this->resultClassName);
113+
$rc = $this->database->querySingle($sql, $this->resultClassName);
114+
if ($this->hasError() && $throwException) {
115+
throw new \Exception('Database error when querying: '.$this->error());
116+
}
117+
return $rc;
110118
}
111119

112120
public function toSqlString() {
@@ -247,12 +255,20 @@ public function quoteName($aliasOrIdentifier, $identifier = NULL) {
247255
return $this->database->quoteName($aliasOrIdentifier);
248256
}
249257

258+
/**
259+
* Returns whether the database has an error.
260+
* @return boolean TRUE when an error exists
261+
*/
262+
public function hasError() {
263+
return $this->database->hasError();
264+
}
265+
250266
/**
251267
* Returns the error from the database connection.
252268
* @return string error text
253269
*/
254270
public function error() {
255-
return $this->error();
271+
return $this->database->error();
256272
}
257273
}
258274

0 commit comments

Comments
 (0)