Schema support for PostgreSQL
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1521 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
4809139347
commit
6420c5848c
|
@ -65,7 +65,7 @@ if ($collations) {
|
|||
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||
<?php
|
||||
if (strlen(DB)) {
|
||||
if (DB != "") {
|
||||
echo "<input type='submit' name='drop' value='" . lang('Drop') . "'$confirm>\n";
|
||||
} elseif (!$_POST["add_x"] && $_GET["db"] == "") {
|
||||
echo "<input type='image' name='add' src='../adminer/static/plus.gif' alt='+' title='" . lang('Add next') . "'>\n";
|
||||
|
|
|
@ -36,8 +36,10 @@ if ($tables_views && !$error && !$_POST["search"]) {
|
|||
queries_redirect(substr(ME, 0, -1), $message, $result);
|
||||
}
|
||||
|
||||
page_header(lang('Database') . ": " . h(DB), $error, true);
|
||||
echo '<p><a href="' . h(ME) . 'database=">' . lang('Alter database') . "</a>\n";
|
||||
page_header(($_GET["ns"] == "" ? lang('Database') . ": " . h(DB) : lang('Schema') . ": " . h($_GET["ns"])), $error, true);
|
||||
echo '<p>' . ($_GET["ns"] == "" ? '<a href="' . h(ME) . 'database=">' . lang('Alter database') . "</a>\n" : "");
|
||||
echo (support("scheme") ? "<a href='" . h(ME) . "scheme='>" . ($_GET["ns"] != "" ? lang('Alter schema') : lang('Create schema')) . "</a>\n" : "");
|
||||
if ($_GET["ns"] !== "") {
|
||||
echo '<a href="' . h(ME) . 'schema=">' . lang('Database schema') . "</a>\n";
|
||||
$sums = array("Data_length" => 0, "Index_length" => 0, "Data_free" => 0);
|
||||
|
||||
|
@ -158,3 +160,4 @@ if ($table_status) {
|
|||
echo "</script>\n";
|
||||
}
|
||||
exit; // page_footer() already called
|
||||
}
|
||||
|
|
|
@ -490,7 +490,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . $connection->quote($table)
|
|||
}
|
||||
|
||||
function support($feature) {
|
||||
return ereg('^(trigger|drop_col)$', $feature); //! view|routine|
|
||||
return ereg('^(trigger|drop_col)$', $feature); //! view|routine|scheme|
|
||||
}
|
||||
|
||||
$driver = "mssql";
|
||||
|
|
|
@ -755,6 +755,28 @@ if (!defined("DRIVER")) {
|
|||
return $connection->query("EXPLAIN $query");
|
||||
}
|
||||
|
||||
/** Get existing schemas
|
||||
* @return array
|
||||
*/
|
||||
function schemas() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/** Get current schema
|
||||
* @return string
|
||||
*/
|
||||
function get_schema() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/** Set current schema
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function set_schema($schema) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Get SQL command to create table
|
||||
* @param string
|
||||
* @return string
|
||||
|
@ -810,7 +832,7 @@ if (!defined("DRIVER")) {
|
|||
*/
|
||||
function support($feature) {
|
||||
global $connection;
|
||||
return ($connection->server_info >= 5.1 || ($connection->server_info >= 5 && !ereg("event|partitioning")) || !ereg("view|routine|trigger"));
|
||||
return !ereg("scheme" . ($connection->server_info < 5.1 ? "|event|partitioning" . ($connection->server_info < 5 ? "|view|routine|trigger" : "") : ""), $feature);
|
||||
}
|
||||
|
||||
$driver = "sql"; ///< @var string JUSH identifier
|
||||
|
|
|
@ -452,12 +452,26 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
|
|||
return $connection->query("EXPLAIN $query");
|
||||
}
|
||||
|
||||
function schemas() {
|
||||
return get_vals("SELECT nspname FROM pg_namespace");
|
||||
}
|
||||
|
||||
function get_schema() {
|
||||
global $connection;
|
||||
return $connection->result("SELECT current_schema()");
|
||||
}
|
||||
|
||||
function set_schema($schema) {
|
||||
global $connection;
|
||||
return $connection->query("SET search_path TO " . idf_escape($schema));
|
||||
}
|
||||
|
||||
function use_sql($database) {
|
||||
return "\connect " . idf_escape($database);
|
||||
}
|
||||
|
||||
function support($feature) {
|
||||
return ereg('^(comment|view|trigger|drop_col)$', $feature); //! routine|
|
||||
return ereg('^(comment|view|scheme|trigger|drop_col)$', $feature); //! routine|sequence|
|
||||
}
|
||||
|
||||
$driver = "pgsql";
|
||||
|
|
|
@ -496,6 +496,18 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
|||
return $connection->query("EXPLAIN $query");
|
||||
}
|
||||
|
||||
function schemas() {
|
||||
return array();
|
||||
}
|
||||
|
||||
function get_schema() {
|
||||
return "";
|
||||
}
|
||||
|
||||
function set_schema($scheme) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function create_sql($table) {
|
||||
global $connection;
|
||||
return $connection->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . $connection->quote($table));
|
||||
|
|
|
@ -506,14 +506,16 @@ document.getElementById('username').focus();
|
|||
<p>
|
||||
<?php hidden_fields_get(); ?>
|
||||
<?php echo ($databases ? html_select("db", array("" => "(" . lang('database') . ")") + $databases, DB, "this.form.submit();") : '<input name="db" value="' . h(DB) . '">'); ?>
|
||||
<?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value=""><?php } ?>
|
||||
<?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value=""><?php } ?>
|
||||
<?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value=""><?php } ?>
|
||||
<input type="submit" value="<?php echo lang('Use'); ?>"<?php echo ($databases ? " class='hidden'" : ""); ?>>
|
||||
</p>
|
||||
</form>
|
||||
<?php
|
||||
if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
|
||||
if (support("scheme")) {
|
||||
echo "<br>" . html_select("ns", array("" => "(" . lang('schema') . ")") + schemas(), $_GET["ns"], "this.form.submit();");
|
||||
if ($_GET["ns"] != "") {
|
||||
set_schema($_GET["ns"]);
|
||||
}
|
||||
}
|
||||
if ($_GET["ns"] !== "") {
|
||||
$tables = tables_list();
|
||||
if (!$tables) {
|
||||
echo "<p class='message'>" . lang('No tables.') . "\n";
|
||||
|
@ -533,6 +535,12 @@ document.getElementById('username').focus();
|
|||
echo '<p><a href="' . h(ME) . 'create=">' . bold(lang('Create new table'), $_GET["create"] === "") . "</a>\n";
|
||||
}
|
||||
}
|
||||
echo (isset($_GET["sql"]) ? '<input type="hidden" name="sql" value="">'
|
||||
: (isset($_GET["schema"]) ? '<input type="hidden" name="schema" value="">'
|
||||
: (isset($_GET["dump"]) ? '<input type="hidden" name="dump" value="">'
|
||||
: "")));
|
||||
echo "</form>\n";
|
||||
}
|
||||
}
|
||||
|
||||
/** Prints table list in menu
|
||||
|
|
|
@ -46,7 +46,7 @@ if (isset($_POST["server"])) {
|
|||
set_session($key, null);
|
||||
}
|
||||
cookie("adminer_permanent", "");
|
||||
redirect(substr(preg_replace('~(username|db)=[^&]*&~', '', ME), 0, -1), lang('Logout successful.'));
|
||||
redirect(substr(preg_replace('~(username|db|ns)=[^&]*&~', '', ME), 0, -1), lang('Logout successful.'));
|
||||
}
|
||||
} elseif ($_COOKIE["adminer_permanent"]) {
|
||||
list($server, $username, $cipher, $system) = array_map('base64_decode', explode(":", $_COOKIE["adminer_permanent"])); // $driver is a global variable
|
||||
|
|
|
@ -71,7 +71,7 @@ define("ME", preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"])
|
|||
. (SID && !$_COOKIE ? SID . '&' : '') // !$_COOKIE - don't pass SID with permanent login
|
||||
. (SERVER !== null ? DRIVER . "=" . urlencode(SERVER) . '&' : '')
|
||||
. (isset($_GET["username"]) ? "username=" . urlencode($_GET["username"]) . '&' : '')
|
||||
. (DB != "" ? 'db=' . urlencode(DB) . '&' : '')
|
||||
. (DB != "" ? 'db=' . urlencode(DB) . '&' . (isset($_GET["ns"]) ? "ns=" . urlencode($_GET["ns"]) . "&" : "") : '')
|
||||
);
|
||||
|
||||
include "../adminer/include/version.inc.php";
|
||||
|
|
|
@ -61,3 +61,7 @@ if (!(DB != "" ? $connection->select_db(DB) : isset($_GET["sql"]) || isset($_GET
|
|||
connect_error(); // separate function to catch SQLite error
|
||||
exit;
|
||||
}
|
||||
|
||||
if (support("scheme") && DB != "" && $_GET["ns"] !== "" && (!isset($_GET["ns"]) || !set_schema($_GET["ns"]))) {
|
||||
redirect(preg_replace('~ns=[^&]*&~', '', ME) . "ns=" . get_schema());
|
||||
}
|
||||
|
|
|
@ -31,17 +31,20 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
|||
<div id="content">
|
||||
<?php
|
||||
if (isset($breadcrumb)) {
|
||||
$link = substr(preg_replace('~(username|db)=[^&]*&~', '', ME), 0, -1);
|
||||
$link = substr(preg_replace('~(username|db|ns)=[^&]*&~', '', ME), 0, -1);
|
||||
echo '<p id="breadcrumb"><a href="' . ($link ? h($link) : ".") . '">' . $drivers[DRIVER] . '</a> » ';
|
||||
$link = substr(preg_replace('~db=[^&]*&~', '', ME), 0, -1);
|
||||
$link = substr(preg_replace('~(db|ns)=[^&]*&~', '', ME), 0, -1);
|
||||
$server = (SERVER != "" ? h(SERVER) : lang('Server'));
|
||||
if ($breadcrumb === false) {
|
||||
echo "$server\n";
|
||||
} else {
|
||||
echo "<a href='" . ($link ? h($link) : ".") . "'>$server</a> » ";
|
||||
if ($_GET["ns"] != "" || (DB != "" && is_array($breadcrumb))) {
|
||||
echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> » ';
|
||||
}
|
||||
if (is_array($breadcrumb)) {
|
||||
if (DB != "") {
|
||||
echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h(DB) . '</a> » ';
|
||||
if ($_GET["ns"] != "") {
|
||||
echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> » ';
|
||||
}
|
||||
foreach ($breadcrumb as $key => $val) {
|
||||
$desc = (is_array($val) ? $val[1] : $val);
|
||||
|
|
|
@ -40,6 +40,8 @@ if (isset($_GET["download"])) {
|
|||
include "./indexes.inc.php";
|
||||
} elseif (isset($_GET["database"])) {
|
||||
include "./database.inc.php";
|
||||
} elseif (isset($_GET["scheme"])) {
|
||||
include "./scheme.inc.php";
|
||||
} elseif (isset($_GET["call"])) {
|
||||
include "./call.inc.php";
|
||||
} elseif (isset($_GET["foreign"])) {
|
||||
|
|
|
@ -237,4 +237,11 @@ $translations = array(
|
|||
'Double click on a value to modify it.' => 'Dvojklikněte na políčko, které chcete změnit.',
|
||||
'Increase text length to modify this value.' => 'Ke změně této hodnoty zvyšte délku textů.',
|
||||
'Use edit link to modify this value.' => 'Ke změně této hodnoty použijte odkaz upravit.',
|
||||
'Alter schema' => 'Pozměnit schéma',
|
||||
'Create schema' => 'Vytvořit schéma',
|
||||
'Schema has been dropped.' => 'Schéma bylo odstraněno.',
|
||||
'Schema has been created.' => 'Schéma bylo vytvořeno.',
|
||||
'Schema has been altered.' => 'Schéma bylo změněno.',
|
||||
'schema' => 'schéma',
|
||||
'Schema' => 'Schéma',
|
||||
);
|
||||
|
|
35
adminer/scheme.inc.php
Normal file
35
adminer/scheme.inc.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
if ($_POST && !$error) {
|
||||
$link = preg_replace('~ns=[^&]*&~', '', ME) . "ns=";
|
||||
if ($_POST["drop"]) {
|
||||
query_redirect("DROP SCHEMA " . idf_escape($_GET["ns"]), $link, lang('Schema has been dropped.'));
|
||||
} else {
|
||||
$link .= urlencode($_POST["name"]);
|
||||
if ($_GET["ns"] == "") {
|
||||
query_redirect("CREATE SCHEMA " . idf_escape($_POST["name"]), $link, lang('Schema has been created.'));
|
||||
} elseif ($_GET["ns"] != $_POST["name"]) {
|
||||
query_redirect("ALTER SCHEMA " . idf_escape($_GET["ns"]) . " RENAME TO " . idf_escape($_POST["name"]), $link, lang('Schema has been altered.'));
|
||||
} else {
|
||||
redirect($link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
page_header($_GET["ns"] != "" ? lang('Alter schema') : lang('Create schema'), $error);
|
||||
|
||||
$row = array("name" => $_GET["ns"]);
|
||||
if ($_POST) {
|
||||
$row = $_POST;
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="" method="post">
|
||||
<p><input name="name" value="<?php echo h($row["name"]); ?>">
|
||||
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||
<?php
|
||||
if ($_GET["ns"] != "") {
|
||||
echo "<input type='submit' name='drop' value='" . lang('Drop') . "'$confirm>\n";
|
||||
}
|
||||
?>
|
||||
</form>
|
|
@ -190,13 +190,15 @@ foreach (glob(dirname(__FILE__) . "/adminer/drivers/" . ($DRIVER ? $DRIVER : "*"
|
|||
}
|
||||
}
|
||||
|
||||
$drivers = array();
|
||||
foreach (array("adminer", "editor") as $project) {
|
||||
$lang_ids = array(); // global variable simplifies usage in a callback function
|
||||
$file = file_get_contents(dirname(__FILE__) . "/$project/index.php");
|
||||
if ($DRIVER && $DRIVER != "mysql") {
|
||||
if ($DRIVER) {
|
||||
$connection = (object) array("server_info" => 5.1); // MySQL support is version specific
|
||||
$_GET[$DRIVER] = true; // to load the driver
|
||||
include_once dirname(__FILE__) . "/adminer/drivers/$DRIVER.inc.php";
|
||||
foreach (array("view", "event", "privileges", "user", "processlist", "variables", "trigger") as $feature) {
|
||||
foreach (array("view", "event", "privileges", "user", "processlist", "variables", "trigger", "scheme") as $feature) {
|
||||
if (!support($feature)) {
|
||||
$file = str_replace("} elseif (isset(\$_GET[\"$feature\"])) {\n\tinclude \"./$feature.inc.php\";\n", "", $file);
|
||||
}
|
||||
|
|
1
todo.txt
1
todo.txt
|
@ -35,7 +35,6 @@ Backward keys in Editor
|
|||
PostgreSQL:
|
||||
Users - SELECT * FROM pg_user
|
||||
ORDER BY COUNT(*)
|
||||
Table schema - SELECT * FROM pg_namespace, CREATE|ALTER|DROP SCHEMA, SET default_tablespace
|
||||
Export - http://www.postgresql.org/docs/8.4/static/functions-info.html
|
||||
Column rights - http://www.postgresql.org/docs/8.4/static/functions-info.html
|
||||
Dollar terminated string in SQL command
|
||||
|
|
Loading…
Reference in a new issue