partial indexes only on 7.2 and greater. fix editing of bytea fields. support xid...
authorchriskl <chriskl>
Tue, 12 Aug 2003 08:18:53 +0000 (08:18 +0000)
committerchriskl <chriskl>
Tue, 12 Aug 2003 08:18:53 +0000 (08:18 +0000)
classes/Misc.php
classes/database/BaseDB.php
classes/database/Postgres.php
classes/database/Postgres72.php
indexes.php

index 24a45bcfce8165800e9dd5cebe15958e80a5ae51..d3a26a14a460c84dcaecffe488955a32fe5211df 100644 (file)
@@ -2,7 +2,7 @@
        /**
         * Class to hold various commonly used functions
         *
-        * $Id: Misc.php,v 1.40 2003/08/11 04:52:32 chriskl Exp $
+        * $Id: Misc.php,v 1.41 2003/08/12 08:18:53 chriskl Exp $
         */
         
        class Misc {
@@ -63,6 +63,9 @@
                                        case 'money':
                                        case 'numeric':
                                        case 'oid':
+                                       case 'xid':
+                                       case 'cid':
+                                       case 'tid':
                                                return "<div align=\"right\">" . nl2br(htmlspecialchars($str)) . "</div>";
                                                break;
                                        case 'bool':
index 23e0c3a114305437ca68c6f648b96906ca7aabe2..2a3da92187841288597ef121203d0134943b0b0d 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: BaseDB.php,v 1.23 2003/08/06 07:04:44 chriskl Exp $
+ * $Id: BaseDB.php,v 1.24 2003/08/12 08:18:54 chriskl Exp $
  */
 
 include_once('classes/database/ADODB_base.php');
@@ -202,6 +202,7 @@ class BaseDB extends ADODB_base {
        function hasAlterTrigger() { return false; }
        function hasWithoutOIDs() { return false; }
        function hasAlterTableOwner() { return false; }
+       function hasPartialIndexes() { return false; }
 
 }
 
index ec62726207db561aa836a8ceffb0709dc1a34f89..cc4e19f946e039c69c3fd5283d228b7a7dc39d80 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.137 2003/08/11 09:15:32 chriskl Exp $
+ * $Id: Postgres.php,v 1.138 2003/08/12 08:18:54 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -365,6 +365,9 @@ class Postgres extends BaseDB {
                                break;
                        case 'text':
                        case 'bytea':
+                               // addCSlashes converts all weird ASCII characters to octal representation,
+                               // EXCEPT the 'special' ones like \r \n \t, etc.
+                               if ($type == 'bytea') $value = addCSlashes($value, "\0..\37\177..\377");
                                echo "<textarea name=\"", htmlspecialchars($name), "\" rows=\"5\" cols=\"28\" wrap=\"virtual\">\n";
                                echo htmlspecialchars($value);
                                echo "</textarea>\n";
@@ -1346,16 +1349,23 @@ class Postgres extends BaseDB {
         * @param $table The table on which to add the index
         * @param $columns An array of columns that form the index
         * @param $type The index type
+        * @param $unique True if unique, false otherwise
+        * @param $where Index predicate ('' for none)
         * @return 0 success
         */
-       function createIndex($name, $table, $columns, $type) {
+       function createIndex($name, $table, $columns, $type, $unique, $where) {
                $this->fieldClean($name);
                $this->fieldClean($table);
                $this->arrayClean($columns);
 
-               $sql = "CREATE INDEX \"{$name}\" ON \"{$table}\" USING {$type} ";
+               $sql = "CREATE";
+               if ($unique) $sql .= " UNIQUE";
+               $sql .= " INDEX \"{$name}\" ON \"{$table}\" USING {$type} ";
                $sql .= "(\"" . implode('","', $columns) . "\")";
-                       
+
+               if ($this->hasPartialIndexes() && trim($where) != '') {
+                       $sql .= " WHERE ({$where})";
+               }
 
                return $this->execute($sql);
        }
index a91ec7e233faa5b4b8741dc0851ab453a9699c50..93164cddce194df18a3e20ad7d6b569fe4d8fb19 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres72.php,v 1.47 2003/08/04 08:27:27 chriskl Exp $
+ * $Id: Postgres72.php,v 1.48 2003/08/12 08:18:54 chriskl Exp $
  */
 
 
@@ -279,6 +279,7 @@ class Postgres72 extends Postgres71 {
 
        // Capabilities
        function hasWithoutOIDs() { return true; }
+       function hasPartialIndexes() { return true; }
 
 }
 
index 6d81f5ad30b8a2b45658e7017bcc13cd7ebf6158..4f39eb99b3cb40c2abf956120ab221b55ae9a439 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List indexes on a table
         *
-        * $Id: indexes.php,v 1.16 2003/08/12 08:11:08 chriskl Exp $
+        * $Id: indexes.php,v 1.17 2003/08/12 08:18:53 chriskl Exp $
         */
 
        // Include application functions
                echo "<th class=\"data\">{$lang['strunique']}</th>";
                echo "<td class=\"data1\"><input type=\"checkbox\" name=\"formUnique\"", (isset($_POST['formUnique']) ? 'checked="checked"' : ''), " /></td>";
                echo "</tr>";
-               echo "<tr>";
-               echo "<th class=\"data\">{$lang['strwhere']}</th>";
-               echo "<td class=\"data1\">(<input name=\"formWhere\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
-                       htmlspecialchars($_POST['formWhere']), "\" />)</td>";
-               echo "</tr>";
+               if ($data->hasPartialIndexes()) {
+                       echo "<tr>";
+                       echo "<th class=\"data\">{$lang['strwhere']}</th>";
+                       echo "<td class=\"data1\">(<input name=\"formWhere\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
+                               htmlspecialchars($_POST['formWhere']), "\" />)</td>";
+                       echo "</tr>";
+               }
                echo "</table>";
 
                echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_index\" />\n";
                global $localData;
                global $lang;
                
+               // Handle databases that don't have partial indexes
+               if (!isset($_POST['formWhere'])) $_POST['formWhere'] = '';
+               
                // 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']);