]> git.joonet.de Git - adminer.git/commitdiff
Remember export setting at SQL command
authorJakub Vrana <jakub@vrana.cz>
Sun, 16 Mar 2025 14:13:10 +0000 (15:13 +0100)
committerJakub Vrana <jakub@vrana.cz>
Sun, 16 Mar 2025 14:13:10 +0000 (15:13 +0100)
adminer/dump.inc.php
adminer/include/editing.inc.php
adminer/select.inc.php
adminer/sql.inc.php
changes.txt

index a5352429ece0ff60e7997ec9175ee778b1631c7f..bdd31c9e351a5cc98463b21350db05cc6ee6a5c8 100644 (file)
@@ -4,11 +4,10 @@ namespace Adminer;
 $TABLE = $_GET["dump"];
 
 if ($_POST && !$error) {
-       $cookie = "";
-       foreach (array("output", "format", "db_style", "types", "routines", "events", "table_style", "auto_increment", "triggers", "data_style") as $key) {
-               $cookie .= "&$key=" . urlencode($_POST[$key]);
-       }
-       cookie("adminer_export", substr($cookie, 1));
+       set_adminer_settings(
+               array_intersect_key($_POST, array_flip(array("output", "format", "db_style", "types", "routines", "events", "table_style", "auto_increment", "triggers", "data_style"))),
+               "adminer_export"
+       );
        $tables = array_flip((array) $_POST["tables"]) + array_flip((array) $_POST["data"]);
        $ext = dump_headers(
                (count($tables) == 1 ? key($tables) : DB),
@@ -156,7 +155,7 @@ $data_style = array('', 'TRUNCATE+INSERT', 'INSERT');
 if (JUSH == "sql") { //! use insertUpdate() in all drivers
        $data_style[] = 'INSERT+UPDATE';
 }
-parse_str($_COOKIE["adminer_export"], $row);
+$row = adminer_settings("adminer_export");
 if (!$row) {
        $row = array("output" => "text", "format" => "sql", "db_style" => (DB != "" ? "" : "CREATE"), "table_style" => "DROP+CREATE", "data_style" => "INSERT");
 }
index eb1c05543185c4575fca7a504831bee6b4e06ae2..32a6ee642aba1dc96ba0ab6884a46203222894a4 100644 (file)
@@ -121,28 +121,31 @@ function referencable_primary($self) {
 }
 
 /** Get settings stored in a cookie
+* @param string
 * @return array
 */
-function adminer_settings() {
-       parse_str($_COOKIE["adminer_settings"], $settings);
+function adminer_settings($cookie) {
+       parse_str($_COOKIE[$cookie], $settings);
        return $settings;
 }
 
 /** Get setting stored in a cookie
 * @param string
-* @return array
+* @param string
+* @return mixed
 */
-function adminer_setting($key) {
-       $settings = adminer_settings();
+function adminer_setting($key, $cookie = "adminer_settings") {
+       $settings = adminer_settings($cookie);
        return $settings[$key];
 }
 
 /** Store settings to a cookie
 * @param array
+* @param string
 * @return bool
 */
-function set_adminer_settings($settings) {
-       return cookie("adminer_settings", http_build_query($settings + adminer_settings()));
+function set_adminer_settings($settings, $cookie = "adminer_settings") {
+       return cookie($cookie, http_build_query($settings + adminer_settings($cookie)));
 }
 
 /** Print SQL <textarea> tag
index cc3a808ae56546c104733635ad5b452f7000378d..ca96cde59ba236200baccad59e2774d078cb6209 100644 (file)
@@ -7,7 +7,7 @@ $indexes = indexes($TABLE);
 $fields = fields($TABLE);
 $foreign_keys = column_foreign_keys($TABLE);
 $oid = $table_status["Oid"];
-parse_str($_COOKIE["adminer_import"], $adminer_import);
+$adminer_import = adminer_settings("adminer_import");
 
 $rights = array(); // privilege => 0
 $columns = array(); // selectable columns
@@ -83,7 +83,7 @@ if ($_POST && !$error) {
        }
        $where_check = ($where_check ? "\nWHERE " . implode(" AND ", $where_check) : "");
        if ($_POST["export"]) {
-               cookie("adminer_import", "output=" . urlencode($_POST["output"]) . "&format=" . urlencode($_POST["format"]));
+               set_adminer_settings(array("output" => $_POST["output"], "format" => $_POST["format"]), "adminer_import");
                dump_headers($TABLE);
                $adminer->dumpTable($TABLE, "");
                $from = ($select ? implode(", ", $select) : "*")
@@ -195,7 +195,7 @@ if ($_POST && !$error) {
                } elseif (!preg_match('~~u', $file)) {
                        $error = lang('File must be in UTF-8 encoding.');
                } else {
-                       cookie("adminer_import", "output=" . urlencode($adminer_import["output"]) . "&format=" . urlencode($_POST["separator"]));
+                       set_adminer_settings(array("output" => $adminer_import["output"], "format" => $_POST["separator"]), "adminer_import");
                        $result = true;
                        $cols = array_keys($fields);
                        preg_match_all('~(?>"[^"]*"|[^"\r\n]+)+~', $file, $matches);
index 86181108c2759c3d40f13cab0812d048688c2faa..8da4a03c18a8d5f6db9a65af287556bfebd5cb20 100644 (file)
@@ -2,6 +2,7 @@
 namespace Adminer;
 
 if (!$error && $_POST["export"]) {
+       set_adminer_settings(array("output" => $_POST["output"], "format" => $_POST["format"]), "adminer_import");
        dump_headers("sql");
        $adminer->dumpTable("", "");
        $adminer->dumpData("", "table", $_POST["query"]);
@@ -64,7 +65,7 @@ if (!$error && $_POST) {
                $errors = array();
                $parse = '[\'"' . (JUSH == "sql" ? '`#' : (JUSH == "sqlite" ? '`[' : (JUSH == "mssql" ? '[' : ''))) . ']|/\*|-- |$' . (JUSH == "pgsql" ? '|\$[^$]*\$' : '');
                $total_start = microtime(true);
-               parse_str($_COOKIE["adminer_export"], $adminer_export);
+               $adminer_export = adminer_settings("adminer_import"); // this doesn't offer SQL export so we match the import/export style at select
                $dump_format = $adminer->dumpFormat();
                unset($dump_format["sql"]);
 
index 1d8137283379f20baefe883b35468340c2e01450..a6bf14c2eb59dab3142c6ef4610995333cf60e14 100644 (file)
@@ -1,9 +1,10 @@
 Adminer dev:
 Align numbers right (bug #912)
-CSS: Dark mode syntax highlighting
+Remember export setting at SQL command
 SQL textarea: Open help on Ctrl+click
+CSS: Dark mode syntax highlighting
 Designs named adminer-dark.css use dark basic style
-Plugins: add method syntaxHighlighting()
+Plugins: Add method syntaxHighlighting()
 
 Adminer 5.0.5 (released 2025-03-13):
 MySQL: Display converting function for binary, bit or geometry fields