Skip to content

Commit e360e46

Browse files
committed
fix
1 parent 1360501 commit e360e46

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/Dibi/Drivers/PostgreDriver.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Dibi;
1313
use Dibi\Helpers;
14+
use PgSql;
1415

1516

1617
/**
@@ -29,7 +30,7 @@ class PostgreDriver implements Dibi\Driver
2930
{
3031
use Dibi\Strict;
3132

32-
/** @var resource */
33+
/** @var resource|PgSql\Connection */
3334
private $connection;
3435

3536
/** @var int|null Affected rows */
@@ -74,7 +75,7 @@ public function __construct(array $config)
7475
restore_error_handler();
7576
}
7677

77-
if (!is_resource($this->connection)) {
78+
if (!is_resource($this->connection) && !$this->connection instanceof PgSql\Connection) {
7879
throw new Dibi\DriverException($error ?: 'Connecting error.');
7980
}
8081

@@ -120,7 +121,7 @@ public function query(string $sql): ?Dibi\ResultDriver
120121
if ($res === false) {
121122
throw static::createException(pg_last_error($this->connection), null, $sql);
122123

123-
} elseif (is_resource($res)) {
124+
} elseif (is_resource($res) || $res instanceof PgSql\Result) {
124125
$this->affectedRows = Helpers::false2Null(pg_affected_rows($res));
125126
if (pg_num_fields($res)) {
126127
return $this->createResultDriver($res);
@@ -227,7 +228,9 @@ public function inTransaction(): bool
227228
*/
228229
public function getResource()
229230
{
230-
return is_resource($this->connection) ? $this->connection : null;
231+
return is_resource($this->connection) || $this->connection instanceof PgSql\Connection
232+
? $this->connection
233+
: null;
231234
}
232235

233236

@@ -258,7 +261,7 @@ public function createResultDriver($resource): PostgreResult
258261
*/
259262
public function escapeText(string $value): string
260263
{
261-
if (!is_resource($this->connection)) {
264+
if (!$this->getResource()) {
262265
throw new Dibi\Exception('Lost connection to server.');
263266
}
264267
return "'" . pg_escape_string($this->connection, $value) . "'";
@@ -267,7 +270,7 @@ public function escapeText(string $value): string
267270

268271
public function escapeBinary(string $value): string
269272
{
270-
if (!is_resource($this->connection)) {
273+
if (!$this->getResource()) {
271274
throw new Dibi\Exception('Lost connection to server.');
272275
}
273276
return "'" . pg_escape_bytea($this->connection, $value) . "'";

src/Dibi/Drivers/PostgreResult.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Dibi;
1313
use Dibi\Helpers;
14+
use PgSql;
1415

1516

1617
/**
@@ -20,15 +21,15 @@ class PostgreResult implements Dibi\ResultDriver
2021
{
2122
use Dibi\Strict;
2223

23-
/** @var resource */
24+
/** @var resource|PgSql\Result */
2425
private $resultSet;
2526

2627
/** @var bool */
2728
private $autoFree = true;
2829

2930

3031
/**
31-
* @param resource $resultSet
32+
* @param resource|PgSql\Result $resultSet
3233
*/
3334
public function __construct($resultSet)
3435
{
@@ -108,12 +109,14 @@ public function getResultColumns(): array
108109

109110
/**
110111
* Returns the result set resource.
111-
* @return resource|null
112+
* @return resource|PgSql\Result|null
112113
*/
113114
public function getResultResource()
114115
{
115116
$this->autoFree = false;
116-
return is_resource($this->resultSet) ? $this->resultSet : null;
117+
return is_resource($this->resultSet) || $this->resultSet instanceof PgSql\Result
118+
? $this->resultSet
119+
: null;
117120
}
118121

119122

0 commit comments

Comments
 (0)