Skip to content

Commit

Permalink
Remove $row_number from DatabaseInterface::fetchValue
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
  • Loading branch information
kamil-tekiela committed Dec 21, 2021
1 parent bc570cb commit 70c86f5
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 56 deletions.
2 changes: 1 addition & 1 deletion libraries/classes/ConfigStorage/Relation.php
Expand Up @@ -841,7 +841,7 @@ public function purgeHistory($username): void
ORDER BY `timevalue` DESC
LIMIT ' . $GLOBALS['cfg']['QueryHistoryMax'] . ', 1';

$max_time = $this->dbi->fetchValue($search_query, 0, 0, DatabaseInterface::CONNECT_CONTROL);
$max_time = $this->dbi->fetchValue($search_query, 0, DatabaseInterface::CONNECT_CONTROL);

if (! $max_time) {
return;
Expand Down
Expand Up @@ -81,7 +81,7 @@ private function getHtmlToChooseUserGroup(string $username, RelationParameters $
$userTable,
$this->dbi->escapeString($username)
);
$userGroup = $this->dbi->fetchValue($sqlQuery, 0, 0, DatabaseInterface::CONNECT_CONTROL);
$userGroup = $this->dbi->fetchValue($sqlQuery, 0, DatabaseInterface::CONNECT_CONTROL);

$allUserGroups = [];
$sqlQuery = 'SELECT DISTINCT `usergroup` FROM ' . $groupTable;
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Database/Events.php
Expand Up @@ -479,7 +479,7 @@ public function getQueryFromRequest()

public function getEventSchedulerStatus(): bool
{
$state = (string) $this->dbi->fetchValue('SHOW GLOBAL VARIABLES LIKE \'event_scheduler\'', 0, 1);
$state = (string) $this->dbi->fetchValue('SHOW GLOBAL VARIABLES LIKE \'event_scheduler\'', 1);

return strtoupper($state) === 'ON' || $state === '1';
}
Expand Down
24 changes: 7 additions & 17 deletions libraries/classes/DatabaseInterface.php
Expand Up @@ -1030,7 +1030,7 @@ public function getVariable(
$modifier = '';
}

return $this->fetchValue('SHOW' . $modifier . ' VARIABLES LIKE \'' . $var . '\';', 0, 1, $link);
return $this->fetchValue('SHOW' . $modifier . ' VARIABLES LIKE \'' . $var . '\';', 1, $link);
}

/**
Expand Down Expand Up @@ -1200,18 +1200,15 @@ public function postConnectControl(Relation $relation): void
* // $user_name = 'John Doe'
* </code>
*
* @param string $query The query to execute
* @param int $row_number row to fetch the value from,
* starting at 0, with 0 being default
* @param int|string $field field to fetch the value from,
* starting at 0, with 0 being default
* @param int $link link type
* @param string $query The query to execute
* @param int|string $field field to fetch the value from,
* starting at 0, with 0 being default
* @param int $link link type
*
* @return mixed|false value of first field in first row from result or false if not found
*/
public function fetchValue(
string $query,
int $row_number = 0,
$field = 0,
$link = self::CONNECT_USER
) {
Expand All @@ -1220,14 +1217,7 @@ public function fetchValue(
return false;
}

// return false if result is empty or false
// or requested row is larger than rows in result
if ($this->numRows($result) < $row_number + 1) {
return false;
}

// get requested row
$this->dataSeek($result, $row_number);
$row = $this->fetchByMode($result, is_int($field) ? self::FETCH_NUM : self::FETCH_ASSOC);

// return requested field
Expand Down Expand Up @@ -1507,7 +1497,7 @@ public function getDefinition(
$query = 'SHOW CREATE ' . $which . ' '
. Util::backquote($db) . '.'
. Util::backquote($name);
$result = $this->fetchValue($query, 0, $returned_field[$which], $link);
$result = $this->fetchValue($query, $returned_field[$which], $link);

return is_string($result) ? $result : null;
}
Expand Down Expand Up @@ -2113,7 +2103,7 @@ public function insertId($link = self::CONNECT_USER)
// When no controluser is defined, using mysqli_insert_id($link)
// does not always return the last insert id due to a mixup with
// the tracking mechanism, but this works:
return $this->fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link);
return $this->fetchValue('SELECT LAST_INSERT_ID();', 0, $link);
}

