]> git.joonet.de Git - adminer.git/commitdiff
User types support for PostgreSQL
authorJakub Vrana <jakub@vrana.cz>
Fri, 21 May 2010 14:07:22 +0000 (16:07 +0200)
committerJakub Vrana <jakub@vrana.cz>
Fri, 21 May 2010 14:07:22 +0000 (16:07 +0200)
adminer/db.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/index.php
adminer/lang/cs.inc.php
adminer/type.inc.php [new file with mode: 0644]
changes.txt

index d0251637503aabf070996a3f9ea84533f1205adb..e7251933805124c65af18a146022ececdd04abd8 100644 (file)
@@ -126,6 +126,21 @@ if ($_GET["ns"] !== "") {
                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");
index cde307f356008bfd2ff51436c0270df50c83817b..c46c54ef16c78d7ba4dd00954e6ccbc0ae8657ae 100644 (file)
@@ -777,6 +777,13 @@ if (!defined("DRIVER")) {
                return $connection->query("EXPLAIN $query");
        }
        
+       /** Get user defined types
+       * @return array
+       */
+       function types() {
+               return array();
+       }
+       
        /** Get existing schemas
        * @return array
        */
@@ -854,7 +861,7 @@ if (!defined("DRIVER")) {
        */
        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
index 51cd4e0aed761d3689c174f0a1fd6cc8ddf074c2..a3ff81571a8875fb993d45ea3383b2b7d10c9a83 100644 (file)
@@ -469,6 +469,15 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
                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 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
        
        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 @@ AND typelem = 0"
        }
        
        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";
index 16f3086a886a5f563069c84472d703e813ec7903..bff57f0103006dc2dd6be1de2370681502c401de 100644 (file)
@@ -54,6 +54,8 @@ if (isset($_GET["download"])) {
        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"])) {
index 70131b78897e264e8325beca6863d6fc397d87cd..09d46211ec612a36c107c9887ed982ee43c64f1d 100644 (file)
@@ -251,5 +251,9 @@ $translations = array(
        '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',
 );
diff --git a/adminer/type.inc.php b/adminer/type.inc.php
new file mode 100644 (file)
index 0000000..f8b2ba1
--- /dev/null
@@ -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>
index 7c619dab76fb2265301346987e816f637c52e022..97d4c43df2c93d5fbbdbc0dab694440f0a2668f5 100644 (file)
@@ -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