in reply to DBD Sybase Transaction begin_work fails , post #2

You didn't write a question or problem at all.
1. DBD::Sybase has pretty good examples for this.
2. If you set AutoCommit off, there is no need to explicit do this.
3. A simple ->do should do this when being used on your conn handle
4. You said it. errstr, commit and rollback are your friends

  • Comment on Re: DBD Sybase Transaction begin_work fails , post #2

Replies are listed 'Best First'.
Re^2: DBD Sybase Transaction begin_work fails , post #2
by vcoderv (Initiate) on Sep 16, 2009 at 16:43 UTC
    ....yes, thank you.. The problem is when I explicitly want to rollback the changes..
    here, assuming i have a dbh and sth:

    my $sth = $dbh->prepare("exec PerlTest2 \@RetVal = ? OUTPUT, \@SomePar +am = ? "); $sth->bind_param(1, undef, SQL_INTEGER); $sth->bind_param(2, "val1", SQL_VARCHAR); $sth->execute; # first batch exec $sth->bind_param(1, undef); $sth->bind_param(2, "val22"); $sth->execute; # exec some more $sth->finish; $dbh->rollback; # <---- still records get committed into the dB !!! print "finishing...\n"; $dbh->disconnect; close dbh;

      Shouldn't that be in this order:

      $dbh->rollback; # <---- still records get committed into the dB !!! $sth->finish;

      Also, DBD::Sybase says something about $h->{AutoCommit}... Did you set that to off somewhere?

        Yes, AutoCommit => 0
        when I switch the order:

        $sth->rollback;
        $sth->finish;
        I get this error @ ->rollback :
        DBD::Sybase::db rollback failed: OpenClient message: LAYER = (1) ORIGIN = (1) SEVERITY = (1) NUMBER = (49) Server ETMA_NYDEV_DS, database Message String: ct_send(): user api layer: external error: This routine cannot be called because another command structure has results pending.

        Now the code looks like this:
        my %attr = ( 'RaiseError' => 1, 'PrintError' => 1, 'ChopBlanks' => 1, 'AutoCommit' => 0, ); print "establishingh connection\n"; my $dbh = DBI->connect("dbi:Sybase:server=ETMA_NYDEV_DS;database=tss_d +s_dev2","uid","******", \%attr); print "preparing call to PerlTest sp\n"; my $sth = $dbh->prepare("exec PerlTest2 \@RetVal = ? OUTPUT, \@SomePar +am = ? "); $sth->bind_param(1, undef, SQL_INTEGER); $sth->bind_param(2, "val1", SQL_VARCHAR); print "executing...\n"; $sth->execute; $sth->bind_param(1, undef); $sth->bind_param(2, "val22"); $sth->execute; # exec again... print "rolling back...\n"; # lets rollback $dbh->rollback; $sth->finish; print "finishing...\n"; $dbh->disconnect; close dbh; print "----disconnected------\n"; exit 0;