From: Rafael Kitover Date: Fri, 26 Mar 2010 09:55:55 +0000 (+0000) Subject: savepoints for Informix X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9fb04139a7323dbcf9f2c6f81476e2f10bde95d4;p=dbsrgits%2FDBIx-Class-Historic.git savepoints for Informix --- diff --git a/lib/DBIx/Class/Storage/DBI/Informix.pm b/lib/DBIx/Class/Storage/DBI/Informix.pm index c08cb9a..575bc4b 100644 --- a/lib/DBIx/Class/Storage/DBI/Informix.pm +++ b/lib/DBIx/Class/Storage/DBI/Informix.pm @@ -32,6 +32,22 @@ sub _sql_maker_opts { return { limit_dialect => 'SkipFirst', %{$self->{_sql_maker_opts}||{}} }; } +sub _svp_begin { + my ($self, $name) = @_; + + $self->_get_dbh->do("SAVEPOINT $name"); +} + +# can't release savepoints +sub _svp_release { 1 } + +sub _svp_rollback { + my ($self, $name) = @_; + + $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name") +} + + 1; __END__ diff --git a/t/748informix.t b/t/748informix.t index a1d533a..a9ad66b 100644 --- a/t/748informix.t +++ b/t/748informix.t @@ -13,7 +13,9 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS plan skip_all => 'Set $ENV{DBICTEST_INFORMIX_DSN}, _USER and _PASS to run this test' unless $dsn; -my $schema = DBICTest::Schema->connect($dsn, $user, $pass); +my $schema = DBICTest::Schema->connect($dsn, $user, $pass, { + auto_savepoint => 1 +}); my $dbh = $schema->storage->dbh; @@ -72,6 +74,27 @@ is( $lim->next->artistid, 101, "iterator->next ok" ); is( $lim->next->artistid, 102, "iterator->next ok" ); is( $lim->next, undef, "next past end of resultset ok" ); +# test savepoints +eval { + $schema->txn_do(sub { + eval { + $schema->txn_do(sub { + $ars->create({ name => 'in_savepoint' }); + die "rolling back savepoint"; + }); + }; + ok ((not $ars->search({ name => 'in_savepoint' })->first), + 'savepoint rolled back'); + $ars->create({ name => 'in_outer_txn' }); + die "rolling back outer txn"; + }); +}; + +like $@, qr/rolling back outer txn/, + 'correct exception for rollback'; + +ok ((not $ars->search({ name => 'in_outer_txn' })->first), + 'outer txn rolled back'); done_testing;