Author: timbo
Date: Wed Feb 21 18:36:14 2007
New Revision: 9153

Modified:
   dbi/trunk/DBI.xs
   dbi/trunk/Driver.xst
   dbi/trunk/lib/DBD/ExampleP.pm
   dbi/trunk/lib/DBD/Gofer.pm

Log:
Add a default destroy method in DBI.xs like the one in Driver.xst
that automatically calls finish for Active statement handles.


Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs    (original)
+++ dbi/trunk/DBI.xs    Wed Feb 21 18:36:14 2007
@@ -4550,6 +4550,36 @@
     (void)cv;
 
 
+void
+DESTROY(sth)
+    SV *        sth
+    PPCODE:
+    /* keep in sync with DESTROY in Driver.xst */
+    D_imp_sth(sth);
+    ST(0) = &sv_yes;
+    /* we don't test IMPSET here because this code applies to pure-perl 
drivers */
+    if (DBIc_IADESTROY(imp_sth)) { /* want's ineffective destroy    */
+        DBIc_ACTIVE_off(imp_sth);
+        if (DBIc_DBISTATE(imp_sth)->debug)
+                PerlIO_printf(DBIc_LOGPIO(imp_sth), "         DESTROY %s 
skipped due to InactiveDestroy\n", SvPV_nolen(sth));
+    }
+    if (DBIc_ACTIVE(imp_sth)) {
+        D_imp_dbh_from_sth;
+        if (!dirty && DBIc_ACTIVE(imp_dbh)) {
+            dSP;
+            PUSHMARK(sp);
+            XPUSHs(sth);
+            PUTBACK;
+            perl_call_method("finish", G_SCALAR);
+            SPAGAIN;
+            PUTBACK;
+        }
+        else {
+            DBIc_ACTIVE_off(imp_sth);
+        }
+    }
+
+
 MODULE = DBI   PACKAGE = DBD::_::common
 
 

Modified: dbi/trunk/Driver.xst
==============================================================================
--- dbi/trunk/Driver.xst        (original)
+++ dbi/trunk/Driver.xst        Wed Feb 21 18:36:14 2007
@@ -320,6 +320,7 @@
 DESTROY(dbh)
     SV *       dbh
     PPCODE:
+    /* keep in sync with default DESTROY in DBI.xs */
     D_imp_dbh(dbh);
     ST(0) = &sv_yes;
     if (!DBIc_IMPSET(imp_dbh)) {       /* was never fully set up       */
@@ -718,6 +719,7 @@
 DESTROY(sth)
     SV *       sth
     PPCODE:
+    /* keep in sync with default DESTROY in DBI.xs */
     D_imp_sth(sth);
     ST(0) = &sv_yes;
     if (!DBIc_IMPSET(imp_sth)) {       /* was never fully set up       */

Modified: dbi/trunk/lib/DBD/ExampleP.pm
==============================================================================
--- dbi/trunk/lib/DBD/ExampleP.pm       (original)
+++ dbi/trunk/lib/DBD/ExampleP.pm       Wed Feb 21 18:36:14 2007
@@ -74,7 +74,6 @@
        return ("dbi:ExampleP:dir=.");  # possibly usefully meaningless
     }
 
-    sub DESTROY { undef }
 }
 
 
@@ -415,11 +414,6 @@
        return $sth->SUPER::STORE($attrib, $value);
     }
 
-    sub DESTROY {
-       my $sth = shift;
-        #$sth->finish if $sth->SUPER::FETCH('Active');
-    }
-
     *parse_trace_flag = \&DBD::ExampleP::db::parse_trace_flag;
 }
 

Modified: dbi/trunk/lib/DBD/Gofer.pm
==============================================================================
--- dbi/trunk/lib/DBD/Gofer.pm  (original)
+++ dbi/trunk/lib/DBD/Gofer.pm  Wed Feb 21 18:36:14 2007
@@ -176,9 +176,6 @@
         return $dbh;
     }
 
-    sub DESTROY { undef }
-
-
     sub _load_class { # return true or false+$@
         my $class = shift;
         (my $pm = $class) =~ s{::}{/}g;

Reply via email to