Re: Perl and AutoCommit

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Perl and AutoCommit
Date: 2005-03-27 21:00:39
Message-ID: d252273c12f3cfd318521979b8620dc4@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> $DB->{AutoCommit} = 0 || die...

As someone pointed out, this always dies. In general, you don't
need (or want) to test the results of setting a variable. Also be
aware that in this case you probably want "or" and not "|" - the former
tests the result of "$DB->{AutoCommit} = 0", while the latter actually
tries to set $DB->{AutoCommit} to first "0" and then to the result
of "die". What you want is really

($DB->{AutoCommit} = 0) || die;

which is the same thing, and better written as:

$DB->{AutoCommit} = 0 or die;

Best of all is just to remove the line entirely, as there is no point in
testing the assignment: simply view the contents afterwards:

$DB->{AutoCommit} = 0;
print " |- AutoCommit now: $DB->{AutoCommit}\n";

Also be aware that for DBD::Pg, the following is a known bug
(will be fixed in the upcoming 1.41 release):

> $DB->commit() || die...

In some circumstances commit() returns false when it should return true
(even though it still committed). If you find that happening, simply change
it to $DB->commit(); and trust that the correct thing is indeed happening.

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200503271548
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFCRx7hvJuQZxSWSsgRAntrAKDyjLhxsSMjIhsjMVtuEwbXXdeqSACg+ri1
F65YHQhWg2c0j8ZwT9LMDP4=
=gTE2
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mark Greenbank 2005-03-27 21:39:32 dblinks?
Previous Message Bricklen Anderson 2005-03-27 20:27:54 plpgsql no longer exists