Skip to content

Commit

Permalink
Show query stats for count(*) query
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
  • Loading branch information
MoonE committed Jul 4, 2024
1 parent aa145f3 commit 2a4fb46
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
22 changes: 15 additions & 7 deletions libraries/classes/Display/Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Results
* unlim_num_rows: int|numeric-string|false,
* fields_meta: FieldMetadata[],
* is_count: bool|null,
* is_group: bool|null,
* is_export: bool|null,
* is_func: bool|null,
* is_analyse: bool|null,
Expand Down Expand Up @@ -178,6 +179,8 @@ class Results

'is_count' => null,

'is_group' => null,

'is_export' => null,

'is_func' => null,
Expand Down Expand Up @@ -394,6 +397,7 @@ private function setDefaultTransformations(): void
* any appended "LIMIT" clause programmatically
* @param FieldMetadata[] $fieldsMeta meta information about fields
* @param bool $isCount statement is SELECT COUNT
* @param bool $isGroup statement has GROUP BY
* @param bool $isExport statement contains INTO OUTFILE
* @param bool $isFunction statement contains a function like SUM()
* @param bool $isAnalyse statement contains PROCEDURE ANALYSE
Expand All @@ -415,6 +419,7 @@ public function setProperties(
$unlimNumRows,
array $fieldsMeta,
$isCount,
$isGroup,
$isExport,
$isFunction,
$isAnalyse,
Expand All @@ -433,6 +438,7 @@ public function setProperties(
$this->properties['unlim_num_rows'] = $unlimNumRows;
$this->properties['fields_meta'] = $fieldsMeta;
$this->properties['is_count'] = $isCount;
$this->properties['is_group'] = $isGroup;
$this->properties['is_export'] = $isExport;
$this->properties['is_func'] = $isFunction;
$this->properties['is_analyse'] = $isAnalyse;
Expand Down Expand Up @@ -466,6 +472,7 @@ private function setDisplayPartsForPrintView(array $displayParts)
$displayParts['bkm_form'] = '0';
$displayParts['text_btn'] = '0';
$displayParts['pview_lnk'] = '0';
$displayParts['query_stats'] = '1';

return $displayParts;
}
Expand Down Expand Up @@ -510,6 +517,7 @@ private function setDisplayPartsForShow(array $displayParts)
$displayParts['bkm_form'] = '1';
$displayParts['text_btn'] = '1';
$displayParts['pview_lnk'] = '1';
$displayParts['query_stats'] = '0';

return $displayParts;
}
Expand All @@ -531,6 +539,7 @@ private function setDisplayPartsForNonData(array $displayParts)
$displayParts['sort_lnk'] = '0';
$displayParts['nav_bar'] = '0';
$displayParts['bkm_form'] = '1';
$displayParts['query_stats'] = '0';

