Author: timbo
Date: Sun Nov 14 15:12:10 2004
New Revision: 581
Modified:
dbi/trunk/Changes
dbi/trunk/DBI.pm
dbi/trunk/META.yml
dbi/trunk/t/15array.t
Log:
Changed execute_array() definition, and default implementation,
to not consider scalar values for execute tuple count.
Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes (original)
+++ dbi/trunk/Changes Sun Nov 14 15:12:10 2004
@@ -4,7 +4,7 @@
=cut
-=head2 Changes in DBI 1.46 (svn rev 580), 14th November 2004
+=head2 Changes in DBI 1.46 (svn rev 581), 14th November 2004
Fixed parsing bugs in DBI::SQL::Nano thanks to Jeff Zucker.
Fixed a couple of bad links in docs thanks to Graham Barr.
@@ -12,6 +12,8 @@
Fixed minor issues in DBI::DBD::Metadata thanks to Steffen Goeldner.
Fixed DBI::PurePerl neat() to use double quotes for utf8.
+ Changed execute_array() definition, and default implementation,
+ to not consider scalar values for execute tuple count. See docs.
Changed DBD::File to enable ShowErrorStatement by default,
which affects DBD::File subclasses such as DBD::CSV and DBD::DBM.
Changed use DBI qw(:utils) tag to include $neat_maxlen.
Modified: dbi/trunk/DBI.pm
==============================================================================
--- dbi/trunk/DBI.pm (original)
+++ dbi/trunk/DBI.pm Sun Nov 14 15:12:10 2004
@@ -1848,13 +1848,15 @@
if defined($NUM_OF_PARAMS) && $NUM_OF_PARAMS !=
$NUM_OF_PARAMS_given;
# get the length of a bound array
- my $maxlen = 0;
+ my $maxlen;
my %hash_of_arrays = %{$sth->{ParamArrays}};
foreach (keys(%hash_of_arrays)) {
my $ary = $hash_of_arrays{$_};
- my $len = (ref $ary eq 'ARRAY') ? @$ary : 1;
- $maxlen = $len if $len > $maxlen;
+ next unless ref $ary eq 'ARRAY';
+ $maxlen = @$ary if !$maxlen || @$ary > $maxlen;
}
+ # if there are no arrays then execute scalars once
+ $maxlen = 1 unless defined $maxlen;
my @bind_ids = 1..keys(%hash_of_arrays);
my $tuple_idx = 0;
@@ -5125,7 +5127,7 @@
=item C<execute_array>
$rv = $sth->execute_array(\%attr) or die $sth->errstr;
- $rv = $sth->execute_array(\%attr, @bind_values) or die $sth->errstr;
+ $rv = $sth->execute_array(\%attr, @bind_values) or die $sth->errstr;
Execute the prepared statement once for each parameter tuple
(group of values) provided either in the @bind_values, or by prior
@@ -5149,6 +5151,13 @@
executed. Placeholders with fewer values in their parameter arrays
are treated as if padded with undef (NULL) values.
+If a scalar value is bound, instead of an array reference, it is
+treated as a I<variable> length array with all elements having the
+same value. It's does not influence the number of tuples executed,
+so if all bound arrays have zero elements then zero tuples will
+be executed. If I<all> bound values are scalars then one tuple
+will be executed, making execute_array() act just like execute().
+
The C<ArrayTupleFetch> attribute can be used to specify a reference
to a subroutine that will be called to provide the bind values for
each tuple execution. The subroutine should return an reference to
Modified: dbi/trunk/META.yml
==============================================================================
--- dbi/trunk/META.yml (original)
+++ dbi/trunk/META.yml Sun Nov 14 15:12:10 2004
@@ -1,7 +1,7 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: DBI
-version: 1.45
+version: 1.46
version_from: DBI.pm
installdirs: site
requires:
Modified: dbi/trunk/t/15array.t
==============================================================================
--- dbi/trunk/t/15array.t (original)
+++ dbi/trunk/t/15array.t Sun Nov 14 15:12:10 2004
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 47;
+use Test::More tests => 50;
## ----------------------------------------------------------------------------
## 15array.t
@@ -118,6 +118,16 @@
ok(eq_array( $tuple_status, [1]), '... our tuple_status is as expected');
# -----------------------------------------------
+# --- with mix of scalar values and arrays only arrays control tuples
+
[EMAIL PROTECTED] = ();
+$rv = $sth->execute_array( { ArrayTupleStatus => $tuple_status }, 5, [], 7, 8);
+cmp_ok($rv, '==', 0, '... execute_array should return 0');
+
+cmp_ok(scalar @{$rows}, '==', 0, '... we should have 0 rows');
+cmp_ok(scalar @{$tuple_status}, '==', 0,'... we should have 0 tuple_status');
+
+# -----------------------------------------------
# --- catch 'undefined value' bug with zero bind values
@$rows = ();