From 70c86f5e2115634fd1b774b5d899ae7405255ee0 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 21 Dec 2021 21:02:08 +0000 Subject: [PATCH] Remove $row_number from DatabaseInterface::fetchValue Signed-off-by: Kamil Tekiela --- libraries/classes/ConfigStorage/Relation.php | 2 +- .../Server/UserGroupsFormController.php | 2 +- libraries/classes/Database/Events.php | 2 +- libraries/classes/DatabaseInterface.php | 24 ++++++------------- libraries/classes/Dbal/DbalInterface.php | 14 ++++------- libraries/classes/Engines/Innodb.php | 5 ++-- libraries/classes/Server/Privileges.php | 6 ++--- libraries/classes/Table.php | 1 - libraries/classes/Tracker.php | 2 +- libraries/classes/UserPreferences.php | 2 +- phpstan-baseline.neon | 17 +++++-------- psalm-baseline.xml | 6 ++--- test/classes/Database/QbeTest.php | 2 +- test/classes/UserPreferencesTest.php | 4 ++-- 14 files changed, 33 insertions(+), 56 deletions(-) diff --git a/libraries/classes/ConfigStorage/Relation.php b/libraries/classes/ConfigStorage/Relation.php index 3d7282b420ec..b920e2b31bb0 100644 --- a/libraries/classes/ConfigStorage/Relation.php +++ b/libraries/classes/ConfigStorage/Relation.php @@ -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; diff --git a/libraries/classes/Controllers/Server/UserGroupsFormController.php b/libraries/classes/Controllers/Server/UserGroupsFormController.php index cbd2e9762013..0a5946ae8882 100644 --- a/libraries/classes/Controllers/Server/UserGroupsFormController.php +++ b/libraries/classes/Controllers/Server/UserGroupsFormController.php @@ -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; diff --git a/libraries/classes/Database/Events.php b/libraries/classes/Database/Events.php index 3af9b21709bc..abed13eb2365 100644 --- a/libraries/classes/Database/Events.php +++ b/libraries/classes/Database/Events.php @@ -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'; } diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index 303ccaed10df..893de01d6e13 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -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); } /** @@ -1200,18 +1200,15 @@ public function postConnectControl(Relation $relation): void * // $user_name = 'John Doe' * * - * @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 ) { @@ -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 @@ -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; } @@ -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); } /** diff --git a/libraries/classes/Dbal/DbalInterface.php b/libraries/classes/Dbal/DbalInterface.php index 5db1748c1adc..1e6f082f8b34 100644 --- a/libraries/classes/Dbal/DbalInterface.php +++ b/libraries/classes/Dbal/DbalInterface.php @@ -302,21 +302,17 @@ public function postConnectControl(Relation $relation): void; * // $user_name = 'John Doe' * * - * @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 ); diff --git a/libraries/classes/Engines/Innodb.php b/libraries/classes/Engines/Innodb.php index ab27eba52ac1..e2d374d4663e 100644 --- a/libraries/classes/Engines/Innodb.php +++ b/libraries/classes/Engines/Innodb.php @@ -266,7 +266,6 @@ public function getPageStatus() return '
' . "\n"
             . htmlspecialchars((string) $dbi->fetchValue(
                 'SHOW ENGINE INNODB STATUS;',
-                0,
                 'Status'
             )) . "\n" . '
' . "\n"; } @@ -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 @@ -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'; } } diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php index 1151d9b499aa..7b7c0cfc88ac 100644 --- a/libraries/classes/Server/Privileges.php +++ b/libraries/classes/Server/Privileges.php @@ -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`)' @@ -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); } /** @@ -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; diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php index 314a0897881d..e5bd7347dbd2 100644 --- a/libraries/classes/Table.php +++ b/libraries/classes/Table.php @@ -2616,7 +2616,6 @@ public function showCreate() return $this->dbi->fetchValue( 'SHOW CREATE TABLE ' . Util::backquote($this->dbName) . '.' . Util::backquote($this->name), - 0, 1 ); } diff --git a/libraries/classes/Tracker.php b/libraries/classes/Tracker.php index 3c67bc598e41..b2084f31cd8f 100644 --- a/libraries/classes/Tracker.php +++ b/libraries/classes/Tracker.php @@ -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; diff --git a/libraries/classes/UserPreferences.php b/libraries/classes/UserPreferences.php index 8e8d74517c00..eda6334a7b01 100644 --- a/libraries/classes/UserPreferences.php +++ b/libraries/classes/UserPreferences.php @@ -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 diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 896330fbfdfc..861035e12c28 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 @@ -2932,7 +2927,7 @@ parameters: - message: "#^Parameter \\#1 \\$result of method PhpMyAdmin\\\\DatabaseInterface\\:\\:numRows\\(\\) expects bool\\|object, mixed given\\.$#" - count: 4 + count: 3 path: libraries/classes/DatabaseInterface.php - @@ -2940,6 +2935,11 @@ parameters: 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 @@ -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 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 18691502213b..3de66cf4be19 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -5600,7 +5600,7 @@ $a $b - + $_SERVER['SCRIPT_NAME'] $a $arrayKeys @@ -5640,8 +5640,6 @@ $result $result $result - $result - $result $server $sql $table @@ -5820,7 +5818,7 @@ $tables[$database] $tables[mb_strtolower($database)] - $this->fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link) + $this->fetchValue('SELECT LAST_INSERT_ID();', 0, $link) $this->lowerCaseTableNames $user SessionCache::get('mysql_cur_user') diff --git a/test/classes/Database/QbeTest.php b/test/classes/Database/QbeTest.php index fb0831295422..4a34da34a19f 100644 --- a/test/classes/Database/QbeTest.php +++ b/test/classes/Database/QbeTest.php @@ -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()) diff --git a/test/classes/UserPreferencesTest.php b/test/classes/UserPreferencesTest.php index 58cbd6e31ee7..061eef8f69e0 100644 --- a/test/classes/UserPreferencesTest.php +++ b/test/classes/UserPreferencesTest.php @@ -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()) @@ -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())