@@ 37-59 (lines=23) @@ | ||
34 | * @param \PHPPgAdmin\Database\The|string $table The name of a table whose triggers to retrieve |
|
35 | * @return \PHPPgAdmin\Database\A recordset |
|
36 | */ |
|
37 | public function getTriggers($table = '') |
|
38 | { |
|
39 | $c_schema = $this->_schema; |
|
40 | $this->clean($c_schema); |
|
41 | $this->clean($table); |
|
42 | ||
43 | $sql = "SELECT |
|
44 | t.tgname, pg_catalog.pg_get_triggerdef(t.oid) AS tgdef, |
|
45 | CASE WHEN t.tgenabled = 'D' THEN FALSE ELSE TRUE END AS tgenabled, p.oid AS prooid, |
|
46 | p.proname || ' (' || pg_catalog.oidvectortypes(p.proargtypes) || ')' AS proproto, |
|
47 | ns.nspname AS pronamespace |
|
48 | FROM pg_catalog.pg_trigger t, pg_catalog.pg_proc p, pg_catalog.pg_namespace ns |
|
49 | WHERE t.tgrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}' |
|
50 | AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{$c_schema}')) |
|
51 | AND (NOT tgisconstraint OR NOT EXISTS |
|
52 | (SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c |
|
53 | ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) |
|
54 | WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f')) |
|
55 | AND p.oid=t.tgfoid |
|
56 | AND p.pronamespace = ns.oid"; |
|
57 | ||
58 | return $this->selectSet($sql); |
|
59 | } |
|
60 | ||
61 | /** |
|
62 | * Searches all system catalogs to find objects that match a certain name. |
@@ 1296-1317 (lines=22) @@ | ||
1293 | * @param $table The table to find the parents for |
|
1294 | * @return A recordset |
|
1295 | */ |
|
1296 | public function getTableParents($table) |
|
1297 | { |
|
1298 | $c_schema = $this->_schema; |
|
1299 | $this->clean($c_schema); |
|
1300 | $this->clean($table); |
|
1301 | ||
1302 | $sql = " |
|
1303 | SELECT |
|
1304 | pn.nspname, relname |
|
1305 | FROM |
|
1306 | pg_catalog.pg_class pc, pg_catalog.pg_inherits pi, pg_catalog.pg_namespace pn |
|
1307 | WHERE |
|
1308 | pc.oid=pi.inhparent |
|
1309 | AND pc.relnamespace=pn.oid |
|
1310 | AND pi.inhrelid = (SELECT oid from pg_catalog.pg_class WHERE relname='{$table}' |
|
1311 | AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = '{$c_schema}')) |
|
1312 | ORDER BY |
|
1313 | pi.inhseqno |
|
1314 | "; |
|
1315 | ||
1316 | return $this->selectSet($sql); |
|
1317 | } |
|
1318 | ||
1319 | /** |
|
1320 | * Finds the names and schemas of child tables |
|
@@ 1325-1344 (lines=20) @@ | ||
1322 | * @param $table The table to find the children for |
|
1323 | * @return A recordset |
|
1324 | */ |
|
1325 | public function getTableChildren($table) |
|
1326 | { |
|
1327 | $c_schema = $this->_schema; |
|
1328 | $this->clean($c_schema); |
|
1329 | $this->clean($table); |
|
1330 | ||
1331 | $sql = " |
|
1332 | SELECT |
|
1333 | pn.nspname, relname |
|
1334 | FROM |
|
1335 | pg_catalog.pg_class pc, pg_catalog.pg_inherits pi, pg_catalog.pg_namespace pn |
|
1336 | WHERE |
|
1337 | pc.oid=pi.inhrelid |
|
1338 | AND pc.relnamespace=pn.oid |
|
1339 | AND pi.inhparent = (SELECT oid from pg_catalog.pg_class WHERE relname='{$table}' |
|
1340 | AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = '{$c_schema}')) |
|
1341 | "; |
|
1342 | ||
1343 | return $this->selectSet($sql); |
|
1344 | } |
|
1345 | ||
1346 | /** |
|
1347 | * Returns the SQL definition for the table. |
|
@@ 1681-1701 (lines=21) @@ | ||
1678 | * @param $table The name of the table |
|
1679 | * @return A recordset |
|
1680 | */ |
|
1681 | public function getTable($table) |
|
1682 | { |
|
1683 | $c_schema = $this->_schema; |
|
1684 | $this->clean($c_schema); |
|
1685 | $this->clean($table); |
|
1686 | ||
1687 | $sql = " |
|
1688 | SELECT |
|
1689 | c.relname, n.nspname, u.usename AS relowner, |
|
1690 | pg_catalog.obj_description(c.oid, 'pg_class') AS relcomment, |
|
1691 | (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=c.reltablespace) AS tablespace |
|
1692 | FROM pg_catalog.pg_class c |
|
1693 | LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner |
|
1694 | LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |
|
1695 | WHERE c.relkind = 'r' |
|
1696 | AND n.nspname = '{$c_schema}' |
|
1697 | AND n.oid = c.relnamespace |
|
1698 | AND c.relname = '{$table}'"; |
|
1699 | ||
1700 | return $this->selectSet($sql); |
|
1701 | } |
|
1702 | ||
1703 | /** |
|
1704 | * Retrieve the attribute definition of a table |
|
@@ 1781-1819 (lines=39) @@ | ||
1778 | * @param $table The table to find rules for |
|
1779 | * @return A recordset |
|
1780 | */ |
|
1781 | public function getConstraints($table) |
|
1782 | { |
|
1783 | $c_schema = $this->_schema; |
|
1784 | $this->clean($c_schema); |
|
1785 | $this->clean($table); |
|
1786 | ||
1787 | // This SQL is greatly complicated by the need to retrieve |
|
1788 | // index clustering information for primary and unique constraints |
|
1789 | $sql = "SELECT |
|
1790 | pc.conname, |
|
1791 | pg_catalog.pg_get_constraintdef(pc.oid, true) AS consrc, |
|
1792 | pc.contype, |
|
1793 | CASE WHEN pc.contype='u' OR pc.contype='p' THEN ( |
|
1794 | SELECT |
|
1795 | indisclustered |
|
1796 | FROM |
|
1797 | pg_catalog.pg_depend pd, |
|
1798 | pg_catalog.pg_class pl, |
|
1799 | pg_catalog.pg_index pi |
|
1800 | WHERE |
|
1801 | pd.refclassid=pc.tableoid |
|
1802 | AND pd.refobjid=pc.oid |
|
1803 | AND pd.objid=pl.oid |
|
1804 | AND pl.oid=pi.indexrelid |
|
1805 | ) ELSE |
|
1806 | NULL |
|
1807 | END AS indisclustered |
|
1808 | FROM |
|
1809 | pg_catalog.pg_constraint pc |
|
1810 | WHERE |
|
1811 | pc.conrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}' |
|
1812 | AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace |
|
1813 | WHERE nspname='{$c_schema}')) |
|
1814 | ORDER BY |
|
1815 | 1 |
|
1816 | "; |
|
1817 | ||
1818 | return $this->selectSet($sql); |
|
1819 | } |
|
1820 | ||
1821 | /** |
|
1822 | * Returns the SQL for changing the current user |
|
@@ 2301-2323 (lines=23) @@ | ||
2298 | * @param \PHPPgAdmin\Database\The|string $table The name of a table whose triggers to retrieve |
|
2299 | * @return \PHPPgAdmin\Database\A recordset |
|
2300 | */ |
|
2301 | public function getTriggers($table = '') |
|
2302 | { |
|
2303 | $c_schema = $this->_schema; |
|
2304 | $this->clean($c_schema); |
|
2305 | $this->clean($table); |
|
2306 | ||
2307 | $sql = "SELECT |
|
2308 | t.tgname, pg_catalog.pg_get_triggerdef(t.oid) AS tgdef, |
|
2309 | CASE WHEN t.tgenabled = 'D' THEN FALSE ELSE TRUE END AS tgenabled, p.oid AS prooid, |
|
2310 | p.proname || ' (' || pg_catalog.oidvectortypes(p.proargtypes) || ')' AS proproto, |
|
2311 | ns.nspname AS pronamespace |
|
2312 | FROM pg_catalog.pg_trigger t, pg_catalog.pg_proc p, pg_catalog.pg_namespace ns |
|
2313 | WHERE t.tgrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}' |
|
2314 | AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{$c_schema}')) |
|
2315 | AND ( tgconstraint = 0 OR NOT EXISTS |
|
2316 | (SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c |
|
2317 | ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) |
|
2318 | WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f')) |
|
2319 | AND p.oid=t.tgfoid |
|
2320 | AND p.pronamespace = ns.oid"; |
|
2321 | ||
2322 | return $this->selectSet($sql); |
|
2323 | } |
|
2324 | ||
2325 | /** |
|
2326 | * Returns a list of all rules on a table OR view |
|
@@ 2331-2346 (lines=16) @@ | ||
2328 | * @param $table The table to find rules for |
|
2329 | * @return A recordset |
|
2330 | */ |
|
2331 | public function getRules($table) |
|
2332 | { |
|
2333 | $c_schema = $this->_schema; |
|
2334 | $this->clean($c_schema); |
|
2335 | $this->clean($table); |
|
2336 | ||
2337 | $sql = " |
|
2338 | SELECT * |
|
2339 | FROM pg_catalog.pg_rules |
|
2340 | WHERE |
|
2341 | schemaname='{$c_schema}' AND tablename='{$table}' |
|
2342 | ORDER BY rulename |
|
2343 | "; |
|
2344 | ||
2345 | return $this->selectSet($sql); |
|
2346 | } |
|
2347 | ||
2348 | /** |
|
2349 | * Creates a new table in the database |
|
@@ 4378-4396 (lines=19) @@ | ||
4375 | * |
|
4376 | * @return true if the table has been already clustered |
|
4377 | */ |
|
4378 | public function alreadyClustered($table) |
|
4379 | { |
|
4380 | $c_schema = $this->_schema; |
|
4381 | $this->clean($c_schema); |
|
4382 | $this->clean($table); |
|
4383 | ||
4384 | $sql = "SELECT i.indisclustered |
|
4385 | FROM pg_catalog.pg_class c, pg_catalog.pg_index i |
|
4386 | WHERE c.relname = '{$table}' |
|
4387 | AND c.oid = i.indrelid AND i.indisclustered |
|
4388 | AND c.relnamespace = (SELECT oid FROM pg_catalog.pg_namespace |
|
4389 | WHERE nspname='{$c_schema}') |
|
4390 | "; |
|
4391 | ||
4392 | $v = $this->selectSet($sql); |
|
4393 | ||
4394 | return !($v->recordCount() == 0); |
|
4395 | } |
|
4396 | ||
4397 | /** |
|
4398 | * Creates an index |
|
4399 | * |
|
@@ 4959-4992 (lines=34) @@ | ||
4956 | * @param $table The table to find referrers for |
|
4957 | * @return A recordset |
|
4958 | */ |
|
4959 | public function getReferrers($table) |
|
4960 | { |
|
4961 | $this->clean($table); |
|
4962 | ||
4963 | $status = $this->beginTransaction(); |
|
4964 | if ($status != 0) { |
|
4965 | return -1; |
|
4966 | } |
|
4967 | ||
4968 | $c_schema = $this->_schema; |
|
4969 | $this->clean($c_schema); |
|
4970 | ||
4971 | $sql = " |
|
4972 | SELECT |
|
4973 | pn.nspname, |
|
4974 | pl.relname, |
|
4975 | pc.conname, |
|
4976 | pg_catalog.pg_get_constraintdef(pc.oid) AS consrc |
|
4977 | FROM |
|
4978 | pg_catalog.pg_constraint pc, |
|
4979 | pg_catalog.pg_namespace pn, |
|
4980 | pg_catalog.pg_class pl |
|
4981 | WHERE |
|
4982 | pc.connamespace = pn.oid |
|
4983 | AND pc.conrelid = pl.oid |
|
4984 | AND pc.contype = 'f' |
|
4985 | AND confrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}' |
|
4986 | AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace |
|
4987 | WHERE nspname='{$c_schema}')) |
|
4988 | ORDER BY 1,2,3 |
|
4989 | "; |
|
4990 | ||
4991 | return $this->selectSet($sql); |
|
4992 | } |
|
4993 | ||
4994 | // Type functions |
|
4995 | ||
@@ 6128-6143 (lines=16) @@ | ||
6125 | * @param $trigger The name of the trigger to retrieve |
|
6126 | * @return A recordset |
|
6127 | */ |
|
6128 | public function getTrigger($table, $trigger) |
|
6129 | { |
|
6130 | $c_schema = $this->_schema; |
|
6131 | $this->clean($c_schema); |
|
6132 | $this->clean($table); |
|
6133 | $this->clean($trigger); |
|
6134 | ||
6135 | $sql = " |
|
6136 | SELECT * FROM pg_catalog.pg_trigger t, pg_catalog.pg_class c |
|
6137 | WHERE t.tgrelid=c.oid AND c.relname='{$table}' AND t.tgname='{$trigger}' |
|
6138 | AND c.relnamespace=( |
|
6139 | SELECT oid FROM pg_catalog.pg_namespace |
|
6140 | WHERE nspname='{$c_schema}')"; |
|
6141 | ||
6142 | return $this->selectSet($sql); |
|
6143 | } |
|
6144 | ||
6145 | /** |
|
6146 | * A helper function for getTriggers that translates |
|
@@ 9357-9367 (lines=11) @@ | ||
9354 | * @param $table The table to fetch stats for |
|
9355 | * @return A recordset |
|
9356 | */ |
|
9357 | public function getStatsTableTuples($table) |
|
9358 | { |
|
9359 | $c_schema = $this->_schema; |
|
9360 | $this->clean($c_schema); |
|
9361 | $this->clean($table); |
|
9362 | ||
9363 | $sql = "SELECT * FROM pg_stat_all_tables |
|
9364 | WHERE schemaname='{$c_schema}' AND relname='{$table}'"; |
|
9365 | ||
9366 | return $this->selectSet($sql); |
|
9367 | } |
|
9368 | ||
9369 | /** |
|
9370 | * Fetches I/0 statistics for a table |
|
@@ 9375-9385 (lines=11) @@ | ||
9372 | * @param $table The table to fetch stats for |
|
9373 | * @return A recordset |
|
9374 | */ |
|
9375 | public function getStatsTableIO($table) |
|
9376 | { |
|
9377 | $c_schema = $this->_schema; |
|
9378 | $this->clean($c_schema); |
|
9379 | $this->clean($table); |
|
9380 | ||
9381 | $sql = "SELECT * FROM pg_statio_all_tables |
|
9382 | WHERE schemaname='{$c_schema}' AND relname='{$table}'"; |
|
9383 | ||
9384 | return $this->selectSet($sql); |
|
9385 | } |
|
9386 | ||
9387 | /** |
|
9388 | * Fetches tuple statistics for all indexes on a table |
|
@@ 9393-9403 (lines=11) @@ | ||
9390 | * @param $table The table to fetch index stats for |
|
9391 | * @return A recordset |
|
9392 | */ |
|
9393 | public function getStatsIndexTuples($table) |
|
9394 | { |
|
9395 | $c_schema = $this->_schema; |
|
9396 | $this->clean($c_schema); |
|
9397 | $this->clean($table); |
|
9398 | ||
9399 | $sql = "SELECT * FROM pg_stat_all_indexes |
|
9400 | WHERE schemaname='{$c_schema}' AND relname='{$table}' ORDER BY indexrelname"; |
|
9401 | ||
9402 | return $this->selectSet($sql); |
|
9403 | } |
|
9404 | ||
9405 | /** |
|
9406 | * Fetches I/0 statistics for all indexes on a table |
|
@@ 9411-9422 (lines=12) @@ | ||
9408 | * @param $table The table to fetch index stats for |
|
9409 | * @return A recordset |
|
9410 | */ |
|
9411 | public function getStatsIndexIO($table) |
|
9412 | { |
|
9413 | $c_schema = $this->_schema; |
|
9414 | $this->clean($c_schema); |
|
9415 | $this->clean($table); |
|
9416 | ||
9417 | $sql = "SELECT * FROM pg_statio_all_indexes |
|
9418 | WHERE schemaname='{$c_schema}' AND relname='{$table}' |
|
9419 | ORDER BY indexrelname"; |
|
9420 | ||
9421 | return $this->selectSet($sql); |
|
9422 | } |
|
9423 | ||
9424 | public function hasAggregateSortOp() |
|
9425 | { |
@@ 373-391 (lines=19) @@ | ||
370 | * @param $table The name of the table |
|
371 | * @return A recordset |
|
372 | */ |
|
373 | public function getTable($table) |
|
374 | { |
|
375 | $c_schema = $this->_schema; |
|
376 | $this->clean($c_schema); |
|
377 | $this->clean($table); |
|
378 | ||
379 | $sql = " |
|
380 | SELECT |
|
381 | c.relname, n.nspname, u.usename AS relowner, |
|
382 | pg_catalog.obj_description(c.oid, 'pg_class') AS relcomment |
|
383 | FROM pg_catalog.pg_class c |
|
384 | LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner |
|
385 | LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |
|
386 | WHERE c.relkind = 'r' |
|
387 | AND n.nspname = '{$c_schema}' |
|
388 | AND c.relname = '{$table}'"; |
|
389 | ||
390 | return $this->selectSet($sql); |
|
391 | } |
|
392 | ||
393 | /** |
|
394 | * Return all tables in current database (and schema) |
@@ 171-195 (lines=25) @@ | ||
168 | * @param $basetype The input data type of the aggregate |
|
169 | * @return A recordset |
|
170 | */ |
|
171 | public function getAggregate($name, $basetype) |
|
172 | { |
|
173 | $c_schema = $this->_schema; |
|
174 | $this->clean($c_schema); |
|
175 | $this->clean($name); |
|
176 | $this->clean($basetype); |
|
177 | ||
178 | $sql = " |
|
179 | SELECT p.proname, |
|
180 | CASE p.proargtypes[0] |
|
181 | WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype THEN NULL |
|
182 | ELSE pg_catalog.format_type(p.proargtypes[0], NULL) |
|
183 | END AS proargtypes, a.aggtransfn, format_type(a.aggtranstype, NULL) AS aggstype, |
|
184 | a.aggfinalfn, a.agginitval, u.usename, pg_catalog.obj_description(p.oid, 'pg_proc') AS aggrcomment |
|
185 | FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n, pg_catalog.pg_user u, pg_catalog.pg_aggregate a |
|
186 | WHERE n.oid = p.pronamespace AND p.proowner=u.usesysid AND p.oid=a.aggfnoid |
|
187 | AND p.proisagg AND n.nspname='{$c_schema}' |
|
188 | AND p.proname='{$name}' |
|
189 | AND CASE p.proargtypes[0] |
|
190 | WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype THEN '' |
|
191 | ELSE pg_catalog.format_type(p.proargtypes[0], NULL) |
|
192 | END ='{$basetype}'"; |
|
193 | ||
194 | return $this->selectSet($sql); |
|
195 | } |
|
196 | ||
197 | // Sequence functions |
|
198 |
@@ 131-152 (lines=22) @@ | ||
128 | * @param \PHPPgAdmin\Database\The|string $table The name of a table whose triggers to retrieve |
|
129 | * @return \PHPPgAdmin\Database\A recordset |
|
130 | */ |
|
131 | public function getTriggers($table = '') |
|
132 | { |
|
133 | $c_schema = $this->_schema; |
|
134 | $this->clean($c_schema); |
|
135 | $this->clean($table); |
|
136 | ||
137 | $sql = "SELECT |
|
138 | t.tgname, pg_catalog.pg_get_triggerdef(t.oid) AS tgdef, t.tgenabled, p.oid AS prooid, |
|
139 | p.proname || ' (' || pg_catalog.oidvectortypes(p.proargtypes) || ')' AS proproto, |
|
140 | ns.nspname AS pronamespace |
|
141 | FROM pg_catalog.pg_trigger t, pg_catalog.pg_proc p, pg_catalog.pg_namespace ns |
|
142 | WHERE t.tgrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}' |
|
143 | AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{$c_schema}')) |
|
144 | AND (NOT tgisconstraint OR NOT EXISTS |
|
145 | (SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c |
|
146 | ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) |
|
147 | WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f')) |
|
148 | AND p.oid=t.tgfoid |
|
149 | AND p.pronamespace = ns.oid"; |
|
150 | ||
151 | return $this->selectSet($sql); |
|
152 | } |
|
153 | ||
154 | // Function functions |
|
155 |