Skip to content

Commit

Permalink
add servicename connection parameter to Oracle drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
deeky666 committed Dec 27, 2013
1 parent 2196da9 commit 45113e7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ pdo\_oci / oci8
- ``host`` (string): Hostname of the database to connect to.
- ``port`` (integer): Port of the database to connect to.
- ``dbname`` (string): Name of the database/schema to connect to.
- ``servicename`` (string): Optional name by which clients can
connect to the database instance. Will be used as Oracle's
``SID`` connection parameter if given and defaults to Doctrine's
``dbname`` connection parameter value.
- ``service`` (boolean): Whether to use Oracle's ``SERVICE_NAME``
connection parameter in favour of ``SID`` when connecting. The
value for this will be read from Doctrine's ``servicename`` if
given, ``dbname`` otherwise.
- ``pooled`` (boolean): Whether to enable database resident
connection pooling.
- ``charset`` (string): The charset used when connecting to the
Expand Down
12 changes: 9 additions & 3 deletions lib/Doctrine/DBAL/Driver/OCI8/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,24 @@ protected function _constructDsn(array $params)
$dsn .= '(PORT=1521)';
}

$database = 'SID=' . $params['dbname'];
$serviceName = $params['dbname'];

if ( ! empty($params['servicename'])) {
$serviceName = $params['servicename'];
}

$service = 'SID=' . $serviceName;
$pooled = '';

if (isset($params['service']) && $params['service'] == true) {
$database = 'SERVICE_NAME=' . $params['dbname'];
$service = 'SERVICE_NAME=' . $serviceName;
}

if (isset($params['pooled']) && $params['pooled'] == true) {
$pooled = '(SERVER=POOLED)';
}

$dsn .= '))(CONNECT_DATA=(' . $database . ')' . $pooled . '))';
$dsn .= '))(CONNECT_DATA=(' . $service . ')' . $pooled . '))';
} else {
$dsn .= $params['dbname'];
}
Expand Down
14 changes: 10 additions & 4 deletions lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,24 @@ private function _constructPdoDsn(array $params)
$dsn .= '(PORT=1521)';
}

$database = 'SID=' . $params['dbname'];
$pooled = '';
$serviceName = $params['dbname'];

if ( ! empty($params['servicename'])) {
$serviceName = $params['servicename'];
}

$service = 'SID=' . $serviceName;
$pooled = '';

if (isset($params['service']) && $params['service'] == true) {
$database = 'SERVICE_NAME=' . $params['dbname'];
$service = 'SERVICE_NAME=' . $serviceName;
}

if (isset($params['pooled']) && $params['pooled'] == true) {
$pooled = '(SERVER=POOLED)';
}

$dsn .= '))(CONNECT_DATA=(' . $database . ')' . $pooled . '))';
$dsn .= '))(CONNECT_DATA=(' . $service . ')' . $pooled . '))';
} else {
$dsn .= $params['dbname'];
}
Expand Down

0 comments on commit 45113e7

Please sign in to comment.