Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing default schemes #1718

Closed
MrMitch opened this issue Oct 27, 2023 · 1 comment
Closed

Missing default schemes #1718

MrMitch opened this issue Oct 27, 2023 · 1 comment

Comments

@MrMitch
Copy link

MrMitch commented Oct 27, 2023

Hi,

I've noticed that not all official drivers provided by Doctrine can be used in this bundle with a DSN. Only some drivers have an associated scheme registered in the ConnectionFactory class.

public const DEFAULT_SCHEME_MAP = [
'db2' => 'ibm_db2',
'mssql' => 'pdo_sqlsrv',
'mysql' => 'pdo_mysql',
'mysql2' => 'pdo_mysql', // Amazon RDS, for some weird reason
'postgres' => 'pdo_pgsql',
'postgresql' => 'pdo_pgsql',
'pgsql' => 'pdo_pgsql',
'sqlite' => 'pdo_sqlite',
'sqlite3' => 'pdo_sqlite',
];

Imagine that you want to use the sqlsrv driver. By analogy with the other available drivers, I would expect the DSN for this driver to look like sqlsrv://user:password@host:port.
With the current configuration, using a DSN like this does not work because no driver is mapped to the sqlsrv scheme. In this case the default pdo_mysql driver is used.

Since doctrine/dbal:3.7.0 and doctrine/doctrine-bundle:2.10.0 we can add custom scheme-to-driver mappings with the doctrine.dbal.driver_schemes configuration option (made possible by doctrine/dbal#6059 and #1669).

However, if I try to register the sqlsrv scheme with the doctrine.dbal.driver_schemes option, the configuration fails because of the harcoded list of "official drivers" in the Configuration class.

->arrayNode('driver_schemes')
->useAttributeAsKey('scheme')
->normalizeKeys(false)
->scalarPrototype()->end()
->info('Defines a driver for given URL schemes. Schemes being driver names cannot be redefined. However, other default schemes can be overwritten.')
->validate()
->always()
->then(static function (array $value) {
$unsupportedSchemes = [];
foreach ($value as $scheme => $driver) {
if (! in_array($scheme, ['pdo-mysql', 'pdo-sqlite', 'pdo-pgsql', 'pdo-oci', 'oci8', 'ibm-db2', 'pdo-sqlsrv', 'mysqli', 'pgsql', 'sqlsrv', 'sqlite3'], true)) {
continue;
}
$unsupportedSchemes[] = $scheme;
}
if ($unsupportedSchemes) {
throw new InvalidArgumentException(sprintf('Registering a scheme with the name of one of the official drivers is forbidden, as those are defined in DBAL itself. The following schemes are forbidden: %s', implode(', ', $unsupportedSchemes)));
}
return $value;
})
->end()
->end()

The same limitation applies to the oci8 and mysqli official drivers which are absent from the default schemes listed in ConnectionFactory but forbidden in Configuration.

I would gladely prepare a PR to address this but I'd rather ask for the direction you would prefer to go beforehand

One way to fix this would be to add a few entries to ConnectionFactory::DEFAULT_SCHEME_MAP to enable default support for the missing drivers. This seems to me like the prefered option because it enables more official drivers out of the box. I find it strange that no driver is available to use with a DNS by default for SQL Server and OCI.

Alternatively, the affected drivers could be removed form the hardcoded list in the Configuration class, leaving the responsability to every project needing them to register the drivers manually.

Thank you for taking the time to read this.

@MrMitch
Copy link
Author

MrMitch commented Oct 28, 2023

My problem was caused by something else in my app, this issue is invalid and can be closed.

@MrMitch MrMitch closed this as completed Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant