summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Treat2018-10-27 13:58:25 +0000
committerRobert Treat2018-10-27 13:58:25 +0000
commitdd5958d5ed5e10f51320aac7952cb60a3a547077 (patch)
treee1f58c751c5d03a417d74f5f13ca8f4f44eb4a33
parentc7c6beb7d9f98ff50c0efa3911f1a2d86a5eed95 (diff)
Add support for Postgres 9.6, 10, 11, and 12. Verify tests passing on all supported versions.
-rwxr-xr-xclasses/database/Connection.php9
-rwxr-xr-xclasses/database/Postgres.php30
-rw-r--r--classes/database/Postgres10.php30
-rw-r--r--classes/database/Postgres11.php30
-rw-r--r--classes/database/Postgres95.php55
-rw-r--r--classes/database/Postgres96.php57
6 files changed, 200 insertions, 11 deletions
diff --git a/classes/database/Connection.php b/classes/database/Connection.php
index f20b47fa..eb22cd21 100755
--- a/classes/database/Connection.php
+++ b/classes/database/Connection.php
@@ -75,8 +75,15 @@ class Connection {
$description = "PostgreSQL {$version}";
// Detect version and choose appropriate database driver
+ switch (substr($version,0,2)) {
+ case '10': return 'Postgres10';break;
+ case '11': return 'Postgres11';break;
+ case '12': return 'Postgres';break;
+ }
+
switch (substr($version,0,3)) {
- case '9.5': return 'Postgres'; break;
+ case '9.6': return 'Postgres96'; break;
+ case '9.5': return 'Postgres95'; break;
case '9.4': return 'Postgres94'; break;
case '9.3': return 'Postgres93'; break;
case '9.2': return 'Postgres92'; break;
diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php
index 7b3b8f53..ee19990f 100755
--- a/classes/database/Postgres.php
+++ b/classes/database/Postgres.php
@@ -11,7 +11,7 @@ include_once('./classes/database/ADODB_base.php');
class Postgres extends ADODB_base {
- var $major_version = 9.5;
+ var $major_version = 12;
// Max object name length
var $_maxNameLen = 63;
// Store the current schema
@@ -2639,14 +2639,20 @@ class Postgres extends ADODB_base {
$this->fieldClean($sequence);
$this->clean($c_sequence);
- $sql = "
- SELECT c.relname AS seqname, s.*,
- pg_catalog.obj_description(s.tableoid, 'pg_class') AS seqcomment,
+ $sql = "
+ SELECT
+ c.relname AS seqname, s.*,
+ m.seqstart AS start_value, m.seqincrement AS increment_by, m.seqmax AS max_value, m.seqmin AS min_value,
+ m.seqcache AS cache_value, m.seqcycle AS is_cycled,
+ pg_catalog.obj_description(m.seqrelid, 'pg_class') AS seqcomment,
u.usename AS seqowner, n.nspname
- FROM \"{$sequence}\" AS s, pg_catalog.pg_class c, pg_catalog.pg_user u, pg_catalog.pg_namespace n
- WHERE c.relowner=u.usesysid AND c.relnamespace=n.oid
- AND c.relname = '{$c_sequence}' AND c.relkind = 'S' AND n.nspname='{$c_schema}'
- AND n.oid = c.relnamespace";
+ FROM
+ \"{$sequence}\" AS s, pg_catalog.pg_sequence m,
+ pg_catalog.pg_class c, pg_catalog.pg_user u, pg_catalog.pg_namespace n
+ WHERE
+ c.relowner=u.usesysid AND c.relnamespace=n.oid
+ AND c.oid = m.seqrelid AND c.relname = '{$c_sequence}' AND c.relkind = 'S' AND n.nspname='{$c_schema}'
+ AND n.oid = c.relnamespace";
return $this->selectSet( $sql );
}
@@ -7205,13 +7211,17 @@ class Postgres extends ADODB_base {
*/
function getProcesses($database = null) {
if ($database === null)
- $sql = "SELECT datname, usename, pid, waiting, state_change as query_start,
+ $sql = "SELECT datname, usename, pid,
+ case when wait_event is null then 'false' else wait_event_type || '::' || wait_event end as waiting,
+ query_start, application_name, client_addr,
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 = "SELECT datname, usename, pid, waiting, state_change as query_start,
+ $sql = "SELECT datname, usename, pid,
+ case when wait_event is null then 'false' else wait_event_type || '::' || wait_event end as waiting,
+ query_start, application_name, client_addr,
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='{$database}'
diff --git a/classes/database/Postgres10.php b/classes/database/Postgres10.php
new file mode 100644
index 00000000..5f851d80
--- /dev/null
+++ b/classes/database/Postgres10.php
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * PostgreSQL 10 support
+ *
+ */
+
+include_once('./classes/database/Postgres11.php');
+
+class Postgres10 extends Postgres11 {
+
+ var $major_version = 10;
+
+ /**
+ * Constructor
+ * @param $conn The database connection
+ */
+ function Postgres10($conn) {
+ $this->Postgres($conn);
+ }
+
+ // Help functions
+
+ function getHelpPages() {
+ include_once('./help/PostgresDoc10.php');
+ return $this->help_page;
+ }
+
+}
+?>
diff --git a/classes/database/Postgres11.php b/classes/database/Postgres11.php
new file mode 100644
index 00000000..2a3ae84b
--- /dev/null
+++ b/classes/database/Postgres11.php
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * PostgreSQL 11 support
+ *
+ */
+
+include_once('./classes/database/Postgres.php');
+
+class Postgres11 extends Postgres {
+
+ var $major_version = 11;
+
+ /**
+ * Constructor
+ * @param $conn The database connection
+ */
+ function Postgres11($conn) {
+ $this->Postgres($conn);
+ }
+
+ // Help functions
+
+ function getHelpPages() {
+ include_once('./help/PostgresDoc11.php');
+ return $this->help_page;
+ }
+
+}
+?>
diff --git a/classes/database/Postgres95.php b/classes/database/Postgres95.php
new file mode 100644
index 00000000..0120e550
--- /dev/null
+++ b/classes/database/Postgres95.php
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * PostgreSQL 9.5 support
+ *
+ */
+
+include_once('./classes/database/Postgres96.php');
+
+class Postgres95 extends Postgres96 {
+
+ var $major_version = 9.5;
+
+ /**
+ * Constructor
+ * @param $conn The database connection
+ */
+ function Postgres95($conn) {
+ $this->Postgres($conn);
+ }
+
+ // Help functions
+
+ function getHelpPages() {
+ include_once('./help/PostgresDoc95.php');
+ return $this->help_page;
+ }
+
+
+ /**
+ * Returns all available process information.
+ * @param $database (optional) Find only connections to specified database
+ * @return A recordset
+ */
+ function getProcesses($database = null) {
+ if ($database === null)
+ $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 = "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='{$database}'
+ ORDER BY usename, pid";
+ }
+
+ return $this->selectSet($sql);
+ }
+
+
+}
+?>
diff --git a/classes/database/Postgres96.php b/classes/database/Postgres96.php
new file mode 100644
index 00000000..19397e15
--- /dev/null
+++ b/classes/database/Postgres96.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * PostgreSQL 9.6 support
+ *
+ */
+
+include_once('./classes/database/Postgres10.php');
+
+class Postgres96 extends Postgres10 {
+
+ var $major_version = 9.6;
+
+ /**
+ * Constructor
+ * @param $conn The database connection
+ */
+ function Postgres96($conn) {
+ $this->Postgres($conn);
+ }
+
+ // Help functions
+
+ function getHelpPages() {
+ include_once('./help/PostgresDoc96.php');
+ return $this->help_page;
+ }
+
+ // Sequence functions
+
+ /**
+ * Returns properties of a single sequence
+ * @param $sequence Sequence name
+ * @return A recordset
+ */
+ function getSequence($sequence) {
+ $c_schema = $this->_schema;
+ $this->clean($c_schema);
+ $c_sequence = $sequence;
+ $this->fieldClean($sequence);
+ $this->clean($c_sequence);
+
+ $sql = "
+ SELECT c.relname AS seqname, s.*,
+ pg_catalog.obj_description(s.tableoid, 'pg_class') AS seqcomment,
+ u.usename AS seqowner, n.nspname
+ FROM \"{$sequence}\" AS s, pg_catalog.pg_class c, pg_catalog.pg_user u, pg_catalog.pg_namespace n
+ WHERE c.relowner=u.usesysid AND c.relnamespace=n.oid
+ AND c.relname = '{$c_sequence}' AND c.relkind = 'S' AND n.nspname='{$c_schema}'
+ AND n.oid = c.relnamespace";
+
+ return $this->selectSet( $sql );
+ }
+
+
+}
+?>