From 911d0061f676e90484481544bd8a0e8450775cd0 Mon Sep 17 00:00:00 2001 From: Alexander Melekhovets Date: Mon, 17 Jul 2023 12:15:50 +0300 Subject: [PATCH] Fix blob binding overwrite on DB2 (#6093) --- src/Driver/IBMDB2/Statement.php | 2 ++ tests/Functional/BlobTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Driver/IBMDB2/Statement.php b/src/Driver/IBMDB2/Statement.php index 15c3fdb588a..699e236d715 100644 --- a/src/Driver/IBMDB2/Statement.php +++ b/src/Driver/IBMDB2/Statement.php @@ -182,6 +182,8 @@ private function bindLobs(): array } else { $this->bind($param, $value, DB2_PARAM_IN, DB2_CHAR); } + + unset($value); } return $handles; diff --git a/tests/Functional/BlobTest.php b/tests/Functional/BlobTest.php index 5ff065bd0df..212f4a4480e 100644 --- a/tests/Functional/BlobTest.php +++ b/tests/Functional/BlobTest.php @@ -170,6 +170,34 @@ public function testBindParamProcessesStream(): void $this->assertBlobContains('test'); } + public function testBlobBindingDoesNotOverwritePrevious(): void + { + $table = new Table('blob_table'); + $table->addColumn('id', 'integer'); + $table->addColumn('blobcolumn1', 'blob', ['notnull' => false]); + $table->addColumn('blobcolumn2', 'blob', ['notnull' => false]); + $table->setPrimaryKey(['id']); + $this->dropAndCreateTable($table); + + $params = ['test1', 'test2']; + $this->connection->executeStatement( + 'INSERT INTO blob_table(id, blobcolumn1, blobcolumn2) VALUES (1, ?, ?)', + $params, + [ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT], + ); + + $blobs = $this->connection->fetchNumeric('SELECT blobcolumn1, blobcolumn2 FROM blob_table'); + self::assertIsArray($blobs); + + $actual = []; + foreach ($blobs as $blob) { + $blob = Type::getType('blob')->convertToPHPValue($blob, $this->connection->getDatabasePlatform()); + $actual[] = stream_get_contents($blob); + } + + self::assertEquals(['test1', 'test2'], $actual); + } + private function assertBlobContains(string $text): void { [, $blobValue] = $this->fetchRow();