From 9032f25d64fd95b82a0763c8fb38100f0f877d1a Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Mon, 4 Dec 2017 15:07:21 +0000 Subject: [PATCH] CMDBSource : fix code errors and some warnings SVN:trunk[5149] --- core/cmdbsource.class.inc.php | 67 ++++++++++++++++++++++++++++++++--- core/dbsearch.class.php | 2 +- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/core/cmdbsource.class.inc.php b/core/cmdbsource.class.inc.php index b4e221a4c..95cf4365e 100644 --- a/core/cmdbsource.class.inc.php +++ b/core/cmdbsource.class.inc.php @@ -91,6 +91,14 @@ class CMDBSource /** @var mysqli */ protected static $m_oMysqli; + /** + * @param string $sServer + * @param string $sUser + * @param string $sPwd + * @param string $sSource + * + * @throws \MySQLException + */ public static function Init($sServer, $sUser, $sPwd, $sSource = '') { self::$m_sDBHost = $sServer; @@ -195,7 +203,12 @@ class CMDBSource $aVersions = self::QueryToCol('SELECT Version() as version', 'version'); return $aVersions[0]; } - + + /** + * @param string $sSource + * + * @throws \MySQLException + */ public static function SelectDB($sSource) { if (!((bool)self::$m_oMysqli->query("USE `$sSource`"))) @@ -205,6 +218,12 @@ class CMDBSource self::$m_sDBName = $sSource; } + /** + * @param string $sSource + * + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + */ public static function CreateDB($sSource) { self::Query("CREATE DATABASE `$sSource` CHARACTER SET utf8 COLLATE utf8_unicode_ci"); @@ -373,6 +392,14 @@ class CMDBSource self::Query($sSQLQuery); } + /** + * @param string $sSql + * + * @return string[] first line of results + * @throws \MySQLException if query cannot be processed, or no result found + * + * @uses \mysqli_result->fetch_array + */ public static function QueryToScalar($sSql) { $oKPI = new ExecutionKPI(); @@ -404,6 +431,12 @@ class CMDBSource return $res; } + /** + * @param string $sSql + * + * @return array + * @throws \MySQLException if query cannot be processed + */ public static function QueryToArray($sSql) { $aData = array(); @@ -442,6 +475,12 @@ class CMDBSource return $aColumn; } + /** + * @param string $sSql + * + * @return array + * @throws \MySQLException if query cannot be processed + */ public static function ExplainQuery($sSql) { $aData = array(); @@ -457,8 +496,8 @@ class CMDBSource { throw new MySQLException('Failed to issue SQL query', array('query' => $sSql)); } - - $aNames = self::GetColumns($oResult); + + $aNames = self::GetColumns($oResult, $sSql); $aData[] = $aNames; while ($aRow = $oResult->fetch_array(MYSQLI_ASSOC)) @@ -469,6 +508,12 @@ class CMDBSource return $aData; } + /** + * @param string $sSql + * + * @return string + * @throws \MySQLException if query cannot be processed + */ public static function TestQuery($sSql) { try @@ -506,7 +551,14 @@ class CMDBSource return $oResult->fetch_array(MYSQLI_ASSOC); } - public static function GetColumns($oResult) + /** + * @param mysqli_result $oResult + * @param string $sSql + * + * @return string[] + * @throws \MySQLException + */ + public static function GetColumns($oResult, $sSql) { $aNames = array(); for ($i = 0; $i < (($___mysqli_tmp = $oResult->field_count) ? $___mysqli_tmp : 0) ; $i++) @@ -718,6 +770,12 @@ class CMDBSource //return null; } + /** + * @param string $sTable + * + * @return array + * @throws \MySQLException if query cannot be processed + */ public static function DumpTable($sTable) { $sSql = "SELECT * FROM `$sTable`"; @@ -773,6 +831,7 @@ class CMDBSource } catch(MySQLException $e) { + $iCode = self::GetErrNo(); return "Current user not allowed to see his own privileges (could not access to the database 'mysql' - $iCode)"; } diff --git a/core/dbsearch.class.php b/core/dbsearch.class.php index 6c8d6fba1..e27c2d6b2 100644 --- a/core/dbsearch.class.php +++ b/core/dbsearch.class.php @@ -375,7 +375,7 @@ abstract class DBSearch array_unshift($aColumns, 'id'); } - $aQueryCols = CMDBSource::GetColumns($resQuery); + $aQueryCols = CMDBSource::GetColumns($resQuery, $sSQL); $sClassAlias = $this->GetClassAlias(); $aColMap = array();