I can't comment in general, but DBD::Informix carefully preserves the error from commit when it fails, even when it has to start a new transaction immediately afterwards. Ditto for per statement automatic committing -- if it has to start a transaction and the statement fails, then it ensures that the returned status is that of the statement that generated the error, rather than that of the compensating commit (or rollback). It is one of the things that makes AutoCommit support painful.

On Monday, December 30, 2002, at 07:50 AM, Bruce Momjian wrote:


Can someone comment on this patch? The patch does two things; first
it causes BEGIN to happen after COMMIT even if the commit fails, which
makes sense. Second, it displays the error associated with the commit,
rather than just "commit failed".

Seems both are good improvements. One thing that has me confused is
that the author states that other interfaces also have the old behavior,
which seems wrong too.

----------------------------------------------------------------------- ----

Kai wrote:
On Tue, Dec 17, 2002 at 11:16:59PM -0500, Bruce Momjian wrote:
Would you re-send me the other email that had the script.

Hi Bruce,

Did you have any luck with the buglet below?

Attached is my patch for DBD-Pg-1.20, dbdimp.c, which fixes the problem, but
I'm completely in the dark about any memory leaks I could have introduced,
nor am I allknowing about any unknown behaviour ;-).

I have tested it with the scripts I sent you earlier, and the return of the
commit is now FALSE when thec ommit fails, and the error is stored correctly
in $dbh->errstr().

Regards (and a happy new year),

Kai wrote:
Hello all,

After some investigation of DBI's code, and DBD-Pg I came to the conclusion
that errors from the SQL backend are not reported back to the DBD, and DBD
only reports 'commit failed\n', not the actual error from the SQL backend.
This behaviour seems to be the same for DBD-Oracle and DBD-Sybase.

Secondly if the DBI's connection was in a Non-AutoCommit mode, the
database-state was left without issuing a BEGIN after the failed COMMIT.
Again, this seemed to be missing in the above DBD implementations.

[ this is tested against DBI-1.32 and DBD-Pg-1.20 ]

Now I'm wondering if this behaviour is normal. It seems wrong to me at
least, but it could be ill logic on my side :-/.


I have attached a postgresql create table script, some plain SQL queries,
and a perlscript doing that same queries via DBD::Pg to show a reproducable
commit-error in postgresql. (I have no Oracle at hand, nor Sybase, though I
know that Sybase does the same tricks with triggers invoking at commit).

Interesting output in the script:
DBD::Pg::db commit failed: commit failed at dbh-test.pl line 52.
and:
NOTICE: COMMIT: no transaction in progress

Further along; I could send in a patch for DBD-Pg, but I'm no freak with
memory leaks etc...

Thanks for any enlightenment,
--
Kai

96 pings make up a single Bong (Peter Salus)
[ Attachment, skipping... ]

--
Bruce Momjian | http://candle.pha.pa.us
[EMAIL PROTECTED] | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
*** dbdimp.c.org Wed Nov 27 03:02:39 2002
--- dbdimp.c Mon Dec 30 15:17:11 2002
***************
*** 280,304 ****

if (NULL != imp_dbh->conn) {
PGresult* result = 0;
! ExecStatusType status;

/* execute commit */
result = PQexec(imp_dbh->conn, "commit");
! status = result ? PQresultStatus(result) : -1;
PQclear(result);

/* check result */
! if (status != PGRES_COMMAND_OK) {
! pg_error(dbh, status, "commit failed\n");
! return 0;
}

/* start new transaction. AutoCommit must be FALSE, ref. 20 lines up */
result = PQexec(imp_dbh->conn, "begin");
! status = result ? PQresultStatus(result) : -1;
PQclear(result);
! if (status != PGRES_COMMAND_OK) {
! pg_error(dbh, status, "begin failed\n");
return 0;
}

--- 280,310 ----

if (NULL != imp_dbh->conn) {
PGresult* result = 0;
! ExecStatusType commitstatus, beginstatus;

/* execute commit */
result = PQexec(imp_dbh->conn, "commit");
! commitstatus = result ? PQresultStatus(result) : -1;
PQclear(result);

/* check result */
! if (commitstatus != PGRES_COMMAND_OK) {
! /* Only put the error message in DBH->errstr */
! pg_error(dbh, commitstatus, PQerrorMessage(imp_dbh->conn));
}

/* start new transaction. AutoCommit must be FALSE, ref. 20 lines up */
result = PQexec(imp_dbh->conn, "begin");
! beginstatus = result ? PQresultStatus(result) : -1;
PQclear(result);
! if (beginstatus != PGRES_COMMAND_OK) {
! /* Maybe add some loud barf here? Raising some very high error? */
! pg_error(dbh, beginstatus, "begin failed\n");
! return 0;
! }
!
! /* if the initial COMMIT failed, return 0 now */
! if (commitstatus != PGRES_COMMAND_OK) {
return 0;
}


Jonathan Leffler ([EMAIL PROTECTED], [EMAIL PROTECTED]) #include <disclaimer.h>
"I don't suffer from insanity -- I enjoy every minute of it"
Guardian of DBD::Informix 1.04.PC1 -- http://dbi.perl.org/

Reply via email to