Skip to content

Commit

Permalink
Removes useless call of function_exists since we are PHP5+ only
Browse files Browse the repository at this point in the history
  • Loading branch information
ioguix committed Jun 3, 2011
1 parent 0e8c2bf commit 24f83bb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 65 deletions.
15 changes: 4 additions & 11 deletions classes/database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,9 @@ function Connection($host, $port, $sslmode, $user, $password, $database, $fetchM
* @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)) {
Expand Down Expand Up @@ -105,10 +101,7 @@ function getDriver(&$description) {
* @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);
}
}

Expand Down
50 changes: 11 additions & 39 deletions classes/database/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ function Postgres($conn) {
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;
}

Expand Down Expand Up @@ -222,10 +219,7 @@ function fieldArrayClean(&$arr) {
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;
}
Expand All @@ -236,12 +230,7 @@ function arrayClean(&$arr) {
* @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));
}

/**
Expand Down Expand Up @@ -518,27 +507,14 @@ function getDatabaseOwner($database) {
* @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');
}

/**
* Returns the current default_with_oids setting
* @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";

Expand Down Expand Up @@ -7552,12 +7528,10 @@ function executeScript($name, $callback = null) {
$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
Expand All @@ -7578,7 +7552,7 @@ function executeScript($name, $callback = null) {
$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
Expand Down Expand Up @@ -7617,11 +7591,9 @@ function executeScript($name, $callback = null) {
*/
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
Expand Down
12 changes: 10 additions & 2 deletions classes/database/Postgres74.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ function findObject($term, $filter) {
return $this->selectSet($sql);
}

// Database functions

/**
* Returns table locks information in the current database
* @return A recordset
Expand All @@ -273,6 +271,16 @@ function getLocks() {
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

/**
Expand Down
7 changes: 0 additions & 7 deletions libraries/decorator.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 1 addition & 6 deletions libraries/lib.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 24f83bb

Please sign in to comment.