diff --git a/README.md b/README.md index fbae4da..9ef41b9 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ There are some functionalities that are not supported by Microsoft Access in a P ## OS Requirements - Microsoft Access Database Engine Redistributable ([2010](https://www.microsoft.com/download/details.aspx?id=13255) or [2016](https://www.microsoft.com/download/details.aspx?id=54920)). -- Register a **DSN** in **ODBC Data Source Administrator** (odbcad32.exe). +- Register a **DSN** in **ODBC Data Source Administrator** `odbcad32.exe`. ## Installation diff --git a/src/Doctrine/DBAL/Driver/MicrosoftAccess/Driver.php b/src/Doctrine/DBAL/Driver/MicrosoftAccess/Driver.php index 28814a9..05ee3d6 100644 --- a/src/Doctrine/DBAL/Driver/MicrosoftAccess/Driver.php +++ b/src/Doctrine/DBAL/Driver/MicrosoftAccess/Driver.php @@ -23,7 +23,7 @@ public function connect( $password = null, array $driverOptions = [] ): \Doctrine\DBAL\Driver\Connection { - $this->assertRequiredParameters($driverOptions); + $this->assertRequiredDriverOptions($driverOptions); try { $conn = new PDOConnection( @@ -62,49 +62,25 @@ public function getSchemaManager(Connection $conn): AbstractSchemaManager return new MicrosoftAccessSchemaManager($conn, $this->odbcConnection); } - /** - * @param array $driverOptions - * @throws \Exception - */ - private function assertRequiredParameters(array $driverOptions): void + private function assertRequiredDriverOptions(array $driverOptions): void { - $dsn = $this->getDsn($driverOptions); - - if ($dsn === null) { + if (false === \array_key_exists('dsn', $driverOptions)) { throw new Exception\InvalidArgumentException("The driver option 'dsn' is mandatory"); } } - /** - * Get the DSN for the PDO connection. - * - * @param array $driverOptions - * @return string - */ protected function constructPdoDsn(array $driverOptions): string { return 'odbc:' . $this->getDsn($driverOptions); } - /** - * Get the DSN for the ODBC connection. - * - * @param array $driverOptions - * @return string - */ protected function constructOdbcDsn(array $driverOptions): string { return $this->getDsn($driverOptions); } - /** - * Get the DSN by the driver's parameters and options - * - * @param array $driverOptions - * @return string|null - */ - private function getDsn(array $driverOptions): ?string + private function getDsn(array $driverOptions): string { - return $driverOptions['dsn'] ?? null; + return $driverOptions['dsn']; } } diff --git a/src/Doctrine/DBAL/Platforms/MicrosoftAccessPlatform.php b/src/Doctrine/DBAL/Platforms/MicrosoftAccessPlatform.php index 4f5ce59..11adaed 100644 --- a/src/Doctrine/DBAL/Platforms/MicrosoftAccessPlatform.php +++ b/src/Doctrine/DBAL/Platforms/MicrosoftAccessPlatform.php @@ -8,49 +8,30 @@ final class MicrosoftAccessPlatform extends SQLServer2012Platform { - /** @link \Doctrine\DBAL\Platforms\AbstractPlatform::getName */ + /** + * {@inheritDoc} + */ public function getName(): string { return 'msaccess'; } - /** @link \Doctrine\DBAL\Platforms\AbstractPlatform::supportsForeignKeyConstraints */ + /** + * {@inheritDoc} + */ public function supportsForeignKeyConstraints() { return false; } - /** @link \Doctrine\DBAL\Platforms\SQLServer2005Platform::supportsLimitOffset */ + /** + * {@inheritDoc} + */ public function supportsLimitOffset() { return false; } - /** @link \Doctrine\DBAL\Platforms\AbstractPlatform::initializeDoctrineTypeMappings */ - protected function initializeDoctrineTypeMappings() - { - $this->doctrineTypeMapping = [ - 'bit' => 'boolean', - 'byte' => 'boolean', - 'counter' => 'bigint', - 'currency' => 'decimal', - 'datetime' => 'datetime', - 'double' => 'float', - 'integer' => 'integer', - 'longbinary' => 'binary', - 'longchar' => 'text', - 'real' => 'float', - 'smallint' => 'smallint', - 'varchar' => 'string', - ]; - } - - /** @link \Doctrine\DBAL\Platforms\AbstractPlatform::getReservedKeywordsClass */ - protected function getReservedKeywordsClass(): string - { - return MicrosoftAccessKeywords::class; - } - /** * {@inheritDoc} */ @@ -74,4 +55,33 @@ public function getTimeFormatString() { return 'H:i:s'; } + + /** + * {@inheritDoc} + */ + protected function initializeDoctrineTypeMappings() + { + $this->doctrineTypeMapping = [ + 'bit' => 'boolean', + 'byte' => 'boolean', + 'counter' => 'bigint', + 'currency' => 'decimal', + 'datetime' => 'datetime', + 'double' => 'float', + 'integer' => 'integer', + 'longbinary' => 'binary', + 'longchar' => 'text', + 'real' => 'float', + 'smallint' => 'smallint', + 'varchar' => 'string', + ]; + } + + /** + * {@inheritDoc} + */ + protected function getReservedKeywordsClass(): string + { + return MicrosoftAccessKeywords::class; + } } diff --git a/tests/BaseTest.php b/tests/BaseTest.php index d87e2c9..796e720 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -19,7 +19,6 @@ public function connections(): \Iterator $params = [ 'driverClass' => Driver::class, - 'dsn' => $this->dsn(), 'driverOptions' => $this->driverOptions(), ]; @@ -52,7 +51,9 @@ protected function dsn(): string protected function driverOptions(): array { - return []; + return [ + 'dsn' => $this->dsn(), + ]; } private function isMicrosoftWindows(): bool diff --git a/tests/Doctrine/DBAL/Driver/MicrosoftAccess/StatementTest.php b/tests/Doctrine/DBAL/Driver/MicrosoftAccess/StatementTest.php index bbb1a42..49ae3c9 100644 --- a/tests/Doctrine/DBAL/Driver/MicrosoftAccess/StatementTest.php +++ b/tests/Doctrine/DBAL/Driver/MicrosoftAccess/StatementTest.php @@ -56,8 +56,11 @@ protected function dsn(): string protected function driverOptions(): array { - return [ - 'charset' => 'UTF-8', - ]; + return \array_merge( + parent::driverOptions(), + [ + 'charset' => 'UTF-8', + ], + ); } }