Skip to content

Commit

Permalink
Releasing 1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
technicalguru committed Apr 4, 2021
2 parents d9dbc6a + aa85ca3 commit 9c41e15
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/TgDatabase/Criterion/CriteriaImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,27 @@ public function addCriteria(Criteria $criteria, $joinCriterion) {
/**
* Queries the database and returns all defined rows.
*/
public function list() {
public function list($throwException = FALSE) {
$sql = $this->toSqlString();
\TgLog\Log::debug('criteriaQuery: '.$sql);
return $this->database->queryList($sql, $this->resultClassName);
$rc = $this->database->queryList($sql, $this->resultClassName);
if ($this->hasError() && $throwException) {
throw new \Exception('Database error when querying: '.$this->error());
}
return $rc;
}

/**
* Queries the database and returns only the first row.
*/
public function first() {
public function first($throwException = FALSE) {
$sql = $this->toSqlString();
\TgLog\Log::debug('criteriaQuery: '.$sql);
return $this->database->querySingle($sql, $this->resultClassName);
$rc = $this->database->querySingle($sql, $this->resultClassName);
if ($this->hasError() && $throwException) {
throw new \Exception('Database error when querying: '.$this->error());
}
return $rc;
}

public function toSqlString() {
Expand Down Expand Up @@ -247,12 +255,20 @@ public function quoteName($aliasOrIdentifier, $identifier = NULL) {
return $this->database->quoteName($aliasOrIdentifier);
}

/**
* Returns whether the database has an error.
* @return boolean TRUE when an error exists
*/
public function hasError() {
return $this->database->hasError();
}

/**
* Returns the error from the database connection.
* @return string error text
*/
public function error() {
return $this->error();
return $this->database->error();
}
}

0 comments on commit 9c41e15

Please sign in to comment.