Skip to content

Commit ee6ea9d

Browse files
committed
Doctrine3: OPTIONAL FIXES
SHOULD BE REMOVED AFTER INTEGRATING GH-146 [1]. [1] crate/crate-pdo#146
1 parent 7ebc011 commit ee6ea9d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Crate/DBAL/Driver/PDOCrate/PDOConnection.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
namespace Crate\DBAL\Driver\PDOCrate;
2424

2525
use Crate\PDO\PDO;
26+
use Doctrine\DBAL\Driver\PDO\Exception;
27+
use Doctrine\DBAL\Driver\PDO\Statement;
2628
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
29+
use Doctrine\DBAL\Driver\Statement as StatementInterface;
2730

2831
class PDOConnection extends PDO implements ServerInfoAwareConnection
2932
{
@@ -49,4 +52,41 @@ public function requiresQueryForServerVersion()
4952
{
5053
return false;
5154
}
55+
56+
/**
57+
* {@inheritDoc}
58+
*
59+
* References:
60+
* - https://github.com/doctrine/dbal/issues/2025
61+
* - https://github.com/doctrine/dbal/pull/517
62+
* - https://github.com/doctrine/dbal/pull/373
63+
*/
64+
public function prepare($sql, $options = null): StatementInterface
65+
{
66+
try {
67+
$stmt = $this->connection->prepare($sql, $options);
68+
assert($stmt instanceof PDOStatement);
69+
70+
return new Statement($stmt);
71+
} catch (PDOException $exception) {
72+
throw Exception::new($exception);
73+
}
74+
}
75+
76+
/**
77+
* {@inheritDoc}
78+
*/
79+
public function exec($sql): int
80+
{
81+
try {
82+
$result = $this->connection->exec($sql);
83+
84+
assert($result !== false);
85+
86+
return $result;
87+
} catch (PDOException $exception) {
88+
throw Exception::new($exception);
89+
}
90+
}
91+
5292
}

test/Crate/Test/DBAL/Functional/ConnectionTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public function testGetDriver()
6666
$this->assertInstanceOf('Crate\DBAL\Driver\PDOCrate\Driver', $this->_conn->getDriver());
6767
}
6868

69+
/**
70+
* @var \Doctrine\DBAL\Statement $stmt
71+
*
72+
* @return void
73+
* @throws \Doctrine\DBAL\Exception
74+
*/
6975
public function testStatement()
7076
{
7177
$sql = 'SELECT * FROM sys.cluster';

0 commit comments

Comments
 (0)