@@ 68-105 (lines=38) @@ | ||
65 | * |
|
66 | * @return \PHPPgAdmin\ADORecordSet A list of databases, sorted alphabetically |
|
67 | */ |
|
68 | public function getDatabases($currentdatabase = null) |
|
69 | { |
|
70 | $conf = $this->conf; |
|
71 | $server_info = $this->server_info; |
|
72 | ||
73 | if (isset($conf['owned_only']) && $conf['owned_only'] && !$this->isSuperUser()) { |
|
74 | $username = $server_info['username']; |
|
75 | $this->clean($username); |
|
76 | $clause = " AND pu.usename='{$username}'"; |
|
77 | } else { |
|
78 | $clause = ''; |
|
79 | } |
|
80 | ||
81 | if ($currentdatabase) { |
|
82 | $this->clean($currentdatabase); |
|
83 | $orderby = "ORDER BY pdb.datname = '{$currentdatabase}' DESC, pdb.datname"; |
|
84 | } else { |
|
85 | $orderby = 'ORDER BY pdb.datname'; |
|
86 | } |
|
87 | ||
88 | if (!$conf['show_system']) { |
|
89 | $where = ' AND NOT pdb.datistemplate'; |
|
90 | } else { |
|
91 | $where = ' AND pdb.datallowconn'; |
|
92 | } |
|
93 | ||
94 | $sql = "SELECT pdb.datname AS datname, |
|
95 | pu.usename AS datowner, |
|
96 | pg_encoding_to_char(encoding) AS datencoding, |
|
97 | (SELECT description FROM pg_description pd WHERE pdb.oid=pd.objoid) AS datcomment |
|
98 | FROM pg_database pdb, pg_user pu |
|
99 | WHERE pdb.datdba = pu.usesysid |
|
100 | {$where} |
|
101 | {$clause} |
|
102 | {$orderby}"; |
|
103 | ||
104 | return $this->selectSet($sql); |
|
105 | } |
|
106 | ||
107 | /** |
|
108 | * Searches all system catalogs to find objects that match a certain name. |
@@ 62-100 (lines=39) @@ | ||
59 | * |
|
60 | * @return \PHPPgAdmin\ADORecordSet A list of databases, sorted alphabetically |
|
61 | */ |
|
62 | public function getDatabases($currentdatabase = null) |
|
63 | { |
|
64 | $conf = $this->conf; |
|
65 | $server_info = $this->server_info; |
|
66 | ||
67 | if (isset($conf['owned_only']) && $conf['owned_only'] && !$this->isSuperUser()) { |
|
68 | $username = $server_info['username']; |
|
69 | $this->clean($username); |
|
70 | $clause = " AND pu.usename='{$username}'"; |
|
71 | } else { |
|
72 | $clause = ''; |
|
73 | } |
|
74 | ||
75 | if ($currentdatabase) { |
|
76 | $this->clean($currentdatabase); |
|
77 | $orderby = "ORDER BY pdb.datname = '{$currentdatabase}' DESC, pdb.datname"; |
|
78 | } else { |
|
79 | $orderby = 'ORDER BY pdb.datname'; |
|
80 | } |
|
81 | ||
82 | if (!$conf['show_system']) { |
|
83 | $where = ' AND NOT pdb.datistemplate'; |
|
84 | } else { |
|
85 | $where = ' AND pdb.datallowconn'; |
|
86 | } |
|
87 | ||
88 | $sql = "SELECT pdb.datname AS datname, |
|
89 | pu.usename AS datowner, |
|
90 | pg_encoding_to_char(encoding) AS datencoding, |
|
91 | (SELECT description FROM pg_description pd WHERE pdb.oid=pd.objoid) AS datcomment, |
|
92 | (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pdb.dattablespace) AS tablespace |
|
93 | FROM pg_database pdb, pg_user pu |
|
94 | WHERE pdb.datdba = pu.usesysid |
|
95 | {$where} |
|
96 | {$clause} |
|
97 | {$orderby}"; |
|
98 | ||
99 | return $this->selectSet($sql); |
|
100 | } |
|
101 | ||
102 | // Schema functions |
|
103 |
@@ 59-98 (lines=40) @@ | ||
56 | * |
|
57 | * @return \PHPPgAdmin\ADORecordSet A list of databases, sorted alphabetically |
|
58 | */ |
|
59 | public function getDatabases($currentdatabase = null) |
|
60 | { |
|
61 | $conf = $this->conf; |
|
62 | $server_info = $this->server_info; |
|
63 | ||
64 | if (isset($conf['owned_only']) && $conf['owned_only'] && !$this->isSuperUser()) { |
|
65 | $username = $server_info['username']; |
|
66 | $this->clean($username); |
|
67 | $clause = " AND pr.rolname='{$username}'"; |
|
68 | } else { |
|
69 | $clause = ''; |
|
70 | } |
|
71 | ||
72 | if ($currentdatabase !== null) { |
|
73 | $this->clean($currentdatabase); |
|
74 | $orderby = "ORDER BY pdb.datname = '{$currentdatabase}' DESC, pdb.datname"; |
|
75 | } else { |
|
76 | $orderby = 'ORDER BY pdb.datname'; |
|
77 | } |
|
78 | ||
79 | if (!$conf['show_system']) { |
|
80 | $where = ' AND NOT pdb.datistemplate'; |
|
81 | } else { |
|
82 | $where = ' AND pdb.datallowconn'; |
|
83 | } |
|
84 | ||
85 | $sql = "SELECT |
|
86 | pdb.datname AS datname, |
|
87 | pr.rolname AS datowner, pg_encoding_to_char(encoding) AS datencoding, |
|
88 | (SELECT description FROM pg_catalog.pg_description pd WHERE pdb.oid=pd.objoid) AS datcomment, |
|
89 | (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pdb.dattablespace) AS tablespace, |
|
90 | pg_catalog.pg_database_size(pdb.oid) as dbsize |
|
91 | FROM pg_catalog.pg_database pdb LEFT JOIN pg_catalog.pg_roles pr ON (pdb.datdba = pr.oid) |
|
92 | WHERE true |
|
93 | {$where} |
|
94 | {$clause} |
|
95 | {$orderby}"; |
|
96 | ||
97 | return $this->selectSet($sql); |
|
98 | } |
|
99 | ||
100 | /** |
|
101 | * Alters a database |
@@ 59-97 (lines=39) @@ | ||
56 | * |
|
57 | * @return int|\PHPPgAdmin\ADORecordSet A recordset or an error number A list of databases, sorted alphabetically |
|
58 | */ |
|
59 | public function getDatabases($currentdatabase = null) |
|
60 | { |
|
61 | $conf = $this->conf; |
|
62 | $server_info = $this->server_info; |
|
63 | ||
64 | if (isset($conf['owned_only']) && $conf['owned_only'] && !$this->isSuperUser()) { |
|
65 | $username = $server_info['username']; |
|
66 | $this->clean($username); |
|
67 | $clause = " AND pr.rolname='{$username}'"; |
|
68 | } else { |
|
69 | $clause = ''; |
|
70 | } |
|
71 | ||
72 | if ($currentdatabase != null) { |
|
73 | $this->clean($currentdatabase); |
|
74 | $orderby = "ORDER BY pdb.datname = '{$currentdatabase}' DESC, pdb.datname"; |
|
75 | } else { |
|
76 | $orderby = 'ORDER BY pdb.datname'; |
|
77 | } |
|
78 | ||
79 | if (!$conf['show_system']) { |
|
80 | $where = ' AND NOT pdb.datistemplate'; |
|
81 | } else { |
|
82 | $where = ' AND pdb.datallowconn'; |
|
83 | } |
|
84 | ||
85 | $sql = " |
|
86 | SELECT pdb.datname AS datname, pr.rolname AS datowner, pg_encoding_to_char(encoding) AS datencoding, |
|
87 | (SELECT description FROM pg_catalog.pg_shdescription pd WHERE pdb.oid=pd.objoid AND pd.classoid='pg_database'::regclass) AS datcomment, |
|
88 | (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pdb.dattablespace) AS tablespace, |
|
89 | pg_catalog.pg_database_size(pdb.oid) as dbsize |
|
90 | FROM pg_catalog.pg_database pdb LEFT JOIN pg_catalog.pg_roles pr ON (pdb.datdba = pr.oid) |
|
91 | WHERE true |
|
92 | {$where} |
|
93 | {$clause} |
|
94 | {$orderby}"; |
|
95 | ||
96 | return $this->selectSet($sql); |
|
97 | } |
|
98 | ||
99 | // Administration functions |
|
100 |