@@ -94,19 +94,27 @@ public function addCriteria(Criteria $criteria, $joinCriterion) {
94
94
/**
95
95
* Queries the database and returns all defined rows.
96
96
*/
97
- public function list () {
97
+ public function list ($ throwException = FALSE ) {
98
98
$ sql = $ this ->toSqlString ();
99
99
\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 ;
101
105
}
102
106
103
107
/**
104
108
* Queries the database and returns only the first row.
105
109
*/
106
- public function first () {
110
+ public function first ($ throwException = FALSE ) {
107
111
$ sql = $ this ->toSqlString ();
108
112
\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 ;
110
118
}
111
119
112
120
public function toSqlString () {
@@ -247,12 +255,20 @@ public function quoteName($aliasOrIdentifier, $identifier = NULL) {
247
255
return $ this ->database ->quoteName ($ aliasOrIdentifier );
248
256
}
249
257
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
+
250
266
/**
251
267
* Returns the error from the database connection.
252
268
* @return string error text
253
269
*/
254
270
public function error () {
255
- return $ this ->error ();
271
+ return $ this ->database -> error ();
256
272
}
257
273
}
258
274
0 commit comments