It is Not a serious bug but certainly need to be paid attention to for robustness reasons.

In the db_connect function in includes/database.pgsql.inc file, I prefer to replace

  $conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host'];

with

  $conn_string = "";
  $conn_string .= isset($url['user']) ? ' user='. $url['user'] : '';
  $conn_string .= isset($url['path']) ? ' dbname='. substr($url['path'], 1) : '';
  $conn_string .= isset($url['pass']) ? ' password='. $url['pass'] : '';
  $conn_string .= isset($url['host']) ? ' host=' . $url['host'] : '';
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Cvbge’s picture

Could you explain reasons for this change?

thinker’s picture

1) it will be always better to check variables before using it.

2) In case there is no password given in the settings.php, you will not receive any php notice in the log file.

3) Well structured.

Steve Simms’s picture

Title: postgres db connection » postgres db connection ... eliminate warnings
Version: 4.6.3 » x.y.z
Assigned: thinker » Steve Simms
Priority: Normal » Minor
Status: Active » Needs review
FileSize
1.55 KB

It would be good to eliminate the password notice on systems that don't require one. In PostgreSQL, all of those fields are optional, so it makes sense to only include them if they're set.

The change thinker suggested needs a bit of tweaking, though. The various components of $url are being filtered with urldecode(), which sets all of them.

I've come up with two possible solutions with patches, depending on how the committer wants to solve it. The first one's attached, and I'll add another follow-up with the second one.

I've confirmed that this works properly even when settings.php has $db_url = 'pgsql://';.

Steve Simms’s picture

FileSize
1.04 KB

Here's the second patch for solving it.

Steve Simms’s picture

FileSize
1.55 KB

Here's a new patch, combining elements from the previous two, based on suggestions from cvbge.

Note that using pgsql:// generates a warning from parse_url(), but it does work. Any URL with a host will now be processed without any warnings, regardless of whether or not user, password, or database are present.

Steve Simms’s picture

FileSize
1.46 KB

One more patch. This cleans up the code by combining the two sections in the previous patch.

Again, based on feedback from cvbge on IRC.

Steve Simms’s picture

Also, I added urldecode to the port string, since that was the only one without it, for completeness sake.

sammys’s picture

Version: x.y.z » 4.7.3

This patch is now 4.7 only. Can we get an up-to-date patch. Mail me once it's ready and i'll review it. We can integrate the changes with 4.8+ as well once the 4.7 version is committed.

--
Sammy Spets
Synerger
http://www.synerger.com

Steve Simms’s picture

This patch should still apply cleanly -- looking at CVS, I don't believe the 4.7 version of this file has changed since I wrote it.

sammys’s picture

Status: Needs review » Reviewed & tested by the community

Patch confirmed to work on both 4.7 and HEAD. Ready to go!

Dries’s picture

Committed to CVS HEAD. Thanks.

Dries’s picture

Status: Reviewed & tested by the community » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)
sammys’s picture

Status: Closed (fixed) » Reviewed & tested by the community

This patch is yet to be applied to 4.7 as well. Please commit.

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

committed

sammys’s picture

Status: Fixed » Closed (fixed)