Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions core/DB/PgSQL.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ public function connect()
.($this->basename ? " dbname={$this->basename}" : null)
.($this->port ? " port={$this->port}" : null);

if ($this->persistent)
$this->link = pg_pconnect($conn);
else
$this->link = pg_connect($conn);

if (!$this->link)
try {
if ($this->persistent)
$this->link = pg_pconnect($conn);
else
$this->link = pg_connect($conn);
} catch (Exception $e) {
throw new DatabaseException(
'can not connect to PostgreSQL server: '.pg_errormessage()
'can not connect to PostgreSQL server: '.$e->getMessage(),
$e->getCode(),
$e
);
}

if ($this->encoding)
$this->setDbEncoding();
Expand Down
7 changes: 7 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2012-06-29 N. Konstantinov

* core/DB/PgSQL.class.php
test/core/DbConnectionTest.class.php:

throw DatabaseException instead of BaseException in case of connection's failure

2012-06-27 Alexey S. Denisov

* main/Base/AbstractProtoClass.class.php
Expand Down
30 changes: 30 additions & 0 deletions test/core/DbConnectionTest.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

final class DbConnectionTest extends TestCase
{
public function setUp()
{
DBPool::me()->
addLink(
'badLink',
DB::spawn('PinbedPgSQL', 'postgres', '', 'localhost', 'wrongDatabase')
);
}

public function testPostgresql()
{
try {
$link = DBPool::me()->getLink('badLink');
$this->fail('Unreachable code');
} catch(Exception $e) {
$this->assertInstanceOf('DatabaseException', $e);
}
}

public function tearDown()
{
DBPool::me()->dropLink('badLink');
}
}

?>