From a310d52327d698b0d1b23bc1e86b6a04e9c45aab Mon Sep 17 00:00:00 2001 From: SeaEagle Date: Mon, 29 Jul 2024 19:08:50 +0000 Subject: [PATCH] MySQL: Fix where clause for JSON column Issue: https://github.com/adminerevo/adminerevo/issues/175 --- adminer/include/functions.inc.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index d3384937..4d8db98b 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -482,10 +482,11 @@ function where($where, $fields = array()) { $key = bracket_escape($key, 1); // 1 - back $column = escape_key($key); $return[] = $column - . ($jush == "sql" && is_numeric($val) && preg_match('~\.~', $val) ? " LIKE " . q($val) // LIKE because of floats but slow with ints + . ($jush == "sql" && $fields[$key]["type"] == "json" ? " = CAST(" . q($val) . " AS JSON)" + : ($jush == "sql" && is_numeric($val) && preg_match('~\.~', $val) ? " LIKE " . q($val) // LIKE because of floats but slow with ints : ($jush == "mssql" ? " LIKE " . q(preg_replace('~[_%[]~', '[\0]', $val)) // LIKE because of text : " = " . unconvert_field($fields[$key], q($val)) - )) + ))) ; //! enum and set if ($jush == "sql" && preg_match('~char|text~', $fields[$key]["type"]) && preg_match("~[^ -@]~", $val)) { // not just [a-z] to catch non-ASCII characters $return[] = "$column = " . q($val) . " COLLATE " . charset($connection) . "_bin";