mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°2517 - Supportability - OQL Explain
This commit is contained in:
@@ -961,7 +961,7 @@ abstract class DBSearch
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param array|hash $aOrderBy Array of '[<classalias>.]attcode' => bAscending
|
||||
* @param array $aOrderBy Array of '[<classalias>.]attcode' => bAscending
|
||||
* @param array $aArgs
|
||||
* @param null $aAttToLoad
|
||||
* @param null $aExtendedDataSpec
|
||||
@@ -1038,8 +1038,8 @@ abstract class DBSearch
|
||||
}
|
||||
try
|
||||
{
|
||||
$bBeautifulSQL = self::$m_bTraceQueries || self::$m_bDebugQuery || self::$m_bIndentQueries;
|
||||
$sRes = $oSQLQuery->RenderSelect($aOrderSpec, $aScalarArgs, $iLimitCount, $iLimitStart, $bGetCount, $bBeautifulSQL);
|
||||
// $bBeautifulSQL = self::$m_bTraceQueries || self::$m_bDebugQuery || self::$m_bIndentQueries;
|
||||
$sRes = $oSQLQuery->RenderSelect($aOrderSpec, $aScalarArgs, $iLimitCount, $iLimitStart, $bGetCount, true);
|
||||
if ($sClassAlias == '_itop_')
|
||||
{
|
||||
IssueLog::Info('SQL Query (_itop_): '.$sRes);
|
||||
|
||||
@@ -455,8 +455,9 @@ class DBUnionSearch extends DBSearch
|
||||
|
||||
/**
|
||||
* Returns a new DBUnionSearch object where duplicates queries have been removed based on their OQLs
|
||||
*
|
||||
*
|
||||
* @return \DBUnionSearch
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function RemoveDuplicateQueries()
|
||||
{
|
||||
|
||||
@@ -363,11 +363,11 @@ class SQLObjectQuery extends SQLQuery
|
||||
$sCountFields = implode(', ', $aCountFields);
|
||||
// Count can be limited for performance reason, in this case the total amount is not important,
|
||||
// we only need to know if the number of entries is greater than a certain amount.
|
||||
$sSQL = "SELECT COUNT(*) AS COUNT FROM (SELECT$sLineSep DISTINCT $sCountFields $sLineSep FROM $sFrom$sLineSep WHERE $sWhere $sLimit) AS _tatooine_";
|
||||
$sSQL = "SELECT COUNT(*) AS COUNT FROM (SELECT$sLineSep DISTINCT $sCountFields $sLineSep FROM $sFrom$sLineSep WHERE $sWhere $sLimit) AS _alderaan_";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sSQL = "SELECT COUNT(*) AS COUNT FROM (SELECT$sLineSep 1 $sLineSep FROM $sFrom$sLineSep WHERE $sWhere $sLimit) AS _tatooine_";
|
||||
$sSQL = "SELECT COUNT(*) AS COUNT FROM (SELECT$sLineSep 1 $sLineSep FROM $sFrom$sLineSep WHERE $sWhere $sLimit) AS _alderaan_";
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -116,7 +116,7 @@ class SQLUnionQuery extends SQLQuery
|
||||
{
|
||||
$sSelects = '('.implode(" $sLimit)$sLineSep UNION$sLineSep(", $aSelects)." $sLimit)";
|
||||
$sFrom = "($sLineSep$sSelects$sLineSep) as __selects__";
|
||||
$sSQL = "SELECT COUNT(*) AS COUNT FROM (SELECT$sLineSep 1 $sLineSep FROM $sFrom$sLineSep) AS _union_tatooine_";
|
||||
$sSQL = "SELECT COUNT(*) AS COUNT FROM (SELECT$sLineSep 1 $sLineSep FROM $sFrom$sLineSep) AS _union_alderaan_";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -694,6 +694,10 @@ Dict::Add('EN US', 'English', 'English', array(
|
||||
'UI:RunQuery:MoreInfo' => 'More information about the query: ',
|
||||
'UI:RunQuery:DevelopedQuery' => 'Redevelopped query expression: ',
|
||||
'UI:RunQuery:SerializedFilter' => 'Serialized filter: ',
|
||||
'UI:RunQuery:DevelopedOQL' => 'Developed OQL',
|
||||
'UI:RunQuery:DevelopedOQLCount' => 'Developed OQL for count',
|
||||
'UI:RunQuery:ResultSQLCount' => 'Resulting SQL for count',
|
||||
'UI:RunQuery:ResultSQL' => 'Resulting SQL',
|
||||
'UI:RunQuery:Error' => 'An error occured while running the query: %1$s',
|
||||
'UI:Query:UrlForExcel' => 'URL to use for MS-Excel web queries',
|
||||
'UI:Query:UrlV1' => 'The list of fields has been left unspecified. The page <em>export-V2.php</em> cannot be invoked without this information. Therefore, the URL suggested here below points to the legacy page: <em>export.php</em>. This legacy version of the export has the following limitation: the list of exported fields may vary depending on the output format and the data model of '.ITOP_APPLICATION_SHORT.'. <br/>Should you want to guarantee that the list of exported columns will remain stable on the long run, then you must specify a value for the attribute "Fields" and use the page <em>export-V2.php</em>.',
|
||||
|
||||
@@ -676,6 +676,11 @@ Dict::Add('FR FR', 'French', 'Français', array(
|
||||
'UI:RunQuery:MoreInfo' => 'Plus d\'information sur la requête : ',
|
||||
'UI:RunQuery:DevelopedQuery' => 'Requête OQL décompilée : ',
|
||||
'UI:RunQuery:SerializedFilter' => 'Version sérialisée : ',
|
||||
'UI:RunQuery:DevelopedOQL' => 'OQL développé',
|
||||
'UI:RunQuery:DevelopedOQLCount' => 'OQL développé pour le compte',
|
||||
'UI:RunQuery:ResultSQLCount' => 'SQL généré pour le compte',
|
||||
'UI:RunQuery:ResultSQL' => 'SQL généré',
|
||||
|
||||
'UI:RunQuery:Error' => 'Une erreur s\'est produite durant l\'exécution de la requête : %1$s',
|
||||
'UI:Query:UrlForExcel' => 'Lien à copier-coller dans Excel, pour déclarer une source de données à partir du web',
|
||||
'UI:Query:UrlV1' => 'La liste des champs à exporter n\'a pas été spécifiée. La page <em>export-V2.php</em> ne peut pas fonctionner sans cette information. Par conséquent, le lien fourni ci-dessous pointe sur l\'ancienne page: <em>export.php</em>. Cette ancienne version de l\'export présente la limitation suivante : la liste des champs exportés varie en fonction du format de l\'export et du modèle de données. <br/>Si vous devez garantir la stabilité du format de l\'export (liste des colonnes) sur le long terme, alors vous devrez renseigner l\'attribut "Champs" et utiliser la page <em>export-V2.php</em>.',
|
||||
|
||||
@@ -111,10 +111,6 @@ try
|
||||
$oFilter = DBObjectSearch::unserialize($sExpression);
|
||||
$sExpression = $oFilter->ToOQL();
|
||||
}
|
||||
else
|
||||
{
|
||||
// leave $sExpression as is
|
||||
}
|
||||
|
||||
$oFilter = null;
|
||||
$aArgs = array();
|
||||
@@ -154,10 +150,7 @@ try
|
||||
}
|
||||
}
|
||||
$oFilter->SetInternalParams($aArgs);
|
||||
}
|
||||
elseif ($sSyntaxError)
|
||||
{
|
||||
// Query arguments taken from the page args
|
||||
$aRealArgs = $aArgs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,6 +215,56 @@ EOF
|
||||
$oP->StartCollapsibleSection(Dict::S('UI:RunQuery:MoreInfo'), false, 'runQuery');
|
||||
$oP->p(Dict::S('UI:RunQuery:DevelopedQuery').htmlentities($oFilter->ToOQL(), ENT_QUOTES, 'UTF-8'));
|
||||
$oP->p(Dict::S('UI:RunQuery:SerializedFilter').htmlentities($oFilter->serialize(), ENT_QUOTES, 'UTF-8'));
|
||||
|
||||
|
||||
$aModifierProperties = MetaModel::MakeModifierProperties($oFilter);
|
||||
|
||||
// Avoid adding all the fields for counts or "group by" requests
|
||||
$aCountAttToLoad = array();
|
||||
$sMainClass = null;
|
||||
foreach ($oFilter->GetSelectedClasses() as $sClassAlias => $sClass)
|
||||
{
|
||||
$aCountAttToLoad[$sClassAlias] = array();
|
||||
if (empty($sMainClass))
|
||||
{
|
||||
$sMainClass = $sClass;
|
||||
}
|
||||
}
|
||||
|
||||
$aOrderBy = MetaModel::GetOrderByDefault($sMainClass);
|
||||
|
||||
if ($oFilter instanceof DBObjectSearch)
|
||||
{
|
||||
// OQL Developed for Count
|
||||
$oP->p('');
|
||||
$oP->p(Dict::S('UI:RunQuery:DevelopedOQLCount'));
|
||||
$oSQLObjectQueryBuilder = new SQLObjectQueryBuilder($oFilter);
|
||||
$oBuild = new QueryBuilderContext($oFilter, $aModifierProperties, null, null, null, $aCountAttToLoad);
|
||||
$oP->p('<pre>'.$oSQLObjectQueryBuilder->DebugOQLClassTree($oBuild).'</pre>');
|
||||
}
|
||||
|
||||
// SQL Count
|
||||
$oP->p('');
|
||||
$oP->p(Dict::S('UI:RunQuery:ResultSQLCount'));
|
||||
$sSQL = $oFilter->MakeSelectQuery(array(), $aRealArgs, $aCountAttToLoad, null, 0, 0, true);
|
||||
$oP->p("<pre>$sSQL</pre>");
|
||||
|
||||
if ($oFilter instanceof DBObjectSearch)
|
||||
{
|
||||
// OQL Developed
|
||||
$oP->p('');
|
||||
$oP->p(Dict::S('UI:RunQuery:DevelopedOQL'));
|
||||
$oSQLObjectQueryBuilder = new SQLObjectQueryBuilder($oFilter);
|
||||
$oBuild = new QueryBuilderContext($oFilter, $aModifierProperties);
|
||||
$oP->p('<pre>'.$oSQLObjectQueryBuilder->DebugOQLClassTree($oBuild).'</pre>');
|
||||
}
|
||||
|
||||
// SQL
|
||||
$oP->p('');
|
||||
$oP->p(Dict::S('UI:RunQuery:ResultSQL'));
|
||||
$sSQL = $oFilter->MakeSelectQuery($aOrderBy, $aRealArgs, null, null, 0, 0, false);
|
||||
$oP->p("<pre>$sSQL</pre>");
|
||||
|
||||
$oP->EndCollapsibleSection();
|
||||
}
|
||||
elseif ($sSyntaxError)
|
||||
@@ -266,4 +309,4 @@ catch(Exception $e)
|
||||
}
|
||||
|
||||
$oP->output();
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user