-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The IBM DB2 driver Exception class must implement the DriverException…
… interface
- Loading branch information
Showing
10 changed files
with
175 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
lib/Doctrine/DBAL/Driver/IBMDB2/Exception/ConnectionError.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\IBMDB2\Exception; | ||
|
||
use Doctrine\DBAL\Driver\IBMDB2\DB2Exception; | ||
|
||
use function db2_conn_error; | ||
use function db2_conn_errormsg; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
final class ConnectionError extends DB2Exception | ||
{ | ||
/** | ||
* @param resource $connection | ||
*/ | ||
public static function new($connection): self | ||
{ | ||
return new self(db2_conn_errormsg($connection), db2_conn_error($connection)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
lib/Doctrine/DBAL/Driver/IBMDB2/Exception/ConnectionFailed.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\IBMDB2\Exception; | ||
|
||
use Doctrine\DBAL\Driver\IBMDB2\DB2Exception; | ||
|
||
use function db2_conn_error; | ||
use function db2_conn_errormsg; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
final class ConnectionFailed extends DB2Exception | ||
{ | ||
public static function new(): self | ||
{ | ||
return new self(db2_conn_errormsg(), db2_conn_error()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\IBMDB2\Exception; | ||
|
||
use Doctrine\DBAL\Driver\IBMDB2\DB2Exception; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
final class PrepareFailed extends DB2Exception | ||
{ | ||
public static function new(string $message): self | ||
{ | ||
return new self($message); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
lib/Doctrine/DBAL/Driver/IBMDB2/Exception/StatementError.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\IBMDB2\Exception; | ||
|
||
use Doctrine\DBAL\Driver\IBMDB2\DB2Exception; | ||
|
||
use function db2_stmt_error; | ||
use function db2_stmt_errormsg; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
final class StatementError extends DB2Exception | ||
{ | ||
/** | ||
* @param resource $statement | ||
*/ | ||
public static function new($statement): self | ||
{ | ||
return new self(db2_stmt_errormsg($statement), db2_stmt_error($statement)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/ConnectionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2; | ||
|
||
use Doctrine\DBAL\Driver\IBMDB2\DB2Connection; | ||
use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; | ||
use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionFailed; | ||
use Doctrine\DBAL\Driver\IBMDB2\Exception\PrepareFailed; | ||
use Doctrine\Tests\DbalFunctionalTestCase; | ||
use ReflectionProperty; | ||
|
||
use function db2_close; | ||
use function extension_loaded; | ||
|
||
class ConnectionTest extends DbalFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
if (! extension_loaded('ibm_db2')) { | ||
$this->markTestSkipped('ibm_db2 is not installed.'); | ||
} | ||
|
||
parent::setUp(); | ||
|
||
if ($this->connection->getDriver() instanceof DB2Driver) { | ||
return; | ||
} | ||
|
||
$this->markTestSkipped('ibm_db2 only test.'); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
$this->resetSharedConn(); | ||
} | ||
|
||
public function testConnectionFailure(): void | ||
{ | ||
$this->expectException(ConnectionFailed::class); | ||
new DB2Connection(['dbname' => 'garbage'], '', ''); | ||
} | ||
|
||
public function testPrepareFailure(): void | ||
{ | ||
$driverConnection = $this->connection->getWrappedConnection(); | ||
|
||
$re = new ReflectionProperty($driverConnection, 'conn'); | ||
$re->setAccessible(true); | ||
$conn = $re->getValue($driverConnection); | ||
db2_close($conn); | ||
|
||
$this->expectException(PrepareFailed::class); | ||
$driverConnection->prepare('SELECT 1'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters