Unverified Commit 400f6044 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3738 from ModelTech/hotfix/oci8_named_paramters

Fix breaks named parameters in Oracle
parents 39b76b4b 9f4d9a5b
...@@ -276,9 +276,15 @@ class OCI8Statement implements IteratorAggregate, Statement ...@@ -276,9 +276,15 @@ class OCI8Statement implements IteratorAggregate, Statement
/** /**
* {@inheritdoc} * {@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) { if ($type === ParameterType::LARGE_OBJECT) {
$lob = oci_new_descriptor($this->_dbh, OCI_D_LOB); $lob = oci_new_descriptor($this->_dbh, OCI_D_LOB);
...@@ -291,11 +297,11 @@ class OCI8Statement implements IteratorAggregate, Statement ...@@ -291,11 +297,11 @@ class OCI8Statement implements IteratorAggregate, Statement
$variable =& $lob; $variable =& $lob;
} }
$this->boundValues[$column] =& $variable; $this->boundValues[$param] =& $variable;
return oci_bind_by_name( return oci_bind_by_name(
$this->_sth, $this->_sth,
$column, $param,
$variable, $variable,
$length ?? -1, $length ?? -1,
$this->convertParameterType($type) $this->convertParameterType($type)
......
...@@ -37,17 +37,41 @@ class StatementTest extends DbalFunctionalTestCase ...@@ -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>> * @return array<string, array<int, mixed>>
*/ */
public static function queryConversionProvider() : iterable public static function queryConversionProvider() : iterable
{ {
return [ return [
'simple' => [ 'positional' => [
'SELECT ? COL1 FROM DUAL', 'SELECT ? COL1 FROM DUAL',
[1], [1],
['COL1' => 1], ['COL1' => 1],
], ],
'named' => [
'SELECT :COL COL1 FROM DUAL',
[':COL' => 1],
['COL1' => 1],
],
'literal-with-placeholder' => [ 'literal-with-placeholder' => [
"SELECT '?' COL1, ? COL2 FROM DUAL", "SELECT '?' COL1, ? COL2 FROM DUAL",
[2], [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