From 6dcc5081e17206c6a9da72904dd83de9bdcdda5b Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Mon, 10 Mar 2025 08:33:25 +0100 Subject: [PATCH] Fix importing multiple SQL files not terminated by semicolon Inspired by adminneo-org/adminneo#1c08e86. --- adminer/include/functions.inc.php | 13 +++++++------ adminer/sql.inc.php | 2 +- changes.txt | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index c1f0a67c..0ef1f71c 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -728,9 +728,10 @@ function pagination($page, $current) { /** Get file contents from $_FILES * @param string * @param bool +* @param string * @return mixed int for error, string otherwise */ -function get_file($key, $decompress = false) { +function get_file($key, $decompress = false, $delimiter = "") { $file = $_FILES[$key]; if (!$file) { return null; @@ -752,17 +753,17 @@ function get_file($key, $decompress = false) { ); //! may not be reachable because of open_basedir if ($decompress) { $start = substr($content, 0, 3); - if (function_exists("iconv") && preg_match("~^\xFE\xFF|^\xFF\xFE~", $start, $regs)) { // not ternary operator to save memory + if (function_exists("iconv") && preg_match("~^\xFE\xFF|^\xFF\xFE~", $start)) { // not ternary operator to save memory $content = iconv("utf-16", "utf-8", $content); } elseif ($start == "\xEF\xBB\xBF") { // UTF-8 BOM $content = substr($content, 3); } - $return .= $content . "\n\n"; - } else { - $return .= $content; + } + $return .= $content; + if ($delimiter) { + $return .= (preg_match("($delimiter\\s*\$)", $content) ? "" : $delimiter) . "\n\n"; } } - //! support SQL files not ending with semicolon return $return; } diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index 593cd63f..088be1a0 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -30,7 +30,7 @@ if (!$error && $_POST) { ), "rb"); $query = ($fp ? fread($fp, 1e6) : false); } else { - $query = get_file("sql_file", true); + $query = get_file("sql_file", true, ";"); } if (is_string($query)) { // get_file() returns error as number, fread() as false diff --git a/changes.txt b/changes.txt index 4ac4d2f7..a5e20bb9 100644 --- a/changes.txt +++ b/changes.txt @@ -1,4 +1,5 @@ Adminer dev: +Fix importing multiple SQL files not terminated by semicolon Adminer 5.0.2 (released 2025-03-10): PostgreSQL: Fix setting NULL and original value on enum (bug #884)