Merge pull request #145 from creative-commoners/pulls/3.0/pdo

API Remove PDO support
This commit is contained in:
Guy Sartorelli 2023-03-20 14:25:49 +13:00 committed by GitHub
commit e484046171
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 55 deletions

View File

@ -2,12 +2,6 @@
name: postgresqlconnectors
---
SilverStripe\Core\Injector\Injector:
PostgrePDODatabase:
class: 'SilverStripe\PostgreSQL\PostgreSQLDatabase'
properties:
connector: '%$PDOConnector'
schemaManager: '%$PostgreSQLSchemaManager'
queryBuilder: '%$PostgreSQLQueryBuilder'
PostgreSQLDatabase:
class: 'SilverStripe\PostgreSQL\PostgreSQLDatabase'
properties:

View File

@ -3,23 +3,6 @@
use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
use SilverStripe\PostgreSQL\PostgreSQLDatabaseConfigurationHelper;
// PDO Postgre database
DatabaseAdapterRegistry::register(array(
/** @skipUpgrade */
'class' => 'PostgrePDODatabase',
'module' => 'postgresql',
'title' => 'PostgreSQL 8.3+ (using PDO)',
'helperPath' => __DIR__.'/code/PostgreSQLDatabaseConfigurationHelper.php',
'helperClass' => PostgreSQLDatabaseConfigurationHelper::class,
'supported' => (class_exists('PDO') && in_array('postgresql', PDO::getAvailableDrivers())),
'missingExtensionText' =>
'Either the <a href="http://www.php.net/manual/en/book.pdo.php">PDO Extension</a> or
the <a href="http://www.php.net/manual/en/ref.pdo-sqlsrv.php">SQL Server PDO Driver</a>
are unavailable. Please install or enable these and refresh this page.'
));
// PDO Postgre database
DatabaseAdapterRegistry::register(array(
/** @skipUpgrade */
'class' => 'PostgreSQLDatabase',

View File

@ -72,7 +72,7 @@ class PostgreSQLConnector extends DBConnector
// Note: Postgres always behaves as though $selectDB = true, ignoring
// any value actually passed in. The controller passes in true for other
// connectors such as PDOConnector.
// connectors
// Escape parameters
$arguments = array(
@ -218,7 +218,6 @@ class PostgreSQLConnector extends DBConnector
// Execute query
// Unfortunately error-suppression is required in order to handle sql errors elegantly.
// Please use PDO if you can help it
if (!empty($parameters)) {
$result = @pg_query_params($this->dbConn, $sql, $parameters);
} else {

View File

@ -214,7 +214,7 @@ class PostgreSQLDatabase extends Database
}
$this->schemaOriginal = $parameters['schema'];
// Ensure that driver is available (required by PDO)
// Ensure that driver is available
if (empty($parameters['driver'])) {
$parameters['driver'] = $this->getDatabaseServer();
}

View File

@ -5,7 +5,6 @@ namespace SilverStripe\PostgreSQL;
use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
use SilverStripe\Dev\Install\DatabaseConfigurationHelper;
use Exception;
use PDO;
/**
* This is a helper class for the SS installer.
@ -40,10 +39,6 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
$connstring = "host=$server port=5432 dbname=postgres{$userPart}{$passwordPart}";
$conn = pg_connect($connstring);
break;
case 'PostgrePDODatabase':
// May throw a PDOException if fails
$conn = @new PDO('postgresql:host='.$server.';dbname=postgres;port=5432', $username, $password);
break;
default:
$error = 'Invalid connection type: ' . $databaseConfig['type'];
return null;
@ -92,8 +87,6 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
$conn = $this->createConnection($databaseConfig, $error);
if (!$conn) {
return false;
} elseif ($conn instanceof PDO) {
return $conn->getAttribute(PDO::ATTR_SERVER_VERSION);
} elseif (is_resource($conn)) {
$info = pg_version($conn);
return $info['server'];
@ -139,11 +132,7 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
protected function query($conn, $sql)
{
$items = array();
if ($conn instanceof PDO) {
foreach ($conn->query($sql) as $row) {
$items[] = $row[0];
}
} elseif (is_resource($conn)) {
if (is_resource($conn)) {
$result = pg_query($conn, $sql);
while ($row = pg_fetch_row($result)) {
$items[] = $row[0];

View File

@ -849,23 +849,18 @@ class PostgreSQLSchemaManager extends DBSchemaManager
$trigger['tgargs'] = stream_get_contents($trigger['tgargs']);
}
if (strpos($trigger['tgargs'], "\000") !== false) {
// Option 1: output as a string (PDO)
$argList = array_filter(explode("\000", $trigger['tgargs']));
} else {
// Option 2: hex-encoded (pg_sql non-pdo)
$bytes = str_split($trigger['tgargs'], 2);
$argList = array();
$nextArg = "";
foreach ($bytes as $byte) {
if ($byte == '\x') {
continue;
} elseif ($byte == "00") {
$argList[] = $nextArg;
$nextArg = "";
} else {
$nextArg .= chr(hexdec($byte));
}
// hex-encoded (pg_sql non-pdo)
$bytes = str_split($trigger['tgargs'], 2);
$argList = array();
$nextArg = "";
foreach ($bytes as $byte) {
if ($byte == '\x') {
continue;
} elseif ($byte == "00") {
$argList[] = $nextArg;
$nextArg = "";
} else {
$nextArg .= chr(hexdec($byte));
}
}