Passed
Push — master ( f90c9d...ec36d3 )
by Felipe
12:09 queued 06:02
created

Postgres10::getTables()   A

Complexity

Conditions 6
Paths 2

Size

Total Lines 39
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 14
nc 2
nop 0
dl 0
loc 39
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * PHPPgAdmin v6.0.0-beta.51
5
 */
6
7
namespace PHPPgAdmin\Database;
8
9
/**
10
 * @file
11
 * PostgreSQL 10.x support
12
 *
13
 * @todo add support for identify columns
14
 *
15
 * @see https://blog.2ndquadrant.com/postgresql-10-identity-columns/
16
 */
17
18
/**
19
 * Class to add support for Postgres10.
20
 */
21
class Postgres10 extends Postgres96
22
{
23
    public $major_version = 10;
24
25
    /**
26
     * Return all tables in current database (and schema).
27
     *
28
     * @return \PHPPgAdmin\ADORecordSet All tables, sorted alphabetically
29
     */
30
    public function getTables()
31
    {
32
        $c_schema = $this->_schema;
33
        $this->clean($c_schema);
34
35
        $sql = "
36
                SELECT c.relname,
37
                    pg_catalog.pg_get_userbyid(c.relowner) AS relowner,
38
                    pg_catalog.obj_description(c.oid, 'pg_class') AS relcomment,
39
                    reltuples::bigint as reltuples,
40
                    pt.spcname as tablespace, ";
41
42
        /*
43
         * Either display_sizes is true for tables and schemas,
44
         * or we must check if said config is an associative array
45
         */
46
        if (isset($this->conf['display_sizes']) &&
47
            (
48
                $this->conf['display_sizes'] === true ||
49
                (
50
                    is_array($this->conf['display_sizes']) &&
51
                    array_key_exists('tables', $this->conf['display_sizes']) &&
52
                    $this->conf['display_sizes']['tables'] === true
53
                )
54
            )
55
        ) {
56
            $sql .= ' pg_size_pretty(pg_total_relation_size(c.oid)) as table_size ';
57
        } else {
58
            $sql .= "   'N/A' as table_size ";
59
        }
60
61
        $sql .= " FROM pg_catalog.pg_class c
62
                LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
63
                LEFT JOIN  pg_catalog.pg_tablespace pt ON  pt.oid=c.reltablespace
64
                WHERE c.relkind IN ('r','p')
65
                AND nspname='{$c_schema}'
66
                ORDER BY c.relname";
67
68
        return $this->selectSet($sql);
69
    }
70
}
71