mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-15 04:31:31 +00:00
resolved conflicts
This commit is contained in:
+120
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\DBAL\Driver\API\MySQL;
|
||||
|
||||
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use Doctrine\DBAL\Exception\ConnectionException;
|
||||
use Doctrine\DBAL\Exception\ConnectionLost;
|
||||
use Doctrine\DBAL\Exception\DatabaseDoesNotExist;
|
||||
use Doctrine\DBAL\Exception\DeadlockException;
|
||||
use Doctrine\DBAL\Exception\DriverException;
|
||||
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
|
||||
use Doctrine\DBAL\Exception\InvalidFieldNameException;
|
||||
use Doctrine\DBAL\Exception\LockWaitTimeoutException;
|
||||
use Doctrine\DBAL\Exception\NonUniqueFieldNameException;
|
||||
use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
|
||||
use Doctrine\DBAL\Exception\SyntaxErrorException;
|
||||
use Doctrine\DBAL\Exception\TableExistsException;
|
||||
use Doctrine\DBAL\Exception\TableNotFoundException;
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use Doctrine\DBAL\Query;
|
||||
|
||||
/** @internal */
|
||||
final class ExceptionConverter implements ExceptionConverterInterface
|
||||
{
|
||||
/**
|
||||
* @link https://dev.mysql.com/doc/mysql-errors/8.0/en/client-error-reference.html
|
||||
* @link https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html
|
||||
*/
|
||||
public function convert(Exception $exception, ?Query $query): DriverException
|
||||
{
|
||||
switch ($exception->getCode()) {
|
||||
case 1008:
|
||||
return new DatabaseDoesNotExist($exception, $query);
|
||||
|
||||
case 1213:
|
||||
return new DeadlockException($exception, $query);
|
||||
|
||||
case 1205:
|
||||
return new LockWaitTimeoutException($exception, $query);
|
||||
|
||||
case 1050:
|
||||
return new TableExistsException($exception, $query);
|
||||
|
||||
case 1051:
|
||||
case 1146:
|
||||
return new TableNotFoundException($exception, $query);
|
||||
|
||||
case 1216:
|
||||
case 1217:
|
||||
case 1451:
|
||||
case 1452:
|
||||
case 1701:
|
||||
return new ForeignKeyConstraintViolationException($exception, $query);
|
||||
|
||||
case 1062:
|
||||
case 1557:
|
||||
case 1569:
|
||||
case 1586:
|
||||
return new UniqueConstraintViolationException($exception, $query);
|
||||
|
||||
case 1054:
|
||||
case 1166:
|
||||
case 1611:
|
||||
return new InvalidFieldNameException($exception, $query);
|
||||
|
||||
case 1052:
|
||||
case 1060:
|
||||
case 1110:
|
||||
return new NonUniqueFieldNameException($exception, $query);
|
||||
|
||||
case 1064:
|
||||
case 1149:
|
||||
case 1287:
|
||||
case 1341:
|
||||
case 1342:
|
||||
case 1343:
|
||||
case 1344:
|
||||
case 1382:
|
||||
case 1479:
|
||||
case 1541:
|
||||
case 1554:
|
||||
case 1626:
|
||||
return new SyntaxErrorException($exception, $query);
|
||||
|
||||
case 1044:
|
||||
case 1045:
|
||||
case 1046:
|
||||
case 1049:
|
||||
case 1095:
|
||||
case 1142:
|
||||
case 1143:
|
||||
case 1227:
|
||||
case 1370:
|
||||
case 1429:
|
||||
case 2002:
|
||||
case 2005:
|
||||
case 2054:
|
||||
return new ConnectionException($exception, $query);
|
||||
|
||||
case 2006:
|
||||
case 4031:
|
||||
return new ConnectionLost($exception, $query);
|
||||
|
||||
case 1048:
|
||||
case 1121:
|
||||
case 1138:
|
||||
case 1171:
|
||||
case 1252:
|
||||
case 1263:
|
||||
case 1364:
|
||||
case 1566:
|
||||
return new NotNullConstraintViolationException($exception, $query);
|
||||
}
|
||||
|
||||
return new DriverException($exception, $query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Driver;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
|
||||
use Doctrine\DBAL\Driver\API\IBMDB2\ExceptionConverter;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Platforms\DB2111Platform;
|
||||
use Doctrine\DBAL\Platforms\DB2Platform;
|
||||
use Doctrine\DBAL\Schema\DB2SchemaManager;
|
||||
use Doctrine\DBAL\VersionAwarePlatformDriver;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function assert;
|
||||
use function preg_match;
|
||||
use function version_compare;
|
||||
|
||||
/**
|
||||
* Abstract base implementation of the {@see Driver} interface for IBM DB2 based drivers.
|
||||
*/
|
||||
abstract class AbstractDB2Driver implements VersionAwarePlatformDriver
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getDatabasePlatform()
|
||||
{
|
||||
return new DB2Platform();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated Use {@link DB2Platform::createSchemaManager()} instead.
|
||||
*/
|
||||
public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/5458',
|
||||
'AbstractDB2Driver::getSchemaManager() is deprecated.'
|
||||
. ' Use DB2Platform::createSchemaManager() instead.',
|
||||
);
|
||||
|
||||
assert($platform instanceof DB2Platform);
|
||||
|
||||
return new DB2SchemaManager($conn, $platform);
|
||||
}
|
||||
|
||||
public function getExceptionConverter(): ExceptionConverterInterface
|
||||
{
|
||||
return new ExceptionConverter();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function createDatabasePlatformForVersion($version)
|
||||
{
|
||||
if (version_compare($this->getVersionNumber($version), '11.1', '>=')) {
|
||||
return new DB2111Platform();
|
||||
}
|
||||
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/5156',
|
||||
'IBM DB2 < 11.1 support is deprecated and will be removed in DBAL 4.'
|
||||
. ' Consider upgrading to IBM DB2 11.1 or later.',
|
||||
);
|
||||
|
||||
return $this->getDatabasePlatform();
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects IBM DB2 server version
|
||||
*
|
||||
* @param string $versionString Version string as returned by IBM DB2 server, i.e. 'DB2/LINUXX8664 11.5.8.0'
|
||||
*
|
||||
* @throws DBALException
|
||||
*/
|
||||
private function getVersionNumber(string $versionString): string
|
||||
{
|
||||
if (
|
||||
preg_match(
|
||||
'/^(?:[^\s]+\s)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
|
||||
$versionString,
|
||||
$versionParts,
|
||||
) !== 1
|
||||
) {
|
||||
throw DBALException::invalidPlatformVersionSpecified(
|
||||
$versionString,
|
||||
'^(?:[^\s]+\s)?<major_version>.<minor_version>.<patch_version>',
|
||||
);
|
||||
}
|
||||
|
||||
return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
|
||||
}
|
||||
}
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Driver;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Driver\API\ExceptionConverter;
|
||||
use Doctrine\DBAL\Driver\API\MySQL;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Platforms\MariaDb1010Platform;
|
||||
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
|
||||
use Doctrine\DBAL\Platforms\MariaDb1043Platform;
|
||||
use Doctrine\DBAL\Platforms\MariaDb1052Platform;
|
||||
use Doctrine\DBAL\Platforms\MariaDb1060Platform;
|
||||
use Doctrine\DBAL\Platforms\MySQL57Platform;
|
||||
use Doctrine\DBAL\Platforms\MySQL80Platform;
|
||||
use Doctrine\DBAL\Platforms\MySQL84Platform;
|
||||
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
||||
use Doctrine\DBAL\Schema\MySQLSchemaManager;
|
||||
use Doctrine\DBAL\VersionAwarePlatformDriver;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function assert;
|
||||
use function preg_match;
|
||||
use function stripos;
|
||||
use function version_compare;
|
||||
|
||||
/**
|
||||
* Abstract base implementation of the {@see Driver} interface for MySQL based drivers.
|
||||
*/
|
||||
abstract class AbstractMySQLDriver implements VersionAwarePlatformDriver
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createDatabasePlatformForVersion($version)
|
||||
{
|
||||
$mariadb = stripos($version, 'mariadb') !== false;
|
||||
|
||||
if ($mariadb) {
|
||||
$mariaDbVersion = $this->getMariaDbMysqlVersionNumber($version);
|
||||
if (version_compare($mariaDbVersion, '10.10.0', '>=')) {
|
||||
return new MariaDb1010Platform();
|
||||
}
|
||||
|
||||
if (version_compare($mariaDbVersion, '10.6.0', '>=')) {
|
||||
return new MariaDb1060Platform();
|
||||
}
|
||||
|
||||
if (version_compare($mariaDbVersion, '10.5.2', '>=')) {
|
||||
return new MariaDb1052Platform();
|
||||
}
|
||||
|
||||
if (version_compare($mariaDbVersion, '10.4.3', '>=')) {
|
||||
return new MariaDb1043Platform();
|
||||
}
|
||||
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/6110',
|
||||
'Support for MariaDB < 10.4 is deprecated and will be removed in DBAL 4.'
|
||||
. ' Consider upgrading to a more recent version of MariaDB.',
|
||||
);
|
||||
|
||||
if (version_compare($mariaDbVersion, '10.2.7', '>=')) {
|
||||
return new MariaDb1027Platform();
|
||||
}
|
||||
} else {
|
||||
$oracleMysqlVersion = $this->getOracleMysqlVersionNumber($version);
|
||||
|
||||
if (version_compare($oracleMysqlVersion, '8.4.0', '>=')) {
|
||||
if (! version_compare($version, '8.4.0', '>=')) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/dbal/pull/5779',
|
||||
'Version detection logic for MySQL will change in DBAL 4. '
|
||||
. 'Please specify the version as the server reports it, e.g. "8.4.0" instead of "8.4".',
|
||||
);
|
||||
}
|
||||
|
||||
return new MySQL84Platform();
|
||||
}
|
||||
|
||||
if (version_compare($oracleMysqlVersion, '8', '>=')) {
|
||||
if (! version_compare($version, '8.0.0', '>=')) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/dbal/pull/5779',
|
||||
'Version detection logic for MySQL will change in DBAL 4. '
|
||||
. 'Please specify the version as the server reports it, e.g. "8.0.31" instead of "8".',
|
||||
);
|
||||
}
|
||||
|
||||
return new MySQL80Platform();
|
||||
}
|
||||
|
||||
if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) {
|
||||
if (! version_compare($version, '5.7.9', '>=')) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/dbal/pull/5779',
|
||||
'Version detection logic for MySQL will change in DBAL 4. '
|
||||
. 'Please specify the version as the server reports it, e.g. "5.7.40" instead of "5.7".',
|
||||
);
|
||||
}
|
||||
|
||||
return new MySQL57Platform();
|
||||
}
|
||||
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/5072',
|
||||
'MySQL 5.6 support is deprecated and will be removed in DBAL 4.'
|
||||
. ' Consider upgrading to MySQL 5.7 or later.',
|
||||
);
|
||||
}
|
||||
|
||||
return $this->getDatabasePlatform();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a normalized 'version number' from the server string
|
||||
* returned by Oracle MySQL servers.
|
||||
*
|
||||
* @param string $versionString Version string returned by the driver, i.e. '5.7.10'
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getOracleMysqlVersionNumber(string $versionString): string
|
||||
{
|
||||
if (
|
||||
preg_match(
|
||||
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
|
||||
$versionString,
|
||||
$versionParts,
|
||||
) !== 1
|
||||
) {
|
||||
throw Exception::invalidPlatformVersionSpecified(
|
||||
$versionString,
|
||||
'<major_version>.<minor_version>.<patch_version>',
|
||||
);
|
||||
}
|
||||
|
||||
$majorVersion = $versionParts['major'];
|
||||
$minorVersion = $versionParts['minor'] ?? 0;
|
||||
$patchVersion = $versionParts['patch'] ?? null;
|
||||
|
||||
if ($majorVersion === '5' && $minorVersion === '7') {
|
||||
$patchVersion ??= '9';
|
||||
} else {
|
||||
$patchVersion ??= '0';
|
||||
}
|
||||
|
||||
return $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect MariaDB server version, including hack for some mariadb distributions
|
||||
* that starts with the prefix '5.5.5-'
|
||||
*
|
||||
* @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial'
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getMariaDbMysqlVersionNumber(string $versionString): string
|
||||
{
|
||||
if (stripos($versionString, 'MariaDB') === 0) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/orm',
|
||||
'https://github.com/doctrine/dbal/pull/5779',
|
||||
'Version detection logic for MySQL will change in DBAL 4. '
|
||||
. 'Please specify the version as the server reports it, '
|
||||
. 'e.g. "10.9.3-MariaDB" instead of "mariadb-10.9".',
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
preg_match(
|
||||
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
|
||||
$versionString,
|
||||
$versionParts,
|
||||
) !== 1
|
||||
) {
|
||||
throw Exception::invalidPlatformVersionSpecified(
|
||||
$versionString,
|
||||
'^(?:5\.5\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>',
|
||||
);
|
||||
}
|
||||
|
||||
return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return AbstractMySQLPlatform
|
||||
*/
|
||||
public function getDatabasePlatform()
|
||||
{
|
||||
return new MySQLPlatform();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated Use {@link AbstractMySQLPlatform::createSchemaManager()} instead.
|
||||
*
|
||||
* @return MySQLSchemaManager
|
||||
*/
|
||||
public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/5458',
|
||||
'AbstractMySQLDriver::getSchemaManager() is deprecated.'
|
||||
. ' Use MySQLPlatform::createSchemaManager() instead.',
|
||||
);
|
||||
|
||||
assert($platform instanceof AbstractMySQLPlatform);
|
||||
|
||||
return new MySQLSchemaManager($conn, $platform);
|
||||
}
|
||||
|
||||
public function getExceptionConverter(): ExceptionConverter
|
||||
{
|
||||
return new MySQL\ExceptionConverter();
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Driver;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Driver\API\ExceptionConverter;
|
||||
use Doctrine\DBAL\Driver\API\PostgreSQL;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
|
||||
use Doctrine\DBAL\Platforms\PostgreSQL120Platform;
|
||||
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
|
||||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||
use Doctrine\DBAL\Schema\PostgreSQLSchemaManager;
|
||||
use Doctrine\DBAL\VersionAwarePlatformDriver;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function assert;
|
||||
use function preg_match;
|
||||
use function version_compare;
|
||||
|
||||
/**
|
||||
* Abstract base implementation of the {@see Driver} interface for PostgreSQL based drivers.
|
||||
*/
|
||||
abstract class AbstractPostgreSQLDriver implements VersionAwarePlatformDriver
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function createDatabasePlatformForVersion($version)
|
||||
{
|
||||
if (preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts) !== 1) {
|
||||
throw Exception::invalidPlatformVersionSpecified(
|
||||
$version,
|
||||
'<major_version>.<minor_version>.<patch_version>',
|
||||
);
|
||||
}
|
||||
|
||||
$majorVersion = $versionParts['major'];
|
||||
$minorVersion = $versionParts['minor'] ?? 0;
|
||||
$patchVersion = $versionParts['patch'] ?? 0;
|
||||
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
|
||||
|
||||
if (version_compare($version, '12.0', '>=')) {
|
||||
return new PostgreSQL120Platform();
|
||||
}
|
||||
|
||||
if (version_compare($version, '10.0', '>=')) {
|
||||
return new PostgreSQL100Platform();
|
||||
}
|
||||
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/5060',
|
||||
'PostgreSQL 9 support is deprecated and will be removed in DBAL 4.'
|
||||
. ' Consider upgrading to Postgres 10 or later.',
|
||||
);
|
||||
|
||||
return new PostgreSQL94Platform();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getDatabasePlatform()
|
||||
{
|
||||
return new PostgreSQL94Platform();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated Use {@link PostgreSQLPlatform::createSchemaManager()} instead.
|
||||
*/
|
||||
public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
|
||||
{
|
||||
Deprecation::triggerIfCalledFromOutside(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/5458',
|
||||
'AbstractPostgreSQLDriver::getSchemaManager() is deprecated.'
|
||||
. ' Use PostgreSQLPlatform::createSchemaManager() instead.',
|
||||
);
|
||||
|
||||
assert($platform instanceof PostgreSQLPlatform);
|
||||
|
||||
return new PostgreSQLSchemaManager($conn, $platform);
|
||||
}
|
||||
|
||||
public function getExceptionConverter(): ExceptionConverter
|
||||
{
|
||||
return new PostgreSQL\ExceptionConverter();
|
||||
}
|
||||
}
|
||||
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Driver\OCI8\Middleware;
|
||||
|
||||
use Doctrine\DBAL\Driver;
|
||||
use Doctrine\DBAL\Driver\Connection;
|
||||
use Doctrine\DBAL\Driver\Middleware;
|
||||
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
||||
use SensitiveParameter;
|
||||
|
||||
class InitializeSession implements Middleware
|
||||
{
|
||||
public function wrap(Driver $driver): Driver
|
||||
{
|
||||
return new class ($driver) extends AbstractDriverMiddleware {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function connect(
|
||||
#[SensitiveParameter]
|
||||
array $params
|
||||
): Connection {
|
||||
$connection = parent::connect($params);
|
||||
|
||||
$connection->exec(
|
||||
'ALTER SESSION SET'
|
||||
. " NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"
|
||||
. " NLS_TIME_FORMAT = 'HH24:MI:SS'"
|
||||
. " NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"
|
||||
. " NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS TZH:TZM'"
|
||||
. " NLS_NUMERIC_CHARACTERS = '.,'",
|
||||
);
|
||||
|
||||
return $connection;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Driver\PDO\PgSQL;
|
||||
|
||||
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
|
||||
use Doctrine\DBAL\Driver\PDO\Connection;
|
||||
use Doctrine\DBAL\Driver\PDO\Exception;
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use SensitiveParameter;
|
||||
|
||||
final class Driver extends AbstractPostgreSQLDriver
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return Connection
|
||||
*/
|
||||
public function connect(
|
||||
#[SensitiveParameter]
|
||||
array $params
|
||||
) {
|
||||
$driverOptions = $params['driverOptions'] ?? [];
|
||||
|
||||
if (! empty($params['persistent'])) {
|
||||
$driverOptions[PDO::ATTR_PERSISTENT] = true;
|
||||
}
|
||||
|
||||
$safeParams = $params;
|
||||
unset($safeParams['password'], $safeParams['url']);
|
||||
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
$this->constructPdoDsn($safeParams),
|
||||
$params['user'] ?? '',
|
||||
$params['password'] ?? '',
|
||||
$driverOptions,
|
||||
);
|
||||
} catch (PDOException $exception) {
|
||||
throw Exception::new($exception);
|
||||
}
|
||||
|
||||
if (
|
||||
! isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])
|
||||
|| $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES] === true
|
||||
) {
|
||||
$pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
|
||||
}
|
||||
|
||||
$connection = new Connection($pdo);
|
||||
|
||||
/* defining client_encoding via SET NAMES to avoid inconsistent DSN support
|
||||
* - passing client_encoding via the 'options' param breaks pgbouncer support
|
||||
*/
|
||||
if (isset($params['charset'])) {
|
||||
$connection->exec('SET NAMES \'' . $params['charset'] . '\'');
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the Postgres PDO DSN.
|
||||
*
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
private function constructPdoDsn(array $params): string
|
||||
{
|
||||
$dsn = 'pgsql:';
|
||||
|
||||
if (isset($params['host']) && $params['host'] !== '') {
|
||||
$dsn .= 'host=' . $params['host'] . ';';
|
||||
}
|
||||
|
||||
if (isset($params['port']) && $params['port'] !== '') {
|
||||
$dsn .= 'port=' . $params['port'] . ';';
|
||||
}
|
||||
|
||||
if (isset($params['dbname'])) {
|
||||
$dsn .= 'dbname=' . $params['dbname'] . ';';
|
||||
} elseif (isset($params['default_dbname'])) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/5705',
|
||||
'The "default_dbname" connection parameter is deprecated. Use "dbname" instead.',
|
||||
);
|
||||
|
||||
$dsn .= 'dbname=' . $params['default_dbname'] . ';';
|
||||
} else {
|
||||
if (isset($params['user']) && $params['user'] !== 'postgres') {
|
||||
Deprecation::trigger(
|
||||
'doctrine/dbal',
|
||||
'https://github.com/doctrine/dbal/pull/5705',
|
||||
'Relying on the DBAL connecting to the "postgres" database by default is deprecated.'
|
||||
. ' Unless you want to have the server determine the default database for the connection,'
|
||||
. ' specify the database name explicitly.',
|
||||
);
|
||||
}
|
||||
|
||||
// Used for temporary connections to allow operations like dropping the database currently connected to.
|
||||
$dsn .= 'dbname=postgres;';
|
||||
}
|
||||
|
||||
if (isset($params['sslmode'])) {
|
||||
$dsn .= 'sslmode=' . $params['sslmode'] . ';';
|
||||
}
|
||||
|
||||
if (isset($params['sslrootcert'])) {
|
||||
$dsn .= 'sslrootcert=' . $params['sslrootcert'] . ';';
|
||||
}
|
||||
|
||||
if (isset($params['sslcert'])) {
|
||||
$dsn .= 'sslcert=' . $params['sslcert'] . ';';
|
||||
}
|
||||
|
||||
if (isset($params['sslkey'])) {
|
||||
$dsn .= 'sslkey=' . $params['sslkey'] . ';';
|
||||
}
|
||||
|
||||
if (isset($params['sslcrl'])) {
|
||||
$dsn .= 'sslcrl=' . $params['sslcrl'] . ';';
|
||||
}
|
||||
|
||||
if (isset($params['application_name'])) {
|
||||
$dsn .= 'application_name=' . $params['application_name'] . ';';
|
||||
}
|
||||
|
||||
if (isset($params['gssencmode'])) {
|
||||
$dsn .= 'gssencmode=' . $params['gssencmode'] . ';';
|
||||
}
|
||||
|
||||
return $dsn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\DBAL\Driver\PgSQL;
|
||||
|
||||
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
|
||||
use ErrorException;
|
||||
use SensitiveParameter;
|
||||
|
||||
use function addslashes;
|
||||
use function array_filter;
|
||||
use function array_keys;
|
||||
use function array_map;
|
||||
use function array_slice;
|
||||
use function array_values;
|
||||
use function func_get_args;
|
||||
use function implode;
|
||||
use function pg_connect;
|
||||
use function restore_error_handler;
|
||||
use function set_error_handler;
|
||||
use function sprintf;
|
||||
|
||||
use const PGSQL_CONNECT_FORCE_NEW;
|
||||
|
||||
final class Driver extends AbstractPostgreSQLDriver
|
||||
{
|
||||
/** {@inheritDoc} */
|
||||
public function connect(
|
||||
#[SensitiveParameter]
|
||||
array $params
|
||||
): Connection {
|
||||
set_error_handler(
|
||||
static function (int $severity, string $message) {
|
||||
throw new ErrorException($message, 0, $severity, ...array_slice(func_get_args(), 2, 2));
|
||||
},
|
||||
);
|
||||
|
||||
try {
|
||||
$connection = pg_connect($this->constructConnectionString($params), PGSQL_CONNECT_FORCE_NEW);
|
||||
} catch (ErrorException $e) {
|
||||
throw new Exception($e->getMessage(), '08006', 0, $e);
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
if ($connection === false) {
|
||||
throw new Exception('Unable to connect to Postgres server.');
|
||||
}
|
||||
|
||||
$driverConnection = new Connection($connection);
|
||||
|
||||
if (isset($params['application_name'])) {
|
||||
$driverConnection->exec('SET application_name = ' . $driverConnection->quote($params['application_name']));
|
||||
}
|
||||
|
||||
return $driverConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the Postgres connection string
|
||||
*
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
private function constructConnectionString(
|
||||
#[SensitiveParameter]
|
||||
array $params
|
||||
): string {
|
||||
$components = array_filter(
|
||||
[
|
||||
'host' => $params['host'] ?? null,
|
||||
'port' => $params['port'] ?? null,
|
||||
'dbname' => $params['dbname'] ?? 'postgres',
|
||||
'user' => $params['user'] ?? null,
|
||||
'password' => $params['password'] ?? null,
|
||||
'sslmode' => $params['sslmode'] ?? null,
|
||||
'gssencmode' => $params['gssencmode'] ?? null,
|
||||
],
|
||||
static fn ($value) => $value !== '' && $value !== null,
|
||||
);
|
||||
|
||||
return implode(' ', array_map(
|
||||
static fn ($value, string $key) => sprintf("%s='%s'", $key, addslashes($value)),
|
||||
array_values($components),
|
||||
array_keys($components),
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user