Add support for Postgres 9.6, 10, 11, and 12. Verify tests passing on all supported...
authorRobert Treat <rob@xzilla.net>
Fri, 26 Oct 2018 19:10:40 +0000 (15:10 -0400)
committerRobert Treat <rob@xzilla.net>
Fri, 26 Oct 2018 19:10:40 +0000 (15:10 -0400)
classes/database/Connection.php
classes/database/Postgres.php
classes/database/Postgres10.php [new file with mode: 0644]
classes/database/Postgres11.php [new file with mode: 0644]
classes/database/Postgres95.php [new file with mode: 0644]
classes/database/Postgres96.php [new file with mode: 0644]

index f20b47fa347e044c6920942e34621e106dc8279f..eb22cd2152c98d1e0eb3d01fdb41d91da1ee8fc7 100755 (executable)
@@ -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;
index 7b3b8f530b0e519441dae23b33717c262be243f5..ee19990f29ff8477d1b15d40c92d180acaa2d3f8 100755 (executable)
@@ -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 (file)
index 0000000..5f851d8
--- /dev/null
@@ -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 (file)
index 0000000..2a3ae84
--- /dev/null
@@ -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 (file)
index 0000000..0120e55
--- /dev/null
@@ -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 (file)
index 0000000..19397e1
--- /dev/null
@@ -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 );
+       }
+
+
+}
+?>