From: ioguix Date: Sat, 19 Jan 2008 13:46:15 +0000 (+0000) Subject: Fix BUG #183038 about getAggregate for pg < 7.3, X-Git-Tag: REL_4-2-BETA-2~26 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=7cd91d7d6d5bf4993bccc023cef357099510fcc3;p=phppgadmin.git Fix BUG #183038 about getAggregate for pg < 7.3, 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 --- diff --git a/aggregates.php b/aggregates.php index fe9a0ca8..e571915c 100644 --- a/aggregates.php +++ b/aggregates.php @@ -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 @@ -236,8 +236,10 @@ echo "\t", htmlspecialchars($aggrdata->fields['aggfinalfn']), "\n\n"; echo "\n\t{$lang['straggrinitcond']}\n"; echo "\t", htmlspecialchars($aggrdata->fields['agginitval']), "\n\n"; - echo "\n\t{$lang['straggrsortop']}\n"; - echo "\t", htmlspecialchars($aggrdata->fields['aggsortop']), "\n\n"; + if($data->hasAggregateSortOp()) { + echo "\n\t{$lang['straggrsortop']}\n"; + echo "\t", htmlspecialchars($aggrdata->fields['aggsortop']), "\n\n"; + } echo "\n\t{$lang['strowner']}\n"; echo "\t", htmlspecialchars($aggrdata->fields['usename']), "\n\n"; echo "\n\t{$lang['strcomment']}\n"; diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index c4bec9f3..c60c7633 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -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;} diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index 9e3d789a..98811e58 100644 --- a/classes/database/Postgres73.php +++ b/classes/database/Postgres73.php @@ -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); } diff --git a/classes/database/Postgres81.php b/classes/database/Postgres81.php index 29881e06..8bcded4b 100644 --- a/classes/database/Postgres81.php +++ b/classes/database/Postgres81.php @@ -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; } } ?> diff --git a/tblproperties.php b/tblproperties.php index d5643009..a6fa31b9 100644 --- a/tblproperties.php +++ b/tblproperties.php @@ -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 @@ -458,8 +458,6 @@ $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) @@ -486,15 +484,7 @@ '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'], ), @@ -503,10 +493,23 @@ '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;