From 20a65b0fd92a1e1ec145a49384826ce4f902fcc0 Mon Sep 17 00:00:00 2001 From: chriskl Date: Fri, 16 May 2003 05:58:08 +0000 Subject: [PATCH] fix getDatabases for 7.0. add show_system support to database list --- classes/database/Postgres.php | 14 +++++++++----- classes/database/Postgres71.php | 34 ++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index abe1b70c..0431e3fe 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.106 2003/05/15 14:34:46 chriskl Exp $ + * $Id: Postgres.php,v 1.107 2003/05/16 05:58:08 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -216,11 +216,15 @@ class Postgres extends BaseDB { } else $clause = ''; - $sql = "SELECT pdb.datname, pu.usename AS owner, pg_encoding_to_char(encoding) AS encoding, pde.description FROM - pg_database pdb LEFT JOIN pg_description pde ON pdb.oid=pde.objoid, - pg_user pu + if (!$conf['show_system']) + $where = "AND pdb.datname NOT IN ('template1')"; + else + $where = ''; + + $sql = "SELECT pdb.datname, pu.usename AS owner, pg_encoding_to_char(encoding) AS encoding, NULL AS description FROM + pg_database pdb, pg_user pu WHERE pdb.datdba = pu.usesysid - AND NOT pdb.datistemplate + {$where} {$clause} ORDER BY pdb.datname"; diff --git a/classes/database/Postgres71.php b/classes/database/Postgres71.php index 81c1d9f0..c04ff227 100644 --- a/classes/database/Postgres71.php +++ b/classes/database/Postgres71.php @@ -4,7 +4,7 @@ * A class that implements the DB interface for Postgres * Note: This class uses ADODB and returns RecordSets. * - * $Id: Postgres71.php,v 1.31 2003/05/15 14:34:47 chriskl Exp $ + * $Id: Postgres71.php,v 1.32 2003/05/16 05:58:08 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -36,6 +36,38 @@ class Postgres71 extends Postgres { $this->Postgres($host, $port, $database, $user, $password); } + // Database functions + + /** + * Return all database available on the server + * @return A list of databases, sorted alphabetically + */ + function &getDatabases() { + global $conf; + + if (isset($conf['owned_only']) && $conf['owned_only']) { + $username = $_SESSION['webdbUsername']; + $this->clean($username); + $clause = " AND pu.usename='{$username}'"; + } + else $clause = ''; + + if (!$conf['show_system']) + $where = 'AND NOT pdb.datistemplate'; + else + $where = 'AND pdb.datallowconn'; + + $sql = "SELECT pdb.datname, pu.usename AS owner, pg_encoding_to_char(encoding) AS encoding, pde.description FROM + pg_database pdb LEFT JOIN pg_description pde ON pdb.oid=pde.objoid, + pg_user pu + WHERE pdb.datdba = pu.usesysid + {$where} + {$clause} + ORDER BY pdb.datname"; + + return $this->selectSet($sql); + } + // Table functions /** -- 2.39.5