Passed
Push — develop ( c8a800...ec36d3 )
by Felipe
06:08
created

Postgres11   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 40 3
1
<?php
2
3
/**
4
 * PHPPgAdmin v6.0.0-beta.51
5
 */
6
7
namespace PHPPgAdmin\Database;
8
9
/**
10
 * @file
11
 * PostgreSQL 11.x support
12
 */
13
/**
14
 * Class to add support for Postgres10.
15
 */
16
class Postgres11 extends Postgres10
17
{
18
    public $major_version = 11;
19
20
    /**
21
     * Returns a list of all functions in the database.
22
     * In PG 11 proagg was replaced with prokind.
23
     *
24
     * @see https://www.postgresql.org/docs/11/catalog-pg-proc.html
25
     *
26
     * @param bool  $all  If true, will find all available functions, if false just those in search path
27
     * @param mixed $type If truthy, will return functions of type trigger
28
     *
29
     * @return \PHPPgAdmin\ADORecordSet All functions
30
     */
31
    public function getFunctions($all = false, $type = null)
32
    {
33
        if ($all) {
34
            $where    = 'pg_catalog.pg_function_is_visible(p.oid)';
35
            $distinct = 'DISTINCT ON (p.proname)';
36
37
            if ($type) {
38
                $where .= " AND p.prorettype = (select oid from pg_catalog.pg_type p where p.typname = 'trigger') ";
39
            }
40
        } else {
41
            $c_schema = $this->_schema;
42
            $this->clean($c_schema);
43
            $where    = "n.nspname = '{$c_schema}'";
44
            $distinct = '';
45
        }
46
47
        $sql = "
48
            SELECT
49
                {$distinct}
50
                p.oid AS prooid,
51
                p.proname,
52
                p.proretset,
53
                pg_catalog.format_type(p.prorettype, NULL) AS proresult,
54
                pg_catalog.oidvectortypes(p.proargtypes) AS proarguments,
55
                pl.lanname AS prolanguage,
56
                pg_catalog.obj_description(p.oid, 'pg_proc') AS procomment,
57
                p.proname || ' (' || pg_catalog.oidvectortypes(p.proargtypes) || ')' AS proproto,
58
                CASE WHEN p.proretset THEN 'setof ' ELSE '' END || pg_catalog.format_type(p.prorettype, NULL) AS proreturns,
59
                coalesce(u.usename::text,p.proowner::text) AS proowner
60
61
            FROM pg_catalog.pg_proc p
62
                INNER JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
63
                INNER JOIN pg_catalog.pg_language pl ON pl.oid = p.prolang
64
                LEFT JOIN pg_catalog.pg_user u ON u.usesysid = p.proowner
65
            WHERE p.prokind !='a'
66
                AND {$where}
67
            ORDER BY p.proname, proresult
68
            ";
69
70
        return $this->selectSet($sql);
71
    }
72
}
73