Skip to content

Commit 400f604

Browse files
authored
Merge pull request #3738 from ModelTech/hotfix/oci8_named_paramters
Fix breaks named parameters in Oracle
2 parents 39b76b4 + 9f4d9a5 commit 400f604

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING)
276276
/**
277277
* {@inheritdoc}
278278
*/
279-
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
279+
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
280280
{
281-
$column = $this->_paramMap[$column];
281+
if (is_int($param)) {
282+
if (! isset($this->_paramMap[$param])) {
283+
throw new OCI8Exception(sprintf('Could not find variable mapping with index %d, in the SQL statement', $param));
284+
}
285+
286+
$param = $this->_paramMap[$param];
287+
}
282288

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

294-
$this->boundValues[$column] =& $variable;
300+
$this->boundValues[$param] =& $variable;
295301

296302
return oci_bind_by_name(
297303
$this->_sth,
298-
$column,
304+
$param,
299305
$variable,
300306
$length ?? -1,
301307
$this->convertParameterType($type)

tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,41 @@ public function testQueryConversion(string $query, array $params, array $expecte
3737
);
3838
}
3939

40+
/**
41+
* Low-level approach to working with parameter binding
42+
*
43+
* @param mixed[] $params
44+
* @param mixed[] $expected
45+
*
46+
* @dataProvider queryConversionProvider
47+
*/
48+
public function testStatementBindParameters(string $query, array $params, array $expected) : void
49+
{
50+
$stmt = $this->connection->prepare($query);
51+
$stmt->execute($params);
52+
53+
self::assertEquals(
54+
$expected,
55+
$stmt->fetch()
56+
);
57+
}
58+
4059
/**
4160
* @return array<string, array<int, mixed>>
4261
*/
4362
public static function queryConversionProvider() : iterable
4463
{
4564
return [
46-
'simple' => [
65+
'positional' => [
4766
'SELECT ? COL1 FROM DUAL',
4867
[1],
4968
['COL1' => 1],
5069
],
70+
'named' => [
71+
'SELECT :COL COL1 FROM DUAL',
72+
[':COL' => 1],
73+
['COL1' => 1],
74+
],
5175
'literal-with-placeholder' => [
5276
"SELECT '?' COL1, ? COL2 FROM DUAL",
5377
[2],

0 commit comments

Comments
 (0)