From edc255421c6b11be90b11d513ab92cac9fd09e1a Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Thu, 13 Dec 2012 19:37:23 +0000
Subject: [PATCH] Try connection with specified db when postgres does not work

Conflicts:

	lib/setup.php
---
 lib/setup.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/setup.php b/lib/setup.php
index 71a2d13937e..0db565c6a66 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -320,7 +320,13 @@ class OC_Setup {
 		$connection_string = "host='$e_host' dbname=postgres user='$e_user' password='$e_password'";
 		$connection = @pg_connect($connection_string);
 		if(!$connection) {
-			throw new DatabaseSetupException($l->t('PostgreSQL username and/or password not valid'));
+			// Try if we can't connect with the specified DB name
+			$e_dbname = addslashes($dbname);
+			$connection_string = "host='$e_host' dbname='$dbname' user='$e_user' password='$e_password'";
+			$connection = @pg_connect($connection_string);
+
+			if(!$connection)
+				throw new DatabaseSetupException($l->t('PostgreSQL username and/or password not valid'));
 		}
 		$e_user = pg_escape_string($dbuser);
 		//check for roles creation rights in postgresql
-- 
GitLab