Permalink
Browse files

User types support for PostgreSQL

  • Loading branch information...
1 parent e678e46 commit 3308856f9efec91c9fd52a458e1539d18d56faff @vrana committed May 21, 2010
Showing with 76 additions and 10 deletions.
  1. +15 −0 adminer/db.inc.php
  2. +8 −1 adminer/drivers/mysql.inc.php
  3. +13 −8 adminer/drivers/pgsql.inc.php
  4. +2 −0 adminer/index.php
  5. +4 −0 adminer/lang/cs.inc.php
  6. +33 −0 adminer/type.inc.php
  7. +1 −1 changes.txt
View
15 adminer/db.inc.php
@@ -126,6 +126,21 @@
echo "<p><a href='" . h(ME) . "sequence='>" . lang('Create sequence') . "</a>\n";
}
+ if (support("type")) {
+ echo "<h3>" . lang('User types') . "</h3>\n";
+ $types = types();
+ if ($types) {
+ echo "<table cellspacing='0'>\n";
+ echo "<thead><tr><th>" . lang('Name') . "</thead>\n";
+ odd('');
+ foreach ($types as $val) {
+ echo "<tr" . odd() . "><th><a href='" . h(ME) . "type=" . urlencode($val) . "'>" . h($val) . "</a>\n";
+ }
+ echo "</table>\n";
+ }
+ echo "<p><a href='" . h(ME) . "type='>" . lang('Create type') . "</a>\n";
+ }
+
if (support("event")) {
echo "<h3>" . lang('Events') . "</h3>\n";
$result = $connection->query("SHOW EVENTS");
View
9 adminer/drivers/mysql.inc.php
@@ -777,6 +777,13 @@ function explain($connection, $query) {
return $connection->query("EXPLAIN $query");
}
+ /** Get user defined types
+ * @return array
+ */
+ function types() {
+ return array();
+ }
+
/** Get existing schemas
* @return array
*/
@@ -854,7 +861,7 @@ function show_status() {
*/
function support($feature) {
global $connection;
- return !ereg("scheme|sequence" . ($connection->server_info < 5.1 ? "|event|partitioning" . ($connection->server_info < 5 ? "|view|routine|trigger" : "") : ""), $feature);
+ return !ereg("scheme|sequence|type" . ($connection->server_info < 5.1 ? "|event|partitioning" . ($connection->server_info < 5 ? "|view|routine|trigger" : "") : ""), $feature);
}
$jush = "sql"; ///< @var string JUSH identifier
View
21 adminer/drivers/pgsql.inc.php
@@ -469,6 +469,15 @@ function explain($connection, $query) {
return $connection->query("EXPLAIN $query");
}
+ function types() {
+ return get_vals("SELECT typname
+FROM pg_type
+WHERE typnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())
+AND typtype IN ('b','d','e')
+AND typelem = 0"
+ );
+ }
+
function schemas() {
return get_vals("SELECT nspname FROM pg_namespace");
}
@@ -480,18 +489,14 @@ function get_schema() {
function set_schema($schema) {
global $connection, $types, $structured_types;
- foreach (get_vals("SELECT typname
-FROM pg_type
-WHERE typnamespace = (SELECT oid FROM pg_namespace WHERE nspname = " . $connection->quote($schema) . ")
-AND typtype IN ('b','d','e')
-AND typelem = 0"
- ) as $type) { //! get types from current_schemas('t')
+ $return = $connection->query("SET search_path TO " . idf_escape($schema));
+ foreach (types() as $type) { //! get types from current_schemas('t')
if (!isset($types[$type])) {
$types[$type] = 0;
$structured_types[lang('User types')][] = $type;
}
}
- return $connection->query("SET search_path TO " . idf_escape($schema));
+ return $return;
}
function use_sql($database) {
@@ -503,7 +508,7 @@ function show_variables() {
}
function support($feature) {
- return ereg('^(comment|view|scheme|sequence|trigger|variables|drop_col)$', $feature); //! routine|
+ return ereg('^(comment|view|scheme|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
}
$jush = "pgsql";
View
2 adminer/index.php
@@ -54,6 +54,8 @@
include "./procedure.inc.php";
} elseif (isset($_GET["sequence"])) {
include "./sequence.inc.php";
+} elseif (isset($_GET["type"])) {
+ include "./type.inc.php";
} elseif (isset($_GET["trigger"])) {
include "./trigger.inc.php";
} elseif (isset($_GET["user"])) {
View
4 adminer/lang/cs.inc.php
@@ -251,5 +251,9 @@
'Sequence has been altered.' => 'Sekvence byla změněna.',
'Alter sequence' => 'Pozměnit sekvenci',
'User types' => 'Uživatelské typy',
+ 'Create type' => 'Vytvořit typ',
+ 'Type has been dropped.' => 'Typ byl odstraněn.',
+ 'Type has been created.' => 'Typ byl vytvořen.',
+ 'Alter type' => 'Pozměnit typ',
'Search data in tables' => 'Vyhledat data v tabulkách',
);
View
33 adminer/type.inc.php
@@ -0,0 +1,33 @@
+<?php
+$TYPE = $_GET["type"];
+
+if ($_POST && !$error) {
+ $link = substr(ME, 0, -1);
+ if ($_POST["drop"]) {
+ query_redirect("DROP TYPE " . idf_escape($TYPE), $link, lang('Type has been dropped.'));
+ } else {
+ query_redirect("CREATE TYPE " . idf_escape($_POST["name"]) . " $_POST[as]", $link, lang('Type has been created.'));
+ }
+}
+
+page_header($TYPE != "" ? lang('Alter type') . ": " . h($TYPE) : lang('Create type'), $error);
+
+$row["as"] = "AS ";
+if ($_POST) {
+ $row = $_POST;
+}
+?>
+
+<form action="" method="post">
+<p>
+<input type="hidden" name="token" value="<?php echo $token; ?>">
+<?php
+if ($TYPE != "") {
+ echo "<input type='submit' name='drop' value='" . lang('Drop') . "'$confirm>\n";
+} else {
+ echo "<input name='name' value='" . h($row['name']) . "'>\n";
+ textarea("as", $row["as"]);
+ echo "<p><input type='submit' value='" . lang('Save') . "'>\n";
+}
+?>
+</form>
View
2 changes.txt
@@ -8,7 +8,7 @@ Show number of tables in server overview
Operator LIKE %%
Remember export parameters in cookie
Allow semicolon as CSV separator
-Schema and sequences support (PostgreSQL)
+Schemas, sequences and types support (PostgreSQL)
Autofocus username in login form
Disable spellchecking in SQL textareas
Display auto_increment value of inserted item

0 comments on commit 3308856

Please sign in to comment.