Skip to content

Commit

Permalink
Fixes doctrine#2306. Adds support for a connect string when using Oci8
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvandevijver authored and bburnichon committed Jun 16, 2016
1 parent feadeba commit 6224dc9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ pdo\_oci / oci8
add the INSTANCE_NAME parameter in the connection. It is generally used
to connect to an Oracle RAC server to select the name of a particular instance.

Complete connection descriptors are also supported. You only need to provide the following parameter, and none of the above:
- ``connectstring`` (string): Complete Easy Connect connection descriptor, see https://docs.oracle.com/cd/E11882_01/network.112/e41945/naming.htm.

pdo\_sqlsrv / sqlsrv
^^^^^^^^^^^^^^^^^^^^
Expand Down
7 changes: 6 additions & 1 deletion lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,15 @@ public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
*
* @return string
*
* @link http://download.oracle.com/docs/cd/E11882_01/network.112/e10836/naming.htm
* @link https://docs.oracle.com/cd/E11882_01/network.112/e41945/naming.htm
*/
protected function getEasyConnectString(array $params)
{

if ( ! empty($params['connectstring'])) {
return $params['connectstring'];
}

if ( ! empty($params['host'])) {
if ( ! isset($params['port'])) {
$params['port'] = 1521;
Expand Down
19 changes: 19 additions & 0 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ public function testReturnsDatabaseName()
$this->assertSame($params['user'], $this->driver->getDatabase($connection));
}

public function testReturnsDatabaseNameWithConnectDescriptor()
{
$params = array(
'user' => 'foo',
'password' => 'bar',
'connectionstring' => '(DESCRIPTION=' .
'(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' .
'(CONNECT_DATA=(SERVICE_NAME=baz)))'
);

$connection = $this->getConnectionMock();

$connection->expects($this->once())
->method('getParams')
->will($this->returnValue($params));

$this->assertSame($params['user'], $this->driver->getDatabase($connection));
}

protected function createDriver()
{
return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractOracleDriver');
Expand Down

0 comments on commit 6224dc9

Please sign in to comment.