forked from GNUsocial/gnu-social
extlib/DB/DataObject - Fix PHP 7.3 Warning switch continue -> break
Also reformatted under PSR norms
This commit is contained in:
@@ -54,13 +54,13 @@ class DB_pgsql extends DB_common
|
||||
* The DB driver type (mysql, oci8, odbc, etc.)
|
||||
* @var string
|
||||
*/
|
||||
var $phptype = 'pgsql';
|
||||
public $phptype = 'pgsql';
|
||||
|
||||
/**
|
||||
* The database syntax variant to be used (db2, access, etc.), if any
|
||||
* @var string
|
||||
*/
|
||||
var $dbsyntax = 'pgsql';
|
||||
public $dbsyntax = 'pgsql';
|
||||
|
||||
/**
|
||||
* The capabilities of this DB implementation
|
||||
@@ -75,7 +75,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $features = array(
|
||||
public $features = array(
|
||||
'limit' => 'alter',
|
||||
'new_link' => '4.3.0',
|
||||
'numrows' => true,
|
||||
@@ -89,20 +89,20 @@ class DB_pgsql extends DB_common
|
||||
* A mapping of native error codes to DB error codes
|
||||
* @var array
|
||||
*/
|
||||
var $errorcode_map = array(
|
||||
public $errorcode_map = array(
|
||||
);
|
||||
|
||||
/**
|
||||
* The raw database connection created by PHP
|
||||
* @var resource
|
||||
*/
|
||||
var $connection;
|
||||
public $connection;
|
||||
|
||||
/**
|
||||
* The DSN information for connecting to a database
|
||||
* @var array
|
||||
*/
|
||||
var $dsn = array();
|
||||
public $dsn = array();
|
||||
|
||||
|
||||
/**
|
||||
@@ -110,7 +110,7 @@ class DB_pgsql extends DB_common
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $autocommit = true;
|
||||
public $autocommit = true;
|
||||
|
||||
/**
|
||||
* The quantity of transactions begun
|
||||
@@ -121,27 +121,27 @@ class DB_pgsql extends DB_common
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $transaction_opcount = 0;
|
||||
public $transaction_opcount = 0;
|
||||
|
||||
/**
|
||||
* The number of rows affected by a data manipulation query
|
||||
* @var integer
|
||||
*/
|
||||
var $affected = 0;
|
||||
public $affected = 0;
|
||||
|
||||
/**
|
||||
* The current row being looked at in fetchInto()
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $row = array();
|
||||
public $row = array();
|
||||
|
||||
/**
|
||||
* The number of rows in a given result set
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_num_rows = array();
|
||||
public $_num_rows = array();
|
||||
|
||||
|
||||
// }}}
|
||||
@@ -152,7 +152,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -187,12 +187,12 @@ class DB_pgsql extends DB_common
|
||||
* Example of connecting to a new link via a socket:
|
||||
* <code>
|
||||
* require_once 'DB.php';
|
||||
*
|
||||
*
|
||||
* $dsn = 'pgsql://user:pass@unix(/tmp)/dbname?new_link=true';
|
||||
* $options = array(
|
||||
* 'portability' => DB_PORTABILITY_ALL,
|
||||
* );
|
||||
*
|
||||
*
|
||||
* $db = DB::connect($dsn, $options);
|
||||
* if (PEAR::isError($db)) {
|
||||
* die($db->getMessage());
|
||||
@@ -206,7 +206,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @link http://www.postgresql.org/docs/current/static/libpq.html#LIBPQ-CONNECT
|
||||
*/
|
||||
function connect($dsn, $persistent = false)
|
||||
public function connect($dsn, $persistent = false)
|
||||
{
|
||||
if (!PEAR::loadExtension('pgsql')) {
|
||||
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
|
||||
@@ -262,8 +262,7 @@ class DB_pgsql extends DB_common
|
||||
}
|
||||
|
||||
if (isset($dsn['new_link'])
|
||||
&& ($dsn['new_link'] == 'true' || $dsn['new_link'] === true))
|
||||
{
|
||||
&& ($dsn['new_link'] == 'true' || $dsn['new_link'] === true)) {
|
||||
if (version_compare(phpversion(), '4.3.0', '>=')) {
|
||||
$params[] = PGSQL_CONNECT_FORCE_NEW;
|
||||
}
|
||||
@@ -274,19 +273,27 @@ class DB_pgsql extends DB_common
|
||||
$ini = ini_get('track_errors');
|
||||
$php_errormsg = '';
|
||||
if ($ini) {
|
||||
$this->connection = @call_user_func_array($connect_function,
|
||||
$params);
|
||||
$this->connection = @call_user_func_array(
|
||||
$connect_function,
|
||||
$params
|
||||
);
|
||||
} else {
|
||||
@ini_set('track_errors', 1);
|
||||
$this->connection = @call_user_func_array($connect_function,
|
||||
$params);
|
||||
$this->connection = @call_user_func_array(
|
||||
$connect_function,
|
||||
$params
|
||||
);
|
||||
@ini_set('track_errors', $ini);
|
||||
}
|
||||
|
||||
if (!$this->connection) {
|
||||
return $this->raiseError(DB_ERROR_CONNECT_FAILED,
|
||||
null, null, null,
|
||||
$php_errormsg);
|
||||
return $this->raiseError(
|
||||
DB_ERROR_CONNECT_FAILED,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$php_errormsg
|
||||
);
|
||||
}
|
||||
return DB_OK;
|
||||
}
|
||||
@@ -299,7 +306,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @return bool TRUE on success, FALSE on failure
|
||||
*/
|
||||
function disconnect()
|
||||
public function disconnect()
|
||||
{
|
||||
$ret = @pg_close($this->connection);
|
||||
$this->connection = null;
|
||||
@@ -318,7 +325,7 @@ class DB_pgsql extends DB_common
|
||||
* + the DB_OK constant for other successful queries
|
||||
* + a DB_Error object on failure
|
||||
*/
|
||||
function simpleQuery($query)
|
||||
public function simpleQuery($query)
|
||||
{
|
||||
$ismanip = $this->_checkManip($query);
|
||||
$this->last_query = $query;
|
||||
@@ -353,9 +360,10 @@ class DB_pgsql extends DB_common
|
||||
if ($ismanip) {
|
||||
$this->affected = @pg_affected_rows($result);
|
||||
return DB_OK;
|
||||
} elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW|WITH)\s/si',
|
||||
$query))
|
||||
{
|
||||
} elseif (preg_match(
|
||||
'/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW|WITH)\s/si',
|
||||
$query
|
||||
)) {
|
||||
$this->row[(int)$result] = 0; // reset the row counter.
|
||||
$numrows = $this->numRows($result);
|
||||
if (is_object($numrows)) {
|
||||
@@ -382,7 +390,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @return true if a result is available otherwise return false
|
||||
*/
|
||||
function nextResult($result)
|
||||
public function nextResult($result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -410,7 +418,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @see DB_result::fetchInto()
|
||||
*/
|
||||
function fetchInto($result, &$arr, $fetchmode, $rownum = null)
|
||||
public function fetchInto($result, &$arr, $fetchmode, $rownum = null)
|
||||
{
|
||||
$result_int = (int)$result;
|
||||
$rownum = ($rownum !== null) ? $rownum : $this->row[$result_int];
|
||||
@@ -454,7 +462,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @see DB_result::free()
|
||||
*/
|
||||
function freeResult($result)
|
||||
public function freeResult($result)
|
||||
{
|
||||
if (is_resource($result)) {
|
||||
unset($this->row[(int)$result]);
|
||||
@@ -477,7 +485,8 @@ class DB_pgsql extends DB_common
|
||||
* @see DB_common::quoteSmart()
|
||||
* @since Method available since release 1.7.8.
|
||||
*/
|
||||
function quoteBoolean($boolean) {
|
||||
public function quoteBoolean($boolean)
|
||||
{
|
||||
return $boolean ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
@@ -497,7 +506,7 @@ class DB_pgsql extends DB_common
|
||||
* @see DB_common::quoteSmart()
|
||||
* @since Method available since Release 1.6.0
|
||||
*/
|
||||
function escapeSimple($str)
|
||||
public function escapeSimple($str)
|
||||
{
|
||||
if (function_exists('pg_escape_string')) {
|
||||
/* This fixes an undocumented BC break in PHP 5.2.0 which changed
|
||||
@@ -532,7 +541,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @see DB_result::numCols()
|
||||
*/
|
||||
function numCols($result)
|
||||
public function numCols($result)
|
||||
{
|
||||
$cols = @pg_numfields($result);
|
||||
if (!$cols) {
|
||||
@@ -557,7 +566,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @see DB_result::numRows()
|
||||
*/
|
||||
function numRows($result)
|
||||
public function numRows($result)
|
||||
{
|
||||
$rows = @pg_numrows($result);
|
||||
if ($rows === null) {
|
||||
@@ -577,7 +586,7 @@ class DB_pgsql extends DB_common
|
||||
* @return int DB_OK on success. A DB_Error object if the driver
|
||||
* doesn't support auto-committing transactions.
|
||||
*/
|
||||
function autoCommit($onoff = false)
|
||||
public function autoCommit($onoff = false)
|
||||
{
|
||||
// XXX if $this->transaction_opcount > 0, we should probably
|
||||
// issue a warning here.
|
||||
@@ -593,7 +602,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*/
|
||||
function commit()
|
||||
public function commit()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
// (disabled) hack to shut up error messages from libpq.a
|
||||
@@ -615,7 +624,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @return int DB_OK on success. A DB_Error object on failure.
|
||||
*/
|
||||
function rollback()
|
||||
public function rollback()
|
||||
{
|
||||
if ($this->transaction_opcount > 0) {
|
||||
$result = @pg_exec($this->connection, 'abort;');
|
||||
@@ -637,7 +646,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @return int the number of rows. A DB_Error object on failure.
|
||||
*/
|
||||
function affectedRows()
|
||||
public function affectedRows()
|
||||
{
|
||||
return $this->affected;
|
||||
}
|
||||
@@ -658,7 +667,7 @@ class DB_pgsql extends DB_common
|
||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||
* DB_pgsql::createSequence(), DB_pgsql::dropSequence()
|
||||
*/
|
||||
function nextId($seq_name, $ondemand = true)
|
||||
public function nextId($seq_name, $ondemand = true)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
$repeat = false;
|
||||
@@ -700,7 +709,7 @@ class DB_pgsql extends DB_common
|
||||
* @see DB_common::createSequence(), DB_common::getSequenceName(),
|
||||
* DB_pgsql::nextID(), DB_pgsql::dropSequence()
|
||||
*/
|
||||
function createSequence($seq_name)
|
||||
public function createSequence($seq_name)
|
||||
{
|
||||
$seqname = $this->getSequenceName($seq_name);
|
||||
$result = $this->query("CREATE SEQUENCE ${seqname}");
|
||||
@@ -720,7 +729,7 @@ class DB_pgsql extends DB_common
|
||||
* @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
||||
* DB_pgsql::nextID(), DB_pgsql::createSequence()
|
||||
*/
|
||||
function dropSequence($seq_name)
|
||||
public function dropSequence($seq_name)
|
||||
{
|
||||
return $this->query('DROP SEQUENCE '
|
||||
. $this->getSequenceName($seq_name));
|
||||
@@ -745,7 +754,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function modifyLimitQuery($query, $from, $count, $params = array())
|
||||
public function modifyLimitQuery($query, $from, $count, $params = array())
|
||||
{
|
||||
return "$query LIMIT $count OFFSET $from";
|
||||
}
|
||||
@@ -765,7 +774,7 @@ class DB_pgsql extends DB_common
|
||||
* @see DB_common::raiseError(),
|
||||
* DB_pgsql::errorNative(), DB_pgsql::errorCode()
|
||||
*/
|
||||
function pgsqlRaiseError($errno = null)
|
||||
public function pgsqlRaiseError($errno = null)
|
||||
{
|
||||
$native = $this->errorNative();
|
||||
if (!$native) {
|
||||
@@ -784,12 +793,12 @@ class DB_pgsql extends DB_common
|
||||
/**
|
||||
* Gets the DBMS' native error message produced by the last query
|
||||
*
|
||||
* {@internal Error messages are used instead of error codes
|
||||
* {@internal Error messages are used instead of error codes
|
||||
* in order to support older versions of PostgreSQL.}}
|
||||
*
|
||||
* @return string the DBMS' error message
|
||||
*/
|
||||
function errorNative()
|
||||
public function errorNative()
|
||||
{
|
||||
return @pg_errormessage($this->connection);
|
||||
}
|
||||
@@ -803,7 +812,7 @@ class DB_pgsql extends DB_common
|
||||
* @param string $errormsg error message returned from the database
|
||||
* @return integer an error number from a DB error constant
|
||||
*/
|
||||
function errorCode($errormsg)
|
||||
public function errorCode($errormsg)
|
||||
{
|
||||
static $error_regexps;
|
||||
if (!isset($error_regexps)) {
|
||||
@@ -880,7 +889,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @see DB_common::tableInfo()
|
||||
*/
|
||||
function tableInfo($result, $mode = null)
|
||||
public function tableInfo($result, $mode = null)
|
||||
{
|
||||
if (is_string($result)) {
|
||||
/*
|
||||
@@ -965,7 +974,7 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _pgFieldFlags($resource, $num_field, $table_name)
|
||||
public function _pgFieldFlags($resource, $num_field, $table_name)
|
||||
{
|
||||
$field_name = @pg_fieldname($resource, $num_field);
|
||||
|
||||
@@ -1019,8 +1028,9 @@ class DB_pgsql extends DB_common
|
||||
if (in_array($num_field + 1, $keys)) {
|
||||
$flags .= ($row[0] == 't' && $row[1] == 'f') ? 'unique_key ' : '';
|
||||
$flags .= ($row[1] == 't') ? 'primary_key ' : '';
|
||||
if (count($keys) > 1)
|
||||
if (count($keys) > 1) {
|
||||
$flags .= 'multiple_key ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1041,7 +1051,7 @@ class DB_pgsql extends DB_common
|
||||
* @access protected
|
||||
* @see DB_common::getListOf()
|
||||
*/
|
||||
function getSpecialQuery($type)
|
||||
public function getSpecialQuery($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'tables':
|
||||
@@ -1105,12 +1115,11 @@ class DB_pgsql extends DB_common
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function _checkManip($query)
|
||||
public function _checkManip($query)
|
||||
{
|
||||
return (preg_match('/^\s*(SAVEPOINT|RELEASE)\s+/i', $query)
|
||||
|| parent::_checkManip($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1119,5 +1128,3 @@ class DB_pgsql extends DB_common
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user