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