The stupid question is the question not asked | |
PerlMonks |
Re^3: run 2 query mysqlby Marshall (Canon) |
on Mar 04, 2019 at 20:31 UTC ( [id://1230870]=note: print w/replies, xml ) | Need Help?? |
Well as far as portability goes, you are correct in that BEGIN is not technically an offical SQL statement, but
rather an extremely common alias for the standard SQL command "START TRANSACTION". I am unaware of a DB that
doesn't have the BEGIN alias. But I guess there could be such a critter out there. COMMIT is a standard SQL command. I am certainly not an SQL guru and most of my DB code is fairly straightforward. The Perl DBI is fantastic in how easily command line SQL can be converted into Perl code. I tend to debug my SQL operations from the SQL command line and then transfer that knowledge into Perl DBI code. From that perspective, using BEGIN and COMMIT makes some sense and fits with my work flow. However as youi point out, there are DBI method calls for these SQL commands. I suspect that there is some efficiency to using them. However for me, a typical transaction is 500 operations and that would make no difference.
Error handling is a big, a very big subject, When you go to the trouble of trapping an error (as you show), You have to explictly do something to rollback or otherwise cancel the pending transaction. Then the question becomes "Now What?". If there is no answer to that question, then trapping the error doesn't matter. I have applications that are completely "restartable" as long as each transaction either fully works or doesn't work, the application can just be run again from scratch with an updated input file. Of course in some instance like shown, where a "delta" is being applied to the DB, that simple approach won't work. Lots of possilities that seemed to be outside the scope of the OP's question...
In Section
Seekers of Perl Wisdom
|
|