Skip to content

Commit

Permalink
Update Oracle database DBI parameter generation
Browse files Browse the repository at this point in the history
Again. It now works as follows:

-   If there is not a hostname or port, just use the raw SID or service
    name as the database name: `dbi:Oracle:$name`. This is way 1 in the
    DBD::Oracle documentation
-   If there is a hostname or port, use the EZCONNECT syntax. This is
    way 3 in the DBD::Oracle documentation.
-   If there are query parameters, delimit them by `&` and not `;`.

Use of a port without a host name may not be valid, but it seems most
prudent to build an EZCONNECT that includes the port in this context and
to let Oracle or DBD::Oracle reject it if appropriate. Thanks again to
@vectro for the and diligence, testing, and patience with this issue
(#22).
  • Loading branch information
theory committed Apr 5, 2024
1 parent dedd755 commit bfbd9f8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
11 changes: 11 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Revision history for Perl extension URI::db.

0.22
- Changed Oracle database DBI parameter generation as follows:
- If there is not a hostname or port, just use the raw SID or service
name as the database name: `dbi:Oracle:$name`. This is way 1 in the
DBD::Oracle documentation
- If there is a hostname or port, use the EZCONNECT syntax. This is
way 3 in the DBD::Oracle documentation.
Use of a port without a host name may not be valid, but it seems most
prudent to build an EZCONNECT that includes the port in this context
and to let Oracle or DBD::Oracle reject it if appropriate. Thanks
again to @vectro for the and diligence, testing, and patience with
this issue (#22).

0.21 2023-05-09T22:18:52Z
- Changed Oracle database DBI parameter name from `sid` to
Expand Down
27 changes: 21 additions & 6 deletions lib/URI/oracle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,28 @@ our $VERSION = '0.22';
sub default_port { 1521 }
sub dbi_driver { 'Oracle' }

sub _dbi_param_map {
sub _dsn_params {
my $self = shift;
return (
[ host => scalar $self->host ],
[ port => scalar $self->_port ],
[ service_name => scalar $self->dbname ],
);
my $name = $self->dbname || '';
my $dsn = $self->host;

if (my $p = $self->_port) {
$dsn .= ":$p";
}

return $name unless $dsn;
$dsn .= "/$name";


if (my @p = $self->query_params) {
my @kvpairs;
while (@p) {
push @kvpairs => join '=', shift @p, shift @p;
}
$dsn .= '?' . join '&' => @kvpairs;
}

return "//$dsn";
}

1;
26 changes: 16 additions & 10 deletions t/dbi.t
Original file line number Diff line number Diff line change
Expand Up @@ -206,34 +206,40 @@ for my $spec (
},
{
uri => 'db:oracle://localhost:33/foo',
dsn => 'dbi:Oracle:host=localhost;port=33;service_name=foo',
dbi => [ [host => 'localhost'], [port => 33], [service_name => 'foo'] ],
dsn => 'dbi:Oracle://localhost:33/foo',
dbi => [ [host => 'localhost'], [port => 33], [dbname => 'foo'] ],
qry => [],
},
{
uri => 'db:oracle://localhost/foo',
dsn => 'dbi:Oracle:host=localhost;service_name=foo',
dbi => [ [host => 'localhost'], [port => undef], [service_name => 'foo'] ],
dsn => 'dbi:Oracle://localhost/foo',
dbi => [ [host => 'localhost'], [port => undef], [dbname => 'foo'] ],
qry => [],
},
{
uri => 'db:oracle://:42/foo',
dsn => 'dbi:Oracle:port=42;service_name=foo',
dbi => [ [host => ''], [port => 42], [service_name => 'foo'] ],
dsn => 'dbi:Oracle://:42/foo',
dbi => [ [host => ''], [port => 42], [dbname => 'foo'] ],
qry => [],
},
{
uri => 'db:oracle:foo',
dsn => 'dbi:Oracle:service_name=foo',
dbi => [ [host => undef], [port => undef], [service_name => 'foo'] ],
dsn => 'dbi:Oracle:foo',
dbi => [ [host => undef], [port => undef], [dbname => 'foo'] ],
qry => [],
},
{
uri => 'db:oracle:///foo',
dsn => 'dbi:Oracle:service_name=foo',
dbi => [ [host => ''], [port => undef], [service_name => 'foo'] ],
dsn => 'dbi:Oracle:foo',
dbi => [ [host => ''], [port => undef], [dbname => 'foo'] ],
qry => [],
},
{
uri => 'db:oracle://:42/foo?x=y;a=b',
dsn => 'dbi:Oracle://:42/foo?x=y&a=b',
dbi => [ [host => ''], [port => 42], [dbname => 'foo'] ],
qry => [ x => 'y', a => 'b' ],
},
{
uri => 'db:mssql:',
dsn => 'dbi:ODBC:',
Expand Down

0 comments on commit bfbd9f8

Please sign in to comment.