Driver specific create and drop database
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1480 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
0acc0c297b
commit
edb6401722
|
@ -3,7 +3,7 @@ if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP c
|
|||
restart_session();
|
||||
if ($_POST["drop"]) {
|
||||
set_session("databases", null);
|
||||
query_redirect("DROP DATABASE " . idf_escape(DB), remove_from_uri("db|database"), lang('Database has been dropped.'));
|
||||
queries_redirect(remove_from_uri("db|database"), lang('Database has been dropped.'), drop_databases(array(DB)));
|
||||
} elseif (DB !== $_POST["name"]) {
|
||||
// create or rename database
|
||||
set_session("databases", null); // clear cache
|
||||
|
@ -15,7 +15,7 @@ if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP c
|
|||
$last = "";
|
||||
foreach ($dbs as $db) {
|
||||
if (count($dbs) == 1 || $db != "") { // ignore empty lines but always try to create single database
|
||||
if (!queries("CREATE DATABASE " . idf_escape($db) . ($_POST["collation"] ? " COLLATE " . $connection->quote($_POST["collation"]) : ""))) {
|
||||
if (!create_database($db, $_POST["collation"])) {
|
||||
$success = false;
|
||||
}
|
||||
$last = $db;
|
||||
|
@ -55,11 +55,15 @@ if ($_POST) {
|
|||
|
||||
<form action="" method="post">
|
||||
<p>
|
||||
<?php echo ($_POST["add_x"] || strpos($name, "\n")
|
||||
<?php
|
||||
echo ($_POST["add_x"] || strpos($name, "\n")
|
||||
? '<textarea name="name" rows="10" cols="40">' . h($name) . '</textarea><br>'
|
||||
: '<input name="name" value="' . h($name) . '" maxlength="64">'
|
||||
) . "\n"; ?>
|
||||
<?php echo html_select("collation", array("" => "(" . lang('collation') . ")") + $collations, $collate); ?>
|
||||
) . "\n";
|
||||
if ($collations) {
|
||||
html_select("collation", array("" => "(" . lang('collation') . ")") + $collations, $collate);
|
||||
}
|
||||
?>
|
||||
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||
<?php
|
||||
|
|
|
@ -359,6 +359,14 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
|
|||
return $connection->quote($val);
|
||||
}
|
||||
|
||||
function create_database($db, $collation) {
|
||||
return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " COLLATE " . idf_escape($collation) : ""));
|
||||
}
|
||||
|
||||
function drop_databases($databases) {
|
||||
return queries("DROP DATABASE " . implode(", ", array_map('idf_escape', $databases)));
|
||||
}
|
||||
|
||||
function rename_database($name, $collation) {
|
||||
if ($collation) {
|
||||
queries("ALTER DATABASE " . idf_escape(DB) . " COLLATE " . idf_escape($collation));
|
||||
|
|
|
@ -500,6 +500,27 @@ if (!defined("DRIVER")) {
|
|||
return "BINARY " . $connection->quote($val);
|
||||
}
|
||||
|
||||
/** Create database
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function create_database($db, $collation) {
|
||||
return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " COLLATE " . $connection->quote($collation) : ""));
|
||||
}
|
||||
|
||||
/** Drop databases
|
||||
* @param array
|
||||
* @return bool
|
||||
*/
|
||||
function drop_databases($databases) {
|
||||
foreach ($databases as $db) {
|
||||
if (!queries("DROP DATABASE " . idf_escape($db))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Rename database from DB
|
||||
* @param string new name
|
||||
* @return string
|
||||
|
@ -508,7 +529,7 @@ if (!defined("DRIVER")) {
|
|||
function rename_database($name, $collation) {
|
||||
global $connection;
|
||||
$return = false;
|
||||
if (queries("CREATE DATABASE " . idf_escape($name) . ($collation ? " COLLATE " . $connection->quote($collation) : ""))) {
|
||||
if (create_database($name, $collation)) {
|
||||
//! move triggers
|
||||
$return = true; // table list may by empty
|
||||
foreach (tables_list() as $table) {
|
||||
|
@ -648,6 +669,9 @@ if (!defined("DRIVER")) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/** Get trigger options
|
||||
* @return array ("Timing" => array(), "Type" => array())
|
||||
*/
|
||||
function trigger_options() {
|
||||
return array(
|
||||
"Timing" => array("BEFORE", "AFTER"),
|
||||
|
|
|
@ -52,6 +52,10 @@ if (isset($_GET["pgsql"])) {
|
|||
return $link;
|
||||
}
|
||||
|
||||
function close() {
|
||||
$this->_link = @pg_connect($this->_string);
|
||||
}
|
||||
|
||||
function query($query, $unbuffered = false) {
|
||||
$result = @pg_query($this->_link, $query);
|
||||
if (!$result) {
|
||||
|
@ -134,6 +138,9 @@ if (isset($_GET["pgsql"])) {
|
|||
function select_db($database) {
|
||||
return (DB == $database);
|
||||
}
|
||||
|
||||
function close() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -301,6 +308,21 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
|
|||
return $connection->quote($val);
|
||||
}
|
||||
|
||||
function create_database($db, $collation) {
|
||||
return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " ENCODING " . idf_escape($collation) : ""));
|
||||
}
|
||||
|
||||
function drop_databases($databases) {
|
||||
global $connection;
|
||||
$connection->close();
|
||||
foreach ($databases as $db) {
|
||||
if (!queries("DROP DATABASE " . idf_escape($db))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function rename_database($name, $collation) {
|
||||
//! current database cannot be renamed
|
||||
return queries("ALTER DATABASE " . idf_escape(DB) . " RENAME TO " . idf_escape($name));
|
||||
|
|
|
@ -7,12 +7,7 @@ function connect_error() {
|
|||
} else {
|
||||
if ($_POST["db"] && !$error) {
|
||||
set_session("databases", null);
|
||||
foreach ($_POST["db"] as $db) {
|
||||
if (!queries("DROP DATABASE " . idf_escape($db))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
queries_redirect(substr(ME, 0, -1), lang('Database has been dropped.'), !$connection->error);
|
||||
queries_redirect(substr(ME, 0, -1), lang('Database has been dropped.'), drop_databases($_POST["db"]));
|
||||
}
|
||||
|
||||
page_header(lang('Select database'), $error, false);
|
||||
|
|
Loading…
Reference in a new issue