Author: turnstep
Date: Mon Aug 3 20:46:39 2009
New Revision: 13154
Modified:
DBD-Pg/trunk/Pg.pm
DBD-Pg/trunk/t/03smethod.t
Log:
Fix up execute_array per complaint in RT 39829
Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm (original)
+++ DBD-Pg/trunk/Pg.pm Mon Aug 3 20:46:39 2009
@@ -1659,34 +1659,26 @@
sub bind_param_array {
+ ## Binds an array of data to a specific placeholder in a statement
## The DBI version is broken, so we implement a near-copy here
+
my $sth = shift;
my ($p_id, $value_array, $attr) = @_;
+ ## Bail if the second arg is not undef or an an arrayref
return $sth->set_err(1, "Value for parameter $p_id must be a scalar or an arrayref, not a ".ref($value_array))
if defined $value_array and ref $value_array and ref $value_array ne 'ARRAY';
+ ## Bail if the first arg is not a number
return $sth->set_err(1, q{Can't use named placeholders for non-driver supported bind_param_array})
unless DBI::looks_like_number($p_id); # because we rely on execute(@ary) here
- # get/create arrayref to hold params
- my $hash_of_arrays = $sth->{ParamArrays} ||= { };
-
- if (ref $value_array eq 'ARRAY') {
- # check that input has same length as existing
- # find first arrayref entry (if any)
- for (keys %$hash_of_arrays) {
- my $v = $$hash_of_arrays{$_};
- next unless ref $v eq 'ARRAY';
- return $sth->set_err
- (1,"Arrayref for parameter $p_id has ".@$value_array.' elements'
- ." but parameter $_ has ".@$v)
- if @$value_array != @$v;
- }
- }
+ ## Store the list of items in the hash (will be undef or an arayref)
+ $sth->{ParamArrays}{$p_id} = $value_array;
- $$hash_of_arrays{$p_id} = $value_array;
+ ## If any attribs were passed in, we need to call bind_param
return $sth->bind_param($p_id, '', $attr) if $attr; ## This is the big change so -w does not complain
+
return 1;
} ## end bind_param_array
Modified: DBD-Pg/trunk/t/03smethod.t
==============================================================================
--- DBD-Pg/trunk/t/03smethod.t (original)
+++ DBD-Pg/trunk/t/03smethod.t Mon Aug 3 20:46:39 2009
@@ -236,17 +236,17 @@
};
is ($@, q{}, $t);
-$t='Statement handle method "bind_param_array" fails when binding one value to the first placeholder';
+$t='Statement handle method "bind_param_array" works when binding one value to the second placeholder';
eval {
- $sth->bind_param_array(1, [ 30 ]);
+ $sth->bind_param_array(2, [ 'Mangoz' ]);
};
-isnt ($@, q{}, $t);
+is ($@, q{}, $t);
-$t='Statement handle method "bind_param_array" fails when binding two values to the second placeholder';
+$t='Statement handle method "bind_param_array" works when binding two values to the second placeholder';
eval {
$sth->bind_param_array(2, [ 'Plantain', 'Apple' ]);
};
-isnt ($@, q{}, $t);
+is ($@, q{}, $t);
#
# Test of the "execute_array" statement handle method
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.