Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: SQL through perl is giving error

by ksublondie (Pilgrim)
on Aug 31, 2011 at 23:29 UTC ( #923550=note: print w/ replies, xml ) Need Help??


in reply to Re: SQL through perl is giving error
in thread SQL through perl is giving error

Because I have 3 separate update and/or insert statements per do, wanted to make sure all succeed, and wasn't sure exactly how the return value would account for all possible errors. From my testing, it looks like do returns only the last statement result rows.

Now if I add a rollback before the 2nd eval:

warn $inventoryUpdate.$statement."\n"; eval{ $result=$db->do($inventoryUpdate.$statement); warn "result1=$result\n"; }; if($@){ warn "Can't update. Trying insert.\n\n$inventoryInsert$statement"; $db->rollback; eval{ $result=$db->do($inventoryInsert.$statement); warn "result1=$result\n"; }; if ($@){ warn "Aborted because $@"; $db->rollback; return 0; } } $db->commit;
It works! Apparently, the rollback resets $@, but why is the $@ message different in the 2nd eval without the rollback?


Comment on Re^2: SQL through perl is giving error
Select or Download Code
Re^3: SQL through perl is giving error
by Anonymous Monk on Sep 01, 2011 at 03:17 UTC

    You might try the trace features of DBI to see more of what is going on.

      Suppose there is a table "mytable" with column col_pk as follows.
      col_pk ---- 1 2 3
      And update and insert sql as follows.
      update mytable set col_pk=4 where col_pk=3; insert into mytable (col_pk) values (3);
      If you run the sql above only once, it never yields error. But if you run the sql twice, it will yield error because there is already 4 in mytable.

      I'm not sure. Just guessing.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://923550]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-12-18 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (67 votes), past polls