Skip to content

Commit bfbd9f8

Browse files
committed
Update Oracle database DBI parameter generation
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).
1 parent dedd755 commit bfbd9f8

File tree

3 files changed

+48
-16
lines changed

3 files changed

+48
-16
lines changed

Changes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Revision history for Perl extension URI::db.
22

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

516
0.21 2023-05-09T22:18:52Z
617
- Changed Oracle database DBI parameter name from `sid` to

lib/URI/oracle.pm

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,28 @@ our $VERSION = '0.22';
55
sub default_port { 1521 }
66
sub dbi_driver { 'Oracle' }
77

8-
sub _dbi_param_map {
8+
sub _dsn_params {
99
my $self = shift;
10-
return (
11-
[ host => scalar $self->host ],
12-
[ port => scalar $self->_port ],
13-
[ service_name => scalar $self->dbname ],
14-
);
10+
my $name = $self->dbname || '';
11+
my $dsn = $self->host;
12+
13+
if (my $p = $self->_port) {
14+
$dsn .= ":$p";
15+
}
16+
17+
return $name unless $dsn;
18+
$dsn .= "/$name";
19+
20+
21+
if (my @p = $self->query_params) {
22+
my @kvpairs;
23+
while (@p) {
24+
push @kvpairs => join '=', shift @p, shift @p;
25+
}
26+
$dsn .= '?' . join '&' => @kvpairs;
27+
}
28+
29+
return "//$dsn";
1530
}
1631

1732
1;

t/dbi.t

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,34 +206,40 @@ for my $spec (
206206
},
207207
{
208208
uri => 'db:oracle://localhost:33/foo',
209-
dsn => 'dbi:Oracle:host=localhost;port=33;service_name=foo',
210-
dbi => [ [host => 'localhost'], [port => 33], [service_name => 'foo'] ],
209+
dsn => 'dbi:Oracle://localhost:33/foo',
210+
dbi => [ [host => 'localhost'], [port => 33], [dbname => 'foo'] ],
211211
qry => [],
212212
},
213213
{
214214
uri => 'db:oracle://localhost/foo',
215-
dsn => 'dbi:Oracle:host=localhost;service_name=foo',
216-
dbi => [ [host => 'localhost'], [port => undef], [service_name => 'foo'] ],
215+
dsn => 'dbi:Oracle://localhost/foo',
216+
dbi => [ [host => 'localhost'], [port => undef], [dbname => 'foo'] ],
217217
qry => [],
218218
},
219219
{
220220
uri => 'db:oracle://:42/foo',
221-
dsn => 'dbi:Oracle:port=42;service_name=foo',
222-
dbi => [ [host => ''], [port => 42], [service_name => 'foo'] ],
221+
dsn => 'dbi:Oracle://:42/foo',
222+
dbi => [ [host => ''], [port => 42], [dbname => 'foo'] ],
223223
qry => [],
224224
},
225225
{
226226
uri => 'db:oracle:foo',
227-
dsn => 'dbi:Oracle:service_name=foo',
228-
dbi => [ [host => undef], [port => undef], [service_name => 'foo'] ],
227+
dsn => 'dbi:Oracle:foo',
228+
dbi => [ [host => undef], [port => undef], [dbname => 'foo'] ],
229229
qry => [],
230230
},
231231
{
232232
uri => 'db:oracle:///foo',
233-
dsn => 'dbi:Oracle:service_name=foo',
234-
dbi => [ [host => ''], [port => undef], [service_name => 'foo'] ],
233+
dsn => 'dbi:Oracle:foo',
234+
dbi => [ [host => ''], [port => undef], [dbname => 'foo'] ],
235235
qry => [],
236236
},
237+
{
238+
uri => 'db:oracle://:42/foo?x=y;a=b',
239+
dsn => 'dbi:Oracle://:42/foo?x=y&a=b',
240+
dbi => [ [host => ''], [port => 42], [dbname => 'foo'] ],
241+
qry => [ x => 'y', a => 'b' ],
242+
},
237243
{
238244
uri => 'db:mssql:',
239245
dsn => 'dbi:ODBC:',

0 commit comments

Comments
 (0)