[icinga-checkins] icinga.org: icinga-api/master: * Postgresql attribute name fix

git at icinga.org git at icinga.org
Wed Jul 14 16:30:00 CEST 2010


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

Author: jmosshammer <jmosshammer at ws-jmosshammer.(none)>
Date:   Wed Jul 14 16:25:42 2010 +0200

* Postgresql attribute name fix

---

 objects/result/IcingaApiResultIdo.php              |   11 ++++++++++-
 objects/search/IcingaApiSearchIdo.php              |   16 +++++++++++-----
 .../data_interfaces/IcingaApiSearchIdoPgsql.php    |   16 +++++++++-------
 3 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/objects/result/IcingaApiResultIdo.php b/objects/result/IcingaApiResultIdo.php
index 43fbae2..3a7c480 100644
--- a/objects/result/IcingaApiResultIdo.php
+++ b/objects/result/IcingaApiResultIdo.php
@@ -35,9 +35,11 @@ class IcingaApiResultIdo
 	 * @author Jannis Moßhammer <jannis.mosshammer at netways.de>
 	 */
 	public function rebuildColumnNames($resultSet) {
+
 		if(is_array($resultSet)) {
 			$rebuildResultSet = array();
 			foreach($resultSet as $column=>$value) {
+				$column  =strtoupper($column);
 				if(isset($this->substitutedColumns[$column]))
 					$column = $this->substitutedColumns[$column];
 				$rebuildResultSet[$column] = $value;
@@ -64,7 +66,8 @@ class IcingaApiResultIdo
 	 */
 	public function setSearchObject (&$object) {
 		$this->searchObject = $object;
- 		$this->numResults = $this->searchObject->rowCount();
+ 		 if(!$this->numResults)
+ 			$this->numResults = $this->searchObject->rowCount();
 	}
 
 	/**
@@ -75,6 +78,7 @@ class IcingaApiResultIdo
 	 * @author	Christian Doebler <christian.doebler at netways.de>
 	 */
  	public function next () {
+
  		switch ($this->resultType) {
  			case self::RESULT_OBJECT:
 				$this->resultRow = $this->searchObject->fetchObject();
@@ -120,6 +124,11 @@ class IcingaApiResultIdo
 				}
  				break;
  		}
+ 		if($this->resultRow)
+	 		foreach($this->resultRow as $val=>$entry) {
+	 		 	if(is_object($this->resultRow))
+	 		 		$this->resultRow->{strtoupper($val)} = $entry;
+	 		}
  	}
 
  	/**
diff --git a/objects/search/IcingaApiSearchIdo.php b/objects/search/IcingaApiSearchIdo.php
index 5f98c90..79d9ff6 100644
--- a/objects/search/IcingaApiSearchIdo.php
+++ b/objects/search/IcingaApiSearchIdo.php
@@ -339,8 +339,13 @@ class IcingaApiSearchIdo
 
 				case 'LIMIT':
 					if (!$loopCounter) {
-						list($variableValuesTemplate, $variableValues) =
+						 $limitValues =
 							$this->ifSettings->createQueryLimit($this->searchLimit);
+						$variableValuesTemplate = $limitValues[0];
+						for($i=1;$i<count($limitValues);$i++)
+							$variableValues[] = $limitValues[$i];
+						if(count($variableValues) == 1)
+							$variableValues = $variableValues[0];
 					} elseif ($variableValues !== false) {
 						$this->searchLimit = explode(',', $variableValues);
 					}
@@ -358,11 +363,12 @@ class IcingaApiSearchIdo
 					$variableValues = $variableValuesPrefix . $variableValues;
 				}
 				if ($variableValuesTemplate !== false) {
-					$variableValues = sprintf (
-						$variableValuesTemplate,
-						$variableValues
-					);
+					if(is_array($variableValues)) 
+						$variableValues = sprintf($variableValuesTemplate,$variableValues[0],$variableValues[1]);
+					else 				
+						$variableValues = sprintf($variableValuesTemplate,$variableValues);
 				}
+				
 			} else {
 				$variableValues = null;
 			}
diff --git a/objects/search/data_interfaces/IcingaApiSearchIdoPgsql.php b/objects/search/data_interfaces/IcingaApiSearchIdoPgsql.php
index 8c73f28..73aa4d6 100644
--- a/objects/search/data_interfaces/IcingaApiSearchIdoPgsql.php
+++ b/objects/search/data_interfaces/IcingaApiSearchIdoPgsql.php
@@ -22,7 +22,7 @@ class IcingaApiSearchIdoPgsql
 		'fieldsSuffix'	=> false,
 		'group'			=> ' group by %s ',
 		'order'			=> ' order by ',
-		'limit'			=> ' limit %s '
+		'limit'			=> ' limit %s offset %s'
 	);
 
 	public $queryMap = array (
@@ -297,9 +297,9 @@ class IcingaApiSearchIdoPgsql
 				${FIELDS}
 			from
 				${TABLE_PREFIX}notifications n
-			${if_table:on:inner join ${TABLE_PREFIX}objects `on` on on.object_id = n.object_id and on.is_active = 1}
-			${if_table:s,on:left join ${TABLE_PREFIX}services s on s.service_object_id = on.object_id}
-			${if_table:h,s,on:left join ${TABLE_PREFIX}hosts h on h.host_object_id = on.object_id or h.host_object_id = s.host_object_id}
+			${if_table:on:inner join ${TABLE_PREFIX}objects obn on obn.object_id = n.object_id and obn.is_active = 1}
+			${if_table:s,on:left join ${TABLE_PREFIX}services s on s.service_object_id = obn.object_id}
+			${if_table:h,s,on:left join ${TABLE_PREFIX}hosts h on h.host_object_id = obn.object_id or h.host_object_id = s.host_object_id}
 			${if_table:oh,h,s,on:left join ${TABLE_PREFIX}objects oh on oh.object_id = h.host_object_id}
 			${if_table:os,s,on:left join ${TABLE_PREFIX}objects os on os.object_id = s.service_object_id}
 			${FILTER}
@@ -557,8 +557,8 @@ class IcingaApiSearchIdoPgsql
 		'NOTIFICATION_LONG_OUTPUT' => array('n', 'long_output'),
 		'NOTIFICATION_ESCALATED' => array('n', 'escalated'),
 		'NOTIFICATION_NOTIFIED' => array('n', 'contacts_notified'),
-		'NOTIFICATION_OBJECT_ID' => array('on', 'object_id'),
-		'NOTIFICATION_OBJECTTYPE_ID' => array('on', 'objecttype_id'),
+		'NOTIFICATION_OBJECT_ID' => array('obn', 'object_id'),
+		'NOTIFICATION_OBJECTTYPE_ID' => array('obn', 'objecttype_id'),
 
 		// Summary queries
 		'HOSTGROUP_SUMMARY_COUNT' => array('oh', 'object_id', 'count(%s)'),
@@ -577,7 +577,9 @@ class IcingaApiSearchIdoPgsql
 		$returnValue = array($this->statements['limit']);
 
 		if ($searchLimit !== false) {
-			array_push($returnValue, implode(',', $searchLimit));
+			array_push($returnValue, 
+					   isset($searchLimit[1]) ? $searchLimit[1] : $searchLimit[0],
+					   isset($searchLimit[1]) ? $searchLimit[0] : 0);
 		} else {
 			array_push($returnValue, false);
 		}





More information about the icinga-checkins mailing list