1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPPgAdmin v6.0.0-beta.48 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Database; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @file |
11
|
|
|
* PostgreSQL 9.6 support |
12
|
|
|
*/ |
13
|
|
|
class Postgres96 extends Postgres |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
public $typIndexes = ['BTREE', 'BRIN', 'RTREE', 'GIST', 'GIN', 'HASH', 'SP-GIST']; |
16
|
|
|
public $major_version = 9.6; |
17
|
|
|
|
18
|
|
|
// Administration functions |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Returns all available process information. |
22
|
|
|
* |
23
|
|
|
* @param null|string $database (optional) Find only connections to specified database |
24
|
|
|
* |
25
|
|
|
* @return \PHPPgAdmin\ADORecordSet A recordset |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
public function getProcesses($database = null) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
if ($database === null) { |
30
|
|
|
$sql = "SELECT datid, datname, pid, usename, application_name, client_addr, state, wait_event_type, wait_event, state_change as query_start, |
31
|
|
|
CASE |
32
|
|
|
WHEN state='active' THEN query |
33
|
|
|
ELSE state |
34
|
|
|
END AS query |
35
|
|
|
FROM pg_catalog.pg_stat_activity |
36
|
|
|
ORDER BY datname, usename, pid"; |
37
|
|
|
} else { |
38
|
|
|
$this->clean($database); |
39
|
|
|
$sql = "SELECT datid, datname, pid, usename, application_name, client_addr, state, wait_event_type, wait_event, state_change as query_start, |
40
|
|
|
CASE |
41
|
|
|
WHEN state='active' THEN query |
42
|
|
|
ELSE state |
43
|
|
|
END AS query |
44
|
|
|
FROM pg_catalog.pg_stat_activity |
45
|
|
|
WHERE datname='{$database}' |
46
|
|
|
ORDER BY usename, pid"; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $this->selectSet($sql); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function hasUserSignals() |
53
|
|
|
{ |
54
|
|
|
return true; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Creates a new user. As of PG 9.6, CREATEUSER privilege has been deprecated. |
59
|
|
|
* |
60
|
|
|
* @see {@link https://www.postgresql.org/docs/9.6/static/sql-createrole.html} |
61
|
|
|
* |
62
|
|
|
* @param string $username The username of the user to create |
63
|
|
|
* @param string $password A password for the user |
64
|
|
|
* @param bool $createdb boolean Whether or not the user can create databases |
65
|
|
|
* @param bool $createrole boolean Whether or not the user can create other users |
66
|
|
|
* @param string $expiry string Format 'YYYY-MM-DD HH:MM:SS'. '' means never expire |
67
|
|
|
* @param array $groups The groups to create the user in |
68
|
|
|
* |
69
|
|
|
* @return int 0 if operation was successful |
|
|
|
|
70
|
|
|
* |
71
|
|
|
* @internal param $group (array) The groups to create the user in |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function createUser($username, $password, $createdb, $createrole, $expiry, $groups) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$enc = $this->_encryptPassword($username, $password); |
76
|
|
|
$this->fieldClean($username); |
77
|
|
|
$this->clean($enc); |
78
|
|
|
$this->clean($expiry); |
79
|
|
|
$this->fieldArrayClean($groups); |
80
|
|
|
|
81
|
|
|
$sql = "CREATE USER \"{$username}\""; |
82
|
|
|
if ($password != '') { |
83
|
|
|
$sql .= " WITH ENCRYPTED PASSWORD '{$enc}'"; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$sql .= $createdb ? ' CREATEDB' : ' NOCREATEDB'; |
87
|
|
|
$sql .= $createrole ? ' CREATEROLE' : ' NOCREATEROLE'; |
88
|
|
|
if (is_array($groups) && sizeof($groups) > 0) { |
89
|
|
|
$sql .= ' IN GROUP "'.join('", "', $groups).'"'; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ($expiry != '') { |
93
|
|
|
$sql .= " VALID UNTIL '{$expiry}'"; |
94
|
|
|
} else { |
95
|
|
|
$sql .= " VALID UNTIL 'infinity'"; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $this->execute($sql); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.