diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index c8ed37c9..ae2cd576 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -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(); } diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 1ba8d651..18b8e6b7 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -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) */ diff --git a/adminer/drivers/oracle.inc.php b/adminer/drivers/oracle.inc.php index 1c5b1598..54a673ec 100644 --- a/adminer/drivers/oracle.inc.php +++ b/adminer/drivers/oracle.inc.php @@ -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 diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index f41ea04b..5a626195 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -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")); } diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index e85fd31c..e8ede848 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -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) { diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index 473997f9..4f7b47cd 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -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);