Suppress warning when duplicates in @INC

2005-04-09 Thread Avis, Ed
DBI has a warning about multiple copies of Driver.xst found in @INC, but
this warning also fires when @INC has the same directory in it twice,
which isn't something to worry about.  This patch quietens the warning
in that case.

diff -ru DBI-1.48/lib/DBI/DBD.pm DBI-1.48-new/lib/DBI/DBD.pm
--- DBI-1.48/lib/DBI/DBD.pm 2005-01-31 14:03:56.0 +
+++ DBI-1.48-new/lib/DBI/DBD.pm 2005-04-09 12:06:29.0 +0100
@@ -2849,7 +2849,8 @@
 _inst_checks();
 return '$(INST_ARCHAUTODIR)' if $is_dbi;
 my $dbidir = dbd_dbi_dir();
-my @try = map  {vmsify( unixify($_) . "/auto/DBI/"  ) } @INC;
+my %seen;
+my @try = grep { not $seen{$_}++ } map { vmsify( unixify($_) . 
"/auto/DBI/" ) } @INC;
 my @xst = grep { -f vmsify( unixify($_) . "/Driver.xst" ) } @try;
 Carp::croak("Unable to locate Driver.xst in @try") unless @xst;
 Carp::carp( "Multiple copies of Driver.xst found in: @xst") if @xst > 1;

-- 
Ed Avis <[EMAIL PROTECTED]>


Patch to stop printing password on stderr

2004-01-30 Thread Avis, Ed
This patch stops DBI printing the connection password in an error
message.

diff -ru DBI-1.40/DBI.pm DBI-1.40-new/DBI.pm
--- DBI-1.40/DBI.pm 2004-01-08 14:03:57.0 +
+++ DBI-1.40-new/DBI.pm 2004-01-30 14:54:52.0 +
@@ -532,7 +532,7 @@
 
 # Set $driver. Old style driver, if specified, overrides new dsn style.
 $driver = $old_driver || $1 || $ENV{DBI_DRIVER}
