Line 17 | Line 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 26 | Line 31 |
---|
class dbal_postgres extends dbal { var $last_query_text = '';
|
class dbal_postgres extends dbal { var $last_query_text = '';
|
var $pgsql_version;
| var $connect_error = '';
|
/** * Connect to server
| /** * Connect to server
|
Line 47 | Line 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 77 | Line 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->db_connect_id)
| if ($this->persistency)
|
{
|
{
|
// determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+ if (version_compare(PHP_VERSION, '5.0.0', '>='))
| if (!function_exists('pg_pconnect'))
|
{
|
{
|
$this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version');
| $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 {
|
} else {
|
$query_id = @pg_query($this->db_connect_id, 'SELECT VERSION()'); $row = @pg_fetch_assoc($query_id, null); @pg_free_result($query_id);
if (!empty($row['version']))
| if (!function_exists('pg_connect'))
|
{
|
{
|
$this->pgsql_version = substr($row['version'], 10);
| $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);
|
}
|
}
|
if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8' && $this->pgsql_version[2] >= '2')
| $collector->uninstall();
if ($this->db_connect_id) { if (version_compare($this->sql_server_info(true), '8.2', '>='))
|
{ $this->multi_insert = true; }
| { $this->multi_insert = true; }
|
Line 110 | Line 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
|
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
|
*/
|
*/
|
function sql_server_info()
| function sql_server_info($raw = false, $use_cache = true)
|
{
|
{
|
return 'PostgreSQL ' . $this->pgsql_version;
| global $cache;
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); @pg_free_result($query_id);
$this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0;
if (!empty($cache) && $use_cache) { $cache->put('pgsql_version', $this->sql_server_version); } }
return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version;
|
}
/**
| }
/**
|
Line 202 | Line 236 |
---|
return false; }
|
return false; }
|
return ($this->query_result) ? $this->query_result : false;
| return $this->query_result;
|
}
/**
| }
/**
|
Line 224 | Line 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 360 | Line 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' => '' ); }
|