Exemplo n.º 1
0
 /**
  * Gets the single result of the query.
  * Enforces the uniqueness of the result. If the result is not unique,
  * a QueryException is thrown.
  *
  * @param integer $hydrationMode
  * @return mixed
  * @throws QueryException If the query result is not unique.
  */
 public function getSingleResult($hydrationMode = null)
 {
     $result = $this->execute(array(), $hydrationMode);
     if (is_array($result)) {
         if (count($result) > 1) {
             throw QueryException::nonUniqueResult();
         }
         return array_shift($result);
     } else {
         if (is_object($result)) {
             if (count($result) > 1) {
                 throw QueryException::nonUniqueResult();
             }
             return $result->first();
         }
     }
     return $result;
 }