From f4b107cdbb91a90f41f39d6ee0a2375e8f7ce7a6 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Fri, 11 Jan 2013 10:06:42 +0000 Subject: [PATCH] Issue 92 aggregate functions always returning ints --- README.markdown | 1 + idiorm.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index f5644db9..55864082 100644 --- a/README.markdown +++ b/README.markdown @@ -48,6 +48,7 @@ Changelog * Fix when using `set_expr` alone it doesn't trigger query creation - closes issue #90 * Escape quote symbols in "_quote_identifier_part" - close issue #74 * Add HAVING clause functionality +* Fix issue with aggregate functions always returning `int` when is `float` sometimes required - closes issue #92 #### 1.2.3 - release 2012-11-28 diff --git a/idiorm.php b/idiorm.php index 5e747176..695d6b27 100644 --- a/idiorm.php +++ b/idiorm.php @@ -514,7 +514,16 @@ protected function _call_aggregate_db_function($sql_function, $column) { } $this->select_expr("$sql_function($column)", $alias); $result = $this->find_one(); - return ($result !== false && isset($result->$alias)) ? (int) $result->$alias : 0; + + $return_value = 0; + if($result !== false && isset($result->$alias)) { + if((int) $result->$alias == (float) $result->$alias) { + $return_value = (int) $result->$alias; + } else { + $return_value = (float) $result->$alias; + } + } + return $return_value; } /**