diff --git a/src/Internal/MysqlConnectionStatement.php b/src/Internal/MysqlConnectionStatement.php index 2bc3524..2d0301b 100644 --- a/src/Internal/MysqlConnectionStatement.php +++ b/src/Internal/MysqlConnectionStatement.php @@ -147,7 +147,7 @@ public function execute(array $params = []): MysqlResult } return $this->getProcessor() - ->execute($this->statementId, $this->query, $this->result->params, $prebound, $args) + ->execute($this->statementId, $this->query, $this->result->getParameterDefinitions(), $prebound, $args) ->await(); } diff --git a/test/MysqlConnectionStatementTest.php b/test/MysqlConnectionStatementTest.php new file mode 100644 index 0000000..302d149 --- /dev/null +++ b/test/MysqlConnectionStatementTest.php @@ -0,0 +1,76 @@ +params = \array_slice($definitions, 0, $availableDefinitions); + $result = new MysqlCommandResult(0, 0); + $processor = $this->createMock(ConnectionProcessor::class); + $processor->expects($this->once()) + ->method('execute') + ->with(1, 'SELECT ?, ?', $definitions, [], [1, 2]) + ->willReturn(Future::complete($result)); + $statement = new MysqlConnectionStatement($processor, 'SELECT ?, ?', 1, [], $metadata); + + EventLoop::queue(static function () use ($metadata, $definitions): void { + $metadata->params = $definitions; + $metadata->markDefinitionsFetched(); + }); + + try { + $this->assertSame($result, $statement->execute([1, 2])); + } finally { + $statement->close(); + } + } + + public static function provideAvailableParameterDefinitions(): array + { + return [ + 'no definitions received' => [0], + 'partial definitions received' => [1], + 'all definitions received' => [2], + ]; + } + + public function testMetadataFailurePropagatesWithoutExecution(): void + { + $metadata = new MysqlResultProxy(1, 2); + $processor = $this->createMock(ConnectionProcessor::class); + $processor->expects($this->never())->method('execute'); + $statement = new MysqlConnectionStatement($processor, 'SELECT ?, ?', 1, [], $metadata); + $exception = new SqlConnectionException('Connection lost during statement preparation'); + + EventLoop::queue(static fn () => $metadata->error($exception)); + + $this->expectExceptionObject($exception); + + try { + $statement->execute([1, 2]); + } finally { + $statement->close(); + } + } +}