]> git.joonet.de Git - adminer.git/commitdiff
MS SQL: Fix editing rows with datetime column in primary key
authorJakub Vrana <jakub@vrana.cz>
Wed, 12 Mar 2025 08:26:17 +0000 (09:26 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 12 Mar 2025 08:28:22 +0000 (09:28 +0100)
Inspired by adminneo-org@b4afc08.
This fixes https://sourceforge.net/p/adminer/discussion/960418/thread/a547e79622/.

adminer/include/functions.inc.php
changes.txt

index 8b3aa84d15153b8e4b8f08b13b283bbb2a96c38a..1fa23657193ec1754e6d2670dc40457b75667607 100644 (file)
@@ -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";
                }
        }
index cf4ba1589ae2530737adce8fa98d8a85057bfefd..24c461a26bea13d285f28482fe8de4a0a15b8605 100644 (file)
@@ -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)