Dear friends,

I am a newcomer on Drupal mailing list
and I would like to thank you all for developing this great tool.

I would like to integrate Drupal with existing web services.
Our database is running PostgreSQL 8.2+

PostgreSQL has a neat feature called schema.
A schema is some kind of logical partition in a database.
It is a more powerfull feature than table_prefix as it is more general and built-in.

In database.pgsql.inc, here is what I modified:

  if (isset($url['port'])) {
    $conn_string .= ' port='. urldecode($url['port']);
  }
   $schema='';
  if (isset($url['schema'])) {
    $schema .= urldecode($url['schema']);
  }

  // pg_last_error() does not return a useful error message for database
  // connection errors. We must turn on error tracking to get at a good error
  // message, which will be stored in $php_errormsg.
  $track_errors_previous = ini_get('track_errors');
  ini_set('track_errors', 1);
  //$schema='drupal';
  if ($schema !== '')
  {
    @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema);
  }

  $connection = @pg_connect($conn_string);
  if (!$connection) {
    require_once './includes/unicode.inc';
    _db_error_page(decode_entities($php_errormsg));
  }

I think it is a valuable addition, as it has zero impact on the existing code.

Are you interested in a further implimentation
(including installer and connexion settings)
OR should I keep this hack.

Kind regards,
Jean-Michel Pouré

Comments

grub3’s picture

Sorry, I did not copy the right code !

grub3’s picture

Here it is:

[code]
function db_status_report() {
$t = get_t();

$version = db_version();

$form['pgsql'] = array(
'title' => $t('PostgreSQL database'),
'value' => $version,
);

if (version_compare($version, DRUPAL_MINIMUM_PGSQL) < 0) {
$form['pgsql']['severity'] = REQUIREMENT_ERROR;
$form['pgsql']['description'] = $t('Your PostgreSQL Server is too old. Drupal requires at least PostgreSQL %version.', array('%version' => DRUPAL_MINIMUM_PGSQL));
}

return $form;
}

/**
* Returns the version of the database server currently in use.
*
* @return Database server version
*/
function db_version() {
return db_result(db_query("SHOW SERVER_VERSION"));
}

/**
* Initialize a database connection.
*/
function db_connect($url) {
// Check if PostgreSQL support is present in PHP
if (!function_exists('pg_connect')) {
_db_error_page('Unable to use the PostgreSQL database because the PostgreSQL extension for PHP is not installed. Check your php.ini to see how you can enable it.');
}

$url = parse_url($url);
$conn_string = '';

// Decode url-encoded information in the db connection string
if (isset($url['user'])) {
$conn_string .= ' user='. urldecode($url['user']);
}
if (isset($url['pass'])) {
$conn_string .= ' password='. urldecode($url['pass']);
}
if (isset($url['host'])) {
$conn_string .= ' host='. urldecode($url['host']);
}
if (isset($url['path'])) {
$conn_string .= ' dbname='. substr(urldecode($url['path']), 1);
}
if (isset($url['port'])) {
$conn_string .= ' port='. urldecode($url['port']);
}
$schema='';
if (isset($url['schema'])) {
$schema .= urldecode($url['schema']);
}

// pg_last_error() does not return a useful error message for database
// connection errors. We must turn on error tracking to get at a good error
// message, which will be stored in $php_errormsg.
$track_errors_previous = ini_get('track_errors');
ini_set('track_errors', 1);

$connection = @pg_connect($conn_string);
if (!$connection) {
require_once './includes/unicode.inc';
_db_error_page(decode_entities($php_errormsg));
}

//$schema='drupal';
if ($schema !== '')
{
@pg_query($connection, 'SET search_path TO ' . $schema);
}

// Restore error tracking setting
ini_set('track_errors', $track_errors_previous);

return $connection;
}
[/code]