1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-06 14:46:36 +02:00

Remember export setting at SQL command

This commit is contained in:
Jakub Vrana
2025-03-16 15:13:10 +01:00
parent 517f63835d
commit d20cbf14e7
5 changed files with 23 additions and 19 deletions

View File

@@ -4,11 +4,10 @@ namespace Adminer;
$TABLE = $_GET["dump"]; $TABLE = $_GET["dump"];
if ($_POST && !$error) { if ($_POST && !$error) {
$cookie = ""; set_adminer_settings(
foreach (array("output", "format", "db_style", "types", "routines", "events", "table_style", "auto_increment", "triggers", "data_style") as $key) { array_intersect_key($_POST, array_flip(array("output", "format", "db_style", "types", "routines", "events", "table_style", "auto_increment", "triggers", "data_style"))),
$cookie .= "&$key=" . urlencode($_POST[$key]); "adminer_export"
} );
cookie("adminer_export", substr($cookie, 1));
$tables = array_flip((array) $_POST["tables"]) + array_flip((array) $_POST["data"]); $tables = array_flip((array) $_POST["tables"]) + array_flip((array) $_POST["data"]);
$ext = dump_headers( $ext = dump_headers(
(count($tables) == 1 ? key($tables) : DB), (count($tables) == 1 ? key($tables) : DB),
@@ -156,7 +155,7 @@ $data_style = array('', 'TRUNCATE+INSERT', 'INSERT');
if (JUSH == "sql") { //! use insertUpdate() in all drivers if (JUSH == "sql") { //! use insertUpdate() in all drivers
$data_style[] = 'INSERT+UPDATE'; $data_style[] = 'INSERT+UPDATE';
} }
parse_str($_COOKIE["adminer_export"], $row); $row = adminer_settings("adminer_export");
if (!$row) { if (!$row) {
$row = array("output" => "text", "format" => "sql", "db_style" => (DB != "" ? "" : "CREATE"), "table_style" => "DROP+CREATE", "data_style" => "INSERT"); $row = array("output" => "text", "format" => "sql", "db_style" => (DB != "" ? "" : "CREATE"), "table_style" => "DROP+CREATE", "data_style" => "INSERT");
} }

View File

@@ -121,28 +121,31 @@ function referencable_primary($self) {
} }
/** Get settings stored in a cookie /** Get settings stored in a cookie
* @param string
* @return array * @return array
*/ */
function adminer_settings() { function adminer_settings($cookie) {
parse_str($_COOKIE["adminer_settings"], $settings); parse_str($_COOKIE[$cookie], $settings);
return $settings; return $settings;
} }
/** Get setting stored in a cookie /** Get setting stored in a cookie
* @param string * @param string
* @return array * @param string
* @return mixed
*/ */
function adminer_setting($key) { function adminer_setting($key, $cookie = "adminer_settings") {
$settings = adminer_settings(); $settings = adminer_settings($cookie);
return $settings[$key]; return $settings[$key];
} }
/** Store settings to a cookie /** Store settings to a cookie
* @param array * @param array
* @param string
* @return bool * @return bool
*/ */
function set_adminer_settings($settings) { function set_adminer_settings($settings, $cookie = "adminer_settings") {
return cookie("adminer_settings", http_build_query($settings + adminer_settings())); return cookie($cookie, http_build_query($settings + adminer_settings($cookie)));
} }
/** Print SQL <textarea> tag /** Print SQL <textarea> tag

View File

@@ -7,7 +7,7 @@ $indexes = indexes($TABLE);
$fields = fields($TABLE); $fields = fields($TABLE);
$foreign_keys = column_foreign_keys($TABLE); $foreign_keys = column_foreign_keys($TABLE);
$oid = $table_status["Oid"]; $oid = $table_status["Oid"];
parse_str($_COOKIE["adminer_import"], $adminer_import); $adminer_import = adminer_settings("adminer_import");
$rights = array(); // privilege => 0 $rights = array(); // privilege => 0
$columns = array(); // selectable columns $columns = array(); // selectable columns
@@ -83,7 +83,7 @@ if ($_POST && !$error) {
} }
$where_check = ($where_check ? "\nWHERE " . implode(" AND ", $where_check) : ""); $where_check = ($where_check ? "\nWHERE " . implode(" AND ", $where_check) : "");
if ($_POST["export"]) { 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); dump_headers($TABLE);
$adminer->dumpTable($TABLE, ""); $adminer->dumpTable($TABLE, "");
$from = ($select ? implode(", ", $select) : "*") $from = ($select ? implode(", ", $select) : "*")
@@ -195,7 +195,7 @@ if ($_POST && !$error) {
} elseif (!preg_match('~~u', $file)) { } elseif (!preg_match('~~u', $file)) {
$error = lang('File must be in UTF-8 encoding.'); $error = lang('File must be in UTF-8 encoding.');
} else { } 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; $result = true;
$cols = array_keys($fields); $cols = array_keys($fields);
preg_match_all('~(?>"[^"]*"|[^"\r\n]+)+~', $file, $matches); preg_match_all('~(?>"[^"]*"|[^"\r\n]+)+~', $file, $matches);

View File

@@ -2,6 +2,7 @@
namespace Adminer; namespace Adminer;
if (!$error && $_POST["export"]) { if (!$error && $_POST["export"]) {
set_adminer_settings(array("output" => $_POST["output"], "format" => $_POST["format"]), "adminer_import");
dump_headers("sql"); dump_headers("sql");
$adminer->dumpTable("", ""); $adminer->dumpTable("", "");
$adminer->dumpData("", "table", $_POST["query"]); $adminer->dumpData("", "table", $_POST["query"]);
@@ -64,7 +65,7 @@ if (!$error && $_POST) {
$errors = array(); $errors = array();
$parse = '[\'"' . (JUSH == "sql" ? '`#' : (JUSH == "sqlite" ? '`[' : (JUSH == "mssql" ? '[' : ''))) . ']|/\*|-- |$' . (JUSH == "pgsql" ? '|\$[^$]*\$' : ''); $parse = '[\'"' . (JUSH == "sql" ? '`#' : (JUSH == "sqlite" ? '`[' : (JUSH == "mssql" ? '[' : ''))) . ']|/\*|-- |$' . (JUSH == "pgsql" ? '|\$[^$]*\$' : '');
$total_start = microtime(true); $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(); $dump_format = $adminer->dumpFormat();
unset($dump_format["sql"]); unset($dump_format["sql"]);

View File

@@ -1,9 +1,10 @@
Adminer dev: Adminer dev:
Align numbers right (bug #912) Align numbers right (bug #912)
CSS: Dark mode syntax highlighting Remember export setting at SQL command
SQL textarea: Open help on Ctrl+click SQL textarea: Open help on Ctrl+click
CSS: Dark mode syntax highlighting
Designs named adminer-dark.css use dark basic style 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): Adminer 5.0.5 (released 2025-03-13):
MySQL: Display converting function for binary, bit or geometry fields MySQL: Display converting function for binary, bit or geometry fields