Skip to content

Commit

Permalink
Fix blob binding overwrite on DB2 (#6093)
Browse files Browse the repository at this point in the history
  • Loading branch information
melekhovets authored Jul 17, 2023
1 parent 1c462ee commit 96d5a70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Driver/IBMDB2/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ private function bindLobs(): array
} else {
$this->bind($param, $value, DB2_PARAM_IN, DB2_CHAR);
}

unset($value);
}

return $handles;
Expand Down
28 changes: 28 additions & 0 deletions tests/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,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();
Expand Down

0 comments on commit 96d5a70

Please sign in to comment.