Skip to content
Permalink
Browse files

fixes #996 escape word "groups" in SQL queries, new reserved word wit…

…h MySQL 8
  • Loading branch information...
plegall committed Jun 28, 2019
1 parent 0ef2193 commit c1eecab36415bcba022aa088463ed138fc38b92b
@@ -35,12 +35,12 @@
{
set_make_full_url();
$img = array();
/* TODO: if $category['representative_picture_id']
is empty find child representative_picture_id */
if (!empty($category['representative_picture_id']))
{
$img = array();
$query = '
SELECT id, file, path, representative_ext
FROM '.IMAGES_TABLE.'
@@ -161,7 +161,7 @@
$query = '
SELECT
name
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE id = '.$_POST['group'].'
;';
list($group_name) = pwg_db_fetch_row(pwg_query($query));
@@ -210,7 +210,7 @@
$query = '
SELECT
id AS group_id
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
;';
$all_group_ids = array_from_query($query, 'group_id');
@@ -246,7 +246,7 @@
SELECT
id,
name
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE id IN ('.implode(',', $group_ids).')
ORDER BY name ASC
;';
@@ -192,7 +192,7 @@
$query = '
SELECT id, name
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
ORDER BY name ASC
;';
$groups = simple_hash_from_query($query, 'id', 'name');
@@ -50,7 +50,7 @@
// is the group not already existing ?
$query = '
SELECT COUNT(*)
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE name = \''.$_POST['groupname'].'\'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
@@ -63,7 +63,7 @@
{
// creating the group
$query = '
INSERT INTO '.GROUPS_TABLE.'
INSERT INTO `'.GROUPS_TABLE.'`
(name)
VALUES
(\''.pwg_db_real_escape_string($_POST['groupname']).'\')
@@ -101,20 +101,22 @@
// is the group not already existing ?
$query = '
SELECT name
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
;';
$group_names = array_from_query($query, 'name');
foreach($groups as $group)
{
if ( in_array($_POST['rename_'.$group.''], $group_names))
$_POST['rename_'.$group] = stripslashes($_POST['rename_'.$group]);
if (in_array($_POST['rename_'.$group], $group_names))
{
$page['errors'][] = $_POST['rename_'.$group.''].' | '.l10n('This name is already used by another group.');
$page['errors'][] = $_POST['rename_'.$group].' | '.l10n('This name is already used by another group.');
}
elseif ( !empty($_POST['rename_'.$group.'']))
{
$query = '
UPDATE '.GROUPS_TABLE.'
SET name = \''.pwg_db_real_escape_string($_POST['rename_'.$group.'']).'\'
UPDATE `'.GROUPS_TABLE.'`
SET name = \''.pwg_db_real_escape_string($_POST['rename_'.$group]).'\'
WHERE id = '.$group.'
;';
pwg_query($query);
@@ -149,7 +151,7 @@
$query = '
SELECT id, name
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE id = '.$group.'
;';
@@ -160,7 +162,7 @@
// destruction of the group
$query = '
DELETE
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE id = '.$group.'
;';
pwg_query($query);
@@ -181,7 +183,7 @@
// is the group not already existing ?
$query = '
SELECT COUNT(*)
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE name = \''.pwg_db_real_escape_string($_POST['merge']).'\'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
@@ -193,15 +195,15 @@
{
// creating the group
$query = '
INSERT INTO '.GROUPS_TABLE.'
INSERT INTO `'.GROUPS_TABLE.'`
(name)
VALUES
(\''.pwg_db_real_escape_string($_POST['merge']).'\')
;';
pwg_query($query);
$query = '
SELECT id
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE name = \''.pwg_db_real_escape_string($_POST['merge']).'\'
;';
list($groupid) = pwg_db_fetch_row(pwg_query($query));
@@ -268,7 +270,7 @@
// is the group not already existing ?
$query = '
SELECT COUNT(*)
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE name = \''.pwg_db_real_escape_string($_POST['duplicate_'.$group.'']).'\'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
@@ -279,15 +281,15 @@
}
// creating the group
$query = '
INSERT INTO '.GROUPS_TABLE.'
INSERT INTO `'.GROUPS_TABLE.'`
(name)
VALUES
(\''.pwg_db_real_escape_string($_POST['duplicate_'.$group.'']).'\')
;';
pwg_query($query);
$query = '
SELECT id
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE name = \''.pwg_db_real_escape_string($_POST['duplicate_'.$group.'']).'\'
;';
@@ -340,14 +342,14 @@
{
$query = '
SELECT name, is_default
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE id = '.$group.'
;';
list($groupname, $is_default) = pwg_db_fetch_row(pwg_query($query));
// update of the group
$query = '
UPDATE '.GROUPS_TABLE.'
UPDATE `'.GROUPS_TABLE.'`
SET is_default = \''.boolean_to_string(!get_boolean($is_default)).'\'
WHERE id = '.$group.'
;';
@@ -380,7 +382,7 @@
$query = '
SELECT id, name, is_default
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
ORDER BY name ASC
;';
$result = pwg_query($query);
@@ -2438,7 +2438,7 @@ function get_groupname($group_id)
{
$query = '
SELECT name
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE id = '.intval($group_id).'
;';
$result = pwg_query($query);
@@ -3022,7 +3022,7 @@ function get_admin_client_cache_keys($requested=array())
"_",
COUNT(*)
)
FROM '. $tables[$item] .'
FROM `'. $tables[$item] .'`
;';
list($keys[$item]) = pwg_db_fetch_row(pwg_query($query));
}
@@ -124,7 +124,7 @@
$query = '
SELECT COUNT(*)
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
;';
list($nb_groups) = pwg_db_fetch_row(pwg_query($query));
@@ -31,7 +31,7 @@
$query = '
SELECT id, name
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
ORDER BY name ASC
;';
$result = pwg_query($query);
@@ -203,7 +203,7 @@
user_id,
GROUP_CONCAT(name ORDER BY name SEPARATOR ", ") AS groups
FROM '.USER_GROUP_TABLE.'
JOIN '.GROUPS_TABLE.' ON id = group_id
JOIN `'.GROUPS_TABLE.'` ON id = group_id
WHERE user_id IN ('.implode(',', $user_ids).')
GROUP BY user_id
;';
@@ -286,6 +286,12 @@ function mass_updates($tablename, $dbfields, $datas, $flags=0)
{
$is_first = true;
// escape a reserved word
if ('groups' == $tablename)
{
$tablename = '`'.$tablename.'`';
}
$query = '
UPDATE '.$tablename.'
SET ';
@@ -428,6 +434,12 @@ function single_update($tablename, $datas, $where, $flags=0)
$is_first = true;
// escape a reserved word
if ('groups' == $tablename)
{
$tablename = '`'.$tablename.'`';
}
$query = '
UPDATE '.$tablename.'
SET ';
@@ -515,6 +527,12 @@ function mass_inserts($table_name, $dbfields, $datas, $options=array())
if ($first)
{
// escape a reserved word
if ('groups' == $table_name)
{
$table_name = '`'.$table_name.'`';
}
$query = '
INSERT '.$ignore.' INTO '.$table_name.'
('.implode(',', $dbfields).')
@@ -561,6 +579,12 @@ function single_insert($table_name, $data)
{
if (count($data) != 0)
{
// escape a reserved word
if ('groups' == $table_name)
{
$table_name = '`'.$table_name.'`';
}
$query = '
INSERT INTO '.$table_name.'
('.implode(',', array_keys($data)).')
@@ -184,7 +184,7 @@ function register_user($login, $password, $mail_address, $notify_admin=true, &$e
// Assign by default groups
$query = '
SELECT id
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE is_default = \''.boolean_to_string(true).'\'
ORDER BY id ASC
;';
@@ -30,7 +30,7 @@ function ws_groups_getList($params, &$service)
$query = '
SELECT
g.*, COUNT(user_id) AS nb_users
FROM '. GROUPS_TABLE .' AS g
FROM `'. GROUPS_TABLE .'` AS g
LEFT JOIN '. USER_GROUP_TABLE .' AS ug
ON ug.group_id = g.id
WHERE '. implode(' AND ', $where_clauses) .'
@@ -66,7 +66,7 @@ function ws_groups_add($params, &$service)
// is the name not already used ?
$query = '
SELECT COUNT(*)
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE name = \''.$params['name'].'\'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
@@ -124,7 +124,7 @@ function ws_groups_delete($params, &$service)
$query = '
SELECT id, name
FROM '. GROUPS_TABLE .'
FROM `'. GROUPS_TABLE .'`
WHERE id IN('. $group_id_string .')
;';
@@ -135,7 +135,7 @@ function ws_groups_delete($params, &$service)
// destruction of the group
$query = '
DELETE
FROM '. GROUPS_TABLE .'
FROM `'. GROUPS_TABLE .'`
WHERE id IN('. $group_id_string .')
;';
pwg_query($query);
@@ -169,7 +169,7 @@ function ws_groups_setInfo($params, &$service)
// does the group exist ?
$query = '
SELECT COUNT(*)
FROM '. GROUPS_TABLE .'
FROM `'. GROUPS_TABLE .'`
WHERE id = '. $params['group_id'] .'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
@@ -185,7 +185,7 @@ function ws_groups_setInfo($params, &$service)
// is the name not already used ?
$query = '
SELECT COUNT(*)
FROM '. GROUPS_TABLE .'
FROM `'. GROUPS_TABLE .'`
WHERE name = \''. $params['name'] .'\'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
@@ -230,7 +230,7 @@ function ws_groups_addUser($params, &$service)
// does the group exist ?
$query = '
SELECT COUNT(*)
FROM '. GROUPS_TABLE .'
FROM `'. GROUPS_TABLE .'`
WHERE id = '. $params['group_id'] .'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
@@ -281,7 +281,7 @@ function ws_groups_deleteUser($params, &$service)
// does the group exist ?
$query = '
SELECT COUNT(*)
FROM '. GROUPS_TABLE .'
FROM `'. GROUPS_TABLE .'`
WHERE id = '. $params['group_id'] .'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
@@ -160,7 +160,7 @@ function ws_getInfos($params, &$service)
$query = 'SELECT COUNT(*) FROM '.USERS_TABLE.';';
list($infos['nb_users']) = pwg_db_fetch_row(pwg_query($query));
$query = 'SELECT COUNT(*) FROM '.GROUPS_TABLE.';';
$query = 'SELECT COUNT(*) FROM `'.GROUPS_TABLE.'`;';
list($infos['nb_groups']) = pwg_db_fetch_row(pwg_query($query));
$query = 'SELECT COUNT(*) FROM '.COMMENTS_TABLE.';';
@@ -598,7 +598,7 @@ function ws_users_setInfo($params, &$service)
$query = '
SELECT
id
FROM '.GROUPS_TABLE.'
FROM `'.GROUPS_TABLE.'`
WHERE id IN ('.implode(',', $params['group_id']).')
;';
$group_ids = array_from_query($query, 'id');

0 comments on commit c1eecab

Please sign in to comment.
You can’t perform that action at this time.