Use pg_result_error, not pg_last_error, as the latter gives false negatives.
authorGreg Sabino Mullane <greg@endpoint.com>
Tue, 9 Feb 2016 16:38:21 +0000 (11:38 -0500)
committerGreg Sabino Mullane <greg@endpoint.com>
Thu, 11 Feb 2016 04:10:19 +0000 (23:10 -0500)
Specifically in the savepoint part of the code, where a failed query inside the
savepoint gives a non-false reply to pg_last_error by the time we call it,
which then leads to us doing 'RELEASE' instead of 'ROLLBACK TO', and causes
all sorts of mayhem.

The whole system needs a little cleanup, but this is an important bandaid.

Change-Id: I0223a3599816db5650f45863400e6194468d4361

includes/db/DatabasePostgres.php

index e84f264..c8dcc88 100644 (file)
@@ -840,7 +840,7 @@ __INDEXATTR__;
                                        $tempres = (bool)$this->query( $tempsql, $fname, $savepoint );
 
                                        if ( $savepoint ) {
-                                               $bar = pg_last_error();
+                                               $bar = pg_result_error( $this->mLastResult );
                                                if ( $bar != false ) {
                                                        $savepoint->rollback();
                                                } else {
@@ -865,7 +865,7 @@ __INDEXATTR__;
                        $sql .= '(' . $this->makeList( $args ) . ')';
                        $res = (bool)$this->query( $sql, $fname, $savepoint );
                        if ( $savepoint ) {
-                               $bar = pg_last_error();
+                               $bar = pg_result_error( $this->mLastResult );
                                if ( $bar != false ) {
                                        $savepoint->rollback();
                                } else {
@@ -948,7 +948,7 @@ __INDEXATTR__;
 
                $res = (bool)$this->query( $sql, $fname, $savepoint );
                if ( $savepoint ) {
-                       $bar = pg_last_error();
+                       $bar = pg_result_error( $this->mLastResult );
                        if ( $bar != false ) {
                                $savepoint->rollback();
                        } else {