Author: timbo
Date: Tue Oct 31 03:58:57 2006
New Revision: 7994
Modified:
dbi/trunk/DBI.xs
dbi/trunk/t/11fetch.t
Log:
Improve auto-adjustment of NUM_OF_FIELDS
Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs (original)
+++ dbi/trunk/DBI.xs Tue Oct 31 03:58:57 2006
@@ -1375,13 +1375,16 @@
dTHX;
int i = av_len(av) + 1;
if (i != DBIc_NUM_FIELDS(imp_sth)) {
+ SV *sth = dbih_inner((SV*)DBIc_MY_H(imp_sth), "_get_fbav");
/* warn via PrintWarn */
- set_err_char(DBIc_MY_H(imp_sth), imp_sth, "0", 0, "Number of row
fields inconsistent with NUM_FIELDS, NUM_FIELDS updated", "", "_get_fbav");
+ set_err_char(SvRV(DBIc_MY_H(imp_sth)), (imp_xxh_t*)imp_sth,
+ "0", 0, "Number of row fields inconsistent with
NUM_OF_FIELDS, NUM_OF_FIELDS updated", "", "_get_fbav");
DBIc_NUM_FIELDS(imp_sth) = i;
+ hv_delete((HV*)SvRV(sth), "NUM_OF_FIELDS", 13, G_DISCARD);
}
/* don't let SvUTF8 flag persist from one row to the next */
/* (only affects drivers that use sv_setpv, but most XS do) */
- /* XXX turn into option later */
+ /* XXX turn into option later (force on/force off/ignore) */
while(i--) /* field 1 stored at index 0 */
SvUTF8_off(AvARRAY(av)[i]);
}
@@ -1813,7 +1816,7 @@
IV num_fields = DBIc_NUM_FIELDS(imp_sth);
valuesv = (num_fields < 0) ? &sv_undef : newSViv(num_fields);
if (num_fields > 0)
- cacheit = TRUE; /* can't change once set */
+ cacheit = TRUE; /* can't change once set (XXX except
for multiple result sets) */
}
else if (keylen==13 && strEQ(key, "NUM_OF_PARAMS")) {
D_imp_sth(h);
@@ -4227,7 +4230,7 @@
croak("_set_fbav(%s): not an array ref", neatsvpv(src_rv,0));
src_av = (AV*)SvRV(src_rv);
if (AvFILL(src_av)+1 != num_fields)
- croak("_set_fbav(%s): array has %d fields, should have %d",
+ croak("_set_fbav(%s): array has %d elements, the statement handle
expects %d",
neatsvpv(src_rv,0), AvFILL(src_av)+1, num_fields);
for(i=0; i < num_fields; ++i) { /* copy over the row */
/* If we're given the values, then taint them if required */
Modified: dbi/trunk/t/11fetch.t
==============================================================================
--- dbi/trunk/t/11fetch.t (original)
+++ dbi/trunk/t/11fetch.t Tue Oct 31 03:58:57 2006
@@ -12,7 +12,7 @@
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Quotekeys = 0;
-plan tests => 16;
+plan tests => 23;
my $dbh = DBI->connect("dbi:Sponge:foo","","", {
PrintError => 0,
@@ -88,7 +88,7 @@
my $expected = shift @fetchall_hashref_results;
my $k = (ref $keyfield) ? "[EMAIL PROTECTED]" : $keyfield;
print "# fetchall_hashref($k)\n";
- ok($sth = go);
+ ok($sth = go());
my $result = $sth->fetchall_hashref($keyfield);
ok($result);
is_deeply($result, $expected);
@@ -97,6 +97,26 @@
warn Dumper \%dump if %dump;
+# test auto repair of NUM_OF_FIELDS if size of row buffer is changed
+# (ie by code incompletely handling multiple result sets)
+$sth = go();
+my $row = $sth->fetchrow_arrayref;
+is scalar @$row, 3;
+is $sth->{NUM_OF_FIELDS}, 3;
+if (0) { # manual test as it requires the row buffer to not be readonly
+ push @$row, 'newcol'; # force additional column into row buffer
+ is scalar @$row, 4;
+ # should produce a warning and update NUM_FIELDS
+ ok $row = $sth->fetchrow_arrayref;
+ is scalar @$row, 4;
+ is $sth->{NUM_OF_FIELDS}, 4;
+}
+else {
+ ok(1) for (1..4)
+}
+$sth->finish;
+
+
if (0) {
my @perf = map { [ int($_/100), $_, $_ ] } 0..10000;
require Benchmark;