From: Michael Date: Mon, 15 Jan 2024 16:45:24 +0000 (+0000) Subject: "ANY_VALUE" is removed X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f83f61f7ac17fc451a1186a550afd979015aa187;p=friendica.git "ANY_VALUE" is removed --- diff --git a/mod/photos.php b/mod/photos.php index a4434f4936..322ddd1599 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -215,14 +215,14 @@ function photos_post(App $a) // get the list of photos we are about to delete if ($visitor) { $r = DBA::toArray(DBA::p( - "SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?", + "SELECT distinct(`resource-id`) AS `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?", $visitor, $page_owner_uid, $album )); } else { $r = DBA::toArray(DBA::p( - "SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?", + "SELECT distinct(`resource-id`) AS `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?", DI::userSession()->getLocalUserId(), $album )); @@ -762,7 +762,7 @@ function photos_content(App $a) $total = 0; $r = DBA::toArray(DBA::p( - "SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ? + "SELECT `resource-id`, MAX(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ? AND `scale` <= 4 $sql_extra GROUP BY `resource-id`", $owner_uid, $album @@ -782,9 +782,9 @@ function photos_content(App $a) } $r = DBA::toArray(DBA::p( - "SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, - ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`, - ANY_VALUE(`created`) as `created` + "SELECT `resource-id`, MIN(`id`) AS `id`, MIN(`filename`) AS `filename`, + MIN(`type`) AS `type`, MAX(`scale`) AS `scale`, MIN(`desc`) AS `desc`, + MIN(`created`) AS `created` FROM `photo` WHERE `uid` = ? AND `album` = ? AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?", intval($owner_uid), @@ -1167,11 +1167,11 @@ function photos_content(App $a) } if (!empty($conv_responses['like'][$link_item['uri']])) { - $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']); + $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id'], '', []); } if (!empty($conv_responses['dislike'][$link_item['uri']])) { - $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']); + $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id'], '', []); } if (($can_post || Security::canWriteToUserWall($owner_uid))) { diff --git a/src/Database/DBA.php b/src/Database/DBA.php index d3ccca101f..d5e5a7e59b 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -132,22 +132,6 @@ class DBA return DI::dba()->connected(); } - /** - * Replaces ANY_VALUE() function by MIN() function, - * if the database server does not support ANY_VALUE(). - * - * Considerations for Standard SQL, or MySQL with ONLY_FULL_GROUP_BY (default since 5.7.5). - * ANY_VALUE() is available from MySQL 5.7.5 https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html - * A standard fall-back is to use MIN(). - * - * @param string $sql An SQL string without the values - * @return string The input SQL string modified if necessary. - */ - public static function anyValueFallback(string $sql): string - { - return DI::dba()->anyValueFallback($sql); - } - /** * beautifies the query - useful for "SHOW PROCESSLIST" * diff --git a/src/Database/Database.php b/src/Database/Database.php index d7b9a17e9b..c296683d2b 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -439,28 +439,6 @@ class Database return $connected; } - /** - * Replaces ANY_VALUE() function by MIN() function, - * if the database server does not support ANY_VALUE(). - * - * Considerations for Standard SQL, or MySQL with ONLY_FULL_GROUP_BY (default since 5.7.5). - * ANY_VALUE() is available from MySQL 5.7.5 https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html - * A standard fall-back is to use MIN(). - * - * @param string $sql An SQL string without the values - * - * @return string The input SQL string modified if necessary. - */ - public function anyValueFallback(string $sql): string - { - $server_info = $this->serverInfo(); - if (version_compare($server_info, '5.7.5', '<') || - (stripos($server_info, 'MariaDB') !== false)) { - $sql = str_ireplace('ANY_VALUE(', 'MIN(', $sql); - } - return $sql; - } - /** * Replaces the ? placeholders with the parameters in the $args array * @@ -532,7 +510,6 @@ class Database } $sql = DBA::cleanQuery($sql); - $sql = $this->anyValueFallback($sql); $orig_sql = $sql; @@ -1440,7 +1417,7 @@ class Database private function escapeFields(array $fields, array $options): array { // In the case of a "GROUP BY" we have to add all the ORDER fields to the fieldlist. - // This needs to done to apply the "ANY_VALUE(...)" treatment from below to them. + // This needs to done to apply the "MIN(...)" treatment from below to them. // Otherwise MySQL would report errors. if (!empty($options['group_by']) && !empty($options['order'])) { foreach ($options['order'] as $key => $field) { @@ -1461,7 +1438,7 @@ class Database $value = DBA::quoteIdentifier($field); if (!empty($options['group_by']) && !in_array($field, $options['group_by'])) { - $value = 'ANY_VALUE(' . $value . ') AS ' . $value; + $value = 'MIN(' . $value . ') AS ' . $value; } }); diff --git a/src/Model/Photo.php b/src/Model/Photo.php index d10d70b8eb..6e5773d363 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -229,8 +229,8 @@ class Photo return DBA::toArray( DBA::p( - "SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`, - min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created` + "SELECT `resource-id`, MIN(`id`) AS `id`, MIN(`filename`) AS `filename`, MIN(`type`) AS `type`, + min(`scale`) AS `hiq`, max(`scale`) AS `loq`, MIN(`desc`) AS `desc`, MIN(`created`) AS `created` FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) $sqlExtra GROUP BY `resource-id` $sqlExtra2", $values @@ -751,7 +751,7 @@ class Photo if (!DI::config()->get('system', 'no_count', false)) { /// @todo This query needs to be renewed. It is really slow // At this time we just store the data in the cache - $albums = DBA::toArray(DBA::p("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, ANY_VALUE(`created`) AS `created` + $albums = DBA::toArray(DBA::p("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, MIN(`created`) AS `created` FROM `photo` WHERE `uid` = ? AND `photo-type` IN (?, ?, ?) $sql_extra GROUP BY `album` ORDER BY `created` DESC", diff --git a/src/Module/Admin/Federation.php b/src/Module/Admin/Federation.php index 58b4878fc6..af7e433e14 100644 --- a/src/Module/Admin/Federation.php +++ b/src/Module/Admin/Federation.php @@ -97,7 +97,7 @@ class Federation extends BaseAdmin SUM(IFNULL(`local-posts`, 0) + IFNULL(`local-comments`, 0)) AS `posts`, SUM(IFNULL(`active-month-users`, `active-week-users`)) AS `month`, SUM(IFNULL(`active-halfyear-users`, `active-week-users`)) AS `halfyear`, `platform`, - ANY_VALUE(`network`) AS `network`, MAX(`version`) AS `version` + MIN(`network`) AS `network`, MAX(`version`) AS `version` FROM `gserver` WHERE NOT `failed` AND `platform` != ? AND `detection-method` != ? AND NOT `network` IN (?, ?) GROUP BY `platform`", '', GServer::DETECT_MANUAL, Protocol::PHANTOM, Protocol::FEED); while ($gserver = DBA::fetch($gservers)) { diff --git a/src/Module/Profile/Photos.php b/src/Module/Profile/Photos.php index f80c63d1a4..8b915a4eba 100644 --- a/src/Module/Profile/Photos.php +++ b/src/Module/Profile/Photos.php @@ -322,12 +322,12 @@ class Photos extends \Friendica\Module\BaseProfile $photos = $this->database->toArray($this->database->p( "SELECT `resource-id`, - ANY_VALUE(`id`) AS `id`, - ANY_VALUE(`filename`) AS `filename`, - ANY_VALUE(`type`) AS `type`, - ANY_VALUE(`album`) AS `album`, - max(`scale`) AS `scale`, - ANY_VALUE(`created`) AS `created` + MIN(`id`) AS `id`, + MIN(`filename`) AS `filename`, + MIN(`type`) AS `type`, + MIN(`album`) AS `album`, + MAX(`scale`) AS `scale`, + MIN(`created`) AS `created` FROM `photo` WHERE `uid` = ? AND `photo-type` = ?