Skip to content

Commit a500e1a

Browse files
committed
Merge pull request doctrine#2307 from bobvandevijver/master
[Oracle] Add support for Easy Connect string as connection parameter
2 parents eb48797 + 1592855 commit a500e1a

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

docs/en/reference/configuration.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ pdo\_oci / oci8
295295
- ``instancename`` (string): Optional parameter, complete whether to
296296
add the INSTANCE_NAME parameter in the connection. It is generally used
297297
to connect to an Oracle RAC server to select the name of a particular instance.
298-
298+
- ``connectstring`` (string): Complete Easy Connect connection descriptor,
299+
see https://docs.oracle.com/database/121/NETAG/naming.htm. When using this option,
300+
you will still need to provide the ``user`` and ``password`` parameters, but the other
301+
parameters will no longer be used. Note that when using this parameter, the ``getHost``
302+
and ``getPort`` methods from ``Doctrine\DBAL\Connection`` will no longer function as expected.
299303

300304
pdo\_sqlsrv / sqlsrv
301305
^^^^^^^^^^^^^^^^^^^^

lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,14 @@ public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
109109
*
110110
* @return string
111111
*
112-
* @link http://download.oracle.com/docs/cd/E11882_01/network.112/e10836/naming.htm
112+
* @link https://docs.oracle.com/database/121/NETAG/naming.htm
113113
*/
114114
protected function getEasyConnectString(array $params)
115115
{
116+
if ( ! empty($params['connectstring'])) {
117+
return $params['connectstring'];
118+
}
119+
116120
if ( ! empty($params['host'])) {
117121
if ( ! isset($params['port'])) {
118122
$params['port'] = 1521;

tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ public function testReturnsDatabaseName()
2525
$this->assertSame($params['user'], $this->driver->getDatabase($connection));
2626
}
2727

28+
public function testReturnsDatabaseNameWithConnectDescriptor()
29+
{
30+
$params = array(
31+
'user' => 'foo',
32+
'password' => 'bar',
33+
'connectionstring' => '(DESCRIPTION=' .
34+
'(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' .
35+
'(CONNECT_DATA=(SERVICE_NAME=baz)))'
36+
);
37+
38+
$connection = $this->getConnectionMock();
39+
40+
$connection->expects($this->once())
41+
->method('getParams')
42+
->will($this->returnValue($params));
43+
44+
$this->assertSame($params['user'], $this->driver->getDatabase($connection));
45+
}
46+
2847
protected function createDriver()
2948
{
3049
return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractOracleDriver');

0 commit comments

Comments
 (0)