[icinga-checkins] icinga.org: icinga-api/master: * Added automatic grouping for queries with arithmetic queries

git at icinga.org git at icinga.org
Wed Sep 29 14:38:10 CEST 2010


Module: icinga-api
Branch: master
Commit: 0aed9d4da7347bfc4272fb4bc3f6bea044a77125
URL:    https://git.icinga.org/?p=icinga-api.git;a=commit;h=0aed9d4da7347bfc4272fb4bc3f6bea044a77125

Author: jmosshammer <jannis.mosshammer at netways.com>
Date:   Wed Sep 29 14:37:36 2010 +0200

* Added automatic grouping for queries with  arithmetic queries

---

 .../data_interfaces/IcingaApiSearchIdoPgsql.php    |   39 +++++++++++++++++++-
 1 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/objects/search/data_interfaces/IcingaApiSearchIdoPgsql.php b/objects/search/data_interfaces/IcingaApiSearchIdoPgsql.php
index 800e6b0..cf416f4 100644
--- a/objects/search/data_interfaces/IcingaApiSearchIdoPgsql.php
+++ b/objects/search/data_interfaces/IcingaApiSearchIdoPgsql.php
@@ -15,8 +15,10 @@ class IcingaApiSearchIdoPgsql
 
 	public $tablePrefix = 'icinga_';
 	public $postProcess = false;
+	public $groupByCols = array();
 	public $clearVariables = array();
-
+	public $hasArithmeticField = false;
+	public $originalGrouping = array();
 	public $statements = array (
 		'fieldsSuffix'	=> false,
 		'group'			=> ' group by %s ',
@@ -687,6 +689,39 @@ class IcingaApiSearchIdoPgsql
 	 */
 	public function createQueryGroup ($searchGroup = false, $resultColumns = false) {
 		$returnValue = array($this->statements['group']);
+
+		if (!empty($searchGroup) || $this->hasArithmeticField) {
+			if($this->hasArithmeticField) {
+				foreach ($resultColumns as $currentColumn) {
+					// the following functions are not allowed in oracle groups
+					if(preg_match("/(count|max|avg|min|sum|stddev|variance)/",$currentColumn))
+						continue;
+
+					if (!in_array($currentColumn, $searchGroup)) {
+						array_push($searchGroup, $currentColumn);
+					}
+				}
+			}
+			$this->originalGrouping = implode(',', $searchGroup);
+			if($this->hasArithmeticField)
+				$searchGroup = array_merge($searchGroup,$this->groupByCols);
+
+			array_push($returnValue, implode(',', $searchGroup));
+		} else {
+			array_push($returnValue, false);
+		}
+
+
+		return $returnValue;
+	}
+
+
+	/**
+	 * (non-PHPdoc)
+	 * @see objects/search/ido_interfaces/IcingaApiSearchIdoInterface#createQueryGroup($searchGroup)
+	 */
+	/*public function createQueryGroup ($searchGroup = false, $resultColumns = false) {
+		$returnValue = array($this->statements['group']);
 	
 		if (!empty($searchGroup)) {
 			array_push($returnValue, implode(',', $searchGroup));
@@ -696,7 +731,7 @@ class IcingaApiSearchIdoPgsql
 
 		return $returnValue;
 	}
-	
+	*/
 	
 	
 	/**





More information about the icinga-checkins mailing list