I have a set of updates that need to be done on a set of database tables. The whole update operation must be part of a single transaction. My code for this operation goes as follows.
use Sybase::DBlib; my $dbh = new Sybase::DBlib( <username>, <password>, <server> ); #A reference to my own error handler for sybase errors dberrhandle( \&myerrorhandler ); # if status flag is 1 then transaction was successful else the transac +tion was not successful $status = 1; sub myerrorhandler { < when error occurs the status flag $status is set to 0 > $status &=0; &INT_CANCEL; # in order to continue with the rest of the process } $dbh->nsql( "begin transaction" ); $dbh->nsql( <update query 1> ); . . . $dbh->nsql( <update qurey n> ); if ( $status ) { $dbh->nsql( "commit" ); } else { $dbh->nsql( "rollback" ); }
When I run this code and some kind of database error occurs in update query number 3. The rest of the updates from 3 to n do take place. But since the status is now false, the database has to do a rollback. But the problem is that the updates 1 and 2 get rolled back but the updates that were done after query 3( where the database error occured ) are not rolled back.

Could someone pls tell me about this unpredictable behavior and how can we get around this problem.

Thank you,
Ravi Malayambakkam.


In reply to Sybperl - Problem with Handling Transactions with Commit and Rollback by cool_ravi2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.