mirror of
https://github.com/friendica/friendica
synced 2024-12-22 18:00:16 +00:00
"ANY_VALUE" is removed
This commit is contained in:
parent
4c402f6af4
commit
f83f61f7ac
6 changed files with 20 additions and 59 deletions
|
@ -215,14 +215,14 @@ function photos_post(App $a)
|
||||||
// get the list of photos we are about to delete
|
// get the list of photos we are about to delete
|
||||||
if ($visitor) {
|
if ($visitor) {
|
||||||
$r = DBA::toArray(DBA::p(
|
$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,
|
$visitor,
|
||||||
$page_owner_uid,
|
$page_owner_uid,
|
||||||
$album
|
$album
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$r = DBA::toArray(DBA::p(
|
$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(),
|
DI::userSession()->getLocalUserId(),
|
||||||
$album
|
$album
|
||||||
));
|
));
|
||||||
|
@ -762,7 +762,7 @@ function photos_content(App $a)
|
||||||
|
|
||||||
$total = 0;
|
$total = 0;
|
||||||
$r = DBA::toArray(DBA::p(
|
$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`",
|
AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
|
||||||
$owner_uid,
|
$owner_uid,
|
||||||
$album
|
$album
|
||||||
|
@ -782,9 +782,9 @@ function photos_content(App $a)
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = DBA::toArray(DBA::p(
|
$r = DBA::toArray(DBA::p(
|
||||||
"SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
|
"SELECT `resource-id`, MIN(`id`) AS `id`, MIN(`filename`) AS `filename`,
|
||||||
ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
|
MIN(`type`) AS `type`, MAX(`scale`) AS `scale`, MIN(`desc`) AS `desc`,
|
||||||
ANY_VALUE(`created`) as `created`
|
MIN(`created`) AS `created`
|
||||||
FROM `photo` WHERE `uid` = ? AND `album` = ?
|
FROM `photo` WHERE `uid` = ? AND `album` = ?
|
||||||
AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?",
|
AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?",
|
||||||
intval($owner_uid),
|
intval($owner_uid),
|
||||||
|
@ -1167,11 +1167,11 @@ function photos_content(App $a)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($conv_responses['like'][$link_item['uri']])) {
|
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']])) {
|
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))) {
|
if (($can_post || Security::canWriteToUserWall($owner_uid))) {
|
||||||
|
|
|
@ -132,22 +132,6 @@ class DBA
|
||||||
return DI::dba()->connected();
|
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"
|
* beautifies the query - useful for "SHOW PROCESSLIST"
|
||||||
*
|
*
|
||||||
|
|
|
@ -439,28 +439,6 @@ class Database
|
||||||
return $connected;
|
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
|
* Replaces the ? placeholders with the parameters in the $args array
|
||||||
*
|
*
|
||||||
|
@ -532,7 +510,6 @@ class Database
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = DBA::cleanQuery($sql);
|
$sql = DBA::cleanQuery($sql);
|
||||||
$sql = $this->anyValueFallback($sql);
|
|
||||||
|
|
||||||
$orig_sql = $sql;
|
$orig_sql = $sql;
|
||||||
|
|
||||||
|
@ -1440,7 +1417,7 @@ class Database
|
||||||
private function escapeFields(array $fields, array $options): array
|
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.
|
// 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.
|
// Otherwise MySQL would report errors.
|
||||||
if (!empty($options['group_by']) && !empty($options['order'])) {
|
if (!empty($options['group_by']) && !empty($options['order'])) {
|
||||||
foreach ($options['order'] as $key => $field) {
|
foreach ($options['order'] as $key => $field) {
|
||||||
|
@ -1461,7 +1438,7 @@ class Database
|
||||||
$value = DBA::quoteIdentifier($field);
|
$value = DBA::quoteIdentifier($field);
|
||||||
|
|
||||||
if (!empty($options['group_by']) && !in_array($field, $options['group_by'])) {
|
if (!empty($options['group_by']) && !in_array($field, $options['group_by'])) {
|
||||||
$value = 'ANY_VALUE(' . $value . ') AS ' . $value;
|
$value = 'MIN(' . $value . ') AS ' . $value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -229,8 +229,8 @@ class Photo
|
||||||
|
|
||||||
return DBA::toArray(
|
return DBA::toArray(
|
||||||
DBA::p(
|
DBA::p(
|
||||||
"SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
|
"SELECT `resource-id`, MIN(`id`) AS `id`, MIN(`filename`) AS `filename`, MIN(`type`) AS `type`,
|
||||||
min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
|
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
|
FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) $sqlExtra
|
||||||
GROUP BY `resource-id` $sqlExtra2",
|
GROUP BY `resource-id` $sqlExtra2",
|
||||||
$values
|
$values
|
||||||
|
@ -751,7 +751,7 @@ class Photo
|
||||||
if (!DI::config()->get('system', 'no_count', false)) {
|
if (!DI::config()->get('system', 'no_count', false)) {
|
||||||
/// @todo This query needs to be renewed. It is really slow
|
/// @todo This query needs to be renewed. It is really slow
|
||||||
// At this time we just store the data in the cache
|
// 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`
|
FROM `photo`
|
||||||
WHERE `uid` = ? AND `photo-type` IN (?, ?, ?) $sql_extra
|
WHERE `uid` = ? AND `photo-type` IN (?, ?, ?) $sql_extra
|
||||||
GROUP BY `album` ORDER BY `created` DESC",
|
GROUP BY `album` ORDER BY `created` DESC",
|
||||||
|
|
|
@ -97,7 +97,7 @@ class Federation extends BaseAdmin
|
||||||
SUM(IFNULL(`local-posts`, 0) + IFNULL(`local-comments`, 0)) AS `posts`,
|
SUM(IFNULL(`local-posts`, 0) + IFNULL(`local-comments`, 0)) AS `posts`,
|
||||||
SUM(IFNULL(`active-month-users`, `active-week-users`)) AS `month`,
|
SUM(IFNULL(`active-month-users`, `active-week-users`)) AS `month`,
|
||||||
SUM(IFNULL(`active-halfyear-users`, `active-week-users`)) AS `halfyear`, `platform`,
|
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`",
|
FROM `gserver` WHERE NOT `failed` AND `platform` != ? AND `detection-method` != ? AND NOT `network` IN (?, ?) GROUP BY `platform`",
|
||||||
'', GServer::DETECT_MANUAL, Protocol::PHANTOM, Protocol::FEED);
|
'', GServer::DETECT_MANUAL, Protocol::PHANTOM, Protocol::FEED);
|
||||||
while ($gserver = DBA::fetch($gservers)) {
|
while ($gserver = DBA::fetch($gservers)) {
|
||||||
|
|
|
@ -322,12 +322,12 @@ class Photos extends \Friendica\Module\BaseProfile
|
||||||
$photos = $this->database->toArray($this->database->p(
|
$photos = $this->database->toArray($this->database->p(
|
||||||
"SELECT
|
"SELECT
|
||||||
`resource-id`,
|
`resource-id`,
|
||||||
ANY_VALUE(`id`) AS `id`,
|
MIN(`id`) AS `id`,
|
||||||
ANY_VALUE(`filename`) AS `filename`,
|
MIN(`filename`) AS `filename`,
|
||||||
ANY_VALUE(`type`) AS `type`,
|
MIN(`type`) AS `type`,
|
||||||
ANY_VALUE(`album`) AS `album`,
|
MIN(`album`) AS `album`,
|
||||||
max(`scale`) AS `scale`,
|
MAX(`scale`) AS `scale`,
|
||||||
ANY_VALUE(`created`) AS `created`
|
MIN(`created`) AS `created`
|
||||||
FROM `photo`
|
FROM `photo`
|
||||||
WHERE `uid` = ?
|
WHERE `uid` = ?
|
||||||
AND `photo-type` = ?
|
AND `photo-type` = ?
|
||||||
|
|
Loading…
Reference in a new issue