mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 17:05:45 +02:00
API Remove PDO support
This commit is contained in:
parent
fe426145d8
commit
4f50dd55a2
@ -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:
|
||||
|
@ -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',
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user