Fix BUG #183038 about getAggregate for pg < 7.3,
authorioguix <ioguix>
Sat, 19 Jan 2008 13:46:15 +0000 (13:46 +0000)
committerioguix <ioguix>
Sat, 19 Jan 2008 13:46:15 +0000 (13:46 +0000)
Fix a BUG in getAggregate where field aggsortop doesn't exist for pg < 8.1
Fix a "no result" buggy page when clicking on an aggregate which hasn't basetype (ie. count)
Fix a bug in tblproperties about getConstraintsWithField in pg < 7.3

aggregates.php
classes/database/Postgres.php
classes/database/Postgres73.php
classes/database/Postgres81.php
tblproperties.php

index fe9a0ca8d759752106eeb0cbfc0dbd0b4fc2699f..e571915cbffa165cc6eff99e73bb527a83da41f1 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage aggregates in a database
         *
-        * $Id: aggregates.php,v 1.26 2007/11/30 15:17:22 soranzo Exp $
+        * $Id: aggregates.php,v 1.27 2008/01/19 13:46:15 ioguix Exp $
         */
 
        // Include application functions
                        echo "\t<td class=\"data1\">", htmlspecialchars($aggrdata->fields['aggfinalfn']), "</td>\n</tr>\n";
                        echo "<tr>\n\t<th class=\"data left\">{$lang['straggrinitcond']}</th>\n";
                        echo "\t<td class=\"data1\">", htmlspecialchars($aggrdata->fields['agginitval']), "</td>\n</tr>\n";
-                       echo "<tr>\n\t<th class=\"data left\">{$lang['straggrsortop']}</th>\n";
-                       echo "\t<td class=\"data1\">", htmlspecialchars($aggrdata->fields['aggsortop']), "</td>\n</tr>\n";
+                       if($data->hasAggregateSortOp()) {
+                               echo "<tr>\n\t<th class=\"data left\">{$lang['straggrsortop']}</th>\n";
+                               echo "\t<td class=\"data1\">", htmlspecialchars($aggrdata->fields['aggsortop']), "</td>\n</tr>\n";
+                       }
                        echo "<tr>\n\t<th class=\"data left\">{$lang['strowner']}</th>\n";
                        echo "\t<td class=\"data1\">", htmlspecialchars($aggrdata->fields['usename']), "</td>\n</tr>\n";
                        echo "<tr>\n\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
index c4bec9f3235c9bb7818d6e81fb2d78322c84d41b..c60c76337c8a9181a65e7610a43603dbf1fc1c8c 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.318 2007/12/12 04:11:10 xzilla Exp $
+ * $Id: Postgres.php,v 1.319 2008/01/19 13:46:15 ioguix Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -3948,6 +3948,35 @@ class Postgres extends ADODB_base {
                return $this->selectSet($sql);
        }
 
+       /**
+        * Gets all information for an aggregate
+        * @param $name The name of the aggregate
+        * @param $basetype The input data type of the aggregate
+        * @return A recordset
+        */
+       function getAggregate($name, $basetype) {
+               $this->fieldclean($name);
+               $this->fieldclean($basetype);
+
+               $sql = "
+                       SELECT a.aggname AS proname,
+                               CASE a.aggbasetype
+                               WHEN 0 THEN NULL
+                               ELSE format_type(a.aggbasetype, NULL)
+                               END AS proargtypes,
+                               a.aggtransfn, format_type(a.aggtranstype, NULL) AS aggstype, a.aggfinalfn, a.agginitval, u.usename,
+                               obj_description(a.oid, 'pg_aggregate') AS aggrcomment
+                       FROM pg_user u, pg_aggregate a
+                       WHERE a.aggowner=u.usesysid
+                               AND a.aggname='" . $name . "'
+                               AND CASE a.aggbasetype
+                                       WHEN  0 THEN ''
+                                       ELSE format_type(a.aggbasetype, NULL)
+                                       END ='" . $basetype . "'";
+
+               return $this->selectSet($sql);
+       }
+
        /**
         * Creates a new aggregate in the database
         * @param $name The name of the aggregate
@@ -4878,6 +4907,7 @@ class Postgres extends ADODB_base {
        function hasPreparedXacts() { return false; }
        function hasDisableTriggers() { return false; }
        function hasAlterAggregate() { return false; }
+       function hasAggregateSortOp() { return false; }
        function hasSharedComments() {return false;}
        function hasAnalyze() {return false;}
        function hasCreateTableLike() {return false;}
index 9e3d789a9953d128142bdf7e87bb75c96451d9cc..98811e5853c379d681253a97befba6f1179ebd19 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.185 2007/12/28 16:21:25 ioguix Exp $
+ * $Id: Postgres73.php,v 1.186 2008/01/19 13:46:15 ioguix Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -2522,15 +2522,21 @@ class Postgres73 extends Postgres72 {
                $this->fieldclean($name);
                $this->fieldclean($basetype);
 
-               $sql = "SELECT p.proname, CASE p.proargtypes[0] WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype THEN NULL ELSE
-                          pg_catalog.format_type(p.proargtypes[0], NULL) END AS proargtypes, a.aggtransfn,
-                          format_type(a.aggtranstype, NULL) AS aggstype, a.aggfinalfn, a.agginitval, a.aggsortop, u.usename,
-                          pg_catalog.obj_description(p.oid, 'pg_proc') AS aggrcomment
-                          FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n, pg_catalog.pg_user u, pg_catalog.pg_aggregate a
-                          WHERE n.oid = p.pronamespace AND p.proowner=u.usesysid AND p.oid=a.aggfnoid
-                          AND p.proisagg AND n.nspname='{$this->_schema}'
-                          AND p.proname='" . $name . "' AND CASE p.proargtypes[0] WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype
-                          THEN NULL ELSE pg_catalog.format_type(p.proargtypes[0], NULL) END ='" . $basetype . "'";
+               $sql = "
+                       SELECT p.proname,
+                               CASE p.proargtypes[0]
+                                       WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype THEN NULL
+                                       ELSE pg_catalog.format_type(p.proargtypes[0], NULL)
+                               END AS proargtypes, a.aggtransfn, format_type(a.aggtranstype, NULL) AS aggstype,
+                               a.aggfinalfn, a.agginitval, u.usename, pg_catalog.obj_description(p.oid, 'pg_proc') AS aggrcomment
+                       FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n, pg_catalog.pg_user u, pg_catalog.pg_aggregate a
+                       WHERE n.oid = p.pronamespace AND p.proowner=u.usesysid AND p.oid=a.aggfnoid
+                               AND p.proisagg AND n.nspname='{$this->_schema}'
+                               AND p.proname='" . $name . "'
+                               AND CASE p.proargtypes[0] 
+                                       WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype THEN ''
+                                       ELSE pg_catalog.format_type(p.proargtypes[0], NULL)
+                               END ='" . $basetype . "'";
 
                return $this->selectSet($sql);
        }
index 29881e06016e8696468f55bac1147b093d9c919a..8bcded4b55a9eb9ba700e60da4efd2989621bdc3 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * PostgreSQL 8.1 support
  *
- * $Id: Postgres81.php,v 1.20 2007/12/12 10:45:35 ioguix Exp $
+ * $Id: Postgres81.php,v 1.21 2008/01/19 13:46:15 ioguix Exp $
  */
 
 include_once('./classes/database/Postgres80.php');
