From: Rafael Kitover Date: Fri, 6 Nov 2009 15:01:30 +0000 (+0000) Subject: transactions for MSSQL over DBD::Sybase X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b90d7ebab489e4f53ad02bf4acd45fb01d8e549f;p=dbsrgits%2FDBIx-Class-Historic.git transactions for MSSQL over DBD::Sybase --- diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm index 3d83020..7605080 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm @@ -29,6 +29,24 @@ sub _init { $self->set_textsize; } +sub _dbh_begin_work { + my $self = shift; + + $self->_get_dbh->do('BEGIN TRAN'); +} + +sub _dbh_commit { + my $self = shift; + + $self->_dbh->do('COMMIT'); +} + +sub _dbh_rollback { + my $self = shift; + + $self->_dbh->do('ROLLBACK'); +} + 1; =head1 NAME diff --git a/t/74mssql.t b/t/74mssql.t index 172c78d..007b9d3 100644 --- a/t/74mssql.t +++ b/t/74mssql.t @@ -18,7 +18,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test' unless ($dsn); -my $TESTS = 15; +my $TESTS = 18; plan tests => $TESTS * 2; @@ -145,15 +145,30 @@ SQL $rs->reset; } 'multiple active statements'; - # test multiple active statements in a transaction - TODO: { - local $TODO = 'needs similar FreeTDS fixes to the ones in Sybase.pm'; - lives_ok { - $schema->txn_do(sub { - $rs->create({ amount => 400 }); - }); - } 'simple transaction'; - } + $rs->delete; + + # test simple transaction with commit + lives_ok { + $schema->txn_do(sub { + $rs->create({ amount => 400 }); + }); + } 'simple transaction'; + + cmp_ok $rs->first->amount, '==', 400, 'committed'; + $rs->reset; + + $rs->delete; + + # test rollback + throws_ok { + $schema->txn_do(sub { + $rs->create({ amount => 400 }); + die 'mtfnpy'; + }); + } qr/mtfnpy/, 'simple failed txn'; + + is $rs->first, undef, 'rolled back'; + $rs->reset; } # clean up our mess