Skip to content

Commit

Permalink
Fix breaks named parameters in OCI8Statement
Browse files Browse the repository at this point in the history
  • Loading branch information
eisberg committed Dec 21, 2019
1 parent 9be84e7 commit 9f4d9a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING)
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
{
$column = $this->_paramMap[$column];
if (is_int($param)) {
if (! isset($this->_paramMap[$param])) {
throw new OCI8Exception(sprintf('Could not find variable mapping with index %d, in the SQL statement', $param));
}

$param = $this->_paramMap[$param];
}

if ($type === ParameterType::LARGE_OBJECT) {
$lob = oci_new_descriptor($this->_dbh, OCI_D_LOB);
Expand All @@ -291,11 +297,11 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
$variable =& $lob;
}

$this->boundValues[$column] =& $variable;
$this->boundValues[$param] =& $variable;

return oci_bind_by_name(
$this->_sth,
$column,
$param,
$variable,
$length ?? -1,
$this->convertParameterType($type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,41 @@ public function testQueryConversion(string $query, array $params, array $expecte
);
}

/**
* Low-level approach to working with parameter binding
*
* @param mixed[] $params
* @param mixed[] $expected
*
* @dataProvider queryConversionProvider
*/
public function testStatementBindParameters(string $query, array $params, array $expected) : void
{
$stmt = $this->connection->prepare($query);
$stmt->execute($params);

self::assertEquals(
$expected,
$stmt->fetch()
);
}

/**
* @return array<string, array<int, mixed>>
*/
public static function queryConversionProvider() : iterable
{
return [
'simple' => [
'positional' => [
'SELECT ? COL1 FROM DUAL',
[1],
['COL1' => 1],
],
'named' => [
'SELECT :COL COL1 FROM DUAL',
[':COL' => 1],
['COL1' => 1],
],
'literal-with-placeholder' => [
"SELECT '?' COL1, ? COL2 FROM DUAL",
[2],
Expand Down

0 comments on commit 9f4d9a5

Please sign in to comment.