Skip to content

Commit cefd2dd

Browse files
committed
Add Functional test (OCI8Statement)
1 parent b033c86 commit cefd2dd

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ class OCI8Statement implements IteratorAggregate, Statement
9090
*/
9191
private $result = false;
9292

93+
/**
94+
* @param resource $dbh The connection handle.
95+
*
96+
* @return resource
97+
*/
98+
protected function prepareQuery($dbh, string $query)
99+
{
100+
$stmt = oci_parse($dbh, $query);
101+
assert(is_resource($stmt));
102+
103+
return $stmt;
104+
}
105+
93106
/**
94107
* Creates a new OCI8Statement that uses the given connection handle and SQL statement.
95108
*
@@ -100,10 +113,7 @@ public function __construct($dbh, string $query, OCI8Connection $conn)
100113
{
101114
[$query, $paramMap] = self::convertPositionalToNamedPlaceholders($query);
102115

103-
$stmt = oci_parse($dbh, $query);
104-
assert(is_resource($stmt));
105-
106-
$this->_sth = $stmt;
116+
$this->_sth = $this->prepareQuery($dbh, $query);
107117
$this->_dbh = $dbh;
108118
$this->_paramMap = $paramMap;
109119
$this->_conn = $conn;
@@ -273,7 +283,7 @@ public function bindValue($param, $value, int $type = ParameterType::STRING) : v
273283
*/
274284
public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null) : void
275285
{
276-
$param = $this->_paramMap[$param] ?? $param;
286+
$param = $this->_paramMap[$param] ?? (string) $param;
277287

278288
if ($type === ParameterType::LARGE_OBJECT) {
279289
$lob = oci_new_descriptor($this->_dbh, OCI_D_LOB);

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ public function testQueryConversion(string $query, array $params, array $expecte
3939
);
4040
}
4141

42+
/**
43+
* @param mixed[] $params
44+
* @param mixed[] $expected
45+
*
46+
* @dataProvider queryConversionProvider
47+
*/
48+
public function testQueryPrepare(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+
4259
/**
4360
* @return array<string, array<int, mixed>>
4461
*/
@@ -50,6 +67,11 @@ public static function queryConversionProvider() : iterable
5067
[1],
5168
['COL1' => 1],
5269
],
70+
'named' => [
71+
'SELECT :COL COL1 FROM DUAL',
72+
[':COL' => 1],
73+
['COL1' => 1],
74+
],
5375
'literal-with-placeholder' => [
5476
"SELECT '?' COL1, ? COL2 FROM DUAL",
5577
[2],

0 commit comments

Comments
 (0)