diff options
author | Jehan-Guillaume (ioguix) de Rorthais | 2011-06-03 17:19:32 +0000 |
---|---|---|
committer | Jehan-Guillaume (ioguix) de Rorthais | 2011-06-03 17:19:32 +0000 |
commit | 24f83bb50f41ad95d320e241ac0de58eec7a5367 (patch) | |
tree | c0662b8ad2786a01282af5fa982913c404091906 | |
parent | 0e8c2bf0b3020e6e1dfd2be8f5003bce627c0797 (diff) |
Removes useless call of function_exists since we are PHP5+ only
-rwxr-xr-x | classes/database/Connection.php | 15 | ||||
-rwxr-xr-x | classes/database/Postgres.php | 50 | ||||
-rw-r--r-- | classes/database/Postgres74.php | 12 | ||||
-rw-r--r-- | libraries/decorator.inc.php | 7 | ||||
-rw-r--r-- | libraries/lib.inc.php | 7 |
5 files changed, 26 insertions, 65 deletions
diff --git a/classes/database/Connection.php b/classes/database/Connection.php index f98871b7..16b2abc7 100755 --- a/classes/database/Connection.php +++ b/classes/database/Connection.php @@ -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); } } diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index 456b1268..e6312755 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -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 diff --git a/classes/database/Postgres74.php b/classes/database/Postgres74.php index 66502860..4310eb64 100644 --- a/classes/database/Postgres74.php +++ b/classes/database/Postgres74.php @@ -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 /** diff --git a/libraries/decorator.inc.php b/libraries/decorator.inc.php index 38642cda..fec8f75e 100644 --- a/libraries/decorator.inc.php +++ b/libraries/decorator.inc.php @@ -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) { diff --git a/libraries/lib.inc.php b/libraries/lib.inc.php index 250d1bf3..5e5b7fda 100644 --- a/libraries/lib.inc.php +++ b/libraries/lib.inc.php @@ -225,12 +225,7 @@ // 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); |