@@ -627,6 +627,36 @@ class Postgres81 extends Postgres80 {
                return 0;
        }
        
+       // Aggregate functions
+
+       /**
+        * Gets all information for an aggregate
+        * @param $name The name of the aggregate
+        * @param $basetype The input data type of the aggregate
+        * @return A recordset
+        */
+       function getAggregate($name, $basetype) {
+               $this->fieldclean($name);
+               $this->fieldclean($basetype);
+
+               $sql = "
+                       SELECT p.proname, CASE p.proargtypes[0]
+                               WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype THEN NULL
+                               ELSE pg_catalog.format_type(p.proargtypes[0], NULL) END AS proargtypes,
+                               a.aggtransfn, format_type(a.aggtranstype, NULL) AS aggstype, a.aggfinalfn,
+                               a.agginitval, a.aggsortop, u.usename, pg_catalog.obj_description(p.oid, 'pg_proc') AS aggrcomment
+                       FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n, pg_catalog.pg_user u, pg_catalog.pg_aggregate a
+                       WHERE n.oid = p.pronamespace AND p.proowner=u.usesysid AND p.oid=a.aggfnoid
+                               AND p.proisagg AND n.nspname='{$this->_schema}'
+                               AND p.proname='" . $name . "'
+                               AND CASE p.proargtypes[0] 
+                                       WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype THEN ''
+                                       ELSE pg_catalog.format_type(p.proargtypes[0], NULL)
+                               END ='" . $basetype . "'";
+
+               return $this->selectSet($sql);
+       }
+
        // Capabilities
        function hasServerAdminFuncs() { return true; }
        function hasRoles() { return true; }
@@ -636,6 +666,7 @@ class Postgres81 extends Postgres80 {
        function hasFunctionAlterSchema() { return true; }
        function hasAlterTableSchema() { return true; }
        function hasSequenceAlterSchema() { return true; }
+       function hasAggregateSortOp() { return true; }
 }
 
 ?>
index d56430094bc60423643e5d4627a30b6cc9b610f5..a6fa31b98701c6ffa390683ed3481288f2eb9143 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tblproperties.php,v 1.91 2007/12/28 16:21:25 ioguix Exp $
+        * $Id: tblproperties.php,v 1.92 2008/01/19 13:46:15 ioguix Exp $
         */
 
        // Include application functions
                $tdata = $data->getTable($_REQUEST['table']);
                // Get columns
                $attrs = $data->getTableAttributes($_REQUEST['table']);
-               // Get Pk & Constraints
-               $ck = $data->getConstraintsWithFields($_REQUEST['table']);
 
                // Show comment if any
                if ($tdata->fields['relcomment'] !== null)
                                'title' => $lang['strdefault'],
                                'field' => field('adsrc'),
                        ),
-                       'keyprop' => array(
-                               'title' => $lang['strconstraints'],
-                               'field' => field('attname'),
-                               'type'  => 'callback',
-                               'params'=> array(
-                                       'function' => 'cstrRender',
-                                       'keys' => $ck->getArray()
-                               ),
-                       ),
+                       'keyprop' => 1,
                        'actions' => array(
                                'title' => $lang['stractions'],
                        ),
                                'field' => field('comment'),
                        ),
                );
+
                if (!$data->hasConstraintsInfo()) {
                        unset($columns['keyprop']);
                }
                else {
+                       $ck = $data->getConstraintsWithFields($_REQUEST['table']);
+
+                       $columns['keyprop'] = array(
+                               'title' => $lang['strconstraints'],
+                               'field' => field('attname'),
+                               'type'  => 'callback',
+                               'params'=> array(
+                                       'function' => 'cstrRender',
+                                       'keys' => $ck->getArray()
+       ),
+                       );
+
                        function cstrRender($s, $p) {
                                global $misc, $data;