Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to safely test if a database handle is capable of transactions?

by fmerges (Chaplain)
on Nov 18, 2008 at 21:19 UTC ( #724389=note: print w/ replies, xml ) Need Help??


in reply to How to safely test if a database handle is capable of transactions?

Hi,

While it's not breaking encapsulation, as Limbic~Region corrected, using 'begin_work' is the recommended way, as you get blamed by the driver if it's not supported

eval { $dbh->begin_work; # ... $dbh->commit; }; if ($@) { $dbh->rollback; # If you want to be paranoid, check if it rolled back. # Look at manual: man DBI }

Hope this helps you a bit

Regards,

Update: corrected about the encapsulation, thanks Limbic~Region

fmerges at irc.freenode.net


Comment on Re: How to safely test if a database handle is capable of transactions?
Download Code
Re^2: How to safely test if a database handle is capable of transactions?
by Limbic~Region (Chancellor) on Nov 18, 2008 at 23:24 UTC
    fmerges,
    Where is encapsulation being broken?
    $dbh->{AutoCommit} = 0;
    The DBI is a tied interface and you are not really breaking encapsulation by doing this. This is a perfectly acceptable way of doing business with this module - just see the docs.

    You did indirectly answer the OP's question (begin_work). According to the docs - If the driver does not support transactions then when begin_work attempts to set AutoCommit off the driver will trigger a fatal error. You just need to work it a bit differently since the OP wants to know if transactions are supported prior to trying a transaction. This means checking the actual contents of $@ rather than just seeing if it is set.

    Cheers - L~R

Re^2: How to safely test if a database handle is capable of transactions?
by ikegami (Pope) on Nov 19, 2008 at 17:13 UTC
    The driver will die (or return an error if RaiseError => 0) whichever interface you use if transactions aren't unsupported.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-12-26 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (163 votes), past polls