This commit is contained in:
Guy Sartorelli 2023-03-04 05:31:17 +13:00 committed by GitHub
commit 56c0a23854
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View File

@ -4,6 +4,8 @@ namespace SilverStripe\PostgreSQL;
use SilverStripe\ORM\Connect\DBConnector; use SilverStripe\ORM\Connect\DBConnector;
use ErrorException; use ErrorException;
use PgSql\Connection;
use PgSql\Result;
/** /**
* PostgreSQL connector class using the PostgreSQL specific api * PostgreSQL connector class using the PostgreSQL specific api
@ -17,7 +19,7 @@ class PostgreSQLConnector extends DBConnector
/** /**
* Connection to the PG Database database * Connection to the PG Database database
* *
* @var resource * @var Connection
*/ */
protected $dbConn = null; protected $dbConn = null;
@ -31,7 +33,7 @@ class PostgreSQLConnector extends DBConnector
/** /**
* Reference to the last query result (for pg_affected_rows) * Reference to the last query result (for pg_affected_rows)
* *
* @var resource * @var Result
*/ */
protected $lastQuery = null; protected $lastQuery = null;

View File

@ -6,6 +6,7 @@ use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
use SilverStripe\Dev\Install\DatabaseConfigurationHelper; use SilverStripe\Dev\Install\DatabaseConfigurationHelper;
use Exception; use Exception;
use PDO; use PDO;
use PgSql\Connection;
/** /**
* This is a helper class for the SS installer. * This is a helper class for the SS installer.
@ -94,7 +95,7 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
return false; return false;
} elseif ($conn instanceof PDO) { } elseif ($conn instanceof PDO) {
return $conn->getAttribute(PDO::ATTR_SERVER_VERSION); return $conn->getAttribute(PDO::ATTR_SERVER_VERSION);
} elseif (is_resource($conn)) { } elseif ($conn instanceof Connection) {
$info = pg_version($conn); $info = pg_version($conn);
return $info['server']; return $info['server'];
} else { } else {
@ -132,7 +133,7 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
/** /**
* Helper function to execute a query * Helper function to execute a query
* *
* @param mixed $conn Connection object/resource * @param mixed $conn Connection object
* @param string $sql SQL string to execute * @param string $sql SQL string to execute
* @return array List of first value from each resulting row * @return array List of first value from each resulting row
*/ */
@ -143,7 +144,7 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
foreach ($conn->query($sql) as $row) { foreach ($conn->query($sql) as $row) {
$items[] = $row[0]; $items[] = $row[0];
} }
} elseif (is_resource($conn)) { } elseif ($conn instanceof Connection) {
$result = pg_query($conn, $sql); $result = pg_query($conn, $sql);
while ($row = pg_fetch_row($result)) { while ($row = pg_fetch_row($result)) {
$items[] = $row[0]; $items[] = $row[0];

View File

@ -3,6 +3,7 @@
namespace SilverStripe\PostgreSQL; namespace SilverStripe\PostgreSQL;
use Iterator; use Iterator;
use PgSql\Result;
use SilverStripe\ORM\Connect\Query; use SilverStripe\ORM\Connect\Query;
/** /**
@ -15,7 +16,7 @@ class PostgreSQLQuery extends Query
{ {
/** /**
* The internal Postgres handle that points to the result set. * The internal Postgres handle that points to the result set.
* @var resource * @var Result
*/ */
private $handle; private $handle;
@ -38,7 +39,7 @@ class PostgreSQLQuery extends Query
/** /**
* Hook the result-set given into a Query class, suitable for use by sapphire. * Hook the result-set given into a Query class, suitable for use by sapphire.
* @param resource $handle the internal Postgres handle that is points to the resultset. * @param Result $handle the internal Postgres handle that is points to the resultset.
*/ */
public function __construct($handle) public function __construct($handle)
{ {
@ -52,9 +53,7 @@ class PostgreSQLQuery extends Query
public function __destruct() public function __destruct()
{ {
if (is_resource($this->handle)) { pg_free_result($this->handle);
pg_free_result($this->handle);
}
} }
public function getIterator(): Iterator public function getIterator(): Iterator