Removes useless call of function_exists since we are PHP5+ only
authorJehan-Guillaume (ioguix) de Rorthais <jgdr@dalibo.com>
Fri, 3 Jun 2011 17:19:32 +0000 (19:19 +0200)
committerJehan-Guillaume (ioguix) de Rorthais <jgdr@dalibo.com>
Fri, 3 Jun 2011 17:19:32 +0000 (19:19 +0200)
classes/database/Connection.php
classes/database/Postgres.php
classes/database/Postgres74.php
libraries/decorator.inc.php
libraries/lib.inc.php

index f98871b7301839befd6fd2e2c596179505427554..16b2abc7c0ad78bbcda8146e797efd5294792726 100755 (executable)
@@ -51,13 +51,9 @@ class Connection {
         * @return -3 Database-specific failure
         */
        function getDriver(&$description) {
-               // If we're on a recent enough PHP 5, and against PostgreSQL 7.4 or
-               // higher, we don't need to query for the version.  This gives a great
-               // speed up.                            
-               if (function_exists('pg_version')) {
-                       $v = pg_version($this->conn->_connectionID);
-                       if (isset($v['server'])) $version = $v['server'];                       
-               }
+
+               $v = pg_version($this->conn->_connectionID);
+               if (isset($v['server'])) $version = $v['server'];
                
                // If we didn't manage to get the version without a query, query...
                if (!isset($version)) {
@@ -105,10 +101,7 @@ class Connection {
         * @return Error string
         */
        function getLastError() {               
-               if (function_exists('pg_errormessage'))
-                       return pg_errormessage($this->conn->_connectionID);
-               else
-                       return pg_last_error($this->conn->_connectionID);
+               return pg_last_error($this->conn->_connectionID);
        }
 }
 
index 456b12684e75eef405b5ff67cfbdb9aca1ee15c9..e63127550ece870c62514e5f51a2b796a9a99298 100755 (executable)
@@ -183,10 +183,7 @@ class Postgres extends ADODB_base {
        function clean(&$str) {
                if ($str === null) return null;
                $str = str_replace("\r\n","\n",$str);
-               if (function_exists('pg_escape_string'))
-                       $str = pg_escape_string($str);
-               else
-                       $str = addslashes($str);
+               $str = pg_escape_string($str);
                return $str;
        }
 
@@ -222,10 +219,7 @@ class Postgres extends ADODB_base {
        function arrayClean(&$arr) {
                foreach ($arr as $k => $v) {
                        if ($v === null) continue;
-                       if (function_exists('pg_escape_string'))
-                               $arr[$k] = pg_escape_string($v);
-                       else
-                               $arr[$k] = addslashes($v);
+                       $arr[$k] = pg_escape_string($v);
                }
                return $arr;
        }
@@ -236,12 +230,7 @@ class Postgres extends ADODB_base {
         * @return Data formatted for on-screen display
         */
        function escapeBytea($data) {
-               if (function_exists('pg_escape_bytea'))
-                       return stripslashes(pg_escape_bytea($data));
-               else {
-                               $translations = array('\\a' => '\\007', '\\b' => '\\010', '\\t' => '\\011', '\\n' => '\\012', '\\v' => '\\013', '\\f' => '\\014', '\\r' => '\\015');
-                               return strtr(addCSlashes($data, "\0..\37\177..\377"), $translations);
-               }
+               return stripslashes(pg_escape_bytea($data));
        }
 
        /**
@@ -518,15 +507,7 @@ class Postgres extends ADODB_base {
         * @return The encoding.  eg. SQL_ASCII, UTF-8, etc.
         */
        function getDatabaseEncoding() {
-               // Try to avoid a query if at all possible (5)
-               if (function_exists('pg_parameter_status')) {
-                       $encoding = pg_parameter_status($this->conn->_connectionID, 'server_encoding');
-                       if ($encoding !== false) return $encoding;
-               }
-
-               $sql = "SELECT getdatabaseencoding() AS encoding";
-
-               return $this->selectField($sql, 'encoding');
+               return pg_parameter_status($this->conn->_connectionID, 'server_encoding');
        }
 
        /**
@@ -534,11 +515,6 @@ class Postgres extends ADODB_base {
         * @return default_with_oids setting
         */
        function getDefaultWithOid() {
-               // Try to avoid a query if at all possible (5)
-               if (function_exists('pg_parameter_status')) {
-                       $default = pg_parameter_status($this->conn->_connectionID, 'default_with_oids');
-                       if ($default !== false) return $default;
-               }
 
                $sql = "SHOW default_with_oids";
 
@@ -7552,12 +7528,10 @@ class Postgres extends ADODB_base {
                                        $query_buf .= $subline;
                                        $query_buf .= ';';
 
-                               // Execute the query (supporting 4.1.x PHP...). PHP cannot execute
+                                               // Execute the query. PHP cannot execute
                                // empty queries, unlike libpq
-                               if (function_exists('pg_query'))
-                                       $res = @pg_query($conn, $query_buf);
-                               else
-                                       $res = @pg_exec($conn, $query_buf);
+                                               $res = @pg_query($conn, $query_buf);
+
                                                // Call the callback function for display
                                                if ($callback !== null) $callback($query_buf, $res, $lineno);
                                // Check for COPY request
@@ -7578,7 +7552,7 @@ class Postgres extends ADODB_base {
                                        $query_start = $i + $thislen;
                        }
 
-                       /*
+                               /*
                                 * keyword or identifier?
                                 * We grab the whole string so that we don't
                                 * mistakenly see $foo$ inside an identifier as the start
@@ -7617,11 +7591,9 @@ class Postgres extends ADODB_base {
                 */
        if (strlen($query_buf) > 0 && strspn($query_buf, " \t\n\r") != strlen($query_buf))
        {
-                       // Execute the query (supporting 4.1.x PHP...)
-                       if (function_exists('pg_query'))
-                               $res = @pg_query($conn, $query_buf);
-                       else
-                               $res = @pg_exec($conn, $query_buf);
+                       // Execute the query
+                       $res = @pg_query($conn, $query_buf);
+
                        // Call the callback function for display
                        if ($callback !== null) $callback($query_buf, $res, $lineno);
                        // Check for COPY request
index 665028604d791f8236c029d07b7b093c48681c5c..4310eb642e63d07bacd43981f3e3d03588a9e39c 100644 (file)
@@ -251,8 +251,6 @@ class Postgres74 extends Postgres80 {
                return $this->selectSet($sql);
        }
 
-       // Database functions
-
        /**
         * Returns table locks information in the current database
         * @return A recordset
@@ -273,6 +271,16 @@ class Postgres74 extends Postgres80 {
                return $this->selectSet($sql);
        }
 
+       /**
+        * Returns the current database encoding
+        * @return The encoding.  eg. SQL_ASCII, UTF-8, etc.
+        */
+       function getDatabaseEncoding() {
+               $sql = "SELECT getdatabaseencoding() AS encoding";
+
+               return $this->selectField($sql, 'encoding');
+       }
+
        // Table functions
 
        /**
index 38642cdab5255e20db84834d491ad3a74a32276c..fec8f75e80d6806217a2e9220edc45bce47e0568 100644 (file)
@@ -7,13 +7,6 @@
 
 ###TODO: Better documentation!!!
 
-// Compatibility functions:
-if (!function_exists('is_a')) {
-       function is_a($object, $class) {
-               return is_object($object) && get_class($object) == strtolower($class) || is_subclass_of($object, $class);
-       }
-}
-
 // Construction functions:
 
 function field($fieldName, $default = null) {
index 250d1bf320661e56c588175370d537c7f7c78bc5..5e5b7fda7a449e65d9b0da79ca10f69e27060d9d 100644 (file)
                // Set client encoding to database encoding
                if ($dbEncoding != '') {
                        // Explicitly change client encoding if it's different to server encoding.
-                       if (function_exists('pg_client_encoding'))
-                               $currEncoding = pg_client_encoding($data->conn->_connectionID);
-                       elseif (function_exists('pg_clientencoding'))
-                               $currEncoding = pg_clientencoding($data->conn->_connectionID);
-                       else
-                               $currEncoding = null;
+                       $currEncoding = pg_client_encoding($data->conn->_connectionID);
 
                        if ($currEncoding != $dbEncoding) {
                                $status = $data->setClientEncoding($dbEncoding);