From fe75ce6773afd1b5fea7d2f46d54c321c6937a51 Mon Sep 17 00:00:00 2001 From: Jorge Robles Date: Sat, 21 Apr 2018 15:29:05 +0200 Subject: [PATCH 1/2] Added casting parameter to $query->compare --- Query.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Query.php b/Query.php index 786e648..857c744 100644 --- a/Query.php +++ b/Query.php @@ -364,7 +364,7 @@ public function getDb() * @param boolean $partialMatch * @return EMongoCriteria */ - public function compare($column, $value = null, $partialMatch = false) + public function compare($column, $value = null, $partialMatch = false, $cast=null) { $query = array(); @@ -392,6 +392,13 @@ public function compare($column, $value = null, $partialMatch = false) $value = (int)$value; } } + + switch($cast){ + case 'float': + $value=(float)$value; + break; + //@todo, other types + } switch($op){ case "<>": @@ -562,4 +569,4 @@ public function toArray($onlyCondition = false) } return $result; } -} \ No newline at end of file +} From 6035cb27ee3ef4cc232970a78400fc2c147c3c81 Mon Sep 17 00:00:00 2001 From: Jorge Robles Date: Sun, 22 Apr 2018 12:49:16 +0200 Subject: [PATCH 2/2] Float fix --- Query.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Query.php b/Query.php index 857c744..4481993 100644 --- a/Query.php +++ b/Query.php @@ -364,7 +364,7 @@ public function getDb() * @param boolean $partialMatch * @return EMongoCriteria */ - public function compare($column, $value = null, $partialMatch = false, $cast=null) + public function compare($column, $value = null, $partialMatch = false) { $query = array(); @@ -390,14 +390,9 @@ public function compare($column, $value = null, $partialMatch = false, $cast=nul ) ){ $value = (int)$value; - } - } - - switch($cast){ - case 'float': + } elseif(preg_match('@[0-9]*(\.[0-9]+)?@si',$value)){ $value=(float)$value; - break; - //@todo, other types + } } switch($op){ @@ -569,4 +564,4 @@ public function toArray($onlyCondition = false) } return $result; } -} +} \ No newline at end of file