mirror of
https://github.com/vrana/adminer.git
synced 2026-01-09 17:13:03 +01:00
PostgreSQL: Export DROP and CREATE DATABASE (fix #1140)
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
- PostgreSQL: Fix calling functions with name-less parameters
|
||||
- PostgreSQL: Fix calling functions returing table
|
||||
- PostgreSQL: Don't treat user types containing 'file' as blobs (bug #1118)
|
||||
- PostgreSQL: Export DROP and CREATE DATABASE (bug #1140)
|
||||
- PostgreSQL 11-: Avoid duplicate oid in table status (bug #1089)
|
||||
- Elasticsearch: Support dropping aliases
|
||||
- Plugins: Methods afterConnect(), processList() and killProcess()
|
||||
|
||||
@@ -678,7 +678,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row
|
||||
return "TRUNCATE TABLE " . table($table);
|
||||
}
|
||||
|
||||
function use_sql($database) {
|
||||
function use_sql($database, $style = "") {
|
||||
return "USE " . idf_escape($database);
|
||||
}
|
||||
|
||||
|
||||
@@ -983,8 +983,17 @@ if (!defined('Adminer\DRIVER')) {
|
||||
}
|
||||
|
||||
/** Get SQL command to change database */
|
||||
function use_sql(string $database): string {
|
||||
return "USE " . idf_escape($database);
|
||||
function use_sql(string $database, string $style = ""): string {
|
||||
$name = idf_escape($database);
|
||||
$return = "";
|
||||
if (preg_match('~CREATE~', $style) && ($create = get_val("SHOW CREATE DATABASE $name", 1))) {
|
||||
set_utf8mb4($create);
|
||||
if ($style == "DROP+CREATE") {
|
||||
$return = "DROP DATABASE IF EXISTS $name;\n";
|
||||
}
|
||||
$return .= "$create;\n";
|
||||
}
|
||||
return $return . "USE $name";
|
||||
}
|
||||
|
||||
/** Get SQL commands to create triggers */
|
||||
|
||||
@@ -1013,8 +1013,16 @@ AND typelem = 0"
|
||||
}
|
||||
|
||||
|
||||
function use_sql($database) {
|
||||
return "\connect " . idf_escape($database);
|
||||
function use_sql($database, $style = "") {
|
||||
$name = idf_escape($database);
|
||||
$return = "";
|
||||
if (preg_match('~CREATE~', $style)) {
|
||||
if ($style == "DROP+CREATE") {
|
||||
$return = "DROP DATABASE IF EXISTS $name;\n";
|
||||
}
|
||||
$return .= "CREATE DATABASE $name;\n"; //! get info from pg_database
|
||||
}
|
||||
return "$return\\connect $name";
|
||||
}
|
||||
|
||||
function show_variables() {
|
||||
|
||||
@@ -680,7 +680,7 @@ if (isset($_GET["sqlite"])) {
|
||||
return "DELETE FROM " . table($table);
|
||||
}
|
||||
|
||||
function use_sql($database) {
|
||||
function use_sql($database, $style = "") {
|
||||
}
|
||||
|
||||
function trigger_sql($table) {
|
||||
|
||||
@@ -41,16 +41,9 @@ SET foreign_key_checks = 0;
|
||||
foreach ((array) $databases as $db) {
|
||||
adminer()->dumpDatabase($db);
|
||||
if (connection()->select_db($db)) {
|
||||
if ($is_sql && preg_match('~CREATE~', $style) && ($create = get_val("SHOW CREATE DATABASE " . idf_escape($db), 1))) {
|
||||
set_utf8mb4($create);
|
||||
if ($style == "DROP+CREATE") {
|
||||
echo "DROP DATABASE IF EXISTS " . idf_escape($db) . ";\n";
|
||||
}
|
||||
echo "$create;\n";
|
||||
}
|
||||
if ($is_sql) {
|
||||
if ($style) {
|
||||
echo use_sql($db) . ";\n\n";
|
||||
echo use_sql($db, $style) . ";\n\n";
|
||||
}
|
||||
$out = "";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user