Skip to content

Commit 96d5a70

Browse files
authored
Fix blob binding overwrite on DB2 (#6093)
1 parent 1c462ee commit 96d5a70

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Driver/IBMDB2/Statement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ private function bindLobs(): array
182182
} else {
183183
$this->bind($param, $value, DB2_PARAM_IN, DB2_CHAR);
184184
}
185+
186+
unset($value);
185187
}
186188

187189
return $handles;

tests/Functional/BlobTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,34 @@ public function testBindParamProcessesStream(): void
169169
$this->assertBlobContains('test');
170170
}
171171

172+
public function testBlobBindingDoesNotOverwritePrevious(): void
173+
{
174+
$table = new Table('blob_table');
175+
$table->addColumn('id', 'integer');
176+
$table->addColumn('blobcolumn1', 'blob', ['notnull' => false]);
177+
$table->addColumn('blobcolumn2', 'blob', ['notnull' => false]);
178+
$table->setPrimaryKey(['id']);
179+
$this->dropAndCreateTable($table);
180+
181+
$params = ['test1', 'test2'];
182+
$this->connection->executeStatement(
183+
'INSERT INTO blob_table(id, blobcolumn1, blobcolumn2) VALUES (1, ?, ?)',
184+
$params,
185+
[ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT],
186+
);
187+
188+
$blobs = $this->connection->fetchNumeric('SELECT blobcolumn1, blobcolumn2 FROM blob_table');
189+
self::assertIsArray($blobs);
190+
191+
$actual = [];
192+
foreach ($blobs as $blob) {
193+
$blob = Type::getType('blob')->convertToPHPValue($blob, $this->connection->getDatabasePlatform());
194+
$actual[] = stream_get_contents($blob);
195+
}
196+
197+
self::assertEquals(['test1', 'test2'], $actual);
198+
}
199+
172200
private function assertBlobContains(string $text): void
173201
{
174202
[, $blobValue] = $this->fetchRow();

0 commit comments

Comments
 (0)