From 94633ff448e9253c5503124df6748be1fc26b8e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20Cie=C5=9Blak?= Date: Thu, 8 Mar 2012 21:44:03 +0000 Subject: [PATCH] PostgreSQL: Improve SQL error handling After a query error, PostgreSQL transaction is aborted until it's terminated or the query is closed. All further queries result in: ERROR: current transaction is aborted, commands ignored until end of transaction block Those subsequent errors are ignored by double fault handling in DatabaseBase::reportQueryError but they cause all localization of error messages to fail (unable to issue queries to message tables) and errors lke This resulted in a broken MediaWiki screen with instead of localized error message. We need to fully reset database connection because after pg_connection_reset() various session parameters need to be set again (like "search_path"), otherwise tables will not be found. ERROR: relation "msg_resource" does not exist ERROR: relation "l10n_cache" does not exist --- includes/db/DatabasePostgres.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 893b651011..1f1d7ed1b4 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -159,7 +159,6 @@ class DatabasePostgres extends DatabaseBase { return; } - $this->close(); $this->mServer = $server; $port = $wgDBport; $this->mUser = $user; @@ -177,10 +176,14 @@ class DatabasePostgres extends DatabaseBase { if ( $port != false && $port != '' ) { $connectVars['port'] = $port; } - $connectString = $this->makeConnectionString( $connectVars, PGSQL_CONNECT_FORCE_NEW ); + $this->connectString = $this->makeConnectionString( $connectVars, PGSQL_CONNECT_FORCE_NEW ); + $this->reOpen(); + } + function reOpen() { + $this->close(); $this->installErrorHandler(); - $this->mConn = pg_connect( $connectString ); + $this->mConn = pg_connect( $this->connectString ); $phpError = $this->restoreErrorHandler(); if ( !$this->mConn ) { @@ -253,6 +256,13 @@ class DatabasePostgres extends DatabaseBase { return $this->mLastResult; } + function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) { + $this->rollback( __METHOD__ ); + $this->reOpen(); + parent::reportQueryError( $error, $errno, $sql, $fname, $tempIgnore ); + } + + function queryIgnore( $sql, $fname = 'DatabasePostgres::queryIgnore' ) { return $this->query( $sql, $fname, true ); } -- 2.20.1