-   or Carp::croak("Can't connect(@_), no database driver specified "
+   or Carp::croak("Can't connect to data source $dsn, no database driver 
specified "
."and DBI_DSN env var not set");
 
 if ($ENV{DBI_AUTOPROXY} && $driver ne 'Proxy' && $driver ne 'Sponge' && $driver 
ne 'Switch') {


-- 
Ed Avis <[EMAIL PROTECTED]> 


RE: Patch for undefined value error when zero bind values

2004-01-26 Thread Avis, Ed
[diff to DBI.pm]

>+   ($tuple_status) ? @$tuple_status = () : $tuple_status = [];

AFAIK this code is equivalent to

@$tuple_status = ();

because of autovivification.  But anyway, it works.

-- 
Ed Avis <[EMAIL PROTECTED]>


RE: Patch for undefined value error when zero bind values

2004-01-26 Thread Avis, Ed
Tim Bunce <[EMAIL PROTECTED]> wrote:

>Actualy I did this instead, as it seems more correct:
>
>@@ -1720,5 +1721,6 @@
> sub execute_for_fetch {
>my ($sth, $fetch_tuple_sub, $tuple_status) = @_;
>-   @$tuple_status = () if $tuple_status; # reset the status array
>+   # start with empty status array
>+   ($tuple_status) ? @$tuple_status = () : $tuple_status = undef;

But when I try that code it fails the tests I added.  Did you apply
the patch to the test suite?

-- 
Ed Avis <[EMAIL PROTECTED]>


Patch for undefined value error when zero bind values

2004-01-26 Thread Avis, Ed
This patch to DBI-1.40 fixes an error

Can't use an undefined value as an ARRAY reference at DBI.pm line 1735

when using execute_array() with zero values for a bind parameter.  It
includes some new test cases, but not all of the new tests failed
before.

diff -ru DBI-1.40/DBI.pm DBI-1.40-new/DBI.pm
--- DBI-1.40/DBI.pm 2004-01-08 14:03:57.0 +
+++ DBI-1.40-new/DBI.pm 2004-01-26 10:15:46.0 +
@@ -1719,7 +1719,7 @@
 
 sub execute_for_fetch {
my ($sth, $fetch_tuple_sub, $tuple_status) = @_;
-   @$tuple_status = () if $tuple_status; # reset the status array
+   @$tuple_status = (); # reset the status array
 
my ($err_count, %errstr_cache);
while ( my $tuple = &$fetch_tuple_sub() ) {
diff -ru DBI-1.40/t/15array.t DBI-1.40-new/t/15array.t
--- DBI-1.40/t/15array.t2003-08-20 01:15:34.0 +0100
+++ DBI-1.40-new/t/15array.t2004-01-26 10:15:15.0 +
@@ -3,7 +3,7 @@
 use strict;
 use Test;
 
-BEGIN { plan tests => 34 }
+BEGIN { plan tests => 39 }
 
 use Data::Dumper;
 $Data::Dumper::Indent = 0;
@@ -68,6 +68,25 @@
 $dumped = Dumper($tuple_status);
 ok( $dumped, "[1,1,1]");
 
+# --- with no values for bind params, should execute zero times
+
[EMAIL PROTECTED] = ();
+ok( $sth->execute_array( { ArrayTupleStatus => $tuple_status },
+[], [], [], [],
+),
+0);
+ok( @$rows, 0 );
+ok( @$tuple_status, 0 );
+
+# --- catch 'undefined value' bug with zero bind values
+
[EMAIL PROTECTED] = ();
+my $sth_other = $dbh->prepare("insert", {
+   rows => $rows,  # where to 'insert' (push) the rows
+   NUM_OF_PARAMS => 1,
+});
+ok( $sth_other->execute_array( {}, [] ), 0 );
+ok( @$rows, 0);
 
 # --- ArrayTupleFetch code-ref tests ---
 

-- 
Ed Avis <[EMAIL PROTECTED]>


FW: Problems building DBI-1.37 on Solaris 2.8

2003-08-08 Thread Avis, Ed
Forwarding to dbi-dev to make sure the patch doesn't get lost (it's
likely that the developers read dbi-users, but not certain).

This patch fixes a test failure with 15array.t on some platforms:

diff -Naur DBI-1.37/t/15array.t DBI-1.37-new/t/15array.t
--- DBI-1.37/t/15array.t2003-05-11 13:45:27.0 +0100
+++ DBI-1.37-new/t/15array.t2003-08-07 10:39:20.112963000 +0100
@@ -75,8 +75,11 @@
 my $fetchrow = sub { # generate 5 rows of two integer values
 return if $index >= 2;
 $index +=1;
-# $index is quoted to avoid perl version differences
-return [ "$index", 'a','b','c' ];
+# There doesn't seem any reliable way to force $index to be
+# treated as a string (and so dumped as such).  We just have to
+# make the test case allow either 1 or '1'.
+#
+return [ $index, 'a','b','c' ];
 };
 @$rows = ();
 ok( $sth->execute_array({
@@ -86,7 +89,8 @@
 ok( @$rows, 2 );
 ok( @$tuple_status, 2 );
 $dumped = Dumper($rows);
-ok( $dumped, "[['1','a','b','c'],['2','a','b','c']]");
+$dumped =~ s/'(\d)'/$1/g;
+ok( $dumped, "[[1,'a','b','c'],[2,'a','b','c']]");
 $dumped = Dumper($tuple_status);
 ok( $dumped, "[1,1]");
 

Greg Earle pointed me to

which gives a possible fix for the test failure, but it seems that no
matter how hard you try to make $index a string, something along the
line (perhaps Data::Dumper) reserves the right to treat it as a
number.  The only reasonable fix, it seems, is for the test suite to
accept both syntaxes.

-- 
Ed Avis <[EMAIL PROTECTED]>


Patch to fix uninitalized value warning in error reporting

2003-07-14 Thread Avis, Ed
(I hope you don't mind me jumping in on the dbi-devel list with this small
patch; I am not a subscriber so please cc me on replies.)

Sometimes DBI will give an uninitalized value warning when reporting some
other error.  This is harmless but a bit annoying and worrying.  This patch
fixes the warning:

--- DBI-1.37/DBI.pm 2003-05-15 18:48:56.0 +0100
+++ DBI-1.37-new/DBI.pm 2003-07-14 11:15:32.553096000 +0100
@@ -581,7 +581,10 @@
my $dbh;
unless ($dbh = $drh->$connect_meth($dsn, $user, $pass, $attr)) {
$user = '' if !defined $user;
-   my $msg = "$class connect('$dsn','$user',...) failed: ".$drh->errstr;
+   $dsn = '' if !defined $dsn;
+   my $errstr = $drh->errstr;
+   $errstr = '(no error string)' if !defined $errstr;
+   my $msg = "$class connect('$dsn','$user',...) failed: $errstr";
DBI->trace_msg("   $msg\n");
unless ($attr->{HandleError} && $attr->{HandleError}->($msg, $drh, $dbh)) {
Carp::croak($msg) if $attr->{RaiseError};


-- 
Ed Avis <[EMAIL PROTECTED]>