Giles Lean wrote:
> 
> > The crux of it seems to be this line:
> >
> >   $user = $ENV{DBI_USER} unless $user eq "";
> 
> Here's one way to fix it.

Thanks for the patch, Giles. I think your solution is a bit flawed too
because you test for truth instead of definedness. For example, in your
case if $user was equal to "0", a valid Postgres username, your code
would improperly default to $ENV{DBI_USER} because 0 is _false_ 
although it is _defined_. 

Here's my own patch that tests for definedness and adds a bit of
documentation:

--- Pg.pm.org   Sun Apr 15 20:55:37 2001
+++ Pg.pm       Sun Apr 15 20:54:07 2001
@@ -79,11 +79,15 @@
         $Name =~ s/^.*dbname\s*=\s*//;
         $Name =~ s/\s*;.*$//;
 
-        $user = "" unless defined($user);
-        $auth = "" unless defined($auth);
+       # if the $user and $auth aren't defined,
+       # first default to $ENV{DBI_USER} and $ENV{DBI_PASS}
+       # and then to "" if they are still undefined
+
+        $user = $ENV{DBI_USER} unless defined($user);
+        $auth = $ENV{DBI_PASS} unless defined($auth);
 
-        $user = $ENV{DBI_USER} unless $user eq "";
-        $auth = $ENV{DBI_PASS} unless $auth eq "";
+        $user = ""             unless defined($user);
+        $auth = ""             unless defined($auth);
 
         my($dbh) = DBI::_new_dbh($drh, {
             'Name' => $Name,             
##################

  -mark 





> 
> Regards,
> 
> Giles
> 
> *** DBD-Pg-0.96/Pg.pm-orig      Tue Apr 10 03:44:18 2001
> --- DBD-Pg-0.96/Pg.pm   Sun Apr 15 10:26:16 2001
> ***************
> *** 79,89 ****
>           $Name =~ s/^.*dbname\s*=\s*//;
>           $Name =~ s/\s*;.*$//;
> 
> !         $user = "" unless defined($user);
> !         $auth = "" unless defined($auth);
> !
> !         $user = $ENV{DBI_USER} unless $user eq "";
> !         $auth = $ENV{DBI_PASS} unless $auth eq "";
> 
>           my($dbh) = DBI::_new_dbh($drh, {
>               'Name' => $Name,
> --- 79,88 ----
>           $Name =~ s/^.*dbname\s*=\s*//;
>           $Name =~ s/\s*;.*$//;
> 
> !         $user ||= $ENV{DBI_USER};
> !         $auth ||= $ENV{DBI_PASS};
> !       $user ||= "";
> !       $auth ||= "";
> 
>           my($dbh) = DBI::_new_dbh($drh, {
>               'Name' => $Name,

-- 

http://mark.stosberg.com/

Reply via email to