]> git.joonet.de Git - adminer.git/commitdiff
MySQL: Fix where clause for JSON column
authorSeaEagle <dennis.liu2013@gmail.com>
Mon, 29 Jul 2024 19:08:50 +0000 (19:08 +0000)
committerJakub Vrana <jakub@vrana.cz>
Wed, 19 Feb 2025 10:16:39 +0000 (11:16 +0100)
Issue: https://github.com/adminerevo/adminerevo/issues/175

adminer/include/functions.inc.php

index d3384937b397ffa78e77149435fe891283d0a4b4..4d8db98b722477e500c442831b2d8074c53d2510 100644 (file)
@@ -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";