]> git.joonet.de Git - adminer.git/commitdiff
MySQL, PostgreSQL: Fix queries splitting and string constants
authorPeter Knut <peter@pematon.com>
Fri, 20 Sep 2024 22:39:51 +0000 (00:39 +0200)
committerJakub Vrana <jakub@vrana.cz>
Wed, 19 Feb 2025 10:16:38 +0000 (11:16 +0100)
Thanks to alxivnov (https://github.com/vrana/adminer/pull/490).

adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/sql.inc.php

index c8ed37c99b0edc6bd4f7fa6e4ed0ce7406f42f59..ae2cd5761cf2cf5e73b52eac60d452883faab50b 100644 (file)
@@ -630,6 +630,10 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
                return array();
        }
 
+       function is_c_style_escapes() {
+               return true;
+       }
+
        function show_status() {
                return array();
        }
index 1ba8d651205c673ef98dca197a4bd48b75d0ce17..18b8e6b70875e746adf925c49426115f9d63eb77 100644 (file)
@@ -1056,6 +1056,18 @@ if (!defined("DRIVER")) {
                return get_key_vals("SHOW VARIABLES");
        }
 
+       /** Checks if C-style escapes are supported
+       * @return bool
+       */
+       function is_c_style_escapes() {
+               static $c_style = null;
+               if ($c_style === null) {
+                       $variables = get_key_vals("SHOW VARIABLES LIKE 'sql_mode'");
+                       $c_style = strpos($variables["sql_mode"], 'NO_BACKSLASH_ESCAPES') === false;
+               }
+               return $c_style;
+       }
+
        /** Get process list
        * @return array ($row)
        */
index 1c5b15981e18129a94c5302b223fc640c19717b7..54a673ec68852344bbe16b4832668a805170e152 100644 (file)
@@ -479,6 +479,10 @@ AND c_src.TABLE_NAME = " . q($table);
                return get_key_vals('SELECT name, display_value FROM v$parameter');
        }
 
+       function is_c_style_escapes() {
+               return true;
+       }
+
        function process_list() {
                return get_rows('SELECT sess.process AS "process", sess.username AS "user", sess.schemaname AS "schema", sess.status AS "status", sess.wait_class AS "wait_class", sess.seconds_in_wait AS "seconds_in_wait", sql.sql_text AS "sql_text", sess.machine AS "machine", sess.port AS "port"
 FROM v$session sess LEFT OUTER JOIN v$sql sql
index f41ea04baf0099d59a3858e01429ae6f75d2a609..5a626195791a863d903a1160e688cace65762822 100644 (file)
@@ -860,6 +860,15 @@ AND typelem = 0"
                return get_key_vals("SHOW ALL");
        }
 
+       function is_c_style_escapes() {
+               static $c_style = null;
+               if ($c_style === null) {
+                       $vals = get_vals("SHOW standard_conforming_strings");
+                       $c_style = $vals[0] == "off";
+               }
+               return $c_style;
+       }
+
        function process_list() {
                return get_rows("SELECT * FROM pg_stat_activity ORDER BY " . (min_version(9.2) ? "pid" : "procpid"));
        }
index e85fd31c2372d3ee0bcb933817f8be6666d3f67f..e8ede8486619069eaa3b53ba204c7b4938bad453 100644 (file)
@@ -764,6 +764,10 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                return $return;
        }
 
+       function is_c_style_escapes() {
+               return true;
+       }
+
        function show_status() {
                $return = array();
                foreach (get_vals("PRAGMA compile_options") as $option) {
index 473997f9d3559e4d3ec63b094d45df85b55a624f..4f7b47cdf0cc2d158df90e262f8ddff38a7b73bc 100644 (file)
@@ -81,7 +81,15 @@ if (!$error && $_POST) {
                                        $offset = $pos + strlen($found);
 
                                        if ($found && rtrim($found) != $delimiter) { // find matching quote or comment end
-                                               while (preg_match('(' . ($found == '/*' ? '\*/' : ($found == '[' ? ']' : (preg_match('~^-- |^#~', $found) ? "\n" : preg_quote($found) . "|\\\\."))) . '|$)s', $query, $match, PREG_OFFSET_CAPTURE, $offset)) { //! respect sql_mode NO_BACKSLASH_ESCAPES
+                                               $c_style_escapes = is_c_style_escapes() || ($jush == "pgsql" && ($pos > 0 && strtolower($query[$pos - 1]) == "e"));
+
+                                               $pattern = ($found == '/*' ? '\*/'
+                                                       : ($found == '[' ? ']'
+                                                       : (preg_match('~^-- |^#~', $found) ? "\n"
+                                                       : preg_quote($found) . ($c_style_escapes ? "|\\\\." : "")
+                                               )));
+
+                                               while (preg_match("($pattern|\$)s", $query, $match, PREG_OFFSET_CAPTURE, $offset)) {
                                                        $s = $match[0][0];
                                                        if (!$s && $fp && !feof($fp)) {
                                                                $query .= fread($fp, 1e5);