[development] Supporting PostgreSQL schema level

Jean-Michel Pouré jm at poure.com
Thu Jan 17 10:54:32 UTC 2008


Dear friends,

First of all, thank you for developing Drupal.

I plan to use Drupal for my community site (2.000.000 pages a month)
and would like to contribute some code as regards PostgreSQL support.

You can find here a detailed HOWTO written for PhpBB community,
but I guess it applies for Drupal too : 

PostgreSQL query optimisation HOWTO :
http://area51.phpbb.com/phpBB/viewtopic.php?f=3&t=29292

Now, a question about my first contribution:

I would like to add support for PostgreSQL schema.
A schema is a separate logical space in a database.

I would like to allow the following syntax:

$db_url = 'pgsql://username:password@localhost/databasename/schemaname';

Conditions:

1) Old syntax still valid
$db_url = 'pgsql://username:password@localhost/databasename';
connects to public schema and is still valid.

2) SQL required
The proposed changes only means that we run a single SQL query after
connecting to the PostgreSQL database:

  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));
  }

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

  This does not change other queries.

Now, I would like your opinion on these changes.
Would you like a patch supporting PostgreSQL schema in Drupal code?

Kind regards,
Jean-Michel



More information about the development mailing list