mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 03:39:57 +03:00
fixes #1343 remove auto-escape of reserved keywords on MySQL 8
ie no more adding backticks around "rank" and "groups". Too many collateral damages.
This commit is contained in:
parent
9a840edf66
commit
1ec5a2933c
8 changed files with 15 additions and 32 deletions
|
@ -122,7 +122,7 @@ $sort_fields = array(
|
|||
'hit ASC' => l10n('Visits, low → high'),
|
||||
'id ASC' => l10n('Numeric identifier, 1 → 9'),
|
||||
'id DESC' => l10n('Numeric identifier, 9 → 1'),
|
||||
'rank ASC' => l10n('Manual sort order'),
|
||||
'`rank` ASC' => l10n('Manual sort order'),
|
||||
);
|
||||
|
||||
$comments_order = array(
|
||||
|
|
|
@ -71,7 +71,7 @@ if (isset($_POST['submit']))
|
|||
}
|
||||
elseif ($image_order_choice=='rank')
|
||||
{
|
||||
$image_order = 'rank ASC';
|
||||
$image_order = '`rank` ASC';
|
||||
}
|
||||
$query = '
|
||||
UPDATE '.CATEGORIES_TABLE.'
|
||||
|
|
|
@ -49,7 +49,7 @@ $query.= '
|
|||
if ('recent_cats' != $page['section'])
|
||||
{
|
||||
$query.= '
|
||||
ORDER BY rank';
|
||||
ORDER BY `rank`';
|
||||
}
|
||||
|
||||
$result = pwg_query($query);
|
||||
|
|
|
@ -61,7 +61,7 @@ function pwg_get_db_version()
|
|||
return mysql_get_server_info();
|
||||
}
|
||||
|
||||
function pwg_query($query, $escape_reserved_words=true)
|
||||
function pwg_query($query)
|
||||
{
|
||||
global $conf,$page,$debug,$t2;
|
||||
|
||||
|
|
|
@ -124,27 +124,10 @@ function pwg_get_db_version()
|
|||
* @param string $query
|
||||
* @return mysqli_result|bool
|
||||
*/
|
||||
function pwg_query($query, $escape_reserved_words=true)
|
||||
function pwg_query($query)
|
||||
{
|
||||
global $mysqli, $conf, $page, $debug, $t2;
|
||||
|
||||
// starting with MySQL 8, rank becomes a reserved keyword, we need to escape it
|
||||
if ($escape_reserved_words and preg_match('/\brank\b/', $query))
|
||||
{
|
||||
// first we unescape what's already escaped (to avoid double escaping)
|
||||
$query = preg_replace('/`rank`/', 'rank', $query);
|
||||
// then we escape the keyword
|
||||
$query = preg_replace('/\brank\b/', '`rank`', $query);
|
||||
}
|
||||
|
||||
if ($escape_reserved_words and preg_match('/\bgroups\b/', $query))
|
||||
{
|
||||
// first we unescape what's already escaped (to avoid double escaping)
|
||||
$query = preg_replace('/`groups`/', 'groups', $query);
|
||||
// then we escape the keyword
|
||||
$query = preg_replace('/\bgroups\b/', '`groups`', $query);
|
||||
}
|
||||
|
||||
$start = microtime(true);
|
||||
($result = $mysqli->query($query)) or my_error($query, $conf['die_on_sql_error']);
|
||||
|
||||
|
|
|
@ -1381,7 +1381,7 @@ INSERT INTO
|
|||
ON DUPLICATE KEY UPDATE value = \''.$dbValue.'\'
|
||||
;';
|
||||
|
||||
pwg_query($query, false);
|
||||
pwg_query($query);
|
||||
|
||||
if ($updateGlobal)
|
||||
{
|
||||
|
|
|
@ -581,7 +581,7 @@ function ws_categories_setRank($params, &$service)
|
|||
{
|
||||
// does the category really exist?
|
||||
$query = '
|
||||
SELECT id, id_uppercat, rank
|
||||
SELECT id, id_uppercat, `rank`
|
||||
FROM '.CATEGORIES_TABLE.'
|
||||
WHERE id IN ('.implode(',',$params['category_id']).')
|
||||
;';
|
||||
|
|
|
@ -112,9 +112,9 @@ DELETE
|
|||
if ($search_current_ranks)
|
||||
{
|
||||
$query = '
|
||||
SELECT category_id, MAX(rank) AS max_rank
|
||||
SELECT category_id, MAX(`rank`) AS max_rank
|
||||
FROM '.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE rank IS NOT NULL
|
||||
WHERE `rank` IS NOT NULL
|
||||
AND category_id IN ('.implode(',', $new_cat_ids).')
|
||||
GROUP BY category_id
|
||||
;';
|
||||
|
@ -744,7 +744,7 @@ SELECT
|
|||
image_id
|
||||
FROM '.IMAGE_CATEGORY_TABLE.'
|
||||
WHERE category_id = '.$params['category_id'].'
|
||||
ORDER BY rank ASC
|
||||
ORDER BY `rank` ASC
|
||||
;';
|
||||
$image_ids = query2array($query, null, 'image_id');
|
||||
|
||||
|
@ -790,7 +790,7 @@ SELECT COUNT(*)
|
|||
|
||||
// what is the current higher rank for this category?
|
||||
$query = '
|
||||
SELECT MAX(rank) AS max_rank
|
||||
SELECT MAX(`rank`) AS max_rank
|
||||
FROM '. IMAGE_CATEGORY_TABLE .'
|
||||
WHERE category_id = '. $params['category_id'] .'
|
||||
;';
|
||||
|
@ -811,17 +811,17 @@ SELECT MAX(rank) AS max_rank
|
|||
// update rank for all other photos in the same category
|
||||
$query = '
|
||||
UPDATE '. IMAGE_CATEGORY_TABLE .'
|
||||
SET rank = rank + 1
|
||||
SET `rank` = `rank` + 1
|
||||
WHERE category_id = '. $params['category_id'] .'
|
||||
AND rank IS NOT NULL
|
||||
AND rank >= '. $params['rank'] .'
|
||||
AND `rank` IS NOT NULL
|
||||
AND `rank` >= '. $params['rank'] .'
|
||||
;';
|
||||
pwg_query($query);
|
||||
|
||||
// set the new rank for the photo
|
||||
$query = '
|
||||
UPDATE '. IMAGE_CATEGORY_TABLE .'
|
||||
SET rank = '. $params['rank'] .'
|
||||
SET `rank` = '. $params['rank'] .'
|
||||
WHERE image_id = '. $params['image_id'] .'
|
||||
AND category_id = '. $params['category_id'] .'
|
||||
;';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue