From 3f2e383b47dcce6196c83be4f3f3b492fca49880 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 19 Jan 2012 02:25:30 +0100 Subject: [PATCH] __toString() do not throw an exception [Closes #19] --- dibi/libs/DibiDataSource.php | 18 +++++++++++------- dibi/libs/DibiFluent.php | 6 +++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dibi/libs/DibiDataSource.php b/dibi/libs/DibiDataSource.php index 1fe6ceb4..bb700196 100644 --- a/dibi/libs/DibiDataSource.php +++ b/dibi/libs/DibiDataSource.php @@ -285,13 +285,17 @@ class DibiDataSource extends DibiObject implements IDataSource */ public function __toString() { - return $this->connection->translate(' - SELECT %n', (empty($this->cols) ? '*' : $this->cols), ' - FROM %SQL', $this->sql, ' - %ex', $this->conds ? array('WHERE %and', $this->conds) : NULL, ' - %ex', $this->sorting ? array('ORDER BY %by', $this->sorting) : NULL, ' - %ofs %lmt', $this->offset, $this->limit - ); + try { + return $this->connection->translate(' + SELECT %n', (empty($this->cols) ? '*' : $this->cols), ' + FROM %SQL', $this->sql, ' + %ex', $this->conds ? array('WHERE %and', $this->conds) : NULL, ' + %ex', $this->sorting ? array('ORDER BY %by', $this->sorting) : NULL, ' + %ofs %lmt', $this->offset, $this->limit + ); + } catch (Exception $e) { + trigger_error($e->getMessage(), E_USER_ERROR); + } } diff --git a/dibi/libs/DibiFluent.php b/dibi/libs/DibiFluent.php index 9f06d2a8..dbf2e4a8 100644 --- a/dibi/libs/DibiFluent.php +++ b/dibi/libs/DibiFluent.php @@ -434,7 +434,11 @@ class DibiFluent extends DibiObject implements IDataSource */ final public function __toString() { - return $this->connection->translate($this->_export()); + try { + return $this->connection->translate($this->_export()); + } catch (Exception $e) { + trigger_error($e->getMessage(), E_USER_ERROR); + } }