From a50b3d6385dd6013c55f92f558cdaacbb3a37505 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Wed, 12 Mar 2025 09:26:17 +0100 Subject: [PATCH] MS SQL: Fix editing rows with datetime column in primary key Inspired by adminneo-org@b4afc08. This fixes https://sourceforge.net/p/adminer/discussion/960418/thread/a547e79622/. --- adminer/include/functions.inc.php | 7 ++++--- changes.txt | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 8b3aa84d..1fa23657 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -459,14 +459,15 @@ function where($where, $fields = array()) { foreach ((array) $where["where"] as $key => $val) { $key = bracket_escape($key, 1); // 1 - back $column = escape_key($key); + $field_type = $fields[$key]["type"]; $return[] = $column - . (JUSH == "sql" && $fields[$key]["type"] == "json" ? " = CAST(" . q($val) . " AS JSON)" + . (JUSH == "sql" && $field_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 + : (JUSH == "mssql" && strpos($field_type, "datetime") === false ? " LIKE " . q(preg_replace('~[_%[]~', '[\0]', $val)) // LIKE because of text but it does not work with datetime : " = " . 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 + if (JUSH == "sql" && preg_match('~char|text~', $field_type) && preg_match("~[^ -@]~", $val)) { // not just [a-z] to catch non-ASCII characters $return[] = "$column = " . q($val) . " COLLATE " . charset($connection) . "_bin"; } } diff --git a/changes.txt b/changes.txt index cf4ba158..24c461a2 100644 --- a/changes.txt +++ b/changes.txt @@ -2,6 +2,7 @@ Adminer dev: MySQL: Display default values of binary columns MariaDB: Don't display NULL as default value (regression from 5.0.0) PostgreSQL PDO: Escape bytea values (bug #218) +MS SQL: Fix editing rows with datetime column in primary key Adminer 5.0.4 (released 2025-03-11): Compile: Fix shortening in private methods (regression from 5.0.3)