|The stupid question is the question not asked|
How to safely test if a database handle is capable of transactions?by larryl (Scribe)
|on Nov 18, 2008 at 20:58 UTC||Need Help??|
larryl has asked for the
wisdom of the Perl Monks concerning the following question:
Hi all -
I'm writing a module that receives a DBI database handle as input to my constructor. I'd like to be able to test if the handle is transaction-capable, so that I can conditionally wrap certain code in a transaction like so:
First question, is there a better way to do this?
UPDATE: Thanks to feedback, am now using something like this to handle transactions:
Second, for testing the handle I am doing this in my constructor:
which seems to work for the DBs that I have tried, but is it safe, e.g. what if the handle is already mid-transaction? Is there a better way?
UPDATE: Thanks to feedback, am now using something like this to test for transaction capability:
Third, with the AutoCommit test set up as above, I'm occasionally seeing my test harness report errors like:
if I croak later on in the constructor. For reasons I can't determine, changing the test just by adding a line like so causes those error messages to go away:
Any ideas/comments much appreciated!