support tablespaces on tables, indexes and sequences. that means we have 100% tables...
authorchriskl <chriskl>
Sat, 10 Jul 2004 09:23:24 +0000 (09:23 +0000)
committerchriskl <chriskl>
Sat, 10 Jul 2004 09:23:24 +0000 (09:23 +0000)
classes/database/Postgres.php
classes/database/Postgres75.php
indexes.php
sequences.php
tables.php

index 168a68d0a7da001f4dbdcf581742bba294286525..9d5b65c1505267db0384f23588fefc510d5ba11f 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.231 2004/07/10 08:51:01 chriskl Exp $
+ * $Id: Postgres.php,v 1.232 2004/07/10 09:23:24 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1205,11 +1205,12 @@ class Postgres extends BaseDB {
         * @param $withoutoids True if WITHOUT OIDS, false otherwise
         * @param $colcomment An array of comments
         * @param $comment Table comment
+        * @param $tablespace The tablespace name ('' means none/default)
         * @return 0 success
         * @return -1 no fields supplied
         */
        function createTable($name, $fields, $field, $type, $array, $length, $notnull, 
-                               $default, $withoutoids, $colcomment, $tblcomment) {
+                               $default, $withoutoids, $colcomment, $tblcomment, $tablespace) {
                $this->fieldClean($name);
                $this->clean($tblcomment);
 
@@ -1271,6 +1272,12 @@ class Postgres extends BaseDB {
                // WITHOUT OIDS
                if ($this->hasWithoutOIDs() && $withoutoids)
                        $sql .= ' WITHOUT OIDS';
+                       
+               // Tablespace
+               if ($this->hasTablespaces() && $tablespace != '') {
+                       $this->fieldClean($tablespace);
+                       $sql .= " TABLESPACE \"{$tablespace}\"";
+               }
                
                $status = $this->execute($sql);
                if ($status) {
@@ -1622,9 +1629,11 @@ class Postgres extends BaseDB {
         * @param $startvalue The starting value
         * @param $cachevalue The cache value
         * @param $cycledvalue True if cycled, false otherwise
+        * @param $tablespace The tablespace ('' means none/default)
         * @return 0 success
         */
-       function createSequence($sequence, $increment, $minvalue, $maxvalue, $startvalue, $cachevalue, $cycledvalue) {
+       function createSequence($sequence, $increment, $minvalue, $maxvalue, 
+                                                               $startvalue, $cachevalue, $cycledvalue, $tablespace) {
                $this->fieldClean($sequence);
                $this->clean($increment);
                $this->clean($minvalue);
@@ -1640,6 +1649,12 @@ class Postgres extends BaseDB {
                if ($cachevalue != '') $sql .= " CACHE {$cachevalue}";
                if ($cycledvalue) $sql .= " CYCLE";
                
+               // Tablespace
+               if ($this->hasTablespaces() && $tablespace != '') {
+                       $this->fieldClean($tablespace);
+                       $sql .= " TABLESPACE \"{$tablespace}\"";
+               }
+
                return $this->execute($sql);
        }
 
@@ -2074,9 +2089,10 @@ class Postgres extends BaseDB {
         * @param $type The index type
         * @param $unique True if unique, false otherwise
         * @param $where Index predicate ('' for none)
+        * @param $tablespace The tablespaces ('' means none/default)
         * @return 0 success
         */
-       function createIndex($name, $table, $columns, $type, $unique, $where) {
+       function createIndex($name, $table, $columns, $type, $unique, $where, $tablespace) {
                $this->fieldClean($name);
                $this->fieldClean($table);
                $this->arrayClean($columns);
@@ -2086,6 +2102,13 @@ class Postgres extends BaseDB {
                $sql .= " INDEX \"{$name}\" ON \"{$table}\" USING {$type} ";
                $sql .= "(\"" . implode('","', $columns) . "\")";
 
+               // Tablespace
+               if ($this->hasTablespaces() && $tablespace != '') {
+                       $this->fieldClean($tablespace);
+                       $sql .= " TABLESPACE \"{$tablespace}\"";
+               }
+
+               // Predicate
                if ($this->hasPartialIndexes() && trim($where) != '') {
                        $sql .= " WHERE ({$where})";
                }
index f92f85a38e78e03deb572a59e2ae97600c1e81fb..aa8d7d4a2631eedaaa838e63fdc1686d01079501 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * PostgreSQL 7.5 support
  *
- * $Id: Postgres75.php,v 1.12 2004/07/10 08:51:01 chriskl Exp $
+ * $Id: Postgres75.php,v 1.13 2004/07/10 09:23:24 chriskl Exp $
  */
 
 include_once('./classes/database/Postgres74.php');
@@ -90,6 +90,34 @@ class Postgres75 extends Postgres74 {
                return $this->selectSet($sql);
        }
        
+       // Table functions
+       
+       /**
+        * Return all tables in current database (and schema)
+        * @param $all True to fetch all tables, false for just in current schema
+        * @return All tables, sorted alphabetically 
+        */
+       function &getTables($all = false) {
+               if ($all) {
+                       // Exclude pg_catalog and information_schema tables
+                       $sql = "SELECT schemaname AS nspname, tablename AS relname, tableowner AS relname
+                                FROM pg_catalog.pg_tables 
+                               WHERE schemaname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')
+                               ORDER BY schemaname, tablename";
+               } else {
+                       $sql = "SELECT c.relname, pg_catalog.pg_get_userbyid(c.relowner) AS relowner, 
+                                               pg_catalog.obj_description(c.oid, 'pg_class') AS relcomment,
+                                               (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=c.reltablespace) AS tablespace
+                                       FROM pg_catalog.pg_class c
+                                       LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+                                       WHERE c.relkind = 'r'
+                                       AND nspname='{$this->_schema}'
+                                       ORDER BY c.relname";
+               }               
+
+               return $this->selectSet($sql);
+       }       
+       
        /**
         * Alters a column in a table
         * @param $table The table in which the column resides
@@ -203,6 +231,22 @@ class Postgres75 extends Postgres74 {
 
                return $this->endTransaction();
        }
+
+       // Sequence functions
+
+       /**
+        * Returns all sequences in the current database
+        * @return A recordset
+        */
+       function &getSequences() {
+               $sql = "SELECT c.relname AS seqname, u.usename AS seqowner, pg_catalog.obj_description(c.oid, 'pg_class') AS seqcomment,
+                       (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=c.reltablespace) AS tablespace
+                       FROM pg_catalog.pg_class c, pg_catalog.pg_user u, pg_catalog.pg_namespace n
+                       WHERE c.relowner=u.usesysid AND c.relnamespace=n.oid
+                       AND c.relkind = 'S' AND n.nspname='{$this->_schema}' ORDER BY seqname";
+                       
+               return $this->selectSet( $sql );
+       }
        
        // Tablespace functions
        
index 00fd2fdc1355c776a3a5b0e721e85919e295e336..e3ba2637ffab7735c85736d95fb8b6ddd7656d1b 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List indexes on a table
         *
-        * $Id: indexes.php,v 1.27 2004/07/07 14:48:19 soranzo Exp $
+        * $Id: indexes.php,v 1.28 2004/07/10 09:23:24 chriskl Exp $
         */
 
        // Include application functions
                if (!isset($_POST['formIndexName'])) $_POST['formIndexName'] = '';
                if (!isset($_POST['formIndexType'])) $_POST['formIndexType'] = null;
                if (!isset($_POST['formCols'])) $_POST['formCols'] = '';
-               if (!isset($_POST['formWhere'])) $_POST['formWhere'] = '';              
+               if (!isset($_POST['formWhere'])) $_POST['formWhere'] = '';
+               if (!isset($_POST['formSpc'])) $_POST['formSpc'] = '';
 
+               $attrs = &$data->getTableAttributes($_REQUEST['table']);
+               // Fetch all tablespaces from the database
+               if ($data->hasTablespaces()) $tablespaces = &$data->getTablespaces();
+               
                echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strindexes']}: {$lang['strcreateindex']} </h2>\n";
                $misc->printMsg($msg);
 
-               $attrs = &$data->getTableAttributes($_REQUEST['table']);
-
                $selColumns = new XHTML_select("TableColumnList",true,10);
                $selColumns->set_style("width: 10em;");
 
                                htmlspecialchars($_POST['formWhere']), "\" />)</td>";
                        echo "</tr>";
                }
+               
+               // 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</tr>\n";
+               }
+
                echo "</table>";
 
                echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_index\" />\n";
                
                // Handle databases that don't have partial indexes
                if (!isset($_POST['formWhere'])) $_POST['formWhere'] = '';
+               // Default tablespace to null if it isn't set
+               if (!isset($_POST['formSpc'])) $_POST['formSpc'] = null;
                
                // Check that they've given a name and at least one column
                if ($_POST['formIndexName'] == '') doCreateIndex($lang['strindexneedsname']);
                elseif (!isset($_POST['IndexColumnList']) || $_POST['IndexColumnList'] == '') doCreateIndex($lang['strindexneedscols']);
                else {
                        $status = $data->createIndex($_POST['formIndexName'], $_POST['table'], $_POST['IndexColumnList'], 
-                               $_POST['formIndexType'], isset($_POST['formUnique']), $_POST['formWhere']);
+                               $_POST['formIndexType'], isset($_POST['formUnique']), $_POST['formWhere'], $_POST['formSpc']);
                        if ($status == 0)
                                doDefault($lang['strindexcreated']);
                        else
index 6b8e1a446f4d353cd5a9d6658b4a6d43e9ef3438..ace87257bf69dcf2a1d9d84f033cc0bd23e99046 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage sequences in a database
         *
-        * $Id: sequences.php,v 1.21 2004/07/07 02:59:58 chriskl Exp $
+        * $Id: sequences.php,v 1.22 2004/07/10 09:23:24 chriskl Exp $
         */
        
        // Include application functions
                                'title' => $lang['strowner'],
                                'field' => 'seqowner',
                        ),
+                       'tablespace' => array(
+                               'title' => $lang['strtablespace'],
+                               'field' => 'tablespace'
+                       ),
                        'actions' => array(
                                'title' => $lang['stractions'],
                        ),
@@ -62,6 +66,8 @@
                        ),
                );
                
+               if (!$data->hasTablespaces()) unset($columns['tablespace']);
+               
                $misc->printTable($sequences, $columns, $actions, $lang['strnosequences']);
                
                echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&amp;{$misc->href}\">{$lang['strcreatesequence']}</a></p>\n";
                if (!isset($_POST['formMaxValue'])) $_POST['formMaxValue'] = '';
                if (!isset($_POST['formStartValue'])) $_POST['formStartValue'] = '';
                if (!isset($_POST['formCacheValue'])) $_POST['formCacheValue'] = '';
+               if (!isset($_POST['formSpc'])) $_POST['formSpc'] = '';
+               
+               // Fetch all tablespaces from the database
+               if ($data->hasTablespaces()) $tablespaces = &$data->getTablespaces();
                
                echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strsequences']} : {$lang['strcreatesequence']} </h2>\n";
                $misc->printMsg($msg);
                echo "<tr><th class=\"data left\">{$lang['striscycled']}</th>\n";
                echo "<td class=\"data1\"><input type=\"checkbox\" name=\"formCycledValue\" value=\"",
                        (isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), "\" /></td></tr>\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</tr>\n";
+               }
+                                                               
                echo "</table>\n";
                echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_sequence\" />\n";
                echo $misc->form;
                global $data;
                global $lang;
                
+               // Default tablespace to null if it isn't set
+               if (!isset($_POST['formSpc'])) $_POST['formSpc'] = null;
+               
                // Check that they've given a name and at least one column
                if ($_POST['formSequenceName'] == '') doCreateSequence($lang['strsequenceneedsname']);
                else {
                        $status = $data->createSequence($_POST['formSequenceName'],
                                $_POST['formIncrement'], $_POST['formMinValue'],
                                $_POST['formMaxValue'], $_POST['formStartValue'],
-                               $_POST['formCacheValue'], isset($_POST['formCycledValue']));
+                               $_POST['formCacheValue'], isset($_POST['formCycledValue']), $_POST['formSpc']);
                        if ($status == 0) {
                                doDefault($lang['strsequencecreated']);
                        } else {
index 870efb7ad15fe14433fe49705de2253e44831fad..05d897d5694fcf2396ed69157dd5c9a6ec6aeaae 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.58 2004/07/07 02:59:59 chriskl Exp $
+        * $Id: tables.php,v 1.59 2004/07/10 09:23:24 chriskl Exp $
         */
 
        // Include application functions
                if (!isset($_REQUEST['name'])) $_REQUEST['name'] = '';
                if (!isset($_REQUEST['fields'])) $_REQUEST['fields'] = '';
                if (!isset($_REQUEST['tblcomment'])) $_REQUEST['tblcomment'] = '';
+               if (!isset($_REQUEST['spcname'])) $_REQUEST['spcname'] = '';
 
                switch ($_REQUEST['stage']) {
                        case 1:
+                               // Fetch all tablespaces from the database
+                               if ($data->hasTablespaces()) $tablespaces = &$data->getTablespaces();
+               
                                $misc->printTitle(array($misc->printVal($_REQUEST['database']), $lang['strtables'], $lang['strcreatetable']), 'create_table');
                                $misc->printMsg($msg);
                                
                                        echo "\t\t<td class=\"data\"><input type=\"checkbox\" name=\"withoutoids\"", 
                                                (isset($_REQUEST['withoutoids']) ? ' checked="checked"' : ''), " />WITHOUT OIDS</td>\n\t</tr>\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=\"spcname\">\n";
+                                       // Always offer the default (empty) option
+                                       echo "\t\t\t\t<option value=\"\"",
+                                               ($_REQUEST['spcname'] == '') ? ' 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 == $_REQUEST['spcname']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
+                                               $tablespaces->moveNext();
+                                       }
+                                       echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
+                               }
 
                                echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
                                echo "\t\t<td><textarea name=\"tblcomment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">", 
                                        echo "<input type=\"hidden\" name=\"withoutoids\" value=\"true\" />\n";
                                }
                                echo "<input type=\"hidden\" name=\"tblcomment\" value=\"", htmlspecialchars($_REQUEST['tblcomment']), "\" />\n";
+                               if (isset($_REQUEST['spcname'])) {
+                                       echo "<input type=\"hidden\" name=\"spcname\" value=\"", htmlspecialchars($_REQUEST['spcname']), "\" />\n";
+                               }
                                echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
                                echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
                                echo "</form>\n";
                                global $data, $lang, $_reload_browser;
 
                                if (!isset($_REQUEST['notnull'])) $_REQUEST['notnull'] = array();
+                               // Default tablespace to null if it isn't set
+                               if (!isset($_REQUEST['spcname'])) $_REQUEST['spcname'] = null;
 
                                // Check inputs
                                $fields = trim($_REQUEST['fields']);
                                
                                $status = $data->createTable($_REQUEST['name'], $_REQUEST['fields'], $_REQUEST['field'],
                                                                $_REQUEST['type'], $_REQUEST['array'], $_REQUEST['length'], $_REQUEST['notnull'], $_REQUEST['default'],
-                                                               isset($_REQUEST['withoutoids']), $_REQUEST['colcomment'], $_REQUEST['tblcomment']);
+                                                               isset($_REQUEST['withoutoids']), $_REQUEST['colcomment'], $_REQUEST['tblcomment'], $_REQUEST['spcname']);
 
                                if ($status == 0) {
                                        $_reload_browser = true;
                                'title' => $lang['strowner'],
                                'field' => 'relowner',
                        ),
+                       'tablespace' => array(
+                               'title' => $lang['strtablespace'],
+                               'field' => 'tablespace'
+                       ),
                        'actions' => array(
                                'title' => $lang['stractions'],
                        ),
                        ),
                );
                
+               if (!$data->hasTablespaces()) unset($columns['tablespace']);
+
                $misc->printTable($tables, $columns, $actions, $lang['strnotables']);
 
                echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&amp;{$misc->href}\">{$lang['strcreatetable']}</a></p>\n";