Commit 9f4d9a5b authored by Alexander Rakushin's avatar Alexander Rakushin

Fix breaks named parameters in OCI8Statement

parent 9be84e76
......@@ -276,9 +276,15 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@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);
......@@ -291,11 +297,11 @@ class OCI8Statement implements IteratorAggregate, Statement
$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)
......
......@@ -37,17 +37,41 @@ class StatementTest extends DbalFunctionalTestCase
);
}
/**
* 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],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment