diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 9455710240c..f71fbecb5f2 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1263,7 +1263,9 @@ public function prepare($sql) * @param array|array $params Query parameters * @param array|array $types Parameter types * - * @return ForwardCompatibility\Result The executed statement. + * @return ForwardCompatibility\DriverStatement|ForwardCompatibility\DriverResultStatement + * + * The executed statement or the cached result statement if a query cache profile is used * * @throws Exception */ @@ -1319,7 +1321,7 @@ public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheP * @param array|array $params Query parameters * @param array|array $types Parameter types * - * @return ForwardCompatibility\Result + * @return ForwardCompatibility\DriverResultStatement * * @throws CacheException */ diff --git a/lib/Doctrine/DBAL/ForwardCompatibility/DriverResultStatement.php b/lib/Doctrine/DBAL/ForwardCompatibility/DriverResultStatement.php new file mode 100644 index 00000000000..0cf9aa3dda3 --- /dev/null +++ b/lib/Doctrine/DBAL/ForwardCompatibility/DriverResultStatement.php @@ -0,0 +1,9 @@ +stmt = $stmt; } /** - * @return DriverResultStatement + * @return Driver\ResultStatement */ public function getIterator() { @@ -317,7 +315,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING) 'Result::bindValue() is deprecated, no replacement.' ); - if ($this->stmt instanceof DriverStatement) { + if ($this->stmt instanceof Driver\Statement) { return $this->stmt->bindValue($param, $value, $type); } @@ -337,7 +335,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le 'Result::bindParam() is deprecated, no replacement.' ); - if ($this->stmt instanceof DriverStatement) { + if ($this->stmt instanceof Driver\Statement) { return $this->stmt->bindParam($param, $variable, $type, $length); } @@ -357,7 +355,7 @@ public function errorCode() 'Result::errorCode() is deprecated, the error information is available via exceptions.' ); - if ($this->stmt instanceof DriverStatement) { + if ($this->stmt instanceof Driver\Statement) { return $this->stmt->errorCode(); } @@ -377,7 +375,7 @@ public function errorInfo() 'Result::errorInfo() is deprecated, the error information is available via exceptions.' ); - if ($this->stmt instanceof DriverStatement) { + if ($this->stmt instanceof Driver\Statement) { return $this->stmt->errorInfo(); } @@ -397,7 +395,7 @@ public function execute($params = null) 'Result::execute() is deprecated, no replacement.' ); - if ($this->stmt instanceof DriverStatement) { + if ($this->stmt instanceof Driver\Statement) { return $this->stmt->execute($params); } diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 93714edbecb..205bb37a175 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\ForwardCompatibility\Result as ForwardCompatibleResult; +use Doctrine\DBAL\ForwardCompatibility; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; @@ -201,7 +201,7 @@ public function getState() /** * Executes this query using the bound parameters and their types. * - * @return ForwardCompatibleResult|int + * @return ForwardCompatibility\DriverStatement|ForwardCompatibility\DriverResultStatement|int * * @throws Exception */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index 2fc7f7e6a27..61128bdf6bd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -6,11 +6,13 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Connection; use Doctrine\DBAL\ConnectionException; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\ForwardCompatibility; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalFunctionalTestCase; use Error; @@ -366,7 +368,32 @@ public function testResultCompatibilityWhenExecutingQueryWithoutParam(): void $this->connection->getDatabasePlatform()->getDummySelectSQL() ); - self::assertInstanceOf(ForwardCompatibility\Result::class, $result); + self::assertInstanceOf(Result::class, $result); + self::assertInstanceOf(Driver\Statement::class, $result); + } + + public function testResultCompatibilityWhenExecutingQueryWithParams(): void + { + $result = $this->connection->executeQuery( + $this->connection->getDatabasePlatform()->getDummySelectSQL(), + ['param1' => 'value'] + ); + + self::assertInstanceOf(Result::class, $result); + self::assertInstanceOf(Driver\Statement::class, $result); + } + + public function testResultCompatibilityWhenExecutingQueryWithQueryCacheParam(): void + { + $result = $this->connection->executeQuery( + $this->connection->getDatabasePlatform()->getDummySelectSQL(), + [], + [], + new QueryCacheProfile(1, 'cacheKey', new ArrayCache()) + ); + + self::assertInstanceOf(Result::class, $result); + self::assertInstanceOf(Driver\ResultStatement::class, $result); } public function testResultCompatibilityWhenExecutingCacheQuery(): void @@ -378,6 +405,7 @@ public function testResultCompatibilityWhenExecutingCacheQuery(): void new QueryCacheProfile(1, 'cacheKey', new ArrayCache()) ); - self::assertInstanceOf(ForwardCompatibility\Result::class, $result); + self::assertInstanceOf(Result::class, $result); + self::assertInstanceOf(Driver\ResultStatement::class, $result); } }