diff --git a/core/dbsearch.class.php b/core/dbsearch.class.php index 59861b464..24a11afaf 100644 --- a/core/dbsearch.class.php +++ b/core/dbsearch.class.php @@ -1277,6 +1277,23 @@ abstract class DBSearch { $aQueryData['oql'] = $sOql; unset($aQueryData['filter']); + if (!empty($aAttToLoad)) + { + $aAttToLoadNames = array(); + foreach ($aAttToLoad as $sClass => $aAttributes) + { + $aAttToLoadNames[$sClass] = array(); + foreach ($aAttributes as $sAttCode => $oAttDef) + { + $aAttToLoadNames[$sClass][] = $sAttCode; + } + } + } + else + { + $aAttToLoadNames = null; + } + $aQueryData['att_to_load'] = $aAttToLoadNames; $hLogFile = @fopen(APPROOT.'log/oql_records.txt', 'a'); if ($hLogFile !== false) diff --git a/test/build_test_oql.php b/test/build_test_oql.php index d36e263af..ba25b2978 100644 --- a/test/build_test_oql.php +++ b/test/build_test_oql.php @@ -105,8 +105,8 @@ if ($oOQLHandle) { $iCount++; $sOrderBy = ConvertArray($aRecord['order_by']); $sArgs = ConvertArray($aRecord['args']); - $sGroupByExpr = ConvertArray($aRecord['group_by_expr']); - $sSelectExpr = ConvertArray($aRecord['select_expr']); + $sGroupByExpr = ConvertArray($aRecord['group_by_expr'], true); + $sSelectExpr = ConvertArray($aRecord['select_expr'], true); if ($aRecord['exclude_null_values']) { $bExcludeNullValues = 'true'; @@ -134,7 +134,7 @@ if ($oOQLHandle) { echo "
File '$sTestFile' generated with ".($iCount-1000)." entries (from $iRead captured OQL).\n"; -function ConvertArray($aArray) +function ConvertArray($aArray, $bB64Encode = false) { if (is_null($aArray)) { @@ -146,5 +146,9 @@ function ConvertArray($aArray) return 'array()'; } - return 'unserialize(base64_decode(\''.base64_encode(serialize($aArray)).'\'))'; + if ($bB64Encode) + { + return 'unserialize(base64_decode(\''.base64_encode(serialize($aArray)).'\'))'; + } + return 'unserialize(\''.serialize($aArray).'\')'; } \ No newline at end of file diff --git a/test/core/OQLToSQLTest.php b/test/core/OQLToSQLTest.php index 3ef455f43..cef247f2b 100644 --- a/test/core/OQLToSQLTest.php +++ b/test/core/OQLToSQLTest.php @@ -238,8 +238,31 @@ class OQLToSQLTest extends ItopDataTestCase * @throws \MissingQueryArgument * @throws \OQLException */ - private function OQLSelectRunner($sOQL, $aOrderBy = array(), $aArgs = array(), $aAttToLoad = null, $aExtendedDataSpec = null, $iLimitCount = 20, $iLimitStart = 0) + private function OQLSelectRunner($sOQL, $aOrderBy = array(), $aArgs = array(), $aAttToLoadNames = null, $aExtendedDataSpec = null, $iLimitCount = 20, $iLimitStart = 0) { + if (is_null($aAttToLoadNames)) + { + $aAttToLoad = null; + } + else + { + $aAttToLoad = array(); + foreach ($aAttToLoadNames as $sClass => $aAttCodes) + { + $aAttToLoad[$sClass] = array(); + foreach ($aAttCodes as $sAttCode) + { + if (!empty($sAttCode)) + { + if (MetaModel::IsValidAttCode($sClass, $sAttCode)) + { + $aAttToLoad[$sClass][$sAttCode] = MetaModel::GetAttributeDef($sClass, $sAttCode); + } + } + } + } + } + $oSearch = DBSearch::FromOQL($sOQL); $sSQLCount = $oSearch->MakeSelectQuery($aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, 0, 0, true); @@ -343,12 +366,12 @@ class OQLToSQLTest extends ItopDataTestCase $aAttToLoad150 = array( 'WebServer' => array( - 'business_criticity' => MetaModel::GetAttributeDef('WebServer', 'business_criticity'), - 'description' => MetaModel::GetAttributeDef('WebServer', 'description'), - 'name' => MetaModel::GetAttributeDef('WebServer', 'name'), - 'friendlyname' => MetaModel::GetAttributeDef('WebServer', 'friendlyname'), - 'obsolescence_flag' => MetaModel::GetAttributeDef('WebServer', 'obsolescence_flag'), - 'finalclass' => MetaModel::GetAttributeDef('WebServer', 'finalclass'), + 'business_criticity', + 'description', + 'name', + 'friendlyname', + 'obsolescence_flag', + 'finalclass', ), );