Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / SQLite.pm
index 4311bdf..714b107 100644 (file)
@@ -7,9 +7,11 @@ use base qw/DBIx::Class::Storage::DBI/;
 use mro 'c3';
 
 use SQL::Abstract 'is_plain_value';
-use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer);
+use DBIx::Class::_Util qw(
+  modver_gt_or_eq sigwarn_silencer
+  dbic_internal_try dbic_internal_catch
+);
 use DBIx::Class::Carp;
-use Try::Tiny;
 use namespace::clean;
 
 __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::SQLite');
@@ -63,7 +65,7 @@ Even if you upgrade DBIx::Class (which works around the bug starting from
 version 0.08210) you may still have corrupted/incorrect data in your database.
 DBIx::Class warned about this condition for several years, hoping to give
 anyone affected sufficient notice of the potential issues. The warning was
-removed in version 0.082900.
+removed in 2015/v0.082820.
 
 =back
 
@@ -123,22 +125,17 @@ sub _exec_svp_rollback {
   my ($self, $name) = @_;
 
   $self->_dbh->do("ROLLBACK TO SAVEPOINT $name");
-}
-
-# older SQLite has issues here too - both of these are in fact
-# completely benign warnings (or at least so say the tests)
-sub _exec_txn_rollback {
-  local $SIG{__WARN__} = sigwarn_silencer( qr/rollback ineffective/ )
-    unless $DBD::SQLite::__DBIC_TXN_SYNC_SANE__;
-
-  shift->next::method(@_);
-}
-
-sub _exec_txn_commit {
-  local $SIG{__WARN__} = sigwarn_silencer( qr/commit ineffective/ )
-    unless $DBD::SQLite::__DBIC_TXN_SYNC_SANE__;
 
-  shift->next::method(@_);
+  # resync state for older DBD::SQLite (RT#67843)
+  # https://github.com/DBD-SQLite/DBD-SQLite/commit/9b3cdbf
+  if (
+    ! modver_gt_or_eq('DBD::SQLite', '1.33')
+      and
+    $self->_dbh->FETCH('AutoCommit')
+  ) {
+    $self->_dbh->STORE('AutoCommit', 0);
+    $self->_dbh->STORE('BegunWork', 1);
+  }
 }
 
 sub _ping {
@@ -168,26 +165,29 @@ sub _ping {
   unless ($DBD::SQLite::__DBIC_TXN_SYNC_SANE__) {
     # since we do not have access to sqlite3_get_autocommit(), do a trick
     # to attempt to *safely* determine what state are we *actually* in.
-    # FIXME
-    # also using T::T here leads to bizarre leaks - will figure it out later
-    my $really_not_in_txn = do {
-      local $@;
+
+    my $really_not_in_txn;
+
+    # not assigning RV directly to env above, because this causes a bizarre
+    # leak of the catch{} cref on older perls... wtf
+    dbic_internal_try {
 
       # older versions of DBD::SQLite do not properly detect multiline BEGIN/COMMIT
       # statements to adjust their {AutoCommit} state. Hence use such a statement
       # pair here as well, in order to escape from poking {AutoCommit} needlessly
       # https://rt.cpan.org/Public/Bug/Display.html?id=80087
-      eval {
-        # will fail instantly if already in a txn
-        $dbh->do("-- multiline\nBEGIN");
-        $dbh->do("-- multiline\nCOMMIT");
-        1;
-      } or do {
-        ($@ =~ /transaction within a transaction/)
-          ? 0
-          : undef
-        ;
-      };
+      #
+      # will fail instantly if already in a txn
+      $dbh->do("-- multiline\nBEGIN");
+      $dbh->do("-- multiline\nCOMMIT");
+
+      $really_not_in_txn = 1;
+    }
+    dbic_internal_catch {
+      $really_not_in_txn = ( $_[0] =~ qr/transaction within a transaction/
+        ? 0
+        : undef
+      );
     };
 
     # if we were unable to determine this - we may very well be dead
@@ -212,7 +212,7 @@ sub _ping {
   }
 
   # do the actual test and return on no failure
-  ( $ping_fail ||= ! try { $dbh->do('SELECT * FROM sqlite_master LIMIT 1'); 1 } )
+  ( $ping_fail ||= ! dbic_internal_try { $dbh->do('SELECT * FROM sqlite_master LIMIT 1'); 1 } )
     or return 1; # the actual RV of _ping()
 
   # ping failed (or so it seems) - need to do some cleanup
@@ -221,8 +221,7 @@ sub _ping {
   # keeps the actual file handle open. We don't really want this to happen,
   # so force-close the handle via DBI itself
   #
-  local $@; # so that we do not clobber the real error as set above
-  eval { $dbh->disconnect }; # if it fails - it fails
+  dbic_internal_try { $dbh->disconnect }; # if it fails - it fails
   undef; # the actual RV of _ping()
 }