if ($this->properties['is_maint']) {
$displayParts['text_btn'] = '1';
Expand Down Expand Up @@ -628,14 +637,13 @@ private function setDisplayPartsAndTotal(array $displayParts)
$db = $this->properties['db'];
$table = $this->properties['table'];
$unlimNumRows = $this->properties['unlim_num_rows'];
$numRows = $this->properties['num_rows'];
$printView = $this->properties['printview'];

// 2. Updates the display parts
if ($printView == '1') {
$displayParts = $this->setDisplayPartsForPrintView($displayParts);
} elseif (
$this->properties['is_count'] || $this->properties['is_analyse']
$this->properties['is_analyse']
|| $this->properties['is_maint'] || $this->properties['is_explain']
) {
$displayParts = $this->setDisplayPartsForNonData($displayParts);
Expand All @@ -658,9 +666,9 @@ private function setDisplayPartsAndTotal(array $displayParts)

// if for COUNT query, number of rows returned more than 1
// (may be being used GROUP BY)
if ($this->properties['is_count'] && $numRows > 1) {
$displayParts['nav_bar'] = '1';
$displayParts['sort_lnk'] = '1';
if ($this->properties['is_count'] && ! $this->properties['is_group']) {
$displayParts['nav_bar'] = '0';
$displayParts['sort_lnk'] = '0';
}

// 4. If navigation bar or sorting fields names URLs should be
Expand Down Expand Up @@ -3642,7 +3650,7 @@ public function getTable(
// 1.2 Defines offsets for the next and previous pages
$posNext = 0;
$posPrev = 0;
if ($displayParts['nav_bar'] == '1') {
if ($displayParts['nav_bar'] == '1' || $displayParts['query_stats'] === '1') {
[$posNext, $posPrev] = $this->getOffsets();
}

Expand Down Expand Up @@ -3675,7 +3683,7 @@ public function getTable(

// 2.1 Prepares a messages with position information
$sqlQueryMessage = '';
if ($displayParts['nav_bar'] == '1') {
if ($displayParts['query_stats'] == '1') {
$message = $this->setMessageInformation(
$sortedColumnMessage,
$analyzedSqlResults,
Expand Down
7 changes: 7 additions & 0 deletions libraries/classes/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ private function getQueryResponseForNoResultsReturned(
'bkm_form' => '1',
'text_btn' => '1',
'pview_lnk' => '1',
'query_stats' => '1',
];

$sqlQueryResultsTable = $this->getHtmlForSqlQueryResultsTable(
Expand Down Expand Up @@ -1222,6 +1223,7 @@ private function getHtmlForSqlQueryResultsTable(
$numRows,
$fieldsMeta,
$analyzedSqlResults['is_count'],
$analyzedSqlResults['is_group'],
$analyzedSqlResults['is_export'],
$analyzedSqlResults['is_func'],
$analyzedSqlResults['is_analyse'],
Expand All @@ -1246,6 +1248,7 @@ private function getHtmlForSqlQueryResultsTable(
'bkm_form' => '1',
'text_btn' => '1',
'pview_lnk' => '1',
'query_stats' => '1',
];

$tableHtml .= $displayResultsObject->getTable(
Expand All @@ -1270,6 +1273,7 @@ private function getHtmlForSqlQueryResultsTable(
$unlimNumRows,
$fieldsMeta,
$analyzedSqlResults['is_count'],
$analyzedSqlResults['is_group'],
$analyzedSqlResults['is_export'],
$analyzedSqlResults['is_func'],
$analyzedSqlResults['is_analyse'],
Expand Down Expand Up @@ -1477,6 +1481,7 @@ private function getQueryResponseForResultsReturned(
'bkm_form' => '1',
'text_btn' => '0',
'pview_lnk' => '1',
'query_stats' => '1',
];

if (! $editable) {
Expand All @@ -1488,6 +1493,7 @@ private function getQueryResponseForResultsReturned(
'bkm_form' => '1',
'text_btn' => '1',
'pview_lnk' => '1',
'query_stats' => '1',
];
}

Expand All @@ -1500,6 +1506,7 @@ private function getQueryResponseForResultsReturned(
'bkm_form' => '0',
'text_btn' => '0',
'pview_lnk' => '0',
'query_stats' => '0',
];
}

Expand Down
15 changes: 10 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6066,7 +6066,7 @@
<code>$sortExpression</code>
<code>$urlParams</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess occurrences="68">
<MixedArrayAccess occurrences="69">
<code>$_SESSION['tmpval']['display_binary']</code>
<code>$_SESSION['tmpval']['display_binary']</code>
<code>$_SESSION['tmpval']['display_binary']</code>
Expand Down Expand Up @@ -6112,7 +6112,8 @@
<code>$displayParams['data'][$rowNumber]</code>
<code>$displayParts['nav_bar']</code>
<code>$displayParts['nav_bar']</code>
<code>$displayParts['nav_bar']</code>
<code>$displayParts['query_stats']</code>
<code>$displayParts['query_stats']</code>
<code>$displayParts['sort_lnk']</code>
<code>$oneKey['index_list']</code>
<code>$oneKey['ref_db_name']</code>
Expand Down Expand Up @@ -13141,7 +13142,7 @@
<LessSpecificReturnStatement occurrences="1">
<code>$unlimNumRows</code>
</LessSpecificReturnStatement>
<MixedArgument occurrences="41">
<MixedArgument occurrences="43">
<code>$analyzedSqlResults</code>
<code>$analyzedSqlResults['is_affected']</code>
<code>$analyzedSqlResults['is_analyse']</code>
Expand All @@ -13154,6 +13155,8 @@
<code>$analyzedSqlResults['is_export']</code>
<code>$analyzedSqlResults['is_func']</code>
<code>$analyzedSqlResults['is_func']</code>
<code>$analyzedSqlResults['is_group']</code>
<code>$analyzedSqlResults['is_group']</code>
<code>$analyzedSqlResults['is_maint']</code>
<code>$analyzedSqlResults['is_maint']</code>
<code>$analyzedSqlResults['is_show']</code>
Expand Down Expand Up @@ -15276,7 +15279,7 @@
<DocblockTypeContradiction occurrences="1">
<code>assertSame</code>
</DocblockTypeContradiction>
<MixedArgument occurrences="16">
<MixedArgument occurrences="17">
<code>$actual</code>
<code>$analyzedSqlResults</code>
<code>$analyzedSqlResults</code>
Expand All @@ -15287,18 +15290,20 @@
<code>$analyzedSqlResults['is_explain']</code>
<code>$analyzedSqlResults['is_export']</code>
<code>$analyzedSqlResults['is_func']</code>
<code>$analyzedSqlResults['is_group']</code>
<code>$analyzedSqlResults['is_maint']</code>
<code>$analyzedSqlResults['is_show']</code>
<code>$output</code>
<code>$output</code>
</MixedArgument>
<MixedArrayAccess occurrences="8">
<MixedArrayAccess occurrences="9">
<code>$_SESSION['tmpval']['pftext']</code>
<code>$analyzedSqlResults['is_analyse']</code>
<code>$analyzedSqlResults['is_count']</code>
<code>$analyzedSqlResults['is_explain']</code>
<code>$analyzedSqlResults['is_export']</code>
<code>$analyzedSqlResults['is_func']</code>
<code>$analyzedSqlResults['is_group']</code>
<code>$analyzedSqlResults['is_maint']</code>
<code>$analyzedSqlResults['is_show']</code>
</MixedArrayAccess>
Expand Down
2 changes: 2 additions & 0 deletions test/classes/Display/ResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,7 @@ public function testGetTable(): void
3,
$fieldsMeta,
$analyzedSqlResults['is_count'],
$analyzedSqlResults['is_group'],
$analyzedSqlResults['is_export'],
$analyzedSqlResults['is_func'],
$analyzedSqlResults['is_analyse'],
Expand Down Expand Up @@ -1454,6 +1455,7 @@ public function testGetTable(): void
'bkm_form' => '1',
'text_btn' => '0',
'pview_lnk' => '1',
'query_stats' => '1',
];
$this->assertNotFalse($dtResult);
$actual = $object->getTable($dtResult, $displayParts, $analyzedSqlResults);
Expand Down

0 comments on commit 2a4fb46

Please sign in to comment.