Skip to content

Commit

Permalink
Fix blob binding overwrite on DB2
Browse files Browse the repository at this point in the history
On DB2 when binding more than 1 blob in the same statement each subsequent blob overwrites previous one.
So instead of [1, 2, 3] we get [2, 3, 3]
This happens because of reference between loop variable `$value` and the item in `$this->parameters[]`,
which remains after iteration, see `bindLobs` and `bind` methods in `\Doctrine\DBAL\Driver\IBMDB2\Statement`
  • Loading branch information
melekhovets committed Jul 13, 2023
1 parent 1c462ee commit 5028c59
Show file tree
Hide file tree
Showing 2 changed files with 15 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
13 changes: 13 additions & 0 deletions tests/Functional/Driver/IBMDB2/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\DBAL\Tests\Functional\Driver\IBMDB2;

use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;

Expand Down Expand Up @@ -36,4 +37,16 @@ public function testExecutionErrorsAreNotSuppressed(): void
$this->expectException(StatementError::class);
$stmt->execute([[]]);
}

public function testBlobBindingDoesNotOverwritePrevious(): void
{
$params = ['test1', 'test2'];
$values = $this->connection->fetchNumeric(
'SELECT CAST(? AS VARCHAR) AS a, CAST(? AS VARCHAR) AS b FROM SYSIBM.SYSDUMMY1',
$params,
[ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT],
);

self::assertEquals(['test1', 'test2'], $values);
}
}

0 comments on commit 5028c59

Please sign in to comment.