support for schemas in tablespaces
authorchriskl <chriskl>
Tue, 6 Jul 2004 09:05:41 +0000 (09:05 +0000)
committerchriskl <chriskl>
Tue, 6 Jul 2004 09:05:41 +0000 (09:05 +0000)
HISTORY
classes/database/Postgres73.php
classes/database/Postgres75.php
database.php
lang/english.php
lang/recoded/english.php

diff --git a/HISTORY b/HISTORY
index b961099fd92b37e429666c5d85c1ff3dc84f9cab..09b7c218677949a76e61b6f06c2c7fda7d3ff86e 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -7,6 +7,7 @@ Version 3.5-dev
 Features
 * Context-sensitive online help system
 * Use language preferencies from browser (Markus Bertheau, Nicola Soranzo)
+* Tablespace support for 7.5
 
 Translations
 * Arabic from Zaki
index 2694a4af7d4aeae5444471c9fff370312e3897cb..46881114a4e8880100174447a0756e5da658d9e1 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres73.php,v 1.122 2004/06/28 02:26:57 chriskl Exp $
+ * $Id: Postgres73.php,v 1.123 2004/07/06 09:05:42 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -128,17 +128,19 @@ class Postgres73 extends Postgres72 {
         * Creates a new schema.
         * @param $schemaname The name of the schema to create
         * @param $authorization (optional) The username to create the schema for.
-        * @param $authorization (optional) If omitted, defaults to current user.
+        * @param $tablespace (optional) The tablespace for the schema, '' indicates default.
+        * @param $comment (optional) If omitted, defaults to nothing
         * @return 0 success
         */
-       function createSchema($schemaname, $authorization = '', $comment = '') {
+       function createSchema($schemaname, $authorization = '', $tablespace = '', $comment = '') {
                $this->fieldClean($schemaname);
                $this->fieldClean($authorization);
+               $this->fieldClean($tablespace);
                $this->clean($comment);
 
                $sql = "CREATE SCHEMA \"{$schemaname}\"";
                if ($authorization != '') $sql .= " AUTHORIZATION \"{$authorization}\"";
-               
+               if ($tablespace != '' && $this->hasTablespaces()) $sql .= " TABLESPACE \"{$tablespace}\"";
                
                $status = $this->beginTransaction();
                if ($status != 0) return -1;
@@ -827,6 +829,7 @@ class Postgres73 extends Postgres72 {
                $sql .= "{$returns} AS '\n";
                $sql .= $definition;
                $sql .= "\n'";
+               
                $sql .= " LANGUAGE \"{$language}\"";
                
                // Add flags
index 654d0208145a5befca3046f907bd59aa3d60e1a3..f80bbf0670596385c9d89a08daeb88181c635363 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * PostgreSQL 7.5 support
  *
- * $Id: Postgres75.php,v 1.7 2004/07/04 15:02:35 chriskl Exp $
+ * $Id: Postgres75.php,v 1.8 2004/07/06 09:05:42 chriskl Exp $
  */
 
 include_once('./classes/database/Postgres74.php');
@@ -23,6 +23,26 @@ class Postgres75 extends Postgres74 {
        function Postgres75($conn) {
                $this->Postgres74($conn);
        }
+
+       // Schema functions
+
+       /**
+        * Return all schemas in the current database
+        * @return All schemas, sorted alphabetically
+        */
+       function &getSchemas() {
+               global $conf;
+
+               if (!$conf['show_system']) $and = "AND nspname NOT LIKE 'pg\\\\_%'";
+               else $and = '';
+               $sql = "SELECT pn.nspname, pu.usename AS nspowner, pg_catalog.obj_description(pn.oid, 'pg_namespace') AS comment,
+                                                               (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pn.nsptablespace) AS tablespace
+                        FROM pg_catalog.pg_namespace pn, pg_catalog.pg_user pu
+                       WHERE pn.nspowner = pu.usesysid
+                       {$and} ORDER BY nspname";
+
+               return $this->selectSet($sql);
+       }
        
        /**
         * Alters a column in a table
index d7efef750e0e6c177c350965d7c8390ecfd9b1a8..4561c088f6a7086e88c02d4ad89233d99a923eba 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Manage schemas within a database
         *
-        * $Id: database.php,v 1.48 2004/06/11 05:08:19 xzilla Exp $
+        * $Id: database.php,v 1.49 2004/07/06 09:05:41 chriskl Exp $
         */
 
        // Include application functions
 
                if (!isset($_POST['formName'])) $_POST['formName'] = '';
                if (!isset($_POST['formAuth'])) $_POST['formAuth'] = $_SESSION['webdbUsername'];
+               if (!isset($_POST['formSpc'])) $_POST['formSpc'] = '';
                if (!isset($_POST['formComment'])) $_POST['formComment'] = '';
 
                // Fetch all users from the database
                $users = &$data->getUsers();
+               // Fetch all tablespaces from the database
+               if ($data->hasTablespaces()) $tablespaces = &$data->getTablespaces();
 
                $misc->printTitle(array($misc->printVal($_REQUEST['database']),$lang['strcreateschema']),'create_schema');
                $misc->printMsg($msg);
                echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
                echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
                        htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n";
+               // Owner
                echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strowner']}</th>\n";
                echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formAuth\">\n";
                while (!$users->EOF) {
                }
                echo "\t\t\t</select>\n\t\t</td>\n\t\n";
                
+               // Tablespace (if there are any)
+               if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
+                       echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n";
+                       echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formSpc\">\n";
+                       // Always offer the default (empty) option
+                       echo "\t\t\t\t<option value=\"\"",
+                               ($_POST['formSpc'] == '') ? ' selected="selected"' : '', "></option>\n";
+                       // Display all other tablespaces
+                       while (!$tablespaces->EOF) {
+                               $spcname = htmlspecialchars($tablespaces->f['spcname']);
+                               echo "\t\t\t\t<option value=\"{$spcname}\"",
+                                       ($spcname == $_POST['formSpc']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
+                               $tablespaces->moveNext();
+                       }
+                       echo "\t\t\t</select>\n\t\t</td>\n\t\n";
+               }
+               
                echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
                echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">", 
                        htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
        function doSaveCreate() {
                global $data, $lang, $_reload_browser;
 
+               // Default tablespace to null if it isn't set
+               if (!isset($_POST['formSpc'])) $_POST['formSpc'] = null;
+
                // Check that they've given a name
                if ($_POST['formName'] == '') doCreate($lang['strschemaneedsname']);
                else {
-                       $status = $data->createSchema($_POST['formName'], $_POST['formAuth'],$_POST['formComment']);
+                       $status = $data->createSchema($_POST['formName'], $_POST['formAuth'], $_POST['formSpc'], $_POST['formComment']);
                        if ($status == 0) {
                                $_reload_browser = true;
                                doDefault($lang['strschemacreated']);
                        if ($schemas->recordCount() > 0) {
                                echo "<table>\n";
                                echo "<tr><th class=\"data\">{$lang['strname']}</th><th class=\"data\">{$lang['strowner']}</th>";
+                               if ($data->hasTablespaces()) {
+                                       echo "<th class=\"data\">{$lang['strtablespace']}</th>";
+                               }
                                echo "<th colspan=\"3\" class=\"data\">{$lang['stractions']}</th>";
                                if ($conf['show_comments']) echo "<th class=\"data\">{$lang['strcomment']}</th>\n";
                                echo "</tr>\n";
                                        $id = (($i % 2) == 0 ? '1' : '2');
                                        echo "<tr><td class=\"data{$id}\">", $misc->printVal($schemas->f[$data->nspFields['nspname']]), "</td>\n";
                                        echo "<td class=\"data{$id}\">", $misc->printVal($schemas->f[$data->nspFields['nspowner']]), "</td>\n";
+                                       if ($data->hasTablespaces()) {
+                                               echo "<td class=\"data{$id}\">", $misc->printVal($schemas->f['tablespace']), "</td>\n";
+                                       }
                                        echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop&amp;database=",
                                                urlencode($_REQUEST['database']), "&amp;schema=",
                                                urlencode($schemas->f[$data->nspFields['nspname']]), "\">{$lang['strdrop']}</a></td>\n";
index d52a2aa1045a397ee463467b5cf5a738571719e9..571f0d93ab63bf276ae2607a3193b3009d4fa538 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.149 2004/07/05 09:21:10 soranzo Exp $
+        * $Id: english.php,v 1.150 2004/07/06 09:05:42 chriskl Exp $
         */
 
        // Language and character set
 
        // Tablespaces
        $lang['strtablespaces'] = 'Tablespaces';
+       $lang['strtablespace'] = 'Tablespace';
        $lang['strnotablespaces'] = 'No tablespaces found.';
        $lang['strcreatetablespace'] = 'Create tablespace';
        $lang['strlocation'] = 'Location';
index 25a28e9fe7e03653277cf701eb4585df89404024..eb47cc41f859f7f0524ff10da2d981470a1f3e6b 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.102 2004/07/05 09:21:11 soranzo Exp $
+        * $Id: english.php,v 1.103 2004/07/06 09:05:42 chriskl Exp $
         */
 
        // Language and character set
 
        // Tablespaces
        $lang['strtablespaces'] = 'Tablespaces';
+       $lang['strtablespace'] = 'Tablespace';
        $lang['strnotablespaces'] = 'No tablespaces found.';
        $lang['strcreatetablespace'] = 'Create tablespace';
        $lang['strlocation'] = 'Location';