Skip Menu |

This queue is for tickets about the DBD-Pg CPAN distribution.

Report information
The Basics
Id: 7777
Status: resolved
Priority: 0/
Queue: DBD-Pg

People
Owner: Nobody in particular
Requestors: vrm [...] wom.hu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 1.44



Subject: from gborg: $dbh->commit() does not handle errors
[ this bug was migrated from gborg ] Bug Comments: turnstep : 04/07/2003 I contacted the original submitter of this bug and have managed to create this simple test script. I think that this may be a DBI, not a DBD error, as changing the trace level from 0 to 1 changes the return value of the commit: #!/usr/bin/perl -w use DBI; use strict; my $DSN = 'dbi:Pg:dbname=greg;'; my $USER = 'greg'; my $dbh = DBI->connect($DSN,$USER,'', {AutoCommit=>1,PrintError=>0,RaiseError=>1}); ## Change this to (1) and watch the behavior change: $dbh->trace(0); $dbh->{RaiseError}=0; $dbh->do('DROP TABLE test1'); $dbh->do('DROP TABLE test2'); $dbh->do('DROP SEQUENCE test1_id_seq'); $dbh->do('DROP SEQUENCE test2_id_seq'); $dbh->{RaiseError}=1; $dbh->do('CREATE TABLE test1(id serial not null primary key,val varchar(255) not null)') or die $dbh->errstr; $dbh->do('CREATE TABLE test2(id serial not null primary key,tref int not null references test1 deferrable initially deferred)') or die $dbh->errstr; $dbh->begin_work or die $dbh->errstr; $dbh->do('INSERT INTO test2 (tref) values (1)') or die $dbh->errstr; $dbh->commit or die "*****Commit is false here and DBI::errstr is (" . $DBI::errstr . ")"; die "*****Commit was true "; theory : 10/28/2003 Have you mentioned this on the DBI developers list? damon@aol.net : 07/30/2004 We ran into this bug a few weeks ago. It seems that DBD::Pg is not turning autocommit back on after the commit. This triggers code in DBI (DBI.xs:2778 in DBI 1.43) which forces autocommit back on. The way in which the DBI code is turning autocommit back on is clearing the error status. I made a small patch to DBD::Pg 1.32 to turn autocommit on after a commit failure (which seems to be required by the DBI contract anyway as far as I can tell), and also set the appropriate error message instead of "commit failed". diff -ruw DBD-Pg-1.32/dbdimp.c DBD-Pg-1.32-damon/dbdimp.c --- DBD-Pg-1.32/dbdimp.c Tue Feb 3 14:50:22 2004 +++ DBD-Pg-1.32-damon/dbdimp.c Mon Jul 26 14:31:36 2004 @@ -323,7 +323,8 @@ /* check result */ if (status != PGRES_COMMAND_OK) { - pg_error(dbh, status, "commit failed\n"); + pg_error(dbh, status, PQerrorMessage(imp_dbh->conn)); + DBIc_set(imp_dbh, DBIcf_AutoCommit, 1); return 0; } imp_dbh->done_begin = 0; markjugg : 09/26/2004 I tested this with DBI 1.41 and DBD::Pg from CVS and from what I understood, it's not fixed. "commit()" always returned true for me, when I thought it should return false after the insert fails. I checked the DBI Changelog, and it doesn't seem to indicate something related to this has changed since 1.41. Could someone else look verify the bug status of this as well? Here's the test script I used: #!/usr/bin/perl -w use lib ('/home/mark/tmp/DBD-Pg-1.33/blib/lib'); use lib ('/home/mark/tmp/DBD-Pg-1.33/blib/arch'); use DBI; use strict; my $DSN = 'dbi:Pg:dbname=testdb;'; my $USER = 'postgres'; my $dbh = DBI->connect($DSN,$USER,'', {AutoCommit=>1,PrintError=>0,RaiseError=>1}); print "DBI ver: $DBI::VERSION\n"; print "DBD::Pg ver:: $DBD::Pg::VERSION\n"; ## Change this to (1) and watch the behavior change: $dbh->trace(0); #DBI->trace(0); $dbh->do('DROP TABLE test1'); $dbh->do('CREATE TABLE test1(id int not null)') or die $dbh->errstr; $dbh->begin_work or die $dbh->errstr; $dbh->{RaiseError}=0; $dbh->do("INSERT INTO test1 values (null)"); $dbh->commit or die "*****Commit is false here and DBI::errstr is (" . $DBI::errstr . ")"; die "*****Commit was true