fixes #1292 ability to avoid the reserved words escape in pwg_query

Useful for conf_update_param because we don't want any modification in the config.value and we know we won't use the reserved words in the SQL.
This commit is contained in:
plegall
2021-01-21 16:10:36 +01:00
parent 6704632263
commit 86d212f4f1
3 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ function pwg_get_db_version()
return mysql_get_server_info(); return mysql_get_server_info();
} }
function pwg_query($query) function pwg_query($query, $escape_reserved_words=true)
{ {
global $conf,$page,$debug,$t2; global $conf,$page,$debug,$t2;
+3 -3
View File
@@ -124,12 +124,12 @@ function pwg_get_db_version()
* @param string $query * @param string $query
* @return mysqli_result|bool * @return mysqli_result|bool
*/ */
function pwg_query($query) function pwg_query($query, $escape_reserved_words=true)
{ {
global $mysqli, $conf, $page, $debug, $t2; global $mysqli, $conf, $page, $debug, $t2;
// starting with MySQL 8, rank becomes a reserved keyword, we need to escape it // starting with MySQL 8, rank becomes a reserved keyword, we need to escape it
if (preg_match('/\brank\b/', $query)) if ($escape_reserved_words and preg_match('/\brank\b/', $query))
{ {
// first we unescape what's already escaped (to avoid double escaping) // first we unescape what's already escaped (to avoid double escaping)
$query = preg_replace('/`rank`/', 'rank', $query); $query = preg_replace('/`rank`/', 'rank', $query);
@@ -137,7 +137,7 @@ function pwg_query($query)
$query = preg_replace('/\brank\b/', '`rank`', $query); $query = preg_replace('/\brank\b/', '`rank`', $query);
} }
if (preg_match('/\bgroups\b/', $query)) if ($escape_reserved_words and preg_match('/\bgroups\b/', $query))
{ {
// first we unescape what's already escaped (to avoid double escaping) // first we unescape what's already escaped (to avoid double escaping)
$query = preg_replace('/`groups`/', 'groups', $query); $query = preg_replace('/`groups`/', 'groups', $query);
+1 -1
View File
@@ -1381,7 +1381,7 @@ INSERT INTO
ON DUPLICATE KEY UPDATE value = \''.$dbValue.'\' ON DUPLICATE KEY UPDATE value = \''.$dbValue.'\'
;'; ;';
pwg_query($query); pwg_query($query, false);
if ($updateGlobal) if ($updateGlobal)
{ {