Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Postgres92.php « database « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ee3ccade5d08c045fa7b1a3967b5a06e2b889178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php

/**
 * PHPPgAdmin 6.1.3
 */

namespace PHPPgAdmin\Database;

use PHPPgAdmin\ADORecordSet;
use PHPPgAdmin\Help\PostgresDoc92;

/**
 * @file
 * PostgreSQL 9.2 support
 */
class Postgres92 extends Postgres93
{
    public $typIndexes = ['BTREE', 'RTREE', 'GIST', 'GIN', 'HASH'];

    /**
     * @var float
     */
    public $major_version = 9.2;

    /**
     * @var class-string
     */
    public $help_classname = PostgresDoc92::class;

    /**
     * Returns all available process information.
     *
     * @param null|string $database (optional) Find only connections to specified database
     *
     * @return ADORecordSet|int A recordset
     */
    public function getProcesses($database = null)
    {
        if (null === $database) {
            $sql = "SELECT datname, usename, pid, waiting, state_change as query_start,
                  case when state='idle in transaction' then '<IDLE> in transaction' when state = 'idle' then '<IDLE>' else query end as query
				FROM pg_catalog.pg_stat_activity
				ORDER BY datname, usename, pid";
        } else {
            $this->clean($database);
            $sql = \sprintf(
                'SELECT datname, usename, pid, waiting, state_change as query_start,
                  case when state=\'idle in transaction\' then \'<IDLE> in transaction\' when state = \'idle\' then \'<IDLE>\' else query end as query
				FROM pg_catalog.pg_stat_activity
				WHERE datname=\'%s\'
				ORDER BY usename, pid',
                $database
            );
        }

        return $this->selectSet($sql);
    }

    /**
     * Retrieves information for all tablespaces.
     *
     * @param bool $all Include all tablespaces (necessary when moving objects back to the default space)
     *
     * @return ADORecordSet|int A recordset
     */
    public function getTablespaces($all = false)
    {
        $conf = $this->conf;

        $sql = "SELECT spcname, pg_catalog.pg_get_userbyid(spcowner) AS spcowner, pg_catalog.pg_tablespace_location(oid) as spclocation,
                    (SELECT description FROM pg_catalog.pg_shdescription pd WHERE pg_tablespace.oid=pd.objoid AND pd.classoid='pg_tablespace'::regclass) AS spccomment
					FROM pg_catalog.pg_tablespace";

        if (!$conf['show_system'] && !$all) {
            $sql .= ' WHERE spcname NOT LIKE $$pg\_%$$';
        }

        $sql .= ' ORDER BY spcname';

        return $this->selectSet($sql);
    }

    // Misc functions

    /**
     * Retrieves a tablespace's information.
     *
     * @param string $spcname
     *
     * @return ADORecordSet|int A recordset
     */
    public function getTablespace($spcname)
    {
        $this->clean($spcname);

        $sql = \sprintf(
            'SELECT spcname, pg_catalog.pg_get_userbyid(spcowner) AS spcowner, pg_catalog.pg_tablespace_location(oid) as spclocation,
                    (SELECT description FROM pg_catalog.pg_shdescription pd WHERE pg_tablespace.oid=pd.objoid AND pd.classoid=\'pg_tablespace\'::regclass) AS spccomment
					FROM pg_catalog.pg_tablespace WHERE spcname=\'%s\'',
            $spcname
        );

        return $this->selectSet($sql);
    }
}