Skip to content

Commit

Permalink
Really fix SQLite savepoints unlike the shortsighted 398215b
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed Mar 30, 2016
1 parent 67cbc0a commit 66c817d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -50,6 +50,8 @@ Revision history for DBIx::Class
immediately before the commit is attempted (RT#107159)
- Work around unreliable $sth->finish() on INSERT ... RETURNING within
DBD::Firebird on some compiler/driver combinations (RT#110979)
- Really fix savepoint rollbacks on older DBD::SQLite (fix in 0.082800
was not sufficient to cover up RT#67843)
- Fix several corner cases with Many2Many over custom relationships
- Fix the Sybase ASE storage incorrectly attempting to retrieve an
autoinc value when inserting rows containing blobs (GH#82)
Expand Down
25 changes: 10 additions & 15 deletions lib/DBIx/Class/Storage/DBI/SQLite.pm
Expand Up @@ -123,22 +123,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 {
Expand Down
5 changes: 5 additions & 0 deletions t/752sqlite.t
Expand Up @@ -96,6 +96,11 @@ DDL
}

# test blank begin/svp/commit/begin cycle
#
# need to prime this for exotic testing scenarios
# before testing for lack of warnings
modver_gt_or_eq('DBD::SQLite', '1.33');

warnings_are {
my $schema = DBICTest->init_schema( no_populate => 1 );
my $rs = $schema->resultset('Artist');
Expand Down
18 changes: 4 additions & 14 deletions t/storage/savepoints.t
Expand Up @@ -6,8 +6,7 @@ use warnings;
use Test::More;
use Test::Exception;
use DBIx::Class::Optional::Dependencies;
use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer scope_guard);

use DBIx::Class::_Util qw(sigwarn_silencer scope_guard);

use DBICTest;

Expand Down Expand Up @@ -228,15 +227,6 @@ for ('', keys %$env2optdep) { SKIP: {

is_deeply( $schema->storage->savepoints, [], 'All savepoints forgotten' );

SKIP: {
skip "FIXME: Reading inexplicably fails on very old replicated DBD::SQLite<1.33", 1 if (
$ENV{DBICTEST_VIA_REPLICATED}
and
$prefix eq 'SQLite Internal DB'
and
! modver_gt_or_eq('DBD::SQLite', '1.33')
);

ok($ars->search({ name => 'in_outer_transaction' })->first,
'commit from outer transaction');
ok($ars->search({ name => 'in_outer_transaction2' })->first,
Expand All @@ -246,7 +236,9 @@ SKIP: {
is $ars->search({ name => 'in_inner_transaction_rolling_back' })->first,
undef,
'rollback from inner transaction';
}

# make sure a fresh txn will work after above
$schema->storage->txn_do(sub { ok "noop" } );

### cleanupz
$schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") });
Expand All @@ -255,8 +247,6 @@ SKIP: {
done_testing;

END {
local $SIG{__WARN__} = sigwarn_silencer( qr/Internal transaction state of handle/ )
unless modver_gt_or_eq('DBD::SQLite', '1.33');
eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") }) } if defined $schema;
undef $schema;
}

0 comments on commit 66c817d

Please sign in to comment.