From c8ada84101cf0ef5c1e4c409673570d6584f26bb Mon Sep 17 00:00:00 2001 From: Pierre Rineau Date: Thu, 18 Apr 2024 14:15:46 +0200 Subject: [PATCH] no issue - progressively decouple bridge in order to hide it as an implementation detail --- CHANGELOG.md | 10 ++ docs/content/bridges/error.md | 8 +- docs/content/converter/converter.md | 16 ++- docs/content/introduction/configuration.md | 2 +- docs/content/introduction/getting-started.md | 41 ++++-- docs/content/introduction/usage.md | 3 +- docs/content/query/result.md | 14 +- docs/content/query/schema.md | 9 +- docs/content/query/transaction.md | 33 +++-- src/Bridge/AbstractBridge.php | 2 +- src/Bridge/Bridge.php | 8 -- .../ErrorConverter/DoctrineErrorConverter.php | 18 +-- .../ErrorConverter/PdoMySQLErrorConverter.php | 18 +-- .../PdoPostgreSQLErrorConverter.php | 18 +-- .../PdoSQLServerErrorConverter.php | 18 +-- .../PdoSQLiteErrorConverter.php | 14 +- src/DatabaseSession.php | 10 +- .../AmbiguousIdentifierError.php | 2 +- .../ColumnDoesNotExistError.php | 2 +- .../ConstraintViolationError.php | 2 +- .../DatabaseObjectDoesNotExistError.php | 2 +- .../ForeignKeyConstraintViolationError.php | 2 +- .../NotNullConstraintViolationError.php | 2 +- src/Error/{Bridge => Server}/ServerError.php | 2 +- .../TableDoesNotExistError.php | 2 +- .../TransactionDeadlockError.php | 2 +- .../{Bridge => Server}/TransactionError.php | 2 +- .../TransactionFailedError.php | 2 +- .../TransactionLockWaitTimeoutError.php | 2 +- .../UnableToConnectError.php | 2 +- .../UniqueConstraintViolationError.php | 2 +- .../Schema/SQLServerSchemaManager.php | 2 +- .../Transaction/AbstractTransaction.php | 2 +- src/Platform/Transaction/MySQLTransaction.php | 2 +- src/Schema/SchemaManager.php | 2 +- src/Testing/FunctionalTestCaseTrait.php | 28 ++-- src/Transaction/Transaction.php | 2 +- src/Transaction/TransactionSavepoint.php | 2 +- .../Bridge/AbstractErrorConverterTestCase.php | 46 +++--- .../Doctrine/DoctrineQueryBuilderTest.php | 4 +- tests/Bridge/Pdo/PdoDriverTest.php | 4 +- tests/Functional/SelectFunctionalTest.php | 18 +-- .../Functional/TransactionFunctionalTest.php | 132 +++++++++--------- tests/Functional/UpdateFunctionalTest.php | 22 +-- .../Schema/AbstractSchemaTestCase.php | 50 +++---- 45 files changed, 317 insertions(+), 269 deletions(-) rename src/Error/{Bridge => Server}/AmbiguousIdentifierError.php (64%) rename src/Error/{Bridge => Server}/ColumnDoesNotExistError.php (68%) rename src/Error/{Bridge => Server}/ConstraintViolationError.php (64%) rename src/Error/{Bridge => Server}/DatabaseObjectDoesNotExistError.php (65%) rename src/Error/{Bridge => Server}/ForeignKeyConstraintViolationError.php (69%) rename src/Error/{Bridge => Server}/NotNullConstraintViolationError.php (68%) rename src/Error/{Bridge => Server}/ServerError.php (62%) rename src/Error/{Bridge => Server}/TableDoesNotExistError.php (68%) rename src/Error/{Bridge => Server}/TransactionDeadlockError.php (65%) rename src/Error/{Bridge => Server}/TransactionError.php (61%) rename src/Error/{Bridge => Server}/TransactionFailedError.php (64%) rename src/Error/{Bridge => Server}/TransactionLockWaitTimeoutError.php (66%) rename src/Error/{Bridge => Server}/UnableToConnectError.php (62%) rename src/Error/{Bridge => Server}/UniqueConstraintViolationError.php (68%) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbfc09a..29f5430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## Next + +* [feature] `Bridge::getSchemaManager()` method is moved into the + `DatabaseSession` interface instead. Bridges should now never be used + as a public API for end users. +* [bc] ⚠️ All errors in the `MakinaCorpus\QueryBuilder\Error\Bridge` + namespace are now in the `MakinaCorpus\QueryBuilder\Error\Server` namespace. +* [bc] ⚠️ `FunctionalTestCaseTrait::getBridge()` was renamed to + `FunctionalTestCaseTrait::getDatabaseSession()`. + ## 1.4.0 * [feature] ⭐️ Added `DatabaseSession::getVendorName()`, `DatabaseSession::getVendorVersion()`, diff --git a/docs/content/bridges/error.md b/docs/content/bridges/error.md index 9d45f4e..fe01921 100644 --- a/docs/content/bridges/error.md +++ b/docs/content/bridges/error.md @@ -15,10 +15,10 @@ They all inherit from `MakinaCorpus\QueryBuilder\Error\QueryBuilderError`. ## Server errors All server side errors are exception, when a driver error is caught and supported, -it will be converted to a `MakinaCorpus\QueryBuilder\Error\Bridge\*` exception. +it will be converted to a `MakinaCorpus\QueryBuilder\Error\Server\*` exception. When an error is not supported then the generic -`MakinaCorpus\QueryBuilder\Error\Bridge\ServerError` is raised. +`MakinaCorpus\QueryBuilder\Error\Server\ServerError` is raised. ## Bridge errors passthrough @@ -38,10 +38,10 @@ use Doctrine\DBAL\DriverManager; use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder; $connection = DriverManager::getConnection(['driver' => 'pdo_pgsql', /* ... */]); -$queryBuilder = new DoctrineQueryBuilder($connection); +$bridge = new DoctrineQueryBuilder($connection); // Here it is: -$queryBuilder->disableErrorConverter(); +$bridge->disableErrorConverter(); ``` :::info diff --git a/docs/content/converter/converter.md b/docs/content/converter/converter.md index ff4531b..8bc171f 100644 --- a/docs/content/converter/converter.md +++ b/docs/content/converter/converter.md @@ -6,8 +6,9 @@ **Input value converter** converts user input values **from PHP to SQL**. -It is plugged per default in the `Bridge` or `QueryBuilder` instance then -propagated to the `ArgumentBag` instance prior query execution. +It is plugged per default in the `Bridge` instance, hence for the final user +the `QueryBuilder` and `DatabaseSession` instances, then propagated to the +`ArgumentBag` instance prior query execution. When `ArgumentBag::getAll()` is called, all values are lazily converted from PHP to SQL using the types that were specified during query building. @@ -32,8 +33,9 @@ See the [legacy data type matrix](../query/datatype) until the documentation is **Output value converter** converts user input values **from SQL to PHP**. -It is plugged per default in the `Bridge` or `QueryBuilder` instance then -propagated to the `ResultRow` instance after query execution. +It is plugged per default in the `Bridge` instance, hence for the final user +the `QueryBuilder` and `DatabaseSession` instances, then propagated to the +`ResultRow` instance after query execution. When you decide to iterate over `ResultRow` instances, by calling `Result::fetchRow()` then the output converter may be used if you specify @@ -91,7 +93,7 @@ $escaper = new StandardEscaper(); // Pass here the newly created converter. $writer = new PostgreSQLWriter($escaper, $converter); -$queryBuilder = new DefaultQueryBuilder(); +$session = new DefaultQueryBuilder(); ``` ### When using a bridge @@ -102,10 +104,10 @@ by the bridge, hence the different procedure. ```php use MakinaCorpus\QueryBuilder\Bridge\AbstractBridge; -assert($bridge instanceof AbstractBridge); +assert($session instanceof AbstractBridge); // Directly register your implementation into the bridge. -$bridge +$session ->getConverterPluginRegistry ->register( new MyCustomOutputConverter(), diff --git a/docs/content/introduction/configuration.md b/docs/content/introduction/configuration.md index 6e5505c..f206b6f 100644 --- a/docs/content/introduction/configuration.md +++ b/docs/content/introduction/configuration.md @@ -50,7 +50,7 @@ While your write your SQL queries, you can, and probably will, provide userland arbitrary identifiers, such as table names, column names, ... As show below: ```php -$queryBuilder->select('some_table')->column('some_column'); +$session->select('some_table')->column('some_column'); ``` Those needs escaping, in order to prevent SQL injection or unintential syntax diff --git a/docs/content/introduction/getting-started.md b/docs/content/introduction/getting-started.md index 3c139d9..dd4cd23 100644 --- a/docs/content/introduction/getting-started.md +++ b/docs/content/introduction/getting-started.md @@ -117,6 +117,7 @@ Setting it up is easier than standalone setup: ```php use Doctrine\DBAL\DriverManager; use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder; +use MakinaCorpus\QueryBuilder\DatabaseSession; // Create or fetch your doctrine/dbal connection. $connection = DriverManager::getConnection([ @@ -125,9 +126,19 @@ $connection = DriverManager::getConnection([ ]); // Create the query builder. -$queryBuilder = new DoctrineQueryBuilder($connection); +$session = new DoctrineQueryBuilder($connection); +\assert($session instanceof DatabaseSession); ``` +:::warning +For the final user, the *bridge* should be hidden and the +`MakinaCorpus\QueryBuilder\DatabaseSession` exposed instead. The bridge is an +internal component that ties the query builder with a third-party driver. + +All useful features are exposed via the `DatabaseSession` whereas the bridge +should remain hidden, as its signature is subject to changes. +::: + :::tip You don't need to specify the SQL dialect to use, it will be derived from the `doctrine/dbal` connection automatically, without requiring any extra SQL @@ -139,7 +150,7 @@ query to do so. Now we can write a query and execute it directly: ```php -$result = $queryBuilder +$result = $session ->select('users') ->column('*') ->where('id', 'john.doe@example.com') @@ -179,14 +190,25 @@ Setting it up is easier than standalone setup: ```php use MakinaCorpus\QueryBuilder\Bridge\Pdo\PdoQueryBuilder; +use MakinaCorpus\QueryBuilder\DatabaseSession; // Create or fetch your PDO connection. $connection = new \PDO('pgsql:...'); // User facade for you to build SQL queries. -$queryBuilder = new PdoQueryBuilder($connection); +$session = new PdoQueryBuilder($connection); +\assert($session instanceof DatabaseSession); ``` +:::warning +For the final user, the *bridge* should be hidden and the +`MakinaCorpus\QueryBuilder\DatabaseSession` exposed instead. The bridge is an +internal component that ties the query builder with a third-party driver. + +All useful features are exposed via the `DatabaseSession` whereas the bridge +should remain hidden, as its signature is subject to changes. +::: + :::tip You don't need to specify the SQL dialect to use, it will be derived from the `PDO` connection automatically. @@ -195,7 +217,7 @@ the `PDO` connection automatically. ### 3. Write your query and execute it ```php -$result = $queryBuilder +$result = $session ->select('users') ->column('*') ->where('id', 'john.doe@example.com') @@ -258,7 +280,6 @@ declare (strict_types=1); namespace App\Controller; -use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -267,9 +288,9 @@ class TestingController extends AbstractController { #[Route('/testing/query-builder', name: 'testing_query_builder')] public function testQueryBuilder( - DoctrineQueryBuilder $queryBuilder, + DatabaseSession $session, ): Response { - $result = $queryBuilder + $result = $session ->select('some_table') ->executeQuery() ; @@ -295,10 +316,10 @@ If you need to use another connection, please read the next chapter. ### Using a query builder for another connection You may have configured more than one `doctrine/dbal` connection, this bundle -will register as many `MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder` -services as doctrine connections being configured. +will register as many `MakinaCorpus\QueryBuilder\DatabaseSession` services as +doctrine connections being configured. -Each service identifier is `query_builder.doctrine.CONNECTION_NAME` where +Each service identifier is `query_builder.session.CONNECTION_NAME` where `CONNECTION_NAME` is the Doctrine bundle configured connection identifier. :::tip diff --git a/docs/content/introduction/usage.md b/docs/content/introduction/usage.md index 63cc40a..acb66f3 100644 --- a/docs/content/introduction/usage.md +++ b/docs/content/introduction/usage.md @@ -11,7 +11,8 @@ almost every method call, exception being the methods that create new objects that requires you to manipulate. :::info -In all this page, The `$queryBuilder` variable will always be an instance of `MakinaCorpus\QueryBuilder\QueryBuilder`. +In all this page, The `$queryBuilder` variable will always be an instance of +`MakinaCorpus\QueryBuilder\DatabaseSession` or `MakinaCorpus\QueryBuilder\QueryBuilder`. The `$result` variable will always be an instance of `MakinaCorpus\QueryBuilder\Result\Result`. ::: diff --git a/docs/content/query/result.md b/docs/content/query/result.md index 942b564..8d71910 100644 --- a/docs/content/query/result.md +++ b/docs/content/query/result.md @@ -24,14 +24,14 @@ you can call `Query::executeQuery()` over your queries, for example: use Doctrine\DBAL\DriverManager; use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder; -$queryBuilder = new DoctrineQueryBuilder( +$session = new DoctrineQueryBuilder( DriverManager::getConnection([ 'driver' => 'pdo_pgsql', // ... driver options. ]) ); -$result = $queryBuilder +$result = $session ->select('some_table') ->column('*') ->executeQuery() @@ -48,14 +48,14 @@ You may also directly execute raw SQL code as such: use Doctrine\DBAL\DriverManager; use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder; -$queryBuilder = new DoctrineQueryBuilder( +$session = new DoctrineQueryBuilder( DriverManager::getConnection([ 'driver' => 'pdo_pgsql', // ... driver options. ]) ); -$result = $queryBuilder +$result = $session ->executeQuery( << 'pdo_pgsql', // ... driver options. ]) ); -$result = $queryBuilder +$result = $session ->executeQuery( <<executeQuery( <<getSchemaManager(); +$schemaManager = $session->getSchemaManager(); ``` `$schemaManager` will be an instance of `MakinaCorpus\QueryBuilder\Schema\SchemaManager`. diff --git a/docs/content/query/transaction.md b/docs/content/query/transaction.md index 01f27bf..358e928 100644 --- a/docs/content/query/transaction.md +++ b/docs/content/query/transaction.md @@ -2,7 +2,7 @@ ## Introduction -When used in conjunction with a bridge, you may use transactions. +As soon as you have a working `DatabaseSession` instance, you may use transactions. SQL transaction supports the given level of features: @@ -16,13 +16,21 @@ Consider that you are manipulating a brige instance, which name is `$brige`, you simply start a transaction this way: ```php -$transaction = $bridge->beginTransaction(); +use MakinaCorpus\QueryBuilder\DatabaseSession; + +assert($session instanceof DatabaseSession); + +$transaction = $session->beginTransaction(); ``` You may also create the stub object for it, then start it later: ```php -$transaction = $bridge->createTransaction(); +use MakinaCorpus\QueryBuilder\DatabaseSession; + +assert($session instanceof DatabaseSession); + +$transaction = $session->createTransaction(); $transaction->isStarted(); // returns false @@ -42,11 +50,14 @@ $transaction->commit(); Error handling is up to you, we advice writing such algorightm to do it right: ```sql -use MakinaCorpus\QueryBuilder\Error\Bridge\ServerError; +use MakinaCorpus\QueryBuilder\DatabaseSession; +use MakinaCorpus\QueryBuilder\Error\Server\ServerError; + +assert($session instanceof DatabaseSession); $transaction = null; try { - $transaction = $bridge->beginTransaction(); + $transaction = $session->beginTransaction(); // ... you SQL statements here ... @@ -61,15 +72,17 @@ try { } ``` -Transaction `ROLLBACK` is never issued automatically, one exception stands: if the transaction -objet goes out of scope, when the destructor is called, then `ROLLBACK` is issued. +Transaction `ROLLBACK` is never issued automatically, one exception stands: if +the transaction objet goes out of scope, when the destructor is called, then +`ROLLBACK` is issued. All transactions must be `COMMIT` explicitely, or will be `ROLLBACK` later. :::warning -The bridge is a single SQL session, which means that if you start a transaction, it will -remain in memory until it is being commited or rollbacked. Code later in stack will issue -SQL queries in the same transaction until it's finished. +Transaction is shared for the `DatabaseSession` instance which means that if +you start a transaction, it will remain in memory until it is being commited +or rollbacked. Code later in stack will issue SQL queries in the same +transaction until it's finished. ::: ## Savepoints diff --git a/src/Bridge/AbstractBridge.php b/src/Bridge/AbstractBridge.php index 335950f..cfb1c34 100644 --- a/src/Bridge/AbstractBridge.php +++ b/src/Bridge/AbstractBridge.php @@ -7,8 +7,8 @@ use MakinaCorpus\QueryBuilder\Converter\Converter; use MakinaCorpus\QueryBuilder\Converter\ConverterPluginRegistry; use MakinaCorpus\QueryBuilder\DefaultQueryBuilder; -use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionError; use MakinaCorpus\QueryBuilder\Error\QueryBuilderError; +use MakinaCorpus\QueryBuilder\Error\Server\TransactionError; use MakinaCorpus\QueryBuilder\Error\UnsupportedFeatureError; use MakinaCorpus\QueryBuilder\Escaper\Escaper; use MakinaCorpus\QueryBuilder\Expression; diff --git a/src/Bridge/Bridge.php b/src/Bridge/Bridge.php index 4c74d9f..9d7016a 100644 --- a/src/Bridge/Bridge.php +++ b/src/Bridge/Bridge.php @@ -5,7 +5,6 @@ namespace MakinaCorpus\QueryBuilder\Bridge; use MakinaCorpus\QueryBuilder\DatabaseSession; -use MakinaCorpus\QueryBuilder\Schema\SchemaManager; use MakinaCorpus\QueryBuilder\Writer\Writer; interface Bridge extends DatabaseSession @@ -54,13 +53,6 @@ public function isVersionGreaterOrEqualThan(string $version): bool; */ public function getWriter(): Writer; - /** - * Get schema manager. - * - * @experimental - */ - public function getSchemaManager(): SchemaManager; - /** * Free everything. */ diff --git a/src/Bridge/Doctrine/ErrorConverter/DoctrineErrorConverter.php b/src/Bridge/Doctrine/ErrorConverter/DoctrineErrorConverter.php index befa283..e9e9cf3 100644 --- a/src/Bridge/Doctrine/ErrorConverter/DoctrineErrorConverter.php +++ b/src/Bridge/Doctrine/ErrorConverter/DoctrineErrorConverter.php @@ -20,15 +20,15 @@ use Doctrine\DBAL\Schema\Exception\TableDoesNotExist; use MakinaCorpus\QueryBuilder\Bridge\ErrorConverter; use MakinaCorpus\QueryBuilder\Bridge\Pdo\ErrorConverter\PdoSQLiteErrorConverter; -use MakinaCorpus\QueryBuilder\Error\Bridge\AmbiguousIdentifierError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ColumnDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\DatabaseObjectDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ForeignKeyConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\NotNullConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TableDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\UnableToConnectError; -use MakinaCorpus\QueryBuilder\Error\Bridge\UniqueConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\AmbiguousIdentifierError; +use MakinaCorpus\QueryBuilder\Error\Server\ColumnDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\ConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\DatabaseObjectDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\ForeignKeyConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\NotNullConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\TableDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\UnableToConnectError; +use MakinaCorpus\QueryBuilder\Error\Server\UniqueConstraintViolationError; class DoctrineErrorConverter implements ErrorConverter { diff --git a/src/Bridge/Pdo/ErrorConverter/PdoMySQLErrorConverter.php b/src/Bridge/Pdo/ErrorConverter/PdoMySQLErrorConverter.php index 9ef30e3..8361be4 100644 --- a/src/Bridge/Pdo/ErrorConverter/PdoMySQLErrorConverter.php +++ b/src/Bridge/Pdo/ErrorConverter/PdoMySQLErrorConverter.php @@ -5,15 +5,15 @@ namespace MakinaCorpus\QueryBuilder\Bridge\Pdo\ErrorConverter; use MakinaCorpus\QueryBuilder\Bridge\ErrorConverter; -use MakinaCorpus\QueryBuilder\Error\Bridge\AmbiguousIdentifierError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ForeignKeyConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\NotNullConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TableDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionDeadlockError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionLockWaitTimeoutError; -use MakinaCorpus\QueryBuilder\Error\Bridge\UniqueConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ColumnDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ServerError; +use MakinaCorpus\QueryBuilder\Error\Server\AmbiguousIdentifierError; +use MakinaCorpus\QueryBuilder\Error\Server\ColumnDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\ForeignKeyConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\NotNullConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\ServerError; +use MakinaCorpus\QueryBuilder\Error\Server\TableDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\TransactionDeadlockError; +use MakinaCorpus\QueryBuilder\Error\Server\TransactionLockWaitTimeoutError; +use MakinaCorpus\QueryBuilder\Error\Server\UniqueConstraintViolationError; class PdoMySQLErrorConverter implements ErrorConverter { diff --git a/src/Bridge/Pdo/ErrorConverter/PdoPostgreSQLErrorConverter.php b/src/Bridge/Pdo/ErrorConverter/PdoPostgreSQLErrorConverter.php index 86511a2..d9f388c 100644 --- a/src/Bridge/Pdo/ErrorConverter/PdoPostgreSQLErrorConverter.php +++ b/src/Bridge/Pdo/ErrorConverter/PdoPostgreSQLErrorConverter.php @@ -5,15 +5,15 @@ namespace MakinaCorpus\QueryBuilder\Bridge\Pdo\ErrorConverter; use MakinaCorpus\QueryBuilder\Bridge\ErrorConverter; -use MakinaCorpus\QueryBuilder\Error\Bridge\AmbiguousIdentifierError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ColumnDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ForeignKeyConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\NotNullConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ServerError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TableDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionDeadlockError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionError; -use MakinaCorpus\QueryBuilder\Error\Bridge\UniqueConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\AmbiguousIdentifierError; +use MakinaCorpus\QueryBuilder\Error\Server\ColumnDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\ForeignKeyConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\NotNullConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\ServerError; +use MakinaCorpus\QueryBuilder\Error\Server\TableDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\TransactionDeadlockError; +use MakinaCorpus\QueryBuilder\Error\Server\TransactionError; +use MakinaCorpus\QueryBuilder\Error\Server\UniqueConstraintViolationError; class PdoPostgreSQLErrorConverter implements ErrorConverter { diff --git a/src/Bridge/Pdo/ErrorConverter/PdoSQLServerErrorConverter.php b/src/Bridge/Pdo/ErrorConverter/PdoSQLServerErrorConverter.php index dd0b7c9..c91419e 100644 --- a/src/Bridge/Pdo/ErrorConverter/PdoSQLServerErrorConverter.php +++ b/src/Bridge/Pdo/ErrorConverter/PdoSQLServerErrorConverter.php @@ -5,15 +5,15 @@ namespace MakinaCorpus\QueryBuilder\Bridge\Pdo\ErrorConverter; use MakinaCorpus\QueryBuilder\Bridge\ErrorConverter; -use MakinaCorpus\QueryBuilder\Error\Bridge\AmbiguousIdentifierError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ColumnDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\DatabaseObjectDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ForeignKeyConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\NotNullConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ServerError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TableDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\UnableToConnectError; -use MakinaCorpus\QueryBuilder\Error\Bridge\UniqueConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\AmbiguousIdentifierError; +use MakinaCorpus\QueryBuilder\Error\Server\ColumnDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\DatabaseObjectDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\ForeignKeyConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\NotNullConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\ServerError; +use MakinaCorpus\QueryBuilder\Error\Server\TableDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\UnableToConnectError; +use MakinaCorpus\QueryBuilder\Error\Server\UniqueConstraintViolationError; class PdoSQLServerErrorConverter implements ErrorConverter { diff --git a/src/Bridge/Pdo/ErrorConverter/PdoSQLiteErrorConverter.php b/src/Bridge/Pdo/ErrorConverter/PdoSQLiteErrorConverter.php index 67a24a9..ec191b2 100644 --- a/src/Bridge/Pdo/ErrorConverter/PdoSQLiteErrorConverter.php +++ b/src/Bridge/Pdo/ErrorConverter/PdoSQLiteErrorConverter.php @@ -5,13 +5,13 @@ namespace MakinaCorpus\QueryBuilder\Bridge\Pdo\ErrorConverter; use MakinaCorpus\QueryBuilder\Bridge\ErrorConverter; -use MakinaCorpus\QueryBuilder\Error\Bridge\AmbiguousIdentifierError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ColumnDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\NotNullConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ServerError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TableDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionDeadlockError; -use MakinaCorpus\QueryBuilder\Error\Bridge\UniqueConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\AmbiguousIdentifierError; +use MakinaCorpus\QueryBuilder\Error\Server\ColumnDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\NotNullConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\ServerError; +use MakinaCorpus\QueryBuilder\Error\Server\TableDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\TransactionDeadlockError; +use MakinaCorpus\QueryBuilder\Error\Server\UniqueConstraintViolationError; class PdoSQLiteErrorConverter implements ErrorConverter { diff --git a/src/DatabaseSession.php b/src/DatabaseSession.php index 6770405..fc9f662 100644 --- a/src/DatabaseSession.php +++ b/src/DatabaseSession.php @@ -4,8 +4,9 @@ namespace MakinaCorpus\QueryBuilder; -use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionError; +use MakinaCorpus\QueryBuilder\Error\Server\TransactionError; use MakinaCorpus\QueryBuilder\Result\Result; +use MakinaCorpus\QueryBuilder\Schema\SchemaManager; use MakinaCorpus\QueryBuilder\Transaction\Transaction; /** @@ -105,4 +106,11 @@ public function createTransaction(int $isolationLevel = Transaction::REPEATABLE_ * Alias of createTransaction() but it will force it to start */ public function beginTransaction(int $isolationLevel = Transaction::REPEATABLE_READ, bool $allowPending = true): Transaction; + + /** + * Get schema manager. + * + * @experimental + */ + public function getSchemaManager(): SchemaManager; } diff --git a/src/Error/Bridge/AmbiguousIdentifierError.php b/src/Error/Server/AmbiguousIdentifierError.php similarity index 64% rename from src/Error/Bridge/AmbiguousIdentifierError.php rename to src/Error/Server/AmbiguousIdentifierError.php index 3d867ea..f946cc2 100644 --- a/src/Error/Bridge/AmbiguousIdentifierError.php +++ b/src/Error/Server/AmbiguousIdentifierError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class AmbiguousIdentifierError extends ServerError { diff --git a/src/Error/Bridge/ColumnDoesNotExistError.php b/src/Error/Server/ColumnDoesNotExistError.php similarity index 68% rename from src/Error/Bridge/ColumnDoesNotExistError.php rename to src/Error/Server/ColumnDoesNotExistError.php index 956d04a..447b346 100644 --- a/src/Error/Bridge/ColumnDoesNotExistError.php +++ b/src/Error/Server/ColumnDoesNotExistError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class ColumnDoesNotExistError extends DatabaseObjectDoesNotExistError { diff --git a/src/Error/Bridge/ConstraintViolationError.php b/src/Error/Server/ConstraintViolationError.php similarity index 64% rename from src/Error/Bridge/ConstraintViolationError.php rename to src/Error/Server/ConstraintViolationError.php index 23745b8..4c3a0c4 100644 --- a/src/Error/Bridge/ConstraintViolationError.php +++ b/src/Error/Server/ConstraintViolationError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class ConstraintViolationError extends ServerError { diff --git a/src/Error/Bridge/DatabaseObjectDoesNotExistError.php b/src/Error/Server/DatabaseObjectDoesNotExistError.php similarity index 65% rename from src/Error/Bridge/DatabaseObjectDoesNotExistError.php rename to src/Error/Server/DatabaseObjectDoesNotExistError.php index ca8d684..65918bc 100644 --- a/src/Error/Bridge/DatabaseObjectDoesNotExistError.php +++ b/src/Error/Server/DatabaseObjectDoesNotExistError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class DatabaseObjectDoesNotExistError extends ServerError { diff --git a/src/Error/Bridge/ForeignKeyConstraintViolationError.php b/src/Error/Server/ForeignKeyConstraintViolationError.php similarity index 69% rename from src/Error/Bridge/ForeignKeyConstraintViolationError.php rename to src/Error/Server/ForeignKeyConstraintViolationError.php index 120f586..ddb7e4b 100644 --- a/src/Error/Bridge/ForeignKeyConstraintViolationError.php +++ b/src/Error/Server/ForeignKeyConstraintViolationError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class ForeignKeyConstraintViolationError extends ConstraintViolationError { diff --git a/src/Error/Bridge/NotNullConstraintViolationError.php b/src/Error/Server/NotNullConstraintViolationError.php similarity index 68% rename from src/Error/Bridge/NotNullConstraintViolationError.php rename to src/Error/Server/NotNullConstraintViolationError.php index 37ef404..ea4a7b2 100644 --- a/src/Error/Bridge/NotNullConstraintViolationError.php +++ b/src/Error/Server/NotNullConstraintViolationError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class NotNullConstraintViolationError extends ConstraintViolationError { diff --git a/src/Error/Bridge/ServerError.php b/src/Error/Server/ServerError.php similarity index 62% rename from src/Error/Bridge/ServerError.php rename to src/Error/Server/ServerError.php index fa1183a..85ac8f2 100644 --- a/src/Error/Bridge/ServerError.php +++ b/src/Error/Server/ServerError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class ServerError extends \RuntimeException { diff --git a/src/Error/Bridge/TableDoesNotExistError.php b/src/Error/Server/TableDoesNotExistError.php similarity index 68% rename from src/Error/Bridge/TableDoesNotExistError.php rename to src/Error/Server/TableDoesNotExistError.php index 369dc15..5ebacff 100644 --- a/src/Error/Bridge/TableDoesNotExistError.php +++ b/src/Error/Server/TableDoesNotExistError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class TableDoesNotExistError extends DatabaseObjectDoesNotExistError { diff --git a/src/Error/Bridge/TransactionDeadlockError.php b/src/Error/Server/TransactionDeadlockError.php similarity index 65% rename from src/Error/Bridge/TransactionDeadlockError.php rename to src/Error/Server/TransactionDeadlockError.php index 429d555..3303f60 100644 --- a/src/Error/Bridge/TransactionDeadlockError.php +++ b/src/Error/Server/TransactionDeadlockError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class TransactionDeadlockError extends TransactionError { diff --git a/src/Error/Bridge/TransactionError.php b/src/Error/Server/TransactionError.php similarity index 61% rename from src/Error/Bridge/TransactionError.php rename to src/Error/Server/TransactionError.php index e392384..885b4c6 100644 --- a/src/Error/Bridge/TransactionError.php +++ b/src/Error/Server/TransactionError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class TransactionError extends ServerError { diff --git a/src/Error/Bridge/TransactionFailedError.php b/src/Error/Server/TransactionFailedError.php similarity index 64% rename from src/Error/Bridge/TransactionFailedError.php rename to src/Error/Server/TransactionFailedError.php index 61c9f4f..09fde89 100644 --- a/src/Error/Bridge/TransactionFailedError.php +++ b/src/Error/Server/TransactionFailedError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class TransactionFailedError extends TransactionError { diff --git a/src/Error/Bridge/TransactionLockWaitTimeoutError.php b/src/Error/Server/TransactionLockWaitTimeoutError.php similarity index 66% rename from src/Error/Bridge/TransactionLockWaitTimeoutError.php rename to src/Error/Server/TransactionLockWaitTimeoutError.php index 0c4f4ff..50eb053 100644 --- a/src/Error/Bridge/TransactionLockWaitTimeoutError.php +++ b/src/Error/Server/TransactionLockWaitTimeoutError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class TransactionLockWaitTimeoutError extends TransactionError { diff --git a/src/Error/Bridge/UnableToConnectError.php b/src/Error/Server/UnableToConnectError.php similarity index 62% rename from src/Error/Bridge/UnableToConnectError.php rename to src/Error/Server/UnableToConnectError.php index 1b0495d..a3d8b76 100644 --- a/src/Error/Bridge/UnableToConnectError.php +++ b/src/Error/Server/UnableToConnectError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class UnableToConnectError extends ServerError { diff --git a/src/Error/Bridge/UniqueConstraintViolationError.php b/src/Error/Server/UniqueConstraintViolationError.php similarity index 68% rename from src/Error/Bridge/UniqueConstraintViolationError.php rename to src/Error/Server/UniqueConstraintViolationError.php index 278ae7d..96aa954 100644 --- a/src/Error/Bridge/UniqueConstraintViolationError.php +++ b/src/Error/Server/UniqueConstraintViolationError.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\QueryBuilder\Error\Bridge; +namespace MakinaCorpus\QueryBuilder\Error\Server; class UniqueConstraintViolationError extends ConstraintViolationError { diff --git a/src/Platform/Schema/SQLServerSchemaManager.php b/src/Platform/Schema/SQLServerSchemaManager.php index bf198b6..1da5d04 100644 --- a/src/Platform/Schema/SQLServerSchemaManager.php +++ b/src/Platform/Schema/SQLServerSchemaManager.php @@ -138,7 +138,7 @@ protected function getTableColumns(string $database, string $schema, string $nam { /* $defaultCollation = $this - ->bridge + ->session ->executeQuery( <<connection ??= $this->createBridge(); } @@ -44,7 +44,7 @@ protected function getBridge(): Bridge /** * Create priviledged query builder. */ - protected function getPriviledgedBridge(): Bridge + protected function getDatabaseSessionWithPrivileges(): Bridge { return $this->privConnection ??= $this->createPriviledgeBridge(); } @@ -59,12 +59,12 @@ abstract protected function doCreateBridge(array $params): Bridge; * * This doesn't return any result; but may return affected row count. * - * This is a proxy function to $this->getBridge()->executeStatement(); + * This is a proxy function to $this->getDatabaseSession()->executeStatement(); */ protected function executeStatement(string|Expression $query, ?array $arguments = null): ?int { try { - return $this->getBridge()->executeStatement($query, $arguments); + return $this->getDatabaseSession()->executeStatement($query, $arguments); } catch (\Throwable $e) { throw new QueryBuilderError( \sprintf( @@ -74,7 +74,7 @@ protected function executeStatement(string|Expression $query, ?array $arguments %s TXT, $e->getMessage(), - $this->getBridge()->getWriter()->prepare(\is_string($query) ? new Raw($query, $arguments) : $query)->toString() + $this->getDatabaseSession()->getWriter()->prepare(\is_string($query) ? new Raw($query, $arguments) : $query)->toString() ), $e->getCode(), $e @@ -87,12 +87,12 @@ protected function executeStatement(string|Expression $query, ?array $arguments * * This doesn't return any result; but may return affected row count. * - * This is a proxy function to $this->getBridge()->executeStatement(); + * This is a proxy function to $this->getDatabaseSession()->executeStatement(); */ protected function executeQuery(string|Expression $query, ?array $arguments = null): Result { try { - return $this->getBridge()->executeQuery($query, $arguments); + return $this->getDatabaseSession()->executeQuery($query, $arguments); } catch (\Throwable $e) { throw new QueryBuilderError( \sprintf( @@ -102,7 +102,7 @@ protected function executeQuery(string|Expression $query, ?array $arguments = nu %s TXT, $e->getMessage(), - $this->getBridge()->getWriter()->prepare(\is_string($query) ? new Raw($query, $arguments) : $query)->toString() + $this->getDatabaseSession()->getWriter()->prepare(\is_string($query) ? new Raw($query, $arguments) : $query)->toString() ), $e->getCode(), $e @@ -116,7 +116,7 @@ protected function executeQuery(string|Expression $query, ?array $arguments = nu */ protected function ifDatabase(string|array $database): bool { - return $this->getBridge()->vendorIs($database); + return $this->getDatabaseSession()->vendorIs($database); } /** @@ -125,7 +125,7 @@ protected function ifDatabase(string|array $database): bool */ protected function ifDatabaseNot(string|array $database): bool { - return !$this->getBridge()->vendorIs($database); + return !$this->getDatabaseSession()->vendorIs($database); } /** @@ -155,7 +155,7 @@ protected function skipIfDatabaseGreaterThan(string|array $database, string $ver { $this->skipIfDatabaseNot($database); - if ($this->getBridge()->vendorVersionIs($version)) { + if ($this->getDatabaseSession()->vendorVersionIs($version)) { self::markTestSkipped($message ?? \sprintf("Test disabled for database '%s' at version >= '%s'", $database, $version)); } } @@ -167,7 +167,7 @@ protected function skipIfDatabaseLessThan(string|array $database, string $versio { $this->skipIfDatabaseNot($database); - if ($this->getBridge()->vendorVersionIs($version, '<')) { + if ($this->getDatabaseSession()->vendorVersionIs($version, '<')) { self::markTestSkipped($message ?? \sprintf("Test disabled for database '%s' at version <= '%s'", $database, $version)); } } @@ -193,10 +193,10 @@ private function createBridge(): Bridge */ private function initializeDatabase(string $dbname): void { - $privBridge = $this->getPriviledgedBridge(); + $session = $this->getDatabaseSessionWithPrivileges(); try { - $privBridge->executeStatement("CREATE DATABASE ?::id", ['test_db']); + $session->executeStatement("CREATE DATABASE ?::id", ['test_db']); } catch (\Throwable $e) { // Check database already exists or not. if (!\str_contains($e->getMessage(), 'exist')) { diff --git a/src/Transaction/Transaction.php b/src/Transaction/Transaction.php index f5d5546..5d9c8a1 100644 --- a/src/Transaction/Transaction.php +++ b/src/Transaction/Transaction.php @@ -4,7 +4,7 @@ namespace MakinaCorpus\QueryBuilder\Transaction; -use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionError; +use MakinaCorpus\QueryBuilder\Error\Server\TransactionError; interface Transaction { diff --git a/src/Transaction/TransactionSavepoint.php b/src/Transaction/TransactionSavepoint.php index 2fef0b9..1d91c61 100644 --- a/src/Transaction/TransactionSavepoint.php +++ b/src/Transaction/TransactionSavepoint.php @@ -4,7 +4,7 @@ namespace MakinaCorpus\QueryBuilder\Transaction; -use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionError; +use MakinaCorpus\QueryBuilder\Error\Server\TransactionError; final class TransactionSavepoint implements Transaction { diff --git a/tests/Bridge/AbstractErrorConverterTestCase.php b/tests/Bridge/AbstractErrorConverterTestCase.php index 85ef16b..b9ad470 100644 --- a/tests/Bridge/AbstractErrorConverterTestCase.php +++ b/tests/Bridge/AbstractErrorConverterTestCase.php @@ -5,11 +5,11 @@ namespace MakinaCorpus\QueryBuilder\Tests\Bridge; use MakinaCorpus\QueryBuilder\Vendor; -use MakinaCorpus\QueryBuilder\Error\Bridge\AmbiguousIdentifierError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ColumnDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\ForeignKeyConstraintViolationError; -use MakinaCorpus\QueryBuilder\Error\Bridge\TableDoesNotExistError; -use MakinaCorpus\QueryBuilder\Error\Bridge\UniqueConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\AmbiguousIdentifierError; +use MakinaCorpus\QueryBuilder\Error\Server\ColumnDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\ForeignKeyConstraintViolationError; +use MakinaCorpus\QueryBuilder\Error\Server\TableDoesNotExistError; +use MakinaCorpus\QueryBuilder\Error\Server\UniqueConstraintViolationError; use MakinaCorpus\QueryBuilder\Tests\FunctionalTestCase; use MakinaCorpus\QueryBuilder\Transaction\Transaction; @@ -19,7 +19,7 @@ abstract class AbstractErrorConverterTestCase extends FunctionalTestCase protected function createSchema(): void { try { - $this->getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->getVendorName()) { + switch ($this->getDatabaseSession()->getVendorName()) { case Vendor::MARIADB: case Vendor::MYSQL: - $this->getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge(); + $session = $this->getDatabaseSession(); if (!$runner1->getPlatform()->supportsSchema()) { self::markTestSkipped("This test requires a schema."); diff --git a/tests/Bridge/Doctrine/DoctrineQueryBuilderTest.php b/tests/Bridge/Doctrine/DoctrineQueryBuilderTest.php index c94fb2e..009e0fb 100644 --- a/tests/Bridge/Doctrine/DoctrineQueryBuilderTest.php +++ b/tests/Bridge/Doctrine/DoctrineQueryBuilderTest.php @@ -13,7 +13,7 @@ public function testSelectExecuteQuery(): void self::assertSame( 1, (int) $this - ->getBridge() + ->getDatabaseSession() ->select() ->columnRaw('1') ->executeQuery() @@ -29,7 +29,7 @@ public function testSelectExecuteQuery(): void public function testParameterTypeGuess(): void { $query = $this - ->getBridge() + ->getDatabaseSession() ->raw( 'select ?', [ diff --git a/tests/Bridge/Pdo/PdoDriverTest.php b/tests/Bridge/Pdo/PdoDriverTest.php index e9d1c97..cf77888 100644 --- a/tests/Bridge/Pdo/PdoDriverTest.php +++ b/tests/Bridge/Pdo/PdoDriverTest.php @@ -13,7 +13,7 @@ public function testSelectExecuteQuery(): void self::assertSame( 1, (int) $this - ->getBridge() + ->getDatabaseSession() ->select() ->columnRaw('1', 'foo') ->executeQuery() @@ -29,7 +29,7 @@ public function testSelectExecuteQuery(): void public function testParameterTypeGuess(): void { $query = $this - ->getBridge() + ->getDatabaseSession() ->raw( 'select ?', [ diff --git a/tests/Functional/SelectFunctionalTest.php b/tests/Functional/SelectFunctionalTest.php index 7fa35d2..c499554 100644 --- a/tests/Functional/SelectFunctionalTest.php +++ b/tests/Functional/SelectFunctionalTest.php @@ -23,7 +23,7 @@ class SelectFunctionalTest extends DoctrineTestCase protected function createSchema(): void { try { - $this->getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->getVendorName()) { + switch ($this->getDatabaseSession()->getVendorName()) { case Vendor::MARIADB: case Vendor::MYSQL: - $this->getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge(); + $session = $this->getDatabaseSession(); try { - $bridge->executeStatement( + $session->executeStatement( <<getVendorName()) { + switch ($session->getVendorName()) { case Vendor::MARIADB: case Vendor::MYSQL: - $bridge->executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<insert('transaction_test') ->columns(['foo', 'bar']) ->values([1, 'a']) @@ -138,10 +138,10 @@ protected function createSchema(): void */ public function testTransaction() { - $bridge = $this->getBridge(); - $transaction = $bridge->beginTransaction(); + $session = $this->getDatabaseSession(); + $transaction = $session->beginTransaction(); - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([4, 'd']) @@ -150,7 +150,7 @@ public function testTransaction() $transaction->commit(); - $result = $bridge + $result = $session ->select('transaction_test') ->orderBy('foo') ->executeQuery() @@ -168,30 +168,30 @@ public function testTransaction() public function testNestedTransactionCreatesSavepoint() { - $bridge = $this->getBridge(); + $session = $this->getDatabaseSession(); - /* if (!$bridge->getPlatform()->supportsTransactionSavepoints()) { - self::markTestSkipped(\sprintf("Driver '%s' does not supports savepoints", $bridge->getDriverName())); + /* if (!$session->getPlatform()->supportsTransactionSavepoints()) { + self::markTestSkipped(\sprintf("Driver '%s' does not supports savepoints", $session->getDriverName())); } */ - $bridge->delete('transaction_test')->executeStatement(); + $session->delete('transaction_test')->executeStatement(); - $transaction = $bridge->beginTransaction(); + $transaction = $session->beginTransaction(); - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([789, 'f']) ->executeStatement() ; - $savepoint = $bridge->beginTransaction(); + $savepoint = $session->beginTransaction(); self::assertInstanceOf(TransactionSavepoint::class, $savepoint); self::assertTrue($savepoint->isNested()); self::assertNotNull($savepoint->getSavepointName()); - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([456, 'g']) @@ -200,7 +200,7 @@ public function testNestedTransactionCreatesSavepoint() $transaction->commit(); - $result = $bridge + $result = $session ->select('transaction_test') ->orderBy('foo') ->executeQuery() @@ -216,30 +216,30 @@ public function testNestedTransactionCreatesSavepoint() public function testNestedTransactionRollbackToSavepointTransparently() { - $bridge = $this->getBridge(); + $session = $this->getDatabaseSession(); - /* if (!$bridge->getPlatform()->supportsTransactionSavepoints()) { - self::markTestSkipped(\sprintf("Driver '%s' does not supports savepoints", $bridge->getDriverName())); + /* if (!$session->getPlatform()->supportsTransactionSavepoints()) { + self::markTestSkipped(\sprintf("Driver '%s' does not supports savepoints", $session->getDriverName())); } */ - $bridge->delete('transaction_test')->executeStatement(); + $session->delete('transaction_test')->executeStatement(); - $transaction = $bridge->beginTransaction(); + $transaction = $session->beginTransaction(); - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([789, 'f']) ->executeStatement() ; - $savepoint = $bridge->beginTransaction(); + $savepoint = $session->beginTransaction(); self::assertInstanceOf(TransactionSavepoint::class, $savepoint); self::assertTrue($savepoint->isNested()); self::assertNotNull($savepoint->getSavepointName()); - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([456, 'g']) @@ -249,7 +249,7 @@ public function testNestedTransactionRollbackToSavepointTransparently() $savepoint->rollback(); $transaction->commit(); - $result = $bridge + $result = $session ->select('transaction_test') ->orderBy('foo') ->executeQuery() @@ -273,9 +273,9 @@ public function testImmediateTransactionFail() self::expectNotToPerformAssertions(); - $bridge = $this->getBridge(); + $session = $this->getDatabaseSession(); - $transaction = $bridge + $transaction = $session ->beginTransaction() ->deferred() // Defer all ->immediate('transaction_test_bar') @@ -286,7 +286,7 @@ public function testImmediateTransactionFail() // if backend does not support defering, this will // fail anyway, but the rest of the test is still // valid - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([2, 'd']) @@ -294,7 +294,7 @@ public function testImmediateTransactionFail() ; // This should fail, bar constraint it immediate - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([5, 'b']) @@ -322,13 +322,13 @@ public function testDeferredTransactionFail() self::expectNotToPerformAssertions(); - $bridge = $this->getBridge(); + $session = $this->getDatabaseSession(); - /* if (!$bridge->getPlatform()->supportsDeferingConstraints()) { + /* if (!$session->getPlatform()->supportsDeferingConstraints()) { self::markTestSkipped("driver does not support defering constraints"); } */ - $transaction = $bridge + $transaction = $session ->beginTransaction() ->immediate() // Immediate all ->deferred('transaction_test_foo') @@ -337,7 +337,7 @@ public function testDeferredTransactionFail() try { // This should pass, foo constraint it deferred - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([2, 'd']) @@ -345,7 +345,7 @@ public function testDeferredTransactionFail() ; // This should fail, bar constraint it immediate - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([5, 'b']) @@ -369,13 +369,13 @@ public function testDeferredAllTransactionFail() { self::expectNotToPerformAssertions(); - $bridge = $this->getBridge(); + $session = $this->getDatabaseSession(); - /* if (!$bridge->getPlatform()->supportsDeferingConstraints()) { + /* if (!$session->getPlatform()->supportsDeferingConstraints()) { self::markTestSkipped("driver does not support defering constraints"); } */ - $transaction = $bridge + $transaction = $session ->beginTransaction() ->deferred() ; @@ -383,7 +383,7 @@ public function testDeferredAllTransactionFail() try { // This should pass, all are deferred - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([2, 'd']) @@ -391,7 +391,7 @@ public function testDeferredAllTransactionFail() ; // This should pass, all are deferred - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([5, 'b']) @@ -413,11 +413,11 @@ public function testDeferredAllTransactionFail() */ public function testTransactionRollback() { - $bridge = $this->getBridge(); + $session = $this->getDatabaseSession(); - $transaction = $bridge->beginTransaction(); + $transaction = $session->beginTransaction(); - $bridge + $session ->insert('transaction_test') ->columns(['foo', 'bar']) ->values([4, 'd']) @@ -426,7 +426,7 @@ public function testTransactionRollback() $transaction->rollback(); - $result = $bridge + $result = $session ->select('transaction_test') ->executeQuery() ; @@ -448,19 +448,19 @@ public function testTransactionRollback() */ public function testPendingAllowed() { - $bridge = $this->getBridge(); + $session = $this->getDatabaseSession(); - $transaction = $bridge->beginTransaction(); + $transaction = $session->beginTransaction(); // Fetch another transaction, it should fail try { - $bridge->beginTransaction(Transaction::REPEATABLE_READ, false); + $session->beginTransaction(Transaction::REPEATABLE_READ, false); self::fail(); } catch (TransactionError $e) { } // Fetch another transaction, it should NOT fail - $t3 = $bridge->beginTransaction(Transaction::REPEATABLE_READ, true); + $t3 = $session->beginTransaction(Transaction::REPEATABLE_READ, true); // @todo temporary deactivating this test since that the profiling // transaction makes it harder //self::assertSame($t3, $transaction); @@ -481,11 +481,11 @@ public function testPendingAllowed() */ public function testTransactionSavepoint() { - $bridge = $this->getBridge(); + $session = $this->getDatabaseSession(); - $transaction = $bridge->beginTransaction(); + $transaction = $session->beginTransaction(); - $bridge + $session ->update('transaction_test') ->set('bar', 'z') ->where('foo', 1) @@ -494,7 +494,7 @@ public function testTransactionSavepoint() $transaction->savepoint('bouyaya'); - $bridge + $session ->update('transaction_test') ->set('bar', 'y') ->where('foo', 2) @@ -504,7 +504,7 @@ public function testTransactionSavepoint() $transaction->rollbackToSavepoint('bouyaya'); $transaction->commit(); - $oneBar = $bridge + $oneBar = $session ->select('transaction_test') ->column('bar') ->where('foo', 1) @@ -514,7 +514,7 @@ public function testTransactionSavepoint() // This should have pass since it's before the savepoint self::assertSame('z', $oneBar); - $twoBar = $bridge + $twoBar = $session ->select('transaction_test') ->column('bar') ->where('foo', 2) diff --git a/tests/Functional/UpdateFunctionalTest.php b/tests/Functional/UpdateFunctionalTest.php index 222bb47..35db0dc 100644 --- a/tests/Functional/UpdateFunctionalTest.php +++ b/tests/Functional/UpdateFunctionalTest.php @@ -14,7 +14,7 @@ class UpdateFunctionalTest extends DoctrineTestCase protected function createSchema(): void { try { - $this->getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->getVendorName()) { + switch ($this->getDatabaseSession()->getVendorName()) { case Vendor::MARIADB: case Vendor::MYSQL: - $this->getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge()->executeStatement( + $this->getDatabaseSession()->executeStatement( <<getBridge(); + $session = $this->getDatabaseSession(); foreach ([ 'new_table', @@ -38,15 +38,15 @@ protected function createSchema(): void 'org', ] as $table) { try { - $bridge->executeStatement('DROP TABLE ?::table', [$table]); + $session->executeStatement('DROP TABLE ?::table', [$table]); } catch (DatabaseObjectDoesNotExistError) {} } - switch ($bridge->getVendorName()) { + switch ($session->getVendorName()) { case Vendor::MARIADB: case Vendor::MYSQL: - $bridge->executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<executeStatement( + $session->executeStatement( <<getBridge()->getSchemaManager(); + return $this->getDatabaseSession()->getSchemaManager(); } catch (UnsupportedFeatureError $e) { self::markTestSkipped($e->getMessage()); }