###What happened:
- something
$model::find('count',array('1'));
throws a fatal error, which can not be trapped in try/catch
###What was expected:
numeric result
###Patch
diff --git a/libraries/lithium/data/source/Database.php b/libraries/lithium/data/source/Database.php
index dcb499f..b3069cd 100644
@@ -617,6 +675,29 @@ abstract class Database extends \lithium\data\Source {
}
return (boolean) $value;
}
+
+ /**
+ * Executes calculation-related queries, such as those required for `count`.
+ *
+ * @param string $type Only accepts `count`.
+ * @param mixed $query The query to be executed.
+ * @param array $options Optional arguments for the `read()` query that will be executed
+ * to obtain the calculation result.
+ * @return integer Result of the calculation.
+ */
+ public function calculation($type, $query, array $options = array()) {
+ $query->calculate($type);
+ $query->fields(array("count(*) as C"));
+
+ $sql = $this->renderCommand($query);
+ $res = $this->invokeMethod('_execute', array($sql));
+ if ($res) {
+ $data = $this->result('next', $res, null);
+ return intval(implode('',$data));
+ }
+ return -1;
+ }
+
}
-?>
\ No newline at end of file
+?>
{{{ diff --git a/libraries/lithium/data/source/Database.php b/libraries/lithium/data/source/Database.php index dcb499f..b3069cd 100644 @@ -617,6 +675,29 @@ abstract class Database extends \lithium\data\Source { } return (boolean) $value; } + + /** + * Executes calculation-related queries, such as those required for `count`. + * + * @param string $type Only accepts `count`. + * @param mixed $query The query to be executed. + * @param array $options Optional arguments for the `read()` query that will be executed + * to obtain the calculation result. + * @return integer Result of the calculation. + */ + public function calculation($type, $query, array $options = array()) { + $query->calculate($type); + $query->fields(array("count(*) as C")); + + $sql = $this->renderCommand($query); + $res = $this->invokeMethod('_execute', array($sql)); + if ($res) { + $data = $this->result('next', $res, null); + return intval(implode('',$data)); + } + return -1; + } + } -?> \ No newline at end of file +?> }}}