From: Rafael Kitover Date: Thu, 11 Feb 2010 10:46:58 +0000 (+0000) Subject: savepoints for SQLAnywhere X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9cf3db6f931299a211a15e12421b4ff9766f0dd2;p=dbsrgits%2FDBIx-Class-Historic.git savepoints for SQLAnywhere --- diff --git a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm index c233361..1de7706 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLAnywhere.pm @@ -122,6 +122,21 @@ sub connect_call_datetime_setup { ); } +sub _svp_begin { + my ($self, $name) = @_; + + $self->_get_dbh->do("SAVEPOINT $name"); +} + +# can't release savepoints that have been rolled back +sub _svp_release { 1 } + +sub _svp_rollback { + my ($self, $name) = @_; + + $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name") +} + 1; =head1 AUTHOR diff --git a/t/749sybase_asa.t b/t/749sybase_asa.t index 78efdeb..5656b4c 100644 --- a/t/749sybase_asa.t +++ b/t/749sybase_asa.t @@ -28,7 +28,9 @@ foreach my $info (@info) { next 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; @@ -58,6 +60,28 @@ EOF $new->discard_changes; is($new->artistid, 66, 'Explicit PK assigned'); +# 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'); + # test populate lives_ok (sub { my @pop;