X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabasePostgres.php;h=c6d5a1459f9fc8cd7265ce006cb91ac7c9d435e0;hb=b4e9b1ba621d77b580cfd5b19e927ccaec54831a;hp=8c21d726b0e737a2269b04349bdf8f86f22a4858;hpb=858d9cc5097c0e87992ff4b060ca1411fadedb5e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php index 8c21d726b0..c6d5a1459f 100644 --- a/includes/libs/rdbms/database/DatabasePostgres.php +++ b/includes/libs/rdbms/database/DatabasePostgres.php @@ -24,7 +24,7 @@ namespace Wikimedia\Rdbms; use Wikimedia\Timestamp\ConvertibleTimestamp; use Wikimedia\WaitConditionLoop; -use MediaWiki; +use Wikimedia; use Exception; /** @@ -97,10 +97,10 @@ class DatabasePostgres extends Database { ); } - $this->mServer = $server; - $this->mUser = $user; - $this->mPassword = $password; - $this->mDBname = $dbName; + $this->server = $server; + $this->user = $user; + $this->password = $password; + $this->dbName = $dbName; $connectVars = [ // pg_connect() user $user as the default database. Since a database is *required*, @@ -116,7 +116,7 @@ class DatabasePostgres extends Database { if ( (int)$this->port > 0 ) { $connectVars['port'] = (int)$this->port; } - if ( $this->mFlags & self::DBO_SSL ) { + if ( $this->flags & self::DBO_SSL ) { $connectVars['sslmode'] = 1; } @@ -126,7 +126,7 @@ class DatabasePostgres extends Database { try { // Use new connections to let LoadBalancer/LBFactory handle reuse - $this->mConn = pg_connect( $this->connectString, PGSQL_CONNECT_FORCE_NEW ); + $this->conn = pg_connect( $this->connectString, PGSQL_CONNECT_FORCE_NEW ); } catch ( Exception $ex ) { $this->restoreErrorHandler(); throw $ex; @@ -134,7 +134,7 @@ class DatabasePostgres extends Database { $phpError = $this->restoreErrorHandler(); - if ( !$this->mConn ) { + if ( !$this->conn ) { $this->queryLogger->debug( "DB connection error\n" . "Server: $server, Database: $dbName, User: $user, Password: " . @@ -144,7 +144,7 @@ class DatabasePostgres extends Database { throw new DBConnectionError( $this, str_replace( "\n", ' ', $phpError ) ); } - $this->mOpened = true; + $this->opened = true; # If called from the command-line (e.g. importDump), only show errors if ( $this->cliMode ) { @@ -159,11 +159,11 @@ class DatabasePostgres extends Database { $this->query( "SET bytea_output = 'escape'", __METHOD__ ); // PHP bug 53127 } - $this->determineCoreSchema( $this->mSchema ); + $this->determineCoreSchema( $this->schema ); // The schema to be used is now in the search path; no need for explicit qualification - $this->mSchema = ''; + $this->schema = ''; - return $this->mConn; + return $this->conn; } public function databasesAreIndependent() { @@ -178,8 +178,8 @@ class DatabasePostgres extends Database { * @throws DBUnexpectedError */ public function selectDB( $db ) { - if ( $this->mDBname !== $db ) { - return (bool)$this->open( $this->mServer, $this->mUser, $this->mPassword, $db ); + if ( $this->dbName !== $db ) { + return (bool)$this->open( $this->server, $this->user, $this->password, $db ); } else { return true; } @@ -199,7 +199,12 @@ class DatabasePostgres extends Database { } protected function closeConnection() { - return $this->mConn ? pg_close( $this->mConn ) : true; + return $this->conn ? pg_close( $this->conn ) : true; + } + + protected function isTransactableQuery( $sql ) { + return parent::isTransactableQuery( $sql ) && + !preg_match( '/^SELECT\s+pg_(try_|)advisory_\w+\(/', $sql ); } public function doQuery( $sql ) { @@ -253,7 +258,7 @@ class DatabasePostgres extends Database { } } /* Transaction stays in the ERROR state until rolled back */ - if ( $this->mTrxLevel ) { + if ( $this->trxLevel ) { // Throw away the transaction state, then raise the error as normal. // Note that if this connection is managed by LBFactory, it's already expected // that the other transactions LBFactory manages will be rolled back. @@ -266,9 +271,9 @@ class DatabasePostgres extends Database { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - MediaWiki\suppressWarnings(); + Wikimedia\suppressWarnings(); $ok = pg_free_result( $res ); - MediaWiki\restoreWarnings(); + Wikimedia\restoreWarnings(); if ( !$ok ) { throw new DBUnexpectedError( $this, "Unable to free Postgres result\n" ); } @@ -278,9 +283,9 @@ class DatabasePostgres extends Database { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - MediaWiki\suppressWarnings(); + Wikimedia\suppressWarnings(); $row = pg_fetch_object( $res ); - MediaWiki\restoreWarnings(); + Wikimedia\restoreWarnings(); # @todo FIXME: HACK HACK HACK HACK debug # @todo hashar: not sure if the following test really trigger if the object @@ -300,9 +305,9 @@ class DatabasePostgres extends Database { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - MediaWiki\suppressWarnings(); + Wikimedia\suppressWarnings(); $row = pg_fetch_array( $res ); - MediaWiki\restoreWarnings(); + Wikimedia\restoreWarnings(); $conn = $this->getBindingHandle(); if ( pg_last_error( $conn ) ) { @@ -319,9 +324,9 @@ class DatabasePostgres extends Database { if ( $res instanceof ResultWrapper ) { $res = $res->result; } - MediaWiki\suppressWarnings(); + Wikimedia\suppressWarnings(); $n = pg_num_rows( $res ); - MediaWiki\restoreWarnings(); + Wikimedia\restoreWarnings(); $conn = $this->getBindingHandle(); if ( pg_last_error( $conn ) ) { @@ -365,7 +370,7 @@ class DatabasePostgres extends Database { } public function lastError() { - if ( $this->mConn ) { + if ( $this->conn ) { if ( $this->mLastResult ) { return pg_result_error( $this->mLastResult ); } else { @@ -384,7 +389,7 @@ class DatabasePostgres extends Database { } } - public function affectedRows() { + protected function fetchAffectedRowCount() { if ( !is_null( $this->mAffectedRows ) ) { // Forced result for simulated queries return $this->mAffectedRows; @@ -1255,11 +1260,11 @@ SQL; } public function getDBname() { - return $this->mDBname; + return $this->dbName; } public function getServer() { - return $this->mServer; + return $this->server; } public function buildConcat( $stringList ) { @@ -1319,6 +1324,9 @@ SQL; } public function lockIsFree( $lockName, $method ) { + if ( !parent::lockIsFree( $lockName, $method ) ) { + return false; // already held + } // http://www.postgresql.org/docs/8.2/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS $key = $this->addQuotes( $this->bigintFromLockName( $lockName ) ); $result = $this->query( "SELECT (CASE(pg_try_advisory_lock($key))