On Fri, Sep 30, 2016 at 4:57 AM, Tim Bunce <tim.bu...@pobox.com> wrote: >> > > Should a call to prepare() return an Active statement? (i.e. >> > > $sth->{Active} == 1) >> > > >> > > This appears to be the behaviour of DBD::Sybase, but not DBD::Pg >> >
>> That's unfortunate, because Class::DBI does. >> >> $ grep -r Active . >> ./lib/Class/DBI.pm: $sth->execute(@$args) unless $sth->{Active}; >> >> (from sth_to_objects) >> >> As far as I can see, this is to work out whether the sth that's been >> passed in has already had execute called on it (e.g. part of a multiple >> result loop). Removing the $sth->{Active} check (and ensuring Ima::DBI >> always calls prepare and not prepare_cached (I haven't figured out what's >> going on there yet) gets Class::DBI working with DBD::Sybase. > I'd take the view that $sth->{Active} shouldn't be true until after a > successful execute(). > > I'd happily take a doc patch that tightens up the docs in that direction. Attached is a patch against current CPAN version that modifies the documentation to the following: "Active" Type: boolean, read-only The "Active" attribute is true if the handle object is "active". This is rarely used in applications. The exact meaning of active depends on the database driver, but some aspects of the semantics are defined for interoperability. These include: For a database handle, active typically means that the handle is connected to a database ("$dbh->disconnect" sets "Active" off). For a statement handle it typically means that the handle is a "SELECT" that may have more data to fetch. (Fetching all the data or calling "$sth->finish" sets "Active" off.) Prepared statement handles that must have "execute" called on them before they will return data should not be active until that happens. -- "Teaching radical novelties is our main safeguard against dictatorships" -- Edsger W. Dijkstra
--- DBI.pm_orig 2016-09-30 15:28:20.000000000 -0500 +++ DBI.pm 2016-09-30 15:51:54.000000000 -0500 @@ -3595,13 +3595,19 @@ Type: boolean, read-only The C<Active> attribute is true if the handle object is "active". This is rarely used in -applications. The exact meaning of active is somewhat vague at the -moment. For a database handle it typically means that the handle is -connected to a database (C<$dbh-E<gt>disconnect> sets C<Active> off). For -a statement handle it typically means that the handle is a C<SELECT> +applications. The exact meaning of active depends on the database driver, but some aspects +of the semantics are defined for interoperability. These include: + +For a database handle, active typically means that the handle is +connected to a database (C<$dbh-E<gt>disconnect> sets C<Active> off). + +For a statement handle it typically means that the handle is a C<SELECT> that may have more data to fetch. (Fetching all the data or calling C<$sth-E<gt>finish> sets C<Active> off.) +Prepared statement handles that must have C<execute> called on them before they will return data +should not be active until that happens. + =head3 C<Executed> Type: boolean @@ -6774,7 +6780,7 @@ The C<\%attr> parameter may also contain the following attributes: -=over +=over 4 =item C<StrictlyTyped>