From 201e5b7b8b5513b689ad9713d98b08743a214d68 Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Wed, 27 Feb 2013 11:17:11 +1300 Subject: [PATCH] BUG: Infinite loop on failed connect to a postgresql server When a postgres db server is down or credentials are wrone, the adapter still tries to check for a existing database and loops back into trying to connect again. --- code/PostgreSQLDatabase.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index f376035..d3147e4 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -147,22 +147,26 @@ class PostgreSQLDatabase extends SS_Database { if(self::$check_database_exists) { $this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=postgres' . $username . $password); - if(!$this->databaseExists($dbName)) + if(!$this->dbConn) { + throw new ErrorException("Couldn't connect to PostgreSQL database"); + } + + if(!$this->databaseExists($dbName)) { $this->createDatabase($dbName); + } } //Now we can be sure that this database exists, so we can connect to it $this->dbConn = pg_connect('host=' . $parameters['server'] . ' port=' . $port . ' dbname=' . $dbName . $username . $password); + if(!$this->dbConn) { + throw new ErrorException("Couldn't connect to PostgreSQL database"); + } + //By virtue of getting here, the connection is active: $this->active=true; $this->database = $dbName; - if(!$this->dbConn) { - $this->databaseError("Couldn't connect to PostgreSQL database"); - return false; - } - // Set up the schema if required $schema = isset($parameters['schema']) ? $parameters['schema'] : $this->currentSchema(); // Edge-case - database with no schemas: