diff --git a/core/dbsearch.class.php b/core/dbsearch.class.php index aa2083611..5bc189a81 100644 --- a/core/dbsearch.class.php +++ b/core/dbsearch.class.php @@ -961,7 +961,7 @@ abstract class DBSearch * * @internal * - * @param array|hash $aOrderBy Array of '[.]attcode' => bAscending + * @param array $aOrderBy Array of '[.]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); diff --git a/core/dbunionsearch.class.php b/core/dbunionsearch.class.php index 72769ca42..94f422afb 100644 --- a/core/dbunionsearch.class.php +++ b/core/dbunionsearch.class.php @@ -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() { diff --git a/core/sqlobjectquery.class.inc.php b/core/sqlobjectquery.class.inc.php index e25e6c41e..6ee8c2900 100644 --- a/core/sqlobjectquery.class.inc.php +++ b/core/sqlobjectquery.class.inc.php @@ -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 diff --git a/core/sqlunionquery.class.inc.php b/core/sqlunionquery.class.inc.php index cfc115966..75da141e1 100644 --- a/core/sqlunionquery.class.inc.php +++ b/core/sqlunionquery.class.inc.php @@ -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 { diff --git a/dictionaries/en.dictionary.itop.ui.php b/dictionaries/en.dictionary.itop.ui.php index 0ae4eeb55..5e473efd7 100644 --- a/dictionaries/en.dictionary.itop.ui.php +++ b/dictionaries/en.dictionary.itop.ui.php @@ -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 export-V2.php cannot be invoked without this information. Therefore, the URL suggested here below points to the legacy page: export.php. 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.'.
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 export-V2.php.', diff --git a/dictionaries/fr.dictionary.itop.ui.php b/dictionaries/fr.dictionary.itop.ui.php index 7d82e74d3..905a9630d 100644 --- a/dictionaries/fr.dictionary.itop.ui.php +++ b/dictionaries/fr.dictionary.itop.ui.php @@ -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 export-V2.php ne peut pas fonctionner sans cette information. Par conséquent, le lien fourni ci-dessous pointe sur l\'ancienne page: export.php. 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.
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 export-V2.php.', diff --git a/pages/run_query.php b/pages/run_query.php index 1aec65971..8f5561440 100644 --- a/pages/run_query.php +++ b/pages/run_query.php @@ -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('
'.$oSQLObjectQueryBuilder->DebugOQLClassTree($oBuild).'
'); + } + + // SQL Count + $oP->p(''); + $oP->p(Dict::S('UI:RunQuery:ResultSQLCount')); + $sSQL = $oFilter->MakeSelectQuery(array(), $aRealArgs, $aCountAttToLoad, null, 0, 0, true); + $oP->p("
$sSQL
"); + + 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('
'.$oSQLObjectQueryBuilder->DebugOQLClassTree($oBuild).'
'); + } + + // SQL + $oP->p(''); + $oP->p(Dict::S('UI:RunQuery:ResultSQL')); + $sSQL = $oFilter->MakeSelectQuery($aOrderBy, $aRealArgs, null, null, 0, 0, false); + $oP->p("
$sSQL
"); + $oP->EndCollapsibleSection(); } elseif ($sSyntaxError) @@ -266,4 +309,4 @@ catch(Exception $e) } $oP->output(); -?> +