mirror of
https://github.com/vrana/adminer.git
synced 2025-08-31 18:11:52 +02:00
MySQL: Fix where clause for JSON column
Issue: https://github.com/adminerevo/adminerevo/issues/175
This commit is contained in:
@@ -477,24 +477,36 @@ function escape_key($key) {
|
|||||||
*/
|
*/
|
||||||
function where($where, $fields = array()) {
|
function where($where, $fields = array()) {
|
||||||
global $connection, $jush;
|
global $connection, $jush;
|
||||||
$return = array();
|
|
||||||
|
$conditions = [];
|
||||||
|
|
||||||
foreach ((array) $where["where"] as $key => $val) {
|
foreach ((array) $where["where"] as $key => $val) {
|
||||||
$key = bracket_escape($key, 1); // 1 - back
|
$key = bracket_escape($key, 1); // 1 - back
|
||||||
$column = escape_key($key);
|
$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
|
if ($jush == "sql" && $fields[$key]["type"] == "json") {
|
||||||
: ($jush == "mssql" ? " LIKE " . q(preg_replace('~[_%[]~', '[\0]', $val)) // LIKE because of text
|
$conditions[] = "$column = CAST(" . q($val) . " AS JSON)";
|
||||||
: " = " . unconvert_field($fields[$key], q($val))
|
} elseif ($jush == "sql" && is_numeric($val) && strpos($val, ".") !== false) {
|
||||||
))
|
// LIKE because of floats but slow with ints.
|
||||||
; //! enum and set
|
$conditions[] = "$column LIKE " . q($val);
|
||||||
if ($jush == "sql" && preg_match('~char|text~', $fields[$key]["type"]) && preg_match("~[^ -@]~", $val)) { // not just [a-z] to catch non-ASCII characters
|
} elseif ($jush == "mssql") {
|
||||||
$return[] = "$column = " . q($val) . " COLLATE " . charset($connection) . "_bin";
|
// LIKE because of text.
|
||||||
|
$conditions[] = "$column LIKE " . q(preg_replace('~[_%[]~', '[\0]', $val));
|
||||||
|
} else {
|
||||||
|
$conditions[] = "$column = " . unconvert_field($fields[$key], q($val));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not just [a-z] to catch non-ASCII characters.
|
||||||
|
if ($jush == "sql" && preg_match('~char|text~', $fields[$key]["type"]) && preg_match("~[^ -@]~", $val)) {
|
||||||
|
$conditions[] = "$column = " . q($val) . " COLLATE " . charset($connection) . "_bin";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ((array) $where["null"] as $key) {
|
foreach ((array) $where["null"] as $key) {
|
||||||
$return[] = escape_key($key) . " IS NULL";
|
$conditions[] = escape_key($key) . " IS NULL";
|
||||||
}
|
}
|
||||||
return implode(" AND ", $return);
|
|
||||||
|
return implode(" AND ", $conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create SQL condition from query string
|
/** Create SQL condition from query string
|
||||||
|
Reference in New Issue
Block a user