/**
Expand Down
14 changes: 5 additions & 9 deletions libraries/classes/Dbal/DbalInterface.php
Expand Up @@ -302,21 +302,17 @@ public function postConnectControl(Relation $relation): void;
* // $user_name = 'John Doe'
* </code>
*
* @param string $query The query to execute
* @param int $row_number row to fetch the value from,
* starting at 0, with 0 being
* default
* @param int|string $field field to fetch the value from,
* starting at 0, with 0 being
* default
* @param int $link link type
* @param string $query The query to execute
* @param int|string $field field to fetch the value from,
* starting at 0, with 0 being
* default
* @param int $link link type
*
* @return mixed value of first field in first row from result
* or false if not found
*/
public function fetchValue(
string $query,
int $row_number = 0,
$field = 0,
$link = DatabaseInterface::CONNECT_USER
);
Expand Down
5 changes: 2 additions & 3 deletions libraries/classes/Engines/Innodb.php
Expand Up @@ -266,7 +266,6 @@ public function getPageStatus()
return '<pre id="pre_innodb_status">' . "\n"
. htmlspecialchars((string) $dbi->fetchValue(
'SHOW ENGINE INNODB STATUS;',
0,
'Status'
)) . "\n" . '</pre>' . "\n";
}
Expand Down Expand Up @@ -305,7 +304,7 @@ public function getInnodbFileFormat(): ?string
{
global $dbi;

$value = $dbi->fetchValue("SHOW GLOBAL VARIABLES LIKE 'innodb_file_format';", 0, 1);
$value = $dbi->fetchValue("SHOW GLOBAL VARIABLES LIKE 'innodb_file_format';", 1);

if ($value === false) {
// This variable does not exist anymore on MariaDB >= 10.6.0
Expand All @@ -325,6 +324,6 @@ public function supportsFilePerTable(): bool
{
global $dbi;

return $dbi->fetchValue("SHOW GLOBAL VARIABLES LIKE 'innodb_file_per_table';", 0, 1) === 'ON';
return $dbi->fetchValue("SHOW GLOBAL VARIABLES LIKE 'innodb_file_per_table';", 1) === 'ON';
}
}
6 changes: 3 additions & 3 deletions libraries/classes/Server/Privileges.php
Expand Up @@ -561,7 +561,7 @@ public function setUserGroup($username, $userGroup): void

$sqlQuery = 'SELECT `usergroup` FROM ' . $userTable
. " WHERE `username` = '" . $this->dbi->escapeString($username) . "'";
$oldUserGroup = $this->dbi->fetchValue($sqlQuery, 0, 0, DatabaseInterface::CONNECT_CONTROL);
$oldUserGroup = $this->dbi->fetchValue($sqlQuery, 0, DatabaseInterface::CONNECT_CONTROL);

if ($oldUserGroup === false) {
$updQuery = 'INSERT INTO ' . $userTable . '(`username`, `usergroup`)'
Expand Down Expand Up @@ -1557,7 +1557,7 @@ public function getUserGroupCount(): int
. '.' . Util::backquote($relationParameters->usergroups);
$sqlQuery = 'SELECT COUNT(*) FROM ' . $userGroupTable;

return (int) $this->dbi->fetchValue($sqlQuery, 0, 0, DatabaseInterface::CONNECT_CONTROL);
return (int) $this->dbi->fetchValue($sqlQuery, 0, DatabaseInterface::CONNECT_CONTROL);
}

/**
Expand All @@ -1581,7 +1581,7 @@ public function getUserGroupForUser($username)
. ' WHERE `username` = \'' . $username . '\''
. ' LIMIT 1';

$usergroup = $this->dbi->fetchValue($sqlQuery, 0, 0, DatabaseInterface::CONNECT_CONTROL);
$usergroup = $this->dbi->fetchValue($sqlQuery, 0, DatabaseInterface::CONNECT_CONTROL);

if ($usergroup === false) {
return null;
Expand Down
1 change: 0 additions & 1 deletion libraries/classes/Table.php
Expand Up @@ -2616,7 +2616,6 @@ public function showCreate()
return $this->dbi->fetchValue(
'SHOW CREATE TABLE ' . Util::backquote($this->dbName) . '.'
. Util::backquote($this->name),
0,
1
);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Tracker.php
Expand Up @@ -151,7 +151,7 @@ public static function isTracked($dbName, $tableName): bool
" AND table_name = '" . $dbi->escapeString($tableName) . "' " .
' ORDER BY version DESC LIMIT 1';

$result = $dbi->fetchValue($sqlQuery, 0, 0, DatabaseInterface::CONNECT_CONTROL) == 1;
$result = $dbi->fetchValue($sqlQuery, 0, DatabaseInterface::CONNECT_CONTROL) == 1;

self::$trackingCache[$dbName][$tableName] = $result;

Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/UserPreferences.php
Expand Up @@ -141,7 +141,7 @@ public function save(array $config_array)
. $dbi->escapeString($relationParameters->user)
. '\'';

$has_config = $dbi->fetchValue($query, 0, 0, DatabaseInterface::CONNECT_CONTROL);
$has_config = $dbi->fetchValue($query, 0, DatabaseInterface::CONNECT_CONTROL);
$config_data = json_encode($config_array);
if ($has_config) {
$query = 'UPDATE ' . $query_table
Expand Down
17 changes: 6 additions & 11 deletions phpstan-baseline.neon
Expand Up @@ -2905,11 +2905,6 @@ parameters:
count: 2
path: libraries/classes/DatabaseInterface.php

-
message: "#^Parameter \\#1 \\$result of method PhpMyAdmin\\\\DatabaseInterface\\:\\:dataSeek\\(\\) expects object, mixed given\\.$#"
count: 1
path: libraries/classes/DatabaseInterface.php

-
message: "#^Parameter \\#1 \\$result of method PhpMyAdmin\\\\DatabaseInterface\\:\\:fetchAssoc\\(\\) expects object, mixed given\\.$#"
count: 1
Expand All @@ -2932,14 +2927,19 @@ parameters:

-
message: "#^Parameter \\#1 \\$result of method PhpMyAdmin\\\\DatabaseInterface\\:\\:numRows\\(\\) expects bool\\|object, mixed given\\.$#"
count: 4
count: 3
path: libraries/classes/DatabaseInterface.php

-
message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\Query\\\\Cache\\:\\:cacheTableData\\(\\) expects bool\\|string, array\\|string given\\.$#"
count: 1
path: libraries/classes/DatabaseInterface.php

-
message: "#^Parameter \\#3 \\$link of method PhpMyAdmin\\\\DatabaseInterface\\:\\:fetchValue\\(\\) expects int, mixed given\\.$#"
count: 1
path: libraries/classes/DatabaseInterface.php

-
message: "#^Parameter \\#3 \\$result of static method PhpMyAdmin\\\\Query\\\\Utilities\\:\\:debugLogQueryIntoSession\\(\\) expects bool\\|object, mixed given\\.$#"
count: 1
Expand All @@ -2955,11 +2955,6 @@ parameters:
count: 7
path: libraries/classes/DatabaseInterface.php

-
message: "#^Parameter \\#4 \\$link of method PhpMyAdmin\\\\DatabaseInterface\\:\\:fetchValue\\(\\) expects int, mixed given\\.$#"
count: 1
path: libraries/classes/DatabaseInterface.php

-
message: "#^Parameter \\#7 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
count: 1
Expand Down
6 changes: 2 additions & 4 deletions psalm-baseline.xml
Expand Up @@ -5600,7 +5600,7 @@
<code>$a</code>
<code>$b</code>
</MissingClosureParamType>
<MixedArgument occurrences="65">
<MixedArgument occurrences="63">
<code>$_SERVER['SCRIPT_NAME']</code>
<code>$a</code>
<code>$arrayKeys</code>
Expand Down Expand Up @@ -5640,8 +5640,6 @@
<code>$result</code>
<code>$result</code>
<code>$result</code>
<code>$result</code>
<code>$result</code>
<code>$server</code>
<code>$sql</code>
<code>$table</code>
Expand Down Expand Up @@ -5820,7 +5818,7 @@
<MixedReturnStatement occurrences="7">
<code>$tables[$database]</code>
<code>$tables[mb_strtolower($database)]</code>
<code>$this-&gt;fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link)</code>
<code>$this-&gt;fetchValue('SELECT LAST_INSERT_ID();', 0, $link)</code>
<code>$this-&gt;lowerCaseTableNames</code>
<code>$user</code>
<code>SessionCache::get('mysql_cur_user')</code>
Expand Down
2 changes: 1 addition & 1 deletion test/classes/Database/QbeTest.php
Expand Up @@ -44,7 +44,7 @@ protected function setUp(): void

$dbi->expects($this->any())
->method('fetchValue')
->with('SHOW CREATE TABLE `pma_test`.`table1`', 0, 1)
->with('SHOW CREATE TABLE `pma_test`.`table1`', 1)
->will($this->returnValue($create_table));

$dbi->expects($this->any())
Expand Down
4 changes: 2 additions & 2 deletions test/classes/UserPreferencesTest.php
Expand Up @@ -193,7 +193,7 @@ public function testSave(): void

$dbi->expects($this->once())
->method('fetchValue')
->with($query1, 0, 0, DatabaseInterface::CONNECT_CONTROL)
->with($query1, 0, DatabaseInterface::CONNECT_CONTROL)
->will($this->returnValue(true));

$dbi->expects($this->once())
Expand Down Expand Up @@ -224,7 +224,7 @@ public function testSave(): void

$dbi->expects($this->once())
->method('fetchValue')
->with($query1, 0, 0, DatabaseInterface::CONNECT_CONTROL)
->with($query1, 0, DatabaseInterface::CONNECT_CONTROL)
->will($this->returnValue(false));

$dbi->expects($this->once())
Expand Down

0 comments on commit 70c86f5

Please sign in to comment.