Skip Menu |

This queue is for tickets about the DBD-Pg CPAN distribution.

Report information
The Basics
Id: 61574
Status: resolved
Priority: 0/
Queue: DBD-Pg

People
Owner: Nobody in particular
Requestors: GAAS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.17.1
Fixed in: 2.17.2



Subject: data_sources tweaks
I got test failures from t/04misc.t because the data_sources method could not connect to the database. I tracked this failure down to the fact that DBD::Pg's data_sources method don't accept a DSN that starts with an upper case "DBI:" which was used in my case. I also think it makes more sense for data_sources to return an empty list instead of a list with a single undef value when it can't connect to the database. Suggested patch attached.
Subject: 0001-Fix-data_sources.patch
From 019577bcdeef6b07b7bf8fa219089f91708c550d Mon Sep 17 00:00:00 2001 From: Gisle Aas <gisle@activestate.com> Date: Wed, 22 Sep 2010 14:40:55 -0700 Subject: [PATCH] Fix data_sources Allow $ENV{DBI_DSN} that starts with "DBI:" instead of "dbi:". Return empty list instead of a list one undef when data_sources can't connect to the database. --- Pg.pm | 4 ++-- t/04misc.t | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Pg.pm b/Pg.pm index e4ee327..8e5c572 100644 --- a/Pg.pm +++ b/Pg.pm @@ -178,13 +178,13 @@ use 5.006001; ## Future: connect to "postgres" when the minimum version we support is 8.0 my $connstring = 'dbname=template1'; if ($ENV{DBI_DSN}) { - ($connstring = $ENV{DBI_DSN}) =~ s/dbi:Pg://; + ($connstring = $ENV{DBI_DSN}) =~ s/^(?i:dbi):Pg://; } if (length $attr) { $connstring .= ";$attr"; } - my $dbh = DBD::Pg::dr::connect($drh, $connstring) or return undef; + my $dbh = DBD::Pg::dr::connect($drh, $connstring) or return; $dbh->{AutoCommit}=1; my $SQL = 'SELECT pg_catalog.quote_ident(datname) FROM pg_catalog.pg_database ORDER BY 1'; my $sth = $dbh->prepare($SQL); diff --git a/t/04misc.t b/t/04misc.t index e706791..878e664 100644 --- a/t/04misc.t +++ b/t/04misc.t @@ -282,9 +282,9 @@ else { is (grep (/^dbi:Pg:dbname=template1$/, @result), '1', $t); } -$t='The "data_sources" method returns undef when fed a bogus second argument'; +$t='The "data_sources" method returns nothing when fed a bogus second argument'; @result = DBI->data_sources('Pg','foobar'); -is_deeply (@result, undef, $t); +is (@result, 0, $t); $t='The "data_sources" method returns information when fed a valid port as the second arg'; my $port = $dbh->{pg_port}; -- 1.7.0.5
Applied the undef change in r14455. I don't think we'll apply the case change - the DBI standard seems pretty clear that the literal string 'dbi' (lowercase) should be used.
On Fri Oct 01 23:56:42 2010, greg@turnstep.com wrote: Show quoted text
> Applied the undef change in r14455. I don't think we'll apply the case > change - the DBI standard seems pretty clear that the literal string > 'dbi' (lowercase) should be used.
Take a look at http://search.cpan.org/dist/DBI/DBI.pm#parse_dsn The provided example uses an uppercased "DBI:" prefix: ($scheme, $driver, $attr_string, $attr_hash, $driver_dsn) = DBI->parse_dsn("DBI:MyDriver(RaiseError=>1):db=test;port=42"); $scheme = 'dbi'; $driver = 'MyDriver'; $attr_string = 'RaiseError=>1'; $attr_hash = { 'RaiseError' => '1' }; $driver_dsn = 'db=test;port=42';
From: greg [...] turnstep.com
Fair point: I've made the change in 2.17.2