phpBB

Code Changes

File: includes/db/postgres.php

  Unmodified   Added   Modified   Removed
Line 17Line 17
}

include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);

}

include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);

 

if (!class_exists('phpbb_error_collector'))
{
include($phpbb_root_path . 'includes/error_collector.' . $phpEx);
}


/**
* PostgreSQL Database Abstraction Layer


/**
* PostgreSQL Database Abstraction Layer

Line 26Line 31
class dbal_postgres extends dbal
{
var $last_query_text = '';

class dbal_postgres extends dbal
{
var $last_query_text = '';

 
	var $connect_error = '';

	
/**
* Connect to server

	
/**
* Connect to server

Line 46Line 52

if ($sqlserver)
{


if ($sqlserver)
{

			if (strpos($sqlserver, ':') !== false)




			// $sqlserver can carry a port separated by : for compatibility reasons
// If $sqlserver has more than one : it's probably an IPv6 address.
// In this case we only allow passing a port via the $port variable.
if (substr_count($sqlserver, ':') === 1)

			{
list($sqlserver, $port) = explode(':', $sqlserver);
}

			{
list($sqlserver, $port) = explode(':', $sqlserver);
}

Line 76Line 85

$this->persistency = $persistency;



$this->persistency = $persistency;


		$this->db_connect_id = ($this->persistency) ? @pg_pconnect($connect_string, $new_link) : @pg_connect($connect_string, $new_link);
























		if ($this->persistency)
{
if (!function_exists('pg_pconnect'))
{
$this->connect_error = 'pg_pconnect function does not exist, is pgsql extension installed?';
return $this->sql_error('');
}
$collector = new phpbb_error_collector;
$collector->install();
$this->db_connect_id = (!$new_link) ? @pg_pconnect($connect_string) : @pg_pconnect($connect_string, PGSQL_CONNECT_FORCE_NEW);
}
else
{
if (!function_exists('pg_connect'))
{
$this->connect_error = 'pg_connect function does not exist, is pgsql extension installed?';
return $this->sql_error('');
}
$collector = new phpbb_error_collector;
$collector->install();
$this->db_connect_id = (!$new_link) ? @pg_connect($connect_string) : @pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW);
}

$collector->uninstall();


if ($this->db_connect_id)
{


if ($this->db_connect_id)
{

Line 92Line 124
			return $this->db_connect_id;
}


			return $this->db_connect_id;
}


 
		$this->connect_error = $collector->format_errors();

		return $this->sql_error('');
}

/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version

		return $this->sql_error('');
}

/**
* Version information about used database
* @param bool $raw if true, only return the fetched sql_server_version

 
	* @param bool $use_cache If true, it is safe to retrieve the value from the cache

	* @return string sql server version
*/

	* @return string sql server version
*/

	function sql_server_info($raw = false)

	function sql_server_info($raw = false, $use_cache = true)

	{
global $cache;


	{
global $cache;


		if (empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false)

		if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false)

		{
$query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version');
$row = @pg_fetch_assoc($query_id, null);

		{
$query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version');
$row = @pg_fetch_assoc($query_id, null);

Line 112Line 146

$this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0;



$this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0;


			if (!empty($cache))

			if (!empty($cache) && $use_cache)

			{
$cache->put('pgsql_version', $this->sql_server_version);
}

			{
$cache->put('pgsql_version', $this->sql_server_version);
}

Line 224Line 258
		// if $total is set to 0 we do not want to limit the number of rows
if ($total == 0)
{

		// if $total is set to 0 we do not want to limit the number of rows
if ($total == 0)
{

			$total = -1;

			$total = 'ALL';

		}

$query .= "\n LIMIT $total OFFSET $offset";

		}

$query .= "\n LIMIT $total OFFSET $offset";

Line 360Line 394
	*/
function _sql_error()
{

	*/
function _sql_error()
{

 
		// pg_last_error only works when there is an established connection.
// Connection errors have to be tracked by us manually.
if ($this->db_connect_id)
{
$message = @pg_last_error($this->db_connect_id);
}
else
{
$message = $this->connect_error;
}


		return array(

		return array(

			'message'	=> (!$this->db_connect_id) ? @pg_last_error() : @pg_last_error($this->db_connect_id),

			'message'	=> $message,

			'code'		=> ''
);
}

			'code'		=> ''